From d2fc0e01547d4feddc83a3ce316ed013bfa5737e Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Sun, 16 Feb 2020 13:09:23 +0000 Subject: [PATCH] Migrate ZdoMGMTLQINeighbour status bitfield to structure, fix ordering of ZdoEndDeviceAnnceIndCapabilities. --- device_state.go | 12 ++++++------ network_manager.go | 18 +++++++++++------- network_manager_test.go | 31 +++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/device_state.go b/device_state.go index 3e13d57..ecd8872 100644 --- a/device_state.go +++ b/device_state.go @@ -3,13 +3,13 @@ package zstack import "github.com/shimmeringbee/zigbee" type ZdoEndDeviceAnnceIndCapabilities struct { - AltPANController bool `bcfieldwidth:"1"` - Router bool `bcfieldwidth:"1"` - PowerSource bool `bcfieldwidth:"1"` - ReceiveOnIdle bool `bcfieldwidth:"1"` - Reserved uint8 `bcfieldwidth:"2"` - SecurityCapability bool `bcfieldwidth:"1"` AddressAllocated bool `bcfieldwidth:"1"` + SecurityCapability bool `bcfieldwidth:"1"` + Reserved uint8 `bcfieldwidth:"2"` + ReceiveOnIdle bool `bcfieldwidth:"1"` + PowerSource bool `bcfieldwidth:"1"` + Router bool `bcfieldwidth:"1"` + AltPANController bool `bcfieldwidth:"1"` } type ZdoEndDeviceAnnceInd struct { diff --git a/network_manager.go b/network_manager.go index d5257d3..1b4965c 100644 --- a/network_manager.go +++ b/network_manager.go @@ -136,12 +136,9 @@ func (z *ZStack) processLQITable(lqi ZdoMGMTLQIRsp) { continue } - logicalType := zigbee.LogicalType(neighbour.Status & 0x03) - relationship := zigbee.Relationship((neighbour.Status >> 4) & 0x07) + z.nodeTable.AddOrUpdate(neighbour.IEEEAddress, neighbour.NetworkAddress, LogicalType(neighbour.Status.DeviceType), UpdateDiscovered) - z.nodeTable.AddOrUpdate(neighbour.IEEEAddress, neighbour.NetworkAddress, LogicalType(logicalType), UpdateDiscovered) - - if relationship == zigbee.RelationshipChild { + if neighbour.Status.Relationship == zigbee.RelationshipChild { z.nodeTable.Update(neighbour.IEEEAddress, LQI(neighbour.LQI), Depth(neighbour.Depth)) } } @@ -189,12 +186,19 @@ type ZdoMGMTLQIReqReply GenericZStackStatus const ZdoMGMTLQIReqReplyID uint8 = 0x31 +type ZdoMGMTLQINeighbourStatus struct { + Reserved uint8 `bcfieldwidth:"1"` + Relationship zigbee.Relationship `bcfieldwidth:"3"` + RxOnWhenIdle uint8 `bcfieldwidth:"2"` + DeviceType zigbee.LogicalType `bcfieldwidth:"2"` +} + type ZdoMGMTLQINeighbour struct { ExtendedPANID zigbee.ExtendedPANID IEEEAddress zigbee.IEEEAddress NetworkAddress zigbee.NetworkAddress - Status uint8 - PermitJoining uint8 + Status ZdoMGMTLQINeighbourStatus + PermitJoining bool Depth uint8 LQI uint8 } diff --git a/network_manager_test.go b/network_manager_test.go index 0c04db0..a95c830 100644 --- a/network_manager_test.go +++ b/network_manager_test.go @@ -167,7 +167,7 @@ func Test_NetworkManager(t *testing.T) { Router: true, PowerSource: false, ReceiveOnIdle: false, - Reserved: false, + Reserved: 0, SecurityCapability: false, AddressAllocated: false, }, @@ -281,7 +281,7 @@ func Test_NetworkManager(t *testing.T) { Router: true, PowerSource: false, ReceiveOnIdle: false, - Reserved: false, + Reserved: 0, SecurityCapability: false, AddressAllocated: false, }, @@ -336,8 +336,13 @@ func Test_NetworkManager(t *testing.T) { ExtendedPANID: zstack.NetworkProperties.ExtendedPANID, IEEEAddress: zigbee.IEEEAddress(0x1000), NetworkAddress: zigbee.NetworkAddress(0x2000), - Status: 0b00010001, - PermitJoining: 0, + Status: ZdoMGMTLQINeighbourStatus{ + Reserved: 0, + Relationship: zigbee.RelationshipChild, + RxOnWhenIdle: 0, + DeviceType: zigbee.Router, + }, + PermitJoining: false, Depth: 1, LQI: 67, }, @@ -392,8 +397,13 @@ func Test_NetworkManager(t *testing.T) { ExtendedPANID: 0xfffffff, IEEEAddress: zigbee.IEEEAddress(0x2000), NetworkAddress: zigbee.NetworkAddress(0x4000), - Status: 0b00000001, - PermitJoining: 0, + Status: ZdoMGMTLQINeighbourStatus{ + Reserved: 0, + Relationship: zigbee.RelationshipParent, + RxOnWhenIdle: 0, + DeviceType: zigbee.Router, + }, + PermitJoining: false, Depth: 0, LQI: 67, }, @@ -445,8 +455,13 @@ func Test_NetworkManager(t *testing.T) { ExtendedPANID: zstack.NetworkProperties.ExtendedPANID, IEEEAddress: zigbee.IEEEAddress(0), NetworkAddress: zigbee.NetworkAddress(0x4000), - Status: 0b00000001, - PermitJoining: 0, + Status: ZdoMGMTLQINeighbourStatus{ + Reserved: 0, + Relationship: zigbee.RelationshipParent, + RxOnWhenIdle: 0, + DeviceType: zigbee.Router, + }, + PermitJoining: false, Depth: 0, LQI: 67, },