forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbt.go
47 lines (41 loc) · 1.08 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
package nmea
import (
"fmt"
"github.com/martinlindhe/unit"
)
const (
// TypeDBT type for DBT sentences
TypeDBT = "DBT"
)
// DBT - Depth below transducer
// https://gpsd.gitlab.io/gpsd/NMEA.html#_dbt_depth_below_transducer
type DBT struct {
BaseSentence
DepthFeet Float64
DepthMeters Float64
DepthFathoms Float64
}
// newDBT constructor
func newDBT(s BaseSentence) (DBT, error) {
p := NewParser(s)
p.AssertType(TypeDBT)
return DBT{
BaseSentence: s,
DepthFeet: p.Float64(0, "depth_feet"),
DepthMeters: p.Float64(2, "depth_meters"),
DepthFathoms: p.Float64(4, "depth_fathoms"),
}, p.Err()
}
// GetDepthBelowTransducer retrieves the depth below the transducer from the sentence
func (s DBT) GetDepthBelowTransducer() (float64, error) {
if v, err := s.DepthMeters.GetValue(); err == nil {
return v, nil
}
if v, err := s.DepthFeet.GetValue(); err == nil {
return (unit.Length(v) * unit.Foot).Meters(), nil
}
if v, err := s.DepthFathoms.GetValue(); err == nil {
return (unit.Length(v) * unit.Fathom).Meters(), nil
}
return 0, fmt.Errorf("value is unavailable")
}