forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rot.go
47 lines (39 loc) · 974 Bytes
/
rot.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 (
// TypeROT type for ROT sentences
TypeROT = "ROT"
ValidROT = "A"
InvalidROT = "V"
)
// 1 Rate of turn, degrees/minutes, “–” indicates bow turns to port
// 2 Satus:
// A: Valid data
// V: Invalid data
// ROT - Rate of turn
type ROT struct {
BaseSentence
RateOfTurn Float64 // Rate of turn
Status String
}
// newROT constructor
func newROT(s BaseSentence) (ROT, error) {
p := NewParser(s)
p.AssertType(TypeROT)
m := ROT{
BaseSentence: s,
RateOfTurn: p.Float64(0, "ROT"),
Status: p.EnumString(1, "status", ValidROT, InvalidROT),
}
return m, p.Err()
}
// GetRateOfTurn retrieves the rate of turn from the sentence
func (s ROT) GetRateOfTurn() (float64, error) {
if v, err := s.RateOfTurn.GetValue(); err == nil && s.Status.Value == ValidROT {
return (unit.Angle(v) * unit.Degree).Radians() / 60, nil
}
return 0, fmt.Errorf("value is unavailable")
}