-
Notifications
You must be signed in to change notification settings - Fork 8
/
node_endpoints.go
65 lines (50 loc) · 1.49 KB
/
node_endpoints.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
package zstack
import (
"context"
"fmt"
"github.com/shimmeringbee/zigbee"
)
func (z *ZStack) QueryNodeEndpoints(ctx context.Context, ieeeAddress zigbee.IEEEAddress) ([]zigbee.Endpoint, error) {
networkAddress, err := z.ResolveNodeNWKAddress(ctx, ieeeAddress)
if err != nil {
return []zigbee.Endpoint{}, err
}
if err := z.sem.Acquire(ctx, 1); err != nil {
return nil, fmt.Errorf("failed to acquire semaphore: %w", err)
}
defer z.sem.Release(1)
request := ZdoActiveEpReq{
DestinationAddress: networkAddress,
OfInterestAddress: networkAddress,
}
resp, err := z.nodeRequest(ctx, &request, &ZdoActiveEpReqReply{}, &ZdoActiveEpRsp{}, func(i interface{}) bool {
msg := i.(*ZdoActiveEpRsp)
return msg.OfInterestAddress == networkAddress
})
castResp, ok := resp.(*ZdoActiveEpRsp)
if ok {
return castResp.ActiveEndpoints, err
} else {
return nil, err
}
}
type ZdoActiveEpReq struct {
DestinationAddress zigbee.NetworkAddress
OfInterestAddress zigbee.NetworkAddress
}
const ZdoActiveEpReqID uint8 = 0x05
type ZdoActiveEpReqReply GenericZStackStatus
func (r ZdoActiveEpReqReply) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoActiveEpReqReplyID uint8 = 0x05
type ZdoActiveEpRsp struct {
SourceAddress zigbee.NetworkAddress
Status ZStackStatus
OfInterestAddress zigbee.NetworkAddress
ActiveEndpoints []zigbee.Endpoint `bcsliceprefix:"8"`
}
func (r ZdoActiveEpRsp) WasSuccessful() bool {
return r.Status == ZSuccess
}
const ZdoActiveEpRspID uint8 = 0x85