Skip to content

Commit

Permalink
Migrate ZdoMGMTLQINeighbour status bitfield to structure, fix orderin…
Browse files Browse the repository at this point in the history
…g of ZdoEndDeviceAnnceIndCapabilities.
  • Loading branch information
pwood committed Feb 16, 2020
1 parent 9d1aa35 commit d2fc0e0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
12 changes: 6 additions & 6 deletions device_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 23 additions & 8 deletions network_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Test_NetworkManager(t *testing.T) {
Router: true,
PowerSource: false,
ReceiveOnIdle: false,
Reserved: false,
Reserved: 0,
SecurityCapability: false,
AddressAllocated: false,
},
Expand Down Expand Up @@ -281,7 +281,7 @@ func Test_NetworkManager(t *testing.T) {
Router: true,
PowerSource: false,
ReceiveOnIdle: false,
Reserved: false,
Reserved: 0,
SecurityCapability: false,
AddressAllocated: false,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit d2fc0e0

Please sign in to comment.