-
Notifications
You must be signed in to change notification settings - Fork 0
/
txparamsetup.go
89 lines (69 loc) · 1.63 KB
/
txparamsetup.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
84
85
86
87
88
89
package txparamsetup
import (
"fmt"
"github.com/tkiraly/lorawan/commands"
)
const Reqlen = 2
type TxParamSetupReq interface {
commands.Fopter
DownlinkDwellTime() uint8
UplinkDwellTime() uint8
MaxEIRP() uint8
}
type txParamSetupReq []byte
func (c txParamSetupReq) ByteArray() []byte {
return c
}
func (c txParamSetupReq) Len() uint8 {
return Reqlen
}
func (c txParamSetupReq) String() string {
return fmt.Sprintf("%s! DownlinkDwellTime: %d, UplinkDwellTime: %d, MaxEIRP: %d;",
"TxParamSetupReq",
c.DownlinkDwellTime(),
c.UplinkDwellTime(),
c.MaxEIRP())
}
func ParseReq(bb []byte) commands.Fopter {
b := make([]byte, len(bb))
copy(b, bb)
return txParamSetupReq(b)
}
func NewReq(downlinkdwelltime, uplinkdwelltime, maxeirp uint8) TxParamSetupReq {
return txParamSetupReq([]byte{commands.TxParamSetupReqCommand,
(downlinkdwelltime << 5) |
(uplinkdwelltime << 4) |
maxeirp,
})
}
func (c txParamSetupReq) DownlinkDwellTime() uint8 {
return (c[1] >> 5) & 0x01
}
func (c txParamSetupReq) UplinkDwellTime() uint8 {
return (c[1] >> 4) & 0x01
}
func (c txParamSetupReq) MaxEIRP() uint8 {
return c[1] & 0x0f
}
const Anslen = 1
type TxParamSetupAns interface {
commands.Fopter
}
type txParamSetupAns []byte
func (c txParamSetupAns) ByteArray() []byte {
return c
}
func (c txParamSetupAns) Len() uint8 {
return Anslen
}
func (c txParamSetupAns) String() string {
return fmt.Sprintf("%s!", "TxParamSetupAns")
}
func ParseAns(bb []byte) commands.Fopter {
b := make([]byte, len(bb))
copy(b, bb)
return txParamSetupAns(b)
}
func NewAns() TxParamSetupAns {
return txParamSetupAns([]byte{commands.TxParamSetupAnsCommand})
}