nmea

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: GPL-3.0 Imports: 6 Imported by: 1

README

go-nmea Go Report Card GitHub Repo stars GoDoc Release License Build Status Coverage Status

A Golang library for decode and serialize standard and proprietary NMEA packet message (GPS information dissector).

Tested with this GPS Module cover L80 gps protocol specification v1.0.pdf. See another NMEA specification.

NMEA Specification

NMEA standard specification provide 58 kind of message with different structure. And more according to GPS devices manufacturer (ex: 40 proprietary message identified prefixed by PMTK for L80 GPS protocol specification).

Syntax: $<talker_id><message_id>[<data-fields>...]*<checksum><CRLF>

Supported NMEA message

The following list will be expanded to manage new types, but now the library can decode and serialize:

  • $GPRMC - Recommended Minimum Specific GPS/TRANSIT Data
  • $GPVTG - Track Made Good and Ground Speed
  • $GPGGA - Global Positioning System Fix Data
  • $GPGSA - GPS DOP and active satellites
  • $GPGSV - GPS Satellites in view
  • $GPGLL - Geographic position, latitude / longitude
  • $GPTXT - Transfert various text information

Usage

Library for parsing (read) or serialize (write) NMEA packets (bijective handling), see below:

package main

import "fmt"
import nmea "github.com/pilebones/go-nmea"

func main() {
	raw := "$GPGGA,015540.000,3150.68378,N,11711.93139,E,1,17,0.6,0051.6,M,0.0,M,,*58"

	fmt.Println("Parsing NMEA message:", raw)
	msg, err := nmea.Parse(raw)
	if err != nil {
		fmt.Println("Unable to decode nmea message, err:", err.Error())
		return
	}

	// TODO: Handling complex struct depending on kind of nmea message

	fmt.Println("Craft NMEA packets using Serialize():", msg.Serialize())
}

Documentation

License

go-nmea is available under the GNU GPL v3 - Clause License.

Documentation

Index

Constants

View Source
const (
	InvalidIndicator = iota
	GNSSS
	DGPS
)
View Source
const (
	FixStatusNoFix
	FixStatus2D
	FixStatus3D
)

Variables

View Source
var (
	DMFormat = regexp.MustCompile(`^([0-9]*\.?[0-9]+)\ ?([NSEW])?$`)
)
View Source
var TypeIDs map[string]Header

TypeIDs is a dictionary of all kind of NMEA message header by full-code

Functions

func PrependToFloatXZero

func PrependToFloatXZero(value float64, expected uint) string

PrependToFloatXZero doing same thing that PrependXZeroFloat but with float as input

func PrependToIntXZero

func PrependToIntXZero(value int, expected uint) string

PrependToIntXZero doing same thing that PrependXZeroFloat but with int as input

func PrependXZero

func PrependXZero(value float64, formatString string, expected uint) string

PrependXZero return string with expected number of zero (as prefix) to have X number before coma

func Round

func Round(value float64, expected int, threshold float64) float64

Round a float with expected as accuracy

Types

type CardinalPoint

type CardinalPoint string
const (
	// Allowed cardinal points
	North CardinalPoint = "N"
	South CardinalPoint = "S"
	East  CardinalPoint = "E"
	West  CardinalPoint = "W"
)

func ParseCardinalPoint

func ParseCardinalPoint(raw string) (cp CardinalPoint, err error)

func (CardinalPoint) String

func (c CardinalPoint) String() string

type DataValid

type DataValid bool
const (
	Valid   DataValid = true
	Invalid DataValid = false
)

func (DataValid) Serialize

func (v DataValid) Serialize() string

type FixStatus

type FixStatus int

func ParseFixStatus

func ParseFixStatus(raw string) (fs FixStatus, err error)

func (FixStatus) String

func (s FixStatus) String() string

type GPGGA

type GPGGA struct {
	Message

	TimeUTC            time.Time // Aggregation of TimeUTC data field
	Latitude           LatLong   // In decimal format
	Longitude          LatLong   // In decimal format
	QualityIndicator   QualityIndicator
	NbOfSatellitesUsed uint64
	HDOP               float64
	Altitude           float64
	GeoIDSep           *float64
}

func NewGPGGA

func NewGPGGA(m Message) *GPGGA

func (GPGGA) Serialize

func (m GPGGA) Serialize() string

type GPGLL

type GPGLL struct {
	Message

	TimeUTC             time.Time // Aggregation of TimeUTC data field
	Latitude, Longitude LatLong   // In decimal format
	IsValid             DataValid
	PositioningMode     PositioningMode
}

func NewGPGLL

func NewGPGLL(m Message) *GPGLL

type GPGSA

