-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
83 lines (68 loc) · 1.81 KB
/
types.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Zigbee protocol
package zigbee
import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
)
// looks like "0x842e14fffe6a5cda".
// yes, unfortunately with the "0x" prefix for now
type IEEEAddress string
func (i IEEEAddress) HexPrefixedString() string {
return string(i)
}
const (
CoordinatorNwkAddr = "0x0000" // https://www.eetimes.com/zigbee-applications-part-4-zigbee-addressing/
)
type LogicalType uint8
const (
LogicalTypeCoordinator LogicalType = 0
LogicalTypeRouter LogicalType = 1
LogicalTypeEndDevice LogicalType = 2
LogicalTypeUnknown LogicalType = 0xff
)
func (l LogicalType) String() string {
switch l {
case LogicalTypeCoordinator:
return "Coordinator"
case LogicalTypeRouter:
return "Router"
case LogicalTypeEndDevice:
return "EndDevice"
case LogicalTypeUnknown:
return "Unknown"
default:
panic(fmt.Errorf("unknown LogicalType: %d", l))
}
}
type NetworkKey [16]byte
type PANID uint16
type ExtendedPANID uint64
func (e ExtendedPANID) MarshalJSON() ([]byte, error) {
numBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(numBytes, uint64(e))
return json.Marshal(hex.EncodeToString(numBytes))
}
func (e *ExtendedPANID) UnmarshalJSON(b []byte) error {
numHex := ""
if err := json.Unmarshal(b, &numHex); err != nil {
return err
}
numBytes, err := hex.DecodeString(numHex)
if err != nil {
return err
}
*e = ExtendedPANID(binary.LittleEndian.Uint64(numBytes))
return nil
}
type EndpointId uint8
type ProfileID uint16
const (
ProfileIndustrialPlantMonitoring ProfileID = 0x0101
ProfileHomeAutomation ProfileID = 0x0104
ProfileCommercialBuildingAutomation ProfileID = 0x0105
ProfileTelecomApplications ProfileID = 0x0107
ProfilePersonalHomeAndHospitalCare ProfileID = 0x0108
ProfileAdvancedMeteringInitiative ProfileID = 0x0109
)