-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nmea | ||
|
||
const ( | ||
// PrefixGPHDT prefix of GPHDT sentence type | ||
PrefixGPHDT = "GPHDT" | ||
) | ||
|
||
// GPHDT is the Actual vessel heading in degrees True. | ||
// http://aprs.gids.nl/nmea/#hdt | ||
type GPHDT struct { | ||
BaseSentence | ||
Heading float64 // Heading in degrees | ||
True bool // heading relative to true north if T | ||
} | ||
|
||
// newGPHDT constructor | ||
func newGPHDT(s BaseSentence) (GPHDT, error) { | ||
p := newParser(s, PrefixGPHDT) | ||
m := GPHDT{ | ||
BaseSentence: s, | ||
Heading: p.Float64(0, "heading"), | ||
True: p.EnumString(1, "true", "T") == "T", | ||
} | ||
return m, p.Err() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var gphdttests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg GPHDT | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$GPHDT,123.456,T*32", | ||
msg: GPHDT{ | ||
Heading: 123.456, | ||
True: true, | ||
}, | ||
}, | ||
{ | ||
name: "invalid True", | ||
raw: "$GPHDT,123.456,X*3E", | ||
err: "nmea: GPHDT invalid true: X", | ||
}, | ||
{ | ||
name: "invalid Heading", | ||
raw: "$GPHDT,XXX,T*43", | ||
err: "nmea: GPHDT invalid heading: XXX", | ||
}, | ||
} | ||
|
||
func TestGPHDT(t *testing.T) { | ||
for _, tt := range gphdttests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m, err := Parse(tt.raw) | ||
if tt.err != "" { | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, tt.err) | ||
} else { | ||
assert.NoError(t, err) | ||
gphdt := m.(GPHDT) | ||
gphdt.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, gphdt) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters