From e6e2ef7e1dcc889c0bb076498d30a687fe23fa01 Mon Sep 17 00:00:00 2001 From: Tony Seebregts Date: Mon, 4 Jan 2021 14:30:20 -0800 Subject: [PATCH] Fixed simulator events for v6.62 firmware patch (cf. https://github.com/uhppoted/node-red-contrib-uhppoted/issues/3) --- Makefile | 15 +++++++++++++++ commands/run.go | 16 ++++++++-------- simulator/UT0311L04/UTC0311L04.go | 4 ++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1104d9a..fee8c70 100644 --- a/Makefile +++ b/Makefile @@ -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}" + + diff --git a/commands/run.go b/commands/run.go index e31bae8..1995b30 100644 --- a/commands/run.go +++ b/commands/run.go @@ -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) @@ -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 diff --git a/simulator/UT0311L04/UTC0311L04.go b/simulator/UT0311L04/UTC0311L04.go index c12be32..6e1a95a 100644 --- a/simulator/UT0311L04/UTC0311L04.go +++ b/simulator/UT0311L04/UTC0311L04.go @@ -19,7 +19,7 @@ import ( "github.com/uhppoted/uhppote-simulator/entities" ) -type event messages.GetStatusResponse +type Event messages.GetStatusResponse type UT0311L04 struct { file string @@ -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,