-
Notifications
You must be signed in to change notification settings - Fork 8
/
node_unbind.go
67 lines (53 loc) · 1.71 KB
/
node_unbind.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) UnbindNodeFromController(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 := ZdoUnbindReq{
TargetAddress: networkAddress,
SourceAddress: nodeAddress,
SourceEndpoint: sourceEndpoint,
ClusterID: cluster,
DestinationAddressMode: 0x02, // Network Address (16 bits)
DestinationAddress: uint64(0),
DestinationEndpoint: destinationEndpoint,
}
_, err = z.nodeRequest(ctx, &request, &ZdoUnbindReqReply{}, &ZdoUnbindRsp{}, func(i interface{}) bool {
msg := i.(*ZdoUnbindRsp)
return msg.SourceAddress == networkAddress
})
return err
}
type ZdoUnbindReq struct {
TargetAddress zigbee.NetworkAddress
SourceAddress zigbee.IEEEAddress
SourceEndpoint zigbee.Endpoint
ClusterID zigbee.ClusterID
DestinationAddressMode uint8
DestinationAddress uint64
DestinationEndpoint zigbee.Endpoint
}
const ZdoUnbindReqID uint8 = 0x22
type ZdoUnbindReqReply GenericZStackStatus
func (r ZdoUnbindReqReply) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoUnbindReqReplyID uint8 = 0x22
type ZdoUnbindRsp struct {
SourceAddress zigbee.NetworkAddress
Status ZStackStatus
}
func (r ZdoUnbindRsp) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoUnbindRspID uint8 = 0xa2