Skip to content

Commit

Permalink
Migrate ZdoEndDeviceAnnceInd capabilities bitfield to structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Feb 16, 2020
1 parent bca63fa commit 9d1aa35
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
18 changes: 14 additions & 4 deletions device_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ 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"`
}

type ZdoEndDeviceAnnceInd struct {
SourceAddress zigbee.NetworkAddress
NetworkAddress zigbee.NetworkAddress
IEEEAddress zigbee.IEEEAddress
Capabilities uint8
Capabilities ZdoEndDeviceAnnceIndCapabilities
}

const ZdoEndDeviceAnnceIndID uint8 = 0xc1

type ZdoLeaveInd struct {
SourceAddress zigbee.NetworkAddress
IEEEAddress zigbee.IEEEAddress
Request uint8
Remove uint8
Rejoin uint8
Request bool
Remove bool
Rejoin bool
}

const ZdoLeaveIndID uint8 = 0xc9
Expand Down
2 changes: 1 addition & 1 deletion network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (z *ZStack) networkManager() {
case ZdoEndDeviceAnnceInd:
logicalType := zigbee.EndDevice

if e.Capabilities&0x02 == 0x02 {
if e.Capabilities.Router {
logicalType = zigbee.Router
}

Expand Down
20 changes: 18 additions & 2 deletions network_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ func Test_NetworkManager(t *testing.T) {
SourceAddress: zigbee.NetworkAddress(0x1000),
NetworkAddress: zigbee.NetworkAddress(0x2000),
IEEEAddress: zigbee.IEEEAddress(0x0102030405060708),
Capabilities: 0b00000010,
Capabilities: ZdoEndDeviceAnnceIndCapabilities{
AltPANController: false,
Router: true,
PowerSource: false,
ReceiveOnIdle: false,
Reserved: false,
SecurityCapability: false,
AddressAllocated: false,
},
}

data, _ := bytecodec.Marshal(announce)
Expand Down Expand Up @@ -268,7 +276,15 @@ func Test_NetworkManager(t *testing.T) {
SourceAddress: zigbee.NetworkAddress(0x1000),
NetworkAddress: zigbee.NetworkAddress(0x2000),
IEEEAddress: zigbee.IEEEAddress(0x0102030405060708),
Capabilities: 0b00000010,
Capabilities: ZdoEndDeviceAnnceIndCapabilities{
AltPANController: false,
Router: true,
PowerSource: false,
ReceiveOnIdle: false,
Reserved: false,
SecurityCapability: false,
AddressAllocated: false,
},
}

data, _ := bytecodec.Marshal(announce)
Expand Down

0 comments on commit 9d1aa35

Please sign in to comment.