forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgsa.go
69 lines (65 loc) · 1.62 KB
/
gsa.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
package nmea
const (
// TypeGSA type for GSA sentences
TypeGSA = "GSA"
// Auto - Field 1, auto or manual fix.
Auto = "A"
// Manual - Field 1, auto or manual fix.
Manual = "M"
// FixNone - Field 2, fix type.
FixNone = "1"
// Fix2D - Field 2, fix type.
Fix2D = "2"
// Fix3D - Field 2, fix type.
Fix3D = "3"
)
// GSA represents overview satellite data.
// http://aprs.gids.nl/nmea/#gsa
type GSA struct {
BaseSentence
Mode string // The selection mode.
FixType string // The fix type.
SV []string // List of satellite PRNs used for this fix.
PDOP float64 // Dilution of precision.
HDOP float64 // Horizontal dilution of precision.
VDOP float64 // Vertical dilution of precision.
}
func (s GSA) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"mode": s.Mode,
"fix_type": s.FixType,
"sv": s.SV,
"pdop": s.PDOP,
"hdop": s.HDOP,
"vdop": s.VDOP,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newGSA parses the GSA sentence into this struct.
func newGSA(s BaseSentence) (GSA, error) {
p := NewParser(s)
p.AssertType(TypeGSA)
m := GSA{
BaseSentence: s,
Mode: p.EnumString(0, "selection mode", Auto, Manual),
FixType: p.EnumString(1, "fix type", FixNone, Fix2D, Fix3D),
}
// Satellites in view.
for i := 2; i < 14; i++ {
if v := p.String(i, "satellite in view"); v != "" {
m.SV = append(m.SV, v)
}
}
// Dilution of precision.
m.PDOP = p.Float64(14, "pdop")
m.HDOP = p.Float64(15, "hdop")
m.VDOP = p.Float64(16, "vdop")
return m, p.Err()
}