forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhdg.go
50 lines (46 loc) · 1.16 KB
/
hdg.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
package nmea
const (
// TypeHDG type for HDG sentences
TypeHDG = "HDG"
)
// HDG is the Actual vessel heading in degrees True.
// http://aprs.gids.nl/nmea/#hdt
type HDG struct {
BaseSentence
Heading float64
Deviation float64
DeviationDirection string
Variation float64
VariationDirection string
}
func (s HDG) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"heading": s.Heading,
"deviation": s.Deviation,
"deviation_direction": s.DeviationDirection,
"variation": s.Variation,
"variation_direction": s.VariationDirection,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newHDG constructor
func newHDG(s BaseSentence) (HDG, error) {
p := NewParser(s)
p.AssertType(TypeHDG)
m := HDG{
BaseSentence: s,
Heading: p.Float64(0, "Heading"),
Deviation: p.Float64(1, "Deviation"),
DeviationDirection: p.String(2, "DeviationDirection"),
Variation: p.Float64(3, "Variation"),
VariationDirection: p.String(4, "VariationDirection"),
}
return m, p.Err()
}