-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy patheirp.go
44 lines (40 loc) · 827 Bytes
/
eirp.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
package lorawan
import "errors"
var eirpTable = [...]float32{
8, // 0
10, // 1
12, // 2
13, // 3
14, // 4
16, // 5
18, // 6
20, // 7
21, // 8
24, // 9
26, // 10
27, // 11
29, // 12
30, // 13
33, // 14
36, // 15
}
// GetTXParamSetupEIRPIndex returns the coded value for the given EIRP (dBm).
// Note that it returns the coded value that is closest to the given EIRP,
// without exceeding it.
func GetTXParamSetupEIRPIndex(eirp float32) uint8 {
var out uint8
for i, e := range eirpTable {
if e > eirp {
return out
}
out = uint8(i)
}
return out
}
// GetTXParamsetupEIRP returns the EIRP (dBm) for the coded value.
func GetTXParamSetupEIRP(index uint8) (float32, error) {
if int(index) > len(eirpTable)-1 {
return 0, errors.New("lorawan: invalid eirp index")
}
return eirpTable[index], nil
}