type GPGSA struct {
	Message

	Mode                   Mode
	FixStatus              FixStatus
	SatelliteUsedOnChannel [13]int // Note: index 0 not used (channel 1..12)
	PDOP, HDOP, VDOP       float64
}

func NewGPGSA

func NewGPGSA(m Message) *GPGSA

type GPGSV

type GPGSV struct {
	Message
	NbOfMessage      int // Number of messages, total number of GPGSV messages being output (1 ~ 3)
	SequenceNumber   int // Sequence number of this entry (1 ~ 3)
	SatellitesInView int
	Satellites       []Satellite
}

func NewGPGSV

func NewGPGSV(m Message) *GPGSV

func (GPGSV) Serialize

func (m GPGSV) Serialize() string

type GPRMC

type GPRMC struct {
	Message

	DateTimeUTC       time.Time // Aggregation of TimeUTC+Date data field
	IsValid           DataValid // 'V' =Invalid / 'A' = Valid
	Latitude          LatLong   // In decimal format
	Longitude         LatLong   // In decimal format
	Speed             float64   // Speed over ground in knots
	COG               float64   // Course over ground in degree
	MagneticVariation float64   // Magnetic variation in degree, not being output
	PositioningMode   PositioningMode
}

func NewGPRMC

func NewGPRMC(m Message) *GPRMC

type GPTXT

type GPTXT struct {
	Message

	TotalNbMsgInTx int // Total number of messages in this transmission. (01~99)
	MsgNumInTx     int // Message number in this transmission. (01~99)
	Severity       Severity

	/*
		L80 module supports automatic antenna switching function.
		The GPTXT sentence can be used to identify the status of external active antenna. The status of external active antenna is listed as below:
		1. If ANTSTATUS=OK, it means external active antenna is connected and the module will use external active antenna.
		2. If ANTSTATUS=OPEN, it means open-circuit state is dectected and the internal antenna is used at this time.
		3. If ANTSTATUS=SHORT, it means short circuit state is dectected and the internal antenna is used.
	*/
	TxtMsg string
}

func NewGPTXT

func NewGPTXT(m Message) *GPTXT

func (GPTXT) AntennaStatus

func (m GPTXT) AntennaStatus() *string

func (GPTXT) Env

func (m GPTXT) Env() map[string]string

func (GPTXT) Serialize

func (m GPTXT) Serialize() string

type GPVTG

type GPVTG struct {
	Message

	COG             float64 // Course over ground (true) in degree
	SpeedKnots      float64 // Speed over ground in knots
	SpeedKmh        float64 // Speed over ground in km/h
	PositioningMode PositioningMode
}

func NewGPVTG

func NewGPVTG(m Message) *GPVTG
type Header interface {
	GetTypeID() TypeID
	Serialize() string
}

Header is an interface for each kind of NMEA header according to TalkerId

type LatLong

type LatLong float64
const (
	// LatLong Thresholds (ie: spherical degrees)
	// Min is the minimum value allowed for a LatLong
	Min LatLong = -180
	// Max is the maximum value allowed for a LatLong
	Max LatLong = 180
)

func NewLatLong

func NewLatLong(raw string) (l LatLong, err error)

NewLatLong parses input has coordinate or return error

Allowed format: - DMS (Degrees, Minutes, Secondes), ie: "N 31° 50' 72.38'" - DD (Decimal Degree), ie: "31.8534389" "22.870216666666668"

func ParseDM

func ParseDM(raw string) (LatLong, error)

ParseDM return LatLong from provided format from GPS module (in format ‘ddmm.mmmm’: degree and minutes) Allowed format: "3150.7238N" or "3150.7238 N" @see https://fr.wikipedia.org/wiki/Coordonn%C3%A9es_g%C3%A9ographiques => 1 degree = 60 minutes => 1 minute = 60 secondes Example: Baltimore (United state) => latitude = 39,28° N, longitude = 76,60° O (39° 17′ N, 76° 36′ O). 0.28° = (0.28°*60min)/1° = 16.8min => ~17 minutes

func (LatLong) CardinalPoint

func (l LatLong) CardinalPoint(isLatitude bool) CardinalPoint

CardinalPoint return the cardinal point related to the kind of coordinate (long or lat)

func (LatLong) DM

func (l LatLong) DM() (int, float64)

DM extract degrees and minutes

func (LatLong) DMS

func (l LatLong) DMS() (int, int, float64)

DMS extract degrees, minutes and secondes

func (LatLong) Serialize

func (l LatLong) Serialize() string

Serialize return string like ‘ddmm.mmmm’: degree and minutes as GPS module provide

func (LatLong) ToDM

func (l LatLong) ToDM() string

func (LatLong) ToDMS

