forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgns.go
82 lines (78 loc) · 1.96 KB
/
gns.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
package nmea
const (
// TypeGNS type for GNS sentences
TypeGNS = "GNS"
// NoFixGNS Character
NoFixGNS = "N"
// AutonomousGNS Character
AutonomousGNS = "A"
// DifferentialGNS Character
DifferentialGNS = "D"
// PreciseGNS Character
PreciseGNS = "P"
// RealTimeKinematicGNS Character
RealTimeKinematicGNS = "R"
// FloatRTKGNS RealTime Kinematic Character
FloatRTKGNS = "F"
// EstimatedGNS Fix Character
EstimatedGNS = "E"
// ManualGNS Fix Character
ManualGNS = "M"
// SimulatorGNS Character
SimulatorGNS = "S"
)
// GNS is standard GNSS sentance that combined multiple constellations
type GNS struct {
BaseSentence
Time Time
Latitude float64
Longitude float64
Mode []string
SVs int64
HDOP float64
Altitude float64
Separation float64
Age float64
Station int64
}
func (s GNS) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"time": s.Time.String(),
"latitude": s.Latitude,
"longitude": s.Longitude,
"mode": s.Mode,
"svs": s.SVs,
"hdop": s.HDOP,
"altitude": s.Altitude,
"separation": s.Separation,
"age": s.Age,
"station": s.Station,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newGNS Constructor
func newGNS(s BaseSentence) (GNS, error) {
p := NewParser(s)
p.AssertType(TypeGNS)
m := GNS{
BaseSentence: s,
Time: p.Time(0, "time"),
Latitude: p.LatLong(1, 2, "latitude"),
Longitude: p.LatLong(3, 4, "longitude"),
Mode: p.EnumChars(5, "mode", NoFixGNS, AutonomousGNS, DifferentialGNS, PreciseGNS, RealTimeKinematicGNS, FloatRTKGNS, EstimatedGNS, ManualGNS, SimulatorGNS),
SVs: p.Int64(6, "SVs"),
HDOP: p.Float64(7, "HDOP"),
Altitude: p.Float64(8, "altitude"),
Separation: p.Float64(9, "separation"),
Age: p.Float64(10, "age"),
Station: p.Int64(11, "station"),
}
return m, p.Err()
}