-
Notifications
You must be signed in to change notification settings - Fork 8
/
node_bind.go
67 lines (53 loc) · 1.71 KB
/
node_bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package zstack
import (
"context"
"fmt"
"github.com/shimmeringbee/zigbee"
)
func (z *ZStack) BindNodeToController(ctx context.Context, nodeAddress zigbee.IEEEAddress, sourceEndpoint zigbee.Endpoint, destinationEndpoint zigbee.Endpoint, cluster zigbee.ClusterID) error {
networkAddress, err := z.ResolveNodeNWKAddress(ctx, nodeAddress)
if err != nil {
return nil
}
if err := z.sem.Acquire(ctx, 1); err != nil {
return fmt.Errorf("failed to acquire semaphore: %w", err)
}
defer z.sem.Release(1)
request := ZdoBindReq{
TargetAddress: networkAddress,
SourceAddress: nodeAddress,
SourceEndpoint: sourceEndpoint,
ClusterID: cluster,
DestinationAddressMode: 0x03, // IEEE Address (64 bits)
DestinationAddress: uint64(z.NetworkProperties.IEEEAddress),
DestinationEndpoint: destinationEndpoint,
}
_, err = z.nodeRequest(ctx, &request, &ZdoBindReqReply{}, &ZdoBindRsp{}, func(i interface{}) bool {
msg := i.(*ZdoBindRsp)
return msg.SourceAddress == networkAddress
})
return err
}
type ZdoBindReq struct {
TargetAddress zigbee.NetworkAddress
SourceAddress zigbee.IEEEAddress
SourceEndpoint zigbee.Endpoint
ClusterID zigbee.ClusterID
DestinationAddressMode uint8
DestinationAddress uint64
DestinationEndpoint zigbee.Endpoint
}
const ZdoBindReqID uint8 = 0x21
type ZdoBindReqReply GenericZStackStatus
func (r ZdoBindReqReply) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoBindReqReplyID uint8 = 0x21
type ZdoBindRsp struct {
SourceAddress zigbee.NetworkAddress
Status ZStackStatus
}
func (r ZdoBindRsp) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoBindRspID uint8 = 0xa1