A NMEA parser library in pure Go
@aldas @@bezineb5 @icholy
Full Changelog: https://github.com/adrianmo/go-nmea/compare/v1.7.0...v1.8.0
@aldas
Full Changelog: https://github.com/adrianmo/go-nmea/compare/v1.6.0...v1.7.0
@aldas
Full Changelog: https://github.com/adrianmo/go-nmea/compare/v1.5.0...v1.6.0
@aldas
Full Changelog: https://github.com/adrianmo/go-nmea/compare/v1.4.2...v1.5.0
@aldas @icholy
Full Changelog: https://github.com/adrianmo/go-nmea/compare/v1.4.1...v1.4.2
type TagBlock struct {
Time int64 // TypeUnixTime unix timestamp (unit is likely to be s, but might be ms, YMMV), parameter: -c
RelativeTime int64 // TypeRelativeTime relative time, parameter: -r
Destination string // TypeDestinationID destination identification 15 char max, parameter: -d
Grouping string // TypeGrouping sentence grouping, parameter: -g
LineCount int64 // TypeLineCount line count, parameter: -n
Source string // TypeSourceID source identification 15 char max, parameter: -s
Text string // TypeTextString valid character string, parameter -t
}
Ref.: https://github.com/adrianmo/go-nmea/blob/master/tagblock.go#L10
NMEA 4.10 TAG Block values can be accessed via the message's TagBlock
struct:
package main
import (
"fmt"
"log"
"time"
"github.com/adrianmo/go-nmea"
)
func main() {
sentence := "\\s:Satelite_1,c:1553390539*62\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52"
s, err := nmea.Parse(sentence)
if err != nil {
log.Fatal(err)
}
parsed := s.(nmea.VDMVDO)
fmt.Printf("TAG Block timestamp: %v\n", time.Unix(parsed.TagBlock.Time, 0))
fmt.Printf("TAG Block source: %v\n", parsed.TagBlock.Source)
}
Output (locale/time zone dependent):
$ go run main/main.go
TAG Block timestamp: 2019-03-24 14:22:19 +1300 NZDT
TAG Block source: Satelite_1
@klyve @simeonmiteff @icholy
Message parsing is now talker-agnostic, i.e., it is based on the sentence data type only. For a sentence like $XXYYY,220516,A,23,5133.82,W*42
, where XX
is the talker and YYY
is the sentence data type, the parser will only account for the YYY
data type, which is what defines the structure and format of the sentence.
In your code, given a sentence like the following:
sentence := "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70"
Instead of using the old, deprecated prefixes (e.g. nmea.PrefixGPRMC
) that included the talked ID and the data type:
s, _ := nmea.Parse(sentence)
// Deprecated nmea.PrefixGPRMC, use nmea.TypeRMC instead
if s.Prefix() == nmea.PrefixGPRMC {
m := s.(nmea.GPRMC)
fmt.Printf("Validity: %s\n", m.Validity)
...
}
Use the DataType()
sentence method to determine the parsed sentence data type and then cast it to the right type:
s, _ := nmea.Parse(sentence)
if s.DataType() == nmea.TypeRMC {
m := s.(nmea.RMC)
fmt.Printf("Validity: %s\n", m.Validity)
...
}
@icholy @bmurray @sthorshaug @BertoldVdb @kvartborg @krasi-georgiev @krawczyk87 @yavosh