Skip to content

Commit

Permalink
Updated get-listenener to return auto-send interval (cf. #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 3, 2024
1 parent c26b4fb commit d27fd34
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased

### Added
1. Added _interval_ parameter to _set-listener_ to set auto-send interval.
1. Added auto-send _interval_ parameter to _get-listener_ and _set-listener_ API functions.


## [0.8.9](https://github.com/uhppoted/uhppote-core/releases/tag/v0.8.9) - 2024-09-06
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Sets the IPv4 address, subnet mask and gateway address for a controller.

#### `GetListener`

Retrieves the IPv4 address of the host configured to receive events from the controller.
Retrieves the IPv4 configured address:port to which events are sent from the controller, along with the auto-send interval.

#### `SetListener`

Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# TODO

- [x] set-event-listener: add listen interval (cf. https://github.com/uhppoted/uhppote-core/issues/21)
- [x] event listener: add listen auto-send interval (cf. https://github.com/uhppoted/uhppote-core/issues/21)
- [x] set-event-listener
- [x] get-event-listener
- [x] CHANGELOG
- [x] README

Expand Down
1 change: 1 addition & 0 deletions messages/get_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type GetListenerResponse struct {
MsgType types.MsgType `uhppote:"value:0x92"`
SerialNumber types.SerialNumber `uhppote:"offset:4"`
AddrPort netip.AddrPort `uhppote:"offset:8"`
Interval uint8 `uhppote:"offset:14"`
}
9 changes: 7 additions & 2 deletions messages/get_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestFactoryUnmarshalGetListenerRequest(t *testing.T) {

func TestUnmarshalGetListenerResponse(t *testing.T) {
message := []byte{
0x17, 0x92, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0xc0, 0xa8, 0x00, 0xe1, 0x92, 0x26, 0x00, 0x00,
0x17, 0x92, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0xc0, 0xa8, 0x00, 0xe1, 0x92, 0x26, 0x0d, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -83,11 +83,15 @@ func TestUnmarshalGetListenerResponse(t *testing.T) {
if reply.AddrPort != netip.MustParseAddrPort("192.168.0.225:9874") {
t.Errorf("Incorrect IPv4 address:port - expected:'%v', got:'%v'", netip.MustParseAddrPort("192.168.0.225:9874"), reply.AddrPort)
}

if reply.Interval != 13 {
t.Errorf("Incorrect auto-send interval - expected:%v, got:%v", 13, reply.Interval)
}
}

func TestFactoryUnmarshalGetListenerResponse(t *testing.T) {
message := []byte{
0x17, 0x92, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0xc0, 0xa8, 0x00, 0xe1, 0x92, 0x26, 0x00, 0x00,
0x17, 0x92, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0xc0, 0xa8, 0x00, 0xe1, 0x92, 0x26, 0x0d, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -97,6 +101,7 @@ func TestFactoryUnmarshalGetListenerResponse(t *testing.T) {
MsgType: 0x92,
SerialNumber: 423187757,
AddrPort: netip.MustParseAddrPort("192.168.0.225:9874"),
Interval: 13,
}

response, err := UnmarshalResponse(message)
Expand Down
12 changes: 8 additions & 4 deletions uhppote/get_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import (
"github.com/uhppoted/uhppote-core/types"
)

func (u *uhppote) GetListener(serialNumber uint32) (netip.AddrPort, error) {
// Retrieves the configured events listener address:port and auto-send interval from
// the controller.
//
// Returns an error if something the controller did not respohd.
func (u *uhppote) GetListener(serialNumber uint32) (netip.AddrPort, uint8, error) {
if serialNumber == 0 {
return netip.AddrPort{}, fmt.Errorf("invalid device ID (%v)", serialNumber)
return netip.AddrPort{}, 0, fmt.Errorf("invalid device ID (%v)", serialNumber)
}

request := messages.GetListenerRequest{
SerialNumber: types.SerialNumber(serialNumber),
}

if reply, err := sendto[messages.GetListenerResponse](u, serialNumber, request); err != nil {
return netip.AddrPort{}, err
return netip.AddrPort{}, 0, err
} else {
return reply.AddrPort, nil
return reply.AddrPort, reply.Interval, nil
}
}
2 changes: 1 addition & 1 deletion uhppote/get_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func TestGetListenerWithInvalidDeviceID(t *testing.T) {
u := uhppote{}

_, err := u.GetListener(0)
_, _, err := u.GetListener(0)
if err == nil {
t.Fatalf("Expected 'Invalid device ID' error, got %v", err)
}
Expand Down
7 changes: 6 additions & 1 deletion uhppote/iuhppote.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ type IUHPPOTE interface {
GetDevice(deviceID uint32) (*types.Device, error)

SetAddress(deviceID uint32, address, mask, gateway net.IP) (*types.Result, error)
GetListener(deviceID uint32) (netip.AddrPort, error)

// Retrieves the configured events listener address:port and auto-send interval from
// the controller.
//
// Returns an error if something the controller did not respohd.
GetListener(deviceID uint32) (netip.AddrPort, uint8, error)

// Sets the controller event listener address:port and auto-send interval.
//
Expand Down

0 comments on commit d27fd34

Please sign in to comment.