nmea

package module
v0.0.0-...-e8c5d9a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2021 License: BSD-3-Clause Imports: 9 Imported by: 2

README

Package nmea implements generic parsing of NMEA 0183 sentences.

Build Status coveralls.io GoDoc

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".

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

Constants

This section is empty.

Variables

View Source
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

func AISBitField(b6 []byte, s, e int) []byte

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

func DeArmorAIS(data string) ([]byte, error)

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

func Parse(sentence string) (interface{}, error)

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

func ParseTo(dst interface{}, sentence string) error

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

func SixBitToASCII(b6 byte) byte

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 BOD struct {
	Type string `nmea:"/G[LNP]BOD/"`

	True float64 `nmea:"number"`

	Magnetic float64 `nmea:"number"`

	Destination string `nmea:"string"`
	Start       string `nmea:"string"`

	Checksum byte `nmea:"checksum"`
	// contains filtered or unexported fields
}

http://aprs.gids.nl/nmea/#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
}

http://aprs.gids.nl/nmea/#bwc

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"`
}

http://aprs.gids.nl/nmea/#gga

type GLL

type GLL struct {
	Type string `nmea:"/G[LNP]GLL/"`

	Latitude   float64   `nmea:"latlon"`
	NorthSouth string    `nmea:"string"`
	Longitude  float64   `nmea:"latlon"`
	EastWest   string    `nmea:"string"`
	Timestamp  time.Time `nmea:"time"`

	Checksum byte `nmea:"checksum"`
}

http://aprs.gids.nl/nmea/#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"`
}

http://aprs.gids.nl/nmea/#gsa

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"`
}

http://aprs.gids.nl/nmea/#gsv

type HDT

type HDT struct {
	Type string `nmea:"/G[LNP]HDT/"`

	Heading float64 `nmea:"number"`

	Checksum byte `nmea:"checksum"`
	// contains filtered or unexported fields
}

http://aprs.gids.nl/nmea/#hdt

type LIB

type LIB struct {
	Type string `nmea:"PSLIB"`

	Frequency   float64 `nmea:"number"`
	BitRate     float64 `nmea:"number"`
	RequestType string  `nmea:"string"`

	Checksum byte `nmea:"checksum"`
}

http://aprs.gids.nl/nmea/#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"`
}

http://aprs.gids.nl/nmea/#r00

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
}

http://aprs.gids.nl/nmea/#rma

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"`
}

http://aprs.gids.nl/nmea/#rmb

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"`
}

http://aprs.gids.nl/nmea/#rmc

type RME

type RME struct {
	Type string `nmea:"PGRME"`

	HPE float64 `nmea:"number"`

	VPE float64 `nmea:"number"`

	OSEPE float64 `nmea:"number"`

	Checksum byte `nmea:"checksum"`
	// contains filtered or unexported fields
}

http://aprs.gids.nl/nmea/#rme

type RMM

type RMM struct {
	Type string `nmea:"PGRMM"`

	MapDatum string `nmea:"string"`

	Checksum byte `nmea:"checksum"`
}

http://aprs.gids.nl/nmea/#rmm

type RMZ

type RMZ struct {
	Type string `nmea:"PGRMZ"`

	Altitude float64 `nmea:"number"`

	PositionFixDimensions int8 `nmea:"number"`

	Checksum byte `nmea:"checksum"`
	// contains filtered or unexported fields
}

http://aprs.gids.nl/nmea/#rmz

type STN

type STN struct {
	Type string `nmea:"/G[LNP]STN/"`

	Talker byte `nmea:"number"`
}

http://aprs.gids.nl/nmea/#stn

type THS

type THS struct {
	Type string `nmea:"/..THS/"`

	Heading float64 `nmea:"number"`
	Status  string  `nmea:"string"`

	Checksum byte `nmea:"checksum"`
}

http://www.nuovamarea.net/pytheas_9.html

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"`
}

http://aprs.gids.nl/nmea/#trf

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"`
}

http://aprs.gids.nl/nmea/#vbw

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"`
}

https://gpsd.gitlab.io/gpsd/AIVDM.html

type VTG

type VTG struct {
	Type string `nmea:"/G[LNP]VTG/"`

	TrackTrue float64 `nmea:"number"`

	TrackMagnetic float64 `nmea:"number"`

	SpeedKnots float64 `nmea:"number"`

	SpeedKph float64 `nmea:"number"`

	Checksum byte `nmea:"checksum"`
	// contains filtered or unexported fields
}

http://aprs.gids.nl/nmea/#vtg

type WPL

type WPL struct {
	Type string `nmea:"/G[LNP]WPL/"`

	Latitude   float64 `nmea:"latlon"`
	NorthSouth string  `nmea:"string"`
	Longitude  float64 `nmea:"latlon"`
	EastWest   string  `nmea:"string"`

	Waypoint string `nmea:"string"`

	Checksum byte `nmea:"checksum"`
}

http://aprs.gids.nl/nmea/#wpl

type XTE

type XTE struct {
	Type string `nmea:"/G[LNP]XTE/"`

	GeneralWarning string `nmea:"string"`
	LockFlag       string `nmea:"string"`

	CrossTrackError float64 `nmea:"number"`
	Steer           string  `nmea:"string"`
	Units           string  `nmea:"string"`

	Checksum byte `nmea:"checksum"`
}

http://aprs.gids.nl/nmea/#xte

type ZDA

type ZDA struct {
	Type string `nmea:"/G[LNP]ZDA/"`

	Time            time.Time `nmea:"time"`
	Day             byte      `nmea:"number"`
	Month           byte      `nmea:"number"`
	Year            int       `nmea:"number"`
	TimeZone        int8      `nmea:"number"`
	TimeZoneMinutes int8      `nmea:"number"`
}

http://aprs.gids.nl/nmea/#zda

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL