uhppoted / uhppote-cli

Go CLI for the UHPPOTE UT0311 TCP/IP access controller boards
MIT License
8 stars 4 forks source link

`get-devices` crashes with `panic: Cannot unmarshal field with type 'types.Date'` #4

Closed uhppoted closed 3 years ago

uhppoted commented 3 years ago

CLI get-devices crashes with "panic: Cannot unmarshal field with type 'types.Date'"

...
Now I can run

uhppote-cli --debug get-devices 

... using default configuration from C:\ProgramData\uhppoted\uhppoted.conf
... request
...          00000000  17 94 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...
... sent 64 bytes to 192.168.1.255:60000
... received 64 bytes from 192.168.1.130:60000
...          00000000  17 94 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...
... received 64 bytes from 192.168.1.131:60000
...          00000000  17 94 00 00 e5 d8 4f 0d  c0 a8 01 8d ff ff ff 00  |......O.........|
...          00000010  c0 a8 01 01 00 66 0d 4f  d8 e5 08 98 20 19 05 21  |.....f.O.... ..!|
...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
...
panic: Cannot unmarshal field with type 'types.Date'
goroutine 19 [running]:
github.com/uhppoted/uhppote-core/encoding/UTO311-L0x.unmarshal(0xc000046000, 0x40, 0x800, 0x1127600, 0xc00012e090, 0x199, 0x97, 0x2)
        /usr/local/var/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.10/encoding/UTO311-L0x/UT0311-L0x.go:297 +0x14c5
github.com/uhppoted/uhppote-core/encoding/UTO311-L0x.UnmarshalArray(0xc0000420f0, 0x2, 0x2, 0x10e6580, 0xc000098b00, 0x2, 0x2)
        /usr/local/var/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.10/encoding/UTO311-L0x/UT0311-L0x.go:174 +0x290
github.com/uhppoted/uhppote-core/uhppote.(*UHPPOTE).Broadcast(0xc0000ed560, 0x110c4e0, 0xc0000a2c38, 0x10e6580, 0xc000098b00, 0x0, 0x0)
        /usr/local/var/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.10/uhppote/uhppote.go:148 +0xde
github.com/uhppoted/uhppote-core/uhppote.(*UHPPOTE).FindDevices(0xc0000ed560, 0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/var/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.10/uhppote/find.go:12 +0xcd
github.com/uhppoted/uhppote-cli/commands.(*GetDevices).Execute.func2(0xc0000a2c60, 0xc0000ed560, 0xc000110000, 0xc0000ed5c0)
        /uhppote/uhppoted/uhppote-cli/commands/get_devices.go:34 +0x86
created by github.com/uhppoted/uhppote-cli/commands.(*GetDevices).Execute
        /uhppote/uhppoted/uhppote-cli/commands/get_devices.go:32 +0x1ab
twystd commented 3 years ago

Root cause is that the CLI is receiving it's own UDP request because the CLI is bound to port 6000:

# SYSTEM
bind.address = 192.168.1.130:60000
broadcast.address = 192.168.1.255:60000
listen.address = 192.168.1.130:60001

However:

  1. It should report an error/warning rather than crash
  2. Binding to port 6000 should display an error or warning on startup.
twystd commented 3 years ago

Created project to track work items:

https://github.com/uhppoted/uhppoted/projects/5

twystd commented 3 years ago
  1. Validating bind, broadcast and listen address ports
  2. Discarding invalid replies
  3. Commonalised broadcast and broadcastTo implementations

Pushed to master - leaving this issue open pending release.

uhppoted commented 3 years ago

Fixed in release v0.6.12