-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:klyve/go-nmea
* 'master' of github.com:klyve/go-nmea: Fix checksum ref after branch update Correct copy paste typo Add VHW water speed and heading functions returning a direction sign have been added added latitude range checking added estimated fix which is returned by MTK3339 add mtk test expose xorChecksum revert xorChecksum expose use the parser att support for parsing MTK commands and update go mod files
- Loading branch information
Showing
14 changed files
with
272 additions
and
10 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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module github.com/klyve/go-nmea | ||
|
||
require github.com/stretchr/testify v1.2.1 | ||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/testify v1.2.1 | ||
) |
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,6 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U= | ||
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
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 ( | ||
// TypeMTK type for PMTK sentences | ||
TypeMTK = "PMTK" | ||
) | ||
|
||
// MTK is the Time, position, and fix related data of the receiver. | ||
type MTK struct { | ||
BaseSentence | ||
Cmd, | ||
Flag int64 | ||
} | ||
|
||
// newMTK constructor | ||
func newMTK(s BaseSentence) (MTK, error) { | ||
p := newParser(s) | ||
cmd := p.Int64(0, "command") | ||
flag := p.Int64(1, "flag") | ||
return MTK{ | ||
BaseSentence: s, | ||
Cmd: cmd, | ||
Flag: flag, | ||
}, 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 mtktests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg MTK | ||
}{ | ||
{ | ||
name: "good: Packet Type: 001 PMTK_ACK", | ||
raw: "$PMTK001,604,3*" + Checksum("PMTK001,604,3"), | ||
msg: MTK{ | ||
Cmd: 604, | ||
Flag: 3, | ||
}, | ||
}, | ||
{ | ||
name: "missing flag", | ||
raw: "$PMTK001,604*" + Checksum("PMTK001,604"), | ||
err: "nmea: PMTK001 invalid flag: index out of range", | ||
}, | ||
{ | ||
name: "missing cmd", | ||
raw: "$PMTK001*" + Checksum("PMTK001"), | ||
err: "nmea: PMTK001 invalid command: index out of range", | ||
}, | ||
} | ||
|
||
func TestMTK(t *testing.T) { | ||
for _, tt := range mtktests { | ||
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) | ||
mtk := m.(MTK) | ||
mtk.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, mtk) | ||
} | ||
}) | ||
} | ||
} |
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
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
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
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,28 @@ | ||
package nmea | ||
|
||
const ( | ||
// TypeVHW type for VHW sentences | ||
TypeVHW = "VHW" | ||
) | ||
|
||
// VHW contains information about water speed and heading | ||
type VHW struct { | ||
BaseSentence | ||
TrueHeading float64 | ||
MagneticHeading float64 | ||
SpeedThroughWaterKnots float64 | ||
SpeedThroughWaterKPH float64 | ||
} | ||
|
||
// newVHW constructor | ||
func newVHW(s BaseSentence) (VHW, error) { | ||
p := newParser(s) | ||
p.AssertType(TypeVHW) | ||
return VHW{ | ||
BaseSentence: s, | ||
TrueHeading: p.Float64(0, "true heading"), | ||
MagneticHeading: p.Float64(2, "magnetic heading"), | ||
SpeedThroughWaterKnots: p.Float64(4, "speed through water in knots"), | ||
SpeedThroughWaterKPH: p.Float64(6, "speed through water in kilometers per hour"), | ||
}, 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,47 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var vhw = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg VHW | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$VWVHW,45.0,T,43.0,M,3.5,N,6.4,K*56", | ||
msg: VHW{ | ||
TrueHeading: 45.0, | ||
MagneticHeading: 43.0, | ||
SpeedThroughWaterKnots: 3.5, | ||
SpeedThroughWaterKPH: 6.4, | ||
}, | ||
}, | ||
{ | ||
name: "bad sentence", | ||
raw: "$VWVHW,T,45.0,43.0,M,3.5,N,6.4,K*56", | ||
err: "nmea: VWVHW invalid true heading: T", | ||
}, | ||
} | ||
|
||
func TestVHW(t *testing.T) { | ||
for _, tt := range vhw { | ||
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) | ||
vhw := m.(VHW) | ||
vhw.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, vhw) | ||
} | ||
}) | ||
} | ||
} |