Documentation ¶
Overview ¶
Package nmea implements generic parsing of NMEA 0183 sentences.
The package provides a parsing function that iterates over a NMEA sentences and fills fields of a struct with sequential values according to methods specified in field tags with the name "nmea". A destination struct must have an initial field with the name Type and a struct tag `nmea:"type"` where type is the type of the NMEA sentence or a regexp matching the sentence type if it is quoted in //. If the Type field is a string, the type will be stored in the field.
Parsing methods that are available are:
- "number": set the field to a number parsed from the NMEA value
- "string": set the field to the literal NMEA value
- "latlon": set the field to a latitude or longitude parsed from the NMEA value
- "date": set the field to a data parsed from the NMEA value in the form ddmmyy.
- "time": set the field to a time parsed from the NMEA value in the form hhmmss.ss.
A special case method is "checksum" which will write the value of the sentence checksum if it is available.
Index ¶
- Variables
- func AISBitField(b6 []byte, s, e int) []byte
- func DeArmorAIS(data string) ([]byte, error)
- func Parse(sentence string) (interface{}, error)
- func ParseTo(dst interface{}, sentence string) error
- func Register(typ string, dst interface{})
- func SixBitToASCII(b6 byte) byte
- type BOD
- type BWC
- type GGA
- type GLL
- type GNS
- type GSA
- type GSV
- type HDT
- type LIB
- type R00
- type RMA
- type RMB
- type RMC
- type RME
- type RMM
- type RMZ
- type STN
- type THS
- type TRF
- type VBW
- type VDMVDO
- type VTG
- type WPL
- type XTE
- type ZDA
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooShort = errors.New("nmea: sentence is too short") ErrNoSigil = errors.New("nmea: no initial sentence sigil") ErrChecksum = errors.New("nmea: checksum mismatch") ErrNotPointer = errors.New("nmea: destination not a pointer") ErrNotStruct = errors.New("nmea: destination is not a struct") ErrNMEAType = errors.New("nmea: wrong nmea type for sentence") ErrType = errors.New("nmea: wrong type for method") ErrLateType = errors.New("nmea: late type field") ErrMissingType = errors.New("nmea: missing type field") ErrTypeSyntax = errors.New("nmea: bad syntax for type match") ErrNotRegistered = errors.New("nmea: sentence type not registered") ErrBadBinary = errors.New("nmea: invalid binary data encoding") )
Functions ¶
func AISBitField ¶
AISBitField returns an 8-bit packed byte slice holding the bits of an AIS 6-bit nibble slice, starting from bit s and extending to the bit before e. The resulting byte slice will be shifted such that the last bit of the 6-bit nibble slice will be the lowest significance bit of the returned value. If s or e are outside the length of the 6-bit bit slice, AISBitField will panic.
func DeArmorAIS ¶
DeArmorAIS returns 6-bit-nibble payload data extracted from AIS ASCII armoring. Each byte of the returned byte slice as a single 6-bit value.
See https://gpsd.gitlab.io/gpsd/AIVDM.html#_aivdm_aivdo_payload_armoring
func Parse ¶
Parse parses a raw NMEA 0183 sentence and fills the fields of a destination registered struct with the data contained within the sentence and returns it. If the sentence has a checksum it is compared with the checksum of the sentence's bytes.
func ParseTo ¶
ParseTo parses a raw NMEA 0183 sentence and fills the fields of dst with the data contained within the sentence. If the sentence has a checksum it is compared with the checksum of the sentence's bytes.
The concrete value of dst must be a pointer to a struct.
func Register ¶
func Register(typ string, dst interface{})
Register registers the NMEA 0183 type to be parsed into the given destination type, dst. The kind of dst must be a struct, otherwise Register will panic. Calling Register with an already registered type will overwrite the existing registration. If dst is nil, the type will be deregistered.
The following types are registered by default:
- "AIVDM", "AIVDO": VDMVDO{}
- "GLBOD", "GNBOD", "GPBOD": BOD{}
- "GLBWC", "GNBWC", "GPBWC": BWC{}
- "GLGGA", "GNGGA", "GPGGA": GGA{}
- "GLGLL", "GNGLL", "GPGLL": GLL{}
- "GLGNS", "GNGNS", "GPGNS": GNS{}
- "GLGSA", "GNGSA", "GPGSA": GSA{}
- "GLGSV", "GNGSV", "GPGSV": GSV{}
- "GLHDT", "GNHDT", "GPHDT": HDT{}
- "GLR00", "GNR00", "GPR00": R00{}
- "GLRMA", "GNRMA", "GPRMA": RMA{}
- "GLRMB", "GNRMB", "GPRMB": RMB{}
- "GLRMC", "GNRMC", "GPRMC": RMC{}
- "GLSTN", "GNSTN", "GPSTN": STN{}
- "GLTHS", "GNTHS", "GPTHS": THS{}
- "GLTRF", "GNTRF", "GPTRF": TRF{}
- "GLVBW", "GNVBW", "GPVBW": VBW{}
- "GLVTG", "GNVTG", "GPVTG": VTG{}
- "GLWPL", "GNWPL", "GPWPL": WPL{}
- "GLXTE", "GNXTE", "GPXTE": XTE{}
- "GLZDA", "GNZDA", "GPZDA": ZDA{}
- "PGRME": RME{}
- "PGRMM": RMM{}
- "PGRMZ": RMZ{}
- "PSLIB": LIB{}
func SixBitToASCII ¶
SixBitToASCII returns the ASCII value corresponding to an AIS Sixbit ASCII-encoded character. If b6 is greater than 63, SixBitASCII will panic.
See https://gpsd.gitlab.io/gpsd/AIVDM.html#_ais_payload_data_types
Types ¶
type BOD ¶
type BWC ¶
type BWC struct { Type string `nmea:"/G[LNP]BWC/"` Timestamp time.Time `nmea:"time"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` True float64 `nmea:"number"` Magnetic float64 `nmea:"number"` Range float64 `nmea:"number"` RangeUnit string `nmea:"string"` Waypoint string `nmea:"string"` Checksum byte `nmea:"checksum"` // contains filtered or unexported fields }
type GGA ¶
type GGA struct { Type string `nmea:"/G[LNP]GGA/"` Timestamp time.Time `nmea:"time"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` Quality int `nmea:"number"` Satellites int `nmea:"number"` HDOP float64 `nmea:"number"` Altitude float64 `nmea:"number"` AltitudeUnit string `nmea:"string"` Separation float64 `nmea:"number"` SeparationUnit string `nmea:"string"` Age float64 `nmea:"number"` DiffReferenceStationID string `nmea:"string"` Checksum byte `nmea:"checksum"` }
type GLL ¶
type GNS ¶
type GNS struct { Type string `nmea:"/G[LNP]GNS/"` Timestamp time.Time `nmea:"time"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` Mode string `nmea:"string"` Satellites int `nmea:"number"` HDOP float64 `nmea:"number"` Altitude float64 `nmea:"number"` Separation float64 `nmea:"number"` Age float64 `nmea:"number"` ReferenceStation uint16 `nmea:"number"` Checksum byte `nmea:"checksum"` }
https://www.trimble.com/oem_receiverhelp/v4.44/en/NMEA-0183messages_GNS.html
type GSA ¶
type GSA struct { Type string `nmea:"/G[LNP]GSA/"` Mode string `nmea:"string"` Fix int `nmea:"number"` SV0 string `nmea:"string"` SV1 string `nmea:"string"` SV2 string `nmea:"string"` SV3 string `nmea:"string"` SV4 string `nmea:"string"` SV5 string `nmea:"string"` SV6 string `nmea:"string"` SV7 string `nmea:"string"` SV8 string `nmea:"string"` SV9 string `nmea:"string"` SV10 string `nmea:"string"` SV11 string `nmea:"string"` PDOP float64 `nmea:"number"` HDOP float64 `nmea:"number"` VDOP float64 `nmea:"number"` Checksum byte `nmea:"checksum"` }
type GSV ¶
type GSV struct { Type string `nmea:"/G[LNP]GSV/"` Messages int `nmea:"number"` MessageNumber int `nmea:"number"` SatellitesInView int `nmea:"number"` Satellite0PRN int `nmea:"number"` Elevation0 int `nmea:"number"` Azimuth0 int `nmea:"number"` SNR0 int `nmea:"number"` Satellite1PRN int `nmea:"number"` Elevation1 int `nmea:"number"` Azimuth1 int `nmea:"number"` SNR1 int `nmea:"number"` Satellite2PRN int `nmea:"number"` Elevation2 int `nmea:"number"` Azimuth2 int `nmea:"number"` SNR2 int `nmea:"number"` Satellite3PRN int `nmea:"number"` Elevation3 int `nmea:"number"` Azimuth3 int `nmea:"number"` SNR3 int `nmea:"number"` Checksum byte `nmea:"checksum"` }
type HDT ¶
type LIB ¶
type R00 ¶
type R00 struct { Type string `nmea:"/G[LNP]R00/"` WP0 string `nmea:"string"` WP1 string `nmea:"string"` WP2 string `nmea:"string"` WP3 string `nmea:"string"` WP4 string `nmea:"string"` WP5 string `nmea:"string"` WP6 string `nmea:"string"` WP7 string `nmea:"string"` WP8 string `nmea:"string"` WP9 string `nmea:"string"` WP10 string `nmea:"string"` WP11 string `nmea:"string"` WP13 string `nmea:"string"` Checksum byte `nmea:"checksum"` }
type RMA ¶
type RMA struct { Type string `nmea:"/G[LNP]RMA/"` Status string `nmea:"string"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` Speed float64 `nmea:"number"` CourseOverGround int `nmea:"number"` Variation float64 `nmea:"number"` VarDirection string `nmea:"string"` Checksum byte `nmea:"checksum"` // contains filtered or unexported fields }
type RMB ¶
type RMB struct { Type string `nmea:"/G[LNP]RMB/"` Status string `nmea:"string"` CrosstrackError float64 `nmea:"number"` CorrectDirection string `nmea:"string"` Origin string `nmea:"string"` Destination string `nmea:"string"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` RangeToDestination float64 `nmea:"number"` BearingToDestination float64 `nmea:"number"` ClosingVelocity float64 `nmea:"number"` ArrivalStatus string `nmea:"string"` Checksum byte `nmea:"checksum"` }
type RMC ¶
type RMC struct { Type string `nmea:"/G[LNP]RMC/"` Time time.Time `nmea:"time"` Status string `nmea:"string"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` Speed float64 `nmea:"number"` Track float64 `nmea:"number"` Date time.Time `nmea:"date"` MagneticVariation float64 `nmea:"number"` VarDirection string `nmea:"string"` Checksum byte `nmea:"checksum"` }
type RME ¶
type RMM ¶
type RMZ ¶
type THS ¶
type TRF ¶
type TRF struct { Type string `nmea:"/G[LNP]TRF/"` Time time.Time `nmea:"time"` Date time.Time `nmea:"date"` Latitude float64 `nmea:"latlon"` NorthSouth string `nmea:"string"` Longitude float64 `nmea:"latlon"` EastWest string `nmea:"string"` Elevation float64 `nmea:"number"` Iterations float64 `nmea:"number"` DoplerIntervals float64 `nmea:"number"` UpdateDistance float64 `nmea:"number"` Satellite string `nmea:"string"` }
type VBW ¶
type VBW struct { Type string `nmea:"/G[LNP]VBW/"` LongitudinalWaterSpeed float64 `nmea:"number"` TransverseWaterSpeed float64 `nmea:"number"` WaterSpeedStatus string `nmea:"string"` LongitudinalGroundSpeed float64 `nmea:"number"` TransverseGroundSpeed float64 `nmea:"number"` GroundSpeedStatus string `nmea:"string"` }
type VDMVDO ¶
type VDMVDO struct { Type string `nmea:"/..VD[MO]/"` Fragments int `nmea:"number"` FragmentNumber int `nmea:"number"` MessageID string `nmea:"string"` ChannelCode string `nmea:"string"` // Data is AIS ASCII-armored. Data string `nmea:"string"` Padding byte `nmea:"number"` Checksum byte `nmea:"checksum"` }