forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdbt.go
53 lines (49 loc) · 1.16 KB
/
dbt.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
package nmea
const (
// TypeDBT type for DBT sentences
TypeDBT = "DBT"
)
// DBT depth below keel
// http://aprs.gids.nl/nmea/#DBT
type DBT struct {
BaseSentence
DepthFeet float64 // depth in feet
Feet string // unit 'f'
DepthMeters float64 // depth in meters
Meters string // unit 'M'
DepthFathom float64 // depth in fathom
Fathom string // unit 'F'
}
func (s DBT) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"depth_feed": s.DepthFeet,
"feet": s.Feet,
"depth_meters": s.DepthMeters,
"meters": s.Meters,
"depth_fathom": s.DepthFathom,
"fathom": s.Fathom,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newDBT constructor
func newDBT(s BaseSentence) (DBT, error) {
p := NewParser(s)
p.AssertType(TypeDBT)
m := DBT{
BaseSentence: s,
DepthFeet: p.Float64(0, "DepthFeet"),
Feet: p.String(1, "Feet"),
DepthMeters: p.Float64(2, "DepthMeters"),
Meters: p.String(3, "Meters"),
DepthFathom: p.Float64(4, "DepthFathom"),
Fathom: p.String(5, "Fathom"),
}
return m, p.Err()
}