-
Notifications
You must be signed in to change notification settings - Fork 78
/
mwd.go
67 lines (60 loc) · 2.07 KB
/
mwd.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package nmea
/**
$WIMWD
NMEA 0183 standard Wind Direction and Speed, with respect to north.
Syntax
$WIMWD,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>*hh<CR><LF>
Fields
<1> Wind direction, 0.0 to 359.9 degrees True, to the nearest 0.1 degree
<2> T = True
<3> Wind direction, 0.0 to 359.9 degrees Magnetic, to the nearest 0.1 degree
<4> M = Magnetic
<5> Wind speed, knots, to the nearest 0.1 knot.
<6> N = Knots
<7> Wind speed, meters/second, to the nearest 0.1 m/s.
<8> M = Meters/second
*/
const (
// TypeMWD type for MWD sentences
TypeMWD = "MWD"
// TrueMWD for valid True Direction
TrueMWD = "T"
// MagneticMWD for valid Magnetic direction
MagneticMWD = "M"
// KnotsMWD for valid Knots
KnotsMWD = "N"
// MetersSecondMWD for valid Meters per Second
MetersSecondMWD = "M"
)
// MWD Wind Direction and Speed, with respect to north.
// https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf
// http://gillinstruments.com/data/manuals/OMC-140_Operator_Manual_v1.04_131117.pdf
//
// Format: $--MWD,x.x,T,x.x,M,x.x,N,x.x,M*hh<CR><LF>
// Example: $WIMWD,10.1,T,10.1,M,12,N,40,M*5D
type MWD struct {
BaseSentence
WindDirectionTrue float64
TrueValid bool
WindDirectionMagnetic float64
MagneticValid bool
WindSpeedKnots float64
KnotsValid bool
WindSpeedMeters float64
MetersValid bool
}
func newMWD(s BaseSentence) (Sentence, error) {
p := NewParser(s)
p.AssertType(TypeMWD)
return MWD{
BaseSentence: s,
WindDirectionTrue: p.Float64(0, "true wind direction"),
TrueValid: p.EnumString(1, "true wind valid", TrueMWD) == TrueMWD,
WindDirectionMagnetic: p.Float64(2, "magnetic wind direction"),
MagneticValid: p.EnumString(3, "magnetic direction valid", MagneticMWD) == MagneticMWD,
WindSpeedKnots: p.Float64(4, "windspeed knots"),
KnotsValid: p.EnumString(5, "windspeed knots valid", KnotsMWD) == KnotsMWD,
WindSpeedMeters: p.Float64(6, "windspeed m/s"),
MetersValid: p.EnumString(7, "windspeed m/s valid", MetersSecondMWD) == MetersSecondMWD,
}, p.Err()
}