-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathadapter_info.go
53 lines (40 loc) · 1.32 KB
/
adapter_info.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
package zstack
import (
"context"
"fmt"
"github.com/shimmeringbee/zigbee"
)
func (z *ZStack) AdapterNode() zigbee.Node {
return zigbee.Node{
IEEEAddress: z.NetworkProperties.IEEEAddress,
NetworkAddress: z.NetworkProperties.NetworkAddress,
LogicalType: zigbee.Coordinator,
}
}
func (z *ZStack) GetAdapterIEEEAddress(ctx context.Context) (zigbee.IEEEAddress, error) {
data, err := z.getAddressInfo(ctx)
ieeeAddress := data.IEEEAddress
return ieeeAddress, err
}
func (z *ZStack) GetAdapterNetworkAddress(ctx context.Context) (zigbee.NetworkAddress, error) {
data, err := z.getAddressInfo(ctx)
networkAddress := data.NetworkAddress
return networkAddress, err
}
func (z *ZStack) getAddressInfo(ctx context.Context) (UtilGetDeviceInfoRequestReply, error) {
resp := UtilGetDeviceInfoRequestReply{}
if err := z.sem.Acquire(ctx, 1); err != nil {
return resp, fmt.Errorf("failed to acquire semaphore: %w", err)
}
defer z.sem.Release(1)
err := z.requestResponder.RequestResponse(ctx, UtilGetDeviceInfoRequest{}, &resp)
return resp, err
}
type UtilGetDeviceInfoRequest struct{}
const UtilGetDeviceInfoRequestID uint8 = 0x00
type UtilGetDeviceInfoRequestReply struct {
Status uint8
IEEEAddress zigbee.IEEEAddress
NetworkAddress zigbee.NetworkAddress
}
const UtilGetDeviceInfoRequestReplyID uint8 = 0x00