func (l LatLong) ToDMS() string

PrintDMS return string like: dd° mm' ss.ss" to be human readable

type Message

type Message struct {
	Type     Header
	Fields   []string
	Checksum uint8
}

Message is the base aand low-level struct (envelope) without advanced dissection for each NMEA message

func (Message) ComputeChecksum

func (m Message) ComputeChecksum() (c uint8)

ComputeChecksum recompute checksum from extracted payload

func (Message) Error

func (m Message) Error(err error) error

Error return common error with wrapped data to enhance debugging

func (Message) GetMessage

func (m Message) GetMessage() Message

GetMessage return base Message to respect interface

func (Message) Payload

func (m Message) Payload() string

Payload return data after $ and before *

func (Message) Serialize

func (m Message) Serialize() string

Serialize NMEA message to render raw

type Mode

type Mode string
const (
	ModeManual Mode = "M"
	ModeAuto   Mode = "A"
)

func ParseMode

func ParseMode(raw string) (m Mode, err error)

func (Mode) String

func (m Mode) String() string

type MtkTypeID

type MtkTypeID struct {
	TypeID
	PacketType string
}

func (MtkTypeID) Serialize

func (t MtkTypeID) Serialize() string

type NMEA

type NMEA interface {
	GetMessage() Message
	Error(err error) error
	Serialize() string
}

NMEA is an interface for each kind of NMEA message

func Parse

func Parse(raw string) (NMEA, error)

Parse return message for any kind of NMEA message raw

type PositioningMode

type PositioningMode string
const (
	NoFixMode           PositioningMode = "N"
	AutonomousGNSSFix   PositioningMode = "A"
	DifferentialGNSSFix PositioningMode = "D"
)

func ParsePositioningMode

func ParsePositioningMode(raw string) (pm PositioningMode, err error)

func (PositioningMode) Serialize

func (p PositioningMode) Serialize() string

func (PositioningMode) String

func (p PositioningMode) String() string

type QualityIndicator

type QualityIndicator int

func ParseQualityIndicator

func ParseQualityIndicator(raw string) (qi QualityIndicator, err error)

func (QualityIndicator) String

func (s QualityIndicator) String() string

type Satellite

type Satellite struct {
	ID        string
	Elevation *int // Elevation in degree (0 ~ 90)
	Azimuth   *int // Azimuth in degree (0 ~ 359)
	SNR       *int // Signal to Noise Ration in dBHz (0 ~ 99), empty if not tracking
}

type Severity

type Severity string
const (
	ERROR   Severity = "00"
	WARNING Severity = "01"
	NOTICE  Severity = "02"
	USER    Severity = "07"
)

func ParseSeverity

func ParseSeverity(raw string) (s Severity, err error)

func (Severity) Serialize

func (s Severity) Serialize() string

func (Severity) String

func (s Severity) String() string

type TalkerID

type TalkerID string
const (
	// NMEA special-chars
	// Prefix is special char to begin NMEA message
	Prefix = "$"
	// FieldDelimiter is special char to delimit a field in NMEA message
	FieldDelimiter = ","
	// Suffix is special char to finish NMEA message
	Suffix = "*"

	// Talker IDs
	TalkerIDProprietary TalkerID = "P"  // P for pro proprietary message
	TalkerIDGPS         TalkerID = "GP" // Global Positioning System receiver
	TalkerIDLC          TalkerID = "LC" // Loran-C receiver
	TalkerIDII          TalkerID = "II" // Integrated Instrumentation
	TalkerIDIN          TalkerID = "IN" // Integrated Navigation
	TalkerIDEC          TalkerID = "EC" // Electronic Chart Display & Information System (ECDIS)
	TalkerIDCD          TalkerID = "CD" // Digital Selective Calling (DSC)
	TalkerIDGA          TalkerID = "GA" // Galileo Positioning System
	TalkerIDGL          TalkerID = "GL" // GLONASS, according to IEIC 61162-1
	TalkerIDGN          TalkerID = "GN" // Mixed GPS and GLONASS data, according to IEIC 61162-1
	TalkerIDGB          TalkerID = "GB" // BeiDou (China)
	TalkerIDBD          TalkerID = "BD" // BeiDou (China)
	TalkerIDQZ          TalkerID = "QZ" // QZSS regional GPS augmentation system (Japan)
)

func (TalkerID) Serialize

func (t TalkerID) Serialize() string

type TypeID

type TypeID struct {
	Talker TalkerID
	Code   string
}

func (TypeID) GetTypeID

func (t TypeID) GetTypeID() TypeID

func (TypeID) Serialize

func (t TypeID) Serialize() string

Jump to

Keyboard shortcuts

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