forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ths.go
50 lines (44 loc) · 1.25 KB
/
ths.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
import (
"fmt"
"github.com/martinlindhe/unit"
)
const (
// TypeTHS type for THS sentences
TypeTHS = "THS"
// AutonomousTHS autonomous ths heading
AutonomousTHS = "A"
// EstimatedTHS estimated (dead reckoning) THS heading
EstimatedTHS = "E"
// ManualTHS manual input THS heading
ManualTHS = "M"
// SimulatorTHS simulated THS heading
SimulatorTHS = "S"
// InvalidTHS not valid THS heading (or standby)
InvalidTHS = "V"
)
// THS is the Actual vessel heading in degrees True with status.
// http://www.nuovamarea.net/pytheas_9.html
type THS struct {
BaseSentence
Heading Float64 // Heading in degrees
Status String // Heading status
}
// newTHS constructor
func newTHS(s BaseSentence) (THS, error) {
p := NewParser(s)
p.AssertType(TypeTHS)
m := THS{
BaseSentence: s,
Heading: p.Float64(0, "heading"),
Status: p.EnumString(1, "status", AutonomousTHS, EstimatedTHS, ManualTHS, SimulatorTHS, InvalidTHS),
}
return m, p.Err()
}
// GetTrueHeading retrieves the true heading from the sentence
func (s THS) GetTrueHeading() (float64, error) {
if v, err := s.Heading.GetValue(); err == nil && s.Status.Value != InvalidTHS {
return (unit.Angle(v) * unit.Degree).Radians(), nil
}
return 0, fmt.Errorf("value is unavailable")
}