Skip to content

Commit

Permalink
Fixed simulator events for v6.62 firmware patch (cf. uhppoted/node-re…
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Jan 4, 2021
1 parent 9e7415b commit e6e2ef7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@ close:

button:
curl -X POST "http://127.0.0.1:8000/uhppote/simulator/$(SERIALNO)/door/$(DOOR)" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"action\":\"button\", \"duration\":10}"

# v06.62 events
v6.62-swipe:
curl -X POST "http://127.0.0.1:8000/uhppote/simulator/662/swipe" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"door\":$(DOOR),\"card-number\":$(CARD)}"

v6.62-open:
curl -X POST "http://127.0.0.1:8000/uhppote/simulator/662/door/1" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"action\":\"open\",\"duration\":10}"

v6.62-close:
curl -X POST "http://127.0.0.1:8000/uhppote/simulator/662/door/1" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"action\":\"close\"}"

v6.62-button:
curl -X POST "http://127.0.0.1:8000/uhppote/simulator/662/door/1" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"action\":\"button\", \"duration\":10}"


16 changes: 8 additions & 8 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"encoding/hex"
"errors"
"fmt"
codec "github.com/uhppoted/uhppote-core/encoding/UTO311-L0x"
"github.com/uhppoted/uhppote-core/messages"
"github.com/uhppoted/uhppote-simulator/rest"
"github.com/uhppoted/uhppote-simulator/simulator"
"net"
"os"
"os/signal"
"regexp"
"strings"

codec "github.com/uhppoted/uhppote-core/encoding/UTO311-L0x"
"github.com/uhppoted/uhppote-core/messages"
"github.com/uhppoted/uhppote-simulator/rest"
"github.com/uhppoted/uhppote-simulator/simulator"
"github.com/uhppoted/uhppote-simulator/simulator/UT0311L04"
)

var debug bool = false

type event messages.GetStatusResponse

func Simulate(ctx *simulator.Context, dbg bool) {
debug = dbg
bind, err := net.ResolveUDPAddr("udp4", ctx.BindAddress)
Expand Down Expand Up @@ -122,11 +122,11 @@ func send(c *net.UDPConn, dest *net.UDPAddr, message interface{}) {
return
}

// Ancient and decrepit boards apparently send 0x19 as the event message type
// Firmware v6.62 and earlier apparently send 0x19 as the event message type.
// Identify (for simulation purposes only) these boards as having a serial number
// that starts with '0'. This assumes the convention that one door controllers have
// a serial number starting with 1, two door controllers start with 2, etc.
if event, ok := message.(*event); ok {
if event, ok := message.(*UT0311L04.Event); ok {
deviceID := fmt.Sprintf("%09d", event.SerialNumber)
if strings.HasPrefix(deviceID, "0") {
msg[0] = 0x19
Expand Down
4 changes: 2 additions & 2 deletions simulator/UT0311L04/UTC0311L04.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/uhppoted/uhppote-simulator/entities"
)

type event messages.GetStatusResponse
type Event messages.GetStatusResponse

type UT0311L04 struct {
file string
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *UT0311L04) add(e *entities.Event) uint32 {
utc := time.Now().UTC()
datetime := utc.Add(time.Duration(s.TimeOffset))

e := event{
e := Event{
SerialNumber: s.SerialNumber,
EventIndex: s.Events.Last,
SystemError: s.SystemError,
Expand Down

0 comments on commit e6e2ef7

Please sign in to comment.