-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpacket.go
47 lines (42 loc) · 1.05 KB
/
packet.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
package zcl
import "fmt"
func NewPacket(srcEp uint8, dstAddr Address, dstEp uint8, profile ProfileID, cluster ClusterID, data ...InArg) (p Packet, err error) {
var rawData []byte
for _, v := range data {
if rawData, err = v.MarshalZcl(); err != nil {
return
}
}
return &packet{
srcEp: srcEp,
dstAddr: dstAddr,
dstEp: dstEp,
profile: profile,
cluster: cluster,
data: rawData,
}, nil
}
type packet struct {
srcEp uint8
dstAddr Address
dstEp uint8
profile ProfileID
cluster ClusterID
data []byte
}
func (p packet) SrcEP() uint8 { return p.srcEp }
func (p packet) DstEP() uint8 { return p.dstEp }
func (p packet) DstAddr() Address { return p.dstAddr }
func (p packet) Profile() ProfileID { return p.profile }
func (p packet) Cluster() ClusterID { return p.cluster }
func (p packet) Data() []byte { return p.data }
func (p packet) String() string {
return fmt.Sprintf("[*/%d->%s/%d] P[%04X] C[%04X] Sz[%d]",
p.SrcEP(),
p.DstAddr(),
p.DstEP(),
uint16(p.Profile()),
uint16(p.Cluster()),
len(p.data),
)
}