Skip to content

Commit

Permalink
Merge 1e7fa76 into 2310df0
Browse files Browse the repository at this point in the history
  • Loading branch information
krasi-georgiev committed Aug 7, 2019
2 parents 2310df0 + 1e7fa76 commit 98771bb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ After this command *go-nmea* is ready to use. Its source will be in:
At this moment, this library supports the following sentence types:

- [RMC](http://aprs.gids.nl/nmea/#rmc) - Recommended Minimum Specific GPS/Transit data
- [PMTK](https://www.rhydolabz.com/documents/25/PMTK_A11.pdf) - Messages for setting and reading commands for MediaTek gps modules.
- [GGA](http://aprs.gids.nl/nmea/#gga) - GPS Positioning System Fix Data
- [GSA](http://aprs.gids.nl/nmea/#gsa) - GPS DOP and active satellites
- [GSV](http://aprs.gids.nl/nmea/#gsv) - GPS Satellites in view
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/adrianmo/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
)
6 changes: 6 additions & 0 deletions go.sum
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=
25 changes: 25 additions & 0 deletions mtk.go
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()
}
11 changes: 10 additions & 1 deletion sentence.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func parseSentence(raw string) (BaseSentence, error) {

// parsePrefix takes the first field and splits it into a talker id and data type.
func parsePrefix(s string) (string, string) {
if strings.HasPrefix(s, "PMTK") {
return "PMTK", s[4:]
}
if strings.HasPrefix(s, "P") {
return "P", s[1:]
}
Expand All @@ -97,7 +100,7 @@ func parsePrefix(s string) (string, string) {
return s[:2], s[2:]
}

// xor all the bytes in a string an return it
// xorChecksum xor all the bytes in a string an return it
// as an uppercase hex string
func xorChecksum(s string) string {
var checksum uint8
Expand All @@ -114,6 +117,12 @@ func Parse(raw string) (Sentence, error) {
return nil, err
}
if strings.HasPrefix(s.Raw, SentenceStart) {
// MTK message types share the same format
// so we return the same struct for all types.
switch s.Talker {
case TypeMTK:
return newMTK(s)
}
switch s.Type {
case TypeRMC:
return newRMC(s)
Expand Down

0 comments on commit 98771bb

Please sign in to comment.