-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode_remove.go
67 lines (51 loc) · 1.49 KB
/
node_remove.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) RequestNodeLeave(ctx context.Context, nodeAddress zigbee.IEEEAddress) 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 := ZdoMgmtLeaveReq{
NetworkAddress: networkAddress,
IEEEAddress: nodeAddress,
RemoveChildren: false,
}
_, err = z.nodeRequest(ctx, &request, &ZdoMgmtLeaveReqReply{}, &ZdoMgmtLeaveRsp{}, func(i interface{}) bool {
msg := i.(*ZdoMgmtLeaveRsp)
return msg.SourceAddress == networkAddress
})
return err
}
func (z *ZStack) ForceNodeLeave(ctx context.Context, nodeAddress zigbee.IEEEAddress) error {
if z.removeNode(nodeAddress) {
return nil
}
return fmt.Errorf("no node with address provided could be found: %v", nodeAddress)
}
type ZdoMgmtLeaveReq struct {
NetworkAddress zigbee.NetworkAddress
IEEEAddress zigbee.IEEEAddress
RemoveChildren bool
}
const ZdoMgmtLeaveReqID uint8 = 0x34
type ZdoMgmtLeaveReqReply GenericZStackStatus
func (r ZdoMgmtLeaveReqReply) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoMgmtLeaveReqReplyID uint8 = 0x34
type ZdoMgmtLeaveRsp struct {
SourceAddress zigbee.NetworkAddress
Status ZStackStatus
}
func (r ZdoMgmtLeaveRsp) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoMgmtLeaveRspID uint8 = 0xb4