/
signal_quality.go
73 lines (64 loc) · 1.13 KB
/
signal_quality.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
package parsing
import (
"strconv"
"strings"
)
type SignalQuality struct {
DBM DecibelMilliwatts
BER BitErrorRate
}
type SignalQualityString string
func (s SignalQualityString) Parsed() (sq SignalQuality, err error) {
signal := strings.Split(string(s), ",")
signalStrength, err := strconv.Atoi(signal[0])
if err != nil {
return
}
ber, err := strconv.Atoi(signal[1])
if err != nil {
return
}
sq.BER = BitErrorRate(ber)
if signalStrength != 99 {
sq.DBM = DecibelMilliwatts(-113 + signalStrength*2)
}
return
}
type DecibelMilliwatts int
func (dbm DecibelMilliwatts) Description() string {
if dbm >= -70 {
return "Excellent"
}
if dbm >= -85 {
return "Good"
}
if dbm >= -100 {
return "Fair"
}
if dbm > -110 {
return "Poor"
}
return "No Signal"
}
type BitErrorRate int
func (ber BitErrorRate) Description() string {
switch ber {
case 0:
return "less than 0.2%"
case 1:
return "0.2% to 0.4%"
case 2:
return "0.4% to 0.8%"
case 3:
return "0.8% to 1.6%"
case 4:
return "1.6% to 3.2%"
case 5:
return "3.2% to 6.4%"
case 6:
return "6.4% to 12.8%"
case 7:
return "more than 12.8%"
}
return "N/A"
}