nmea

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: MIT Imports: 6 Imported by: 0

README

go-nmea Build Status Go Report Card Coverage Status GoDoc

This is a NMEA library for the Go programming language (http://golang.org).

Installing

Using go get
go get github.com/adrianmo/go-nmea

After this command go-nmea is ready to use. Its source will be in:

$GOPATH/src/github.com/adrianmo/go-nmea

Supported sentences

At this moment, this library supports the following sentence types:

  • GPRMC - Recommended Minimum Specific GPS/Transit data
  • GNRMC - Recommended Minimum Specific GNSS data
  • GPGGA - GPS Positioning System Fix Data
  • GNGGA - GNSS Positioning System Fix Data
  • GPGSA - GPS DOP and active satellites
  • GPGSV - GPS Satellites in view
  • GLGSV - GLONASS Satellites in view
  • GPGLL - Geographic Position, Latitude / Longitude and time
  • GPVTG - Track Made Good and Ground Speed
  • GPZDA - Date & time data
  • PGRME - Estimated Position Error (Garmin proprietary sentence)

Example

package main

import (
	"fmt"
	"log"
	"github.com/adrianmo/go-nmea"
)

func main() {
	sentence := "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70"
	s, err := nmea.Parse(sentence)
	if err != nil {
		log.Fatal(err)
	}
	m := s.(nmea.GPRMC)
	fmt.Printf("Raw sentence: %v\n", m)
	fmt.Printf("Time: %s\n", m.Time)
	fmt.Printf("Validity: %s\n", m.Validity)
	fmt.Printf("Latitude GPS: %s\n", nmea.FormatGPS(m.Latitude))
	fmt.Printf("Latitude DMS: %s\n", nmea.FormatDMS(m.Latitude))
	fmt.Printf("Longitude GPS: %s\n", nmea.FormatGPS(m.Longitude))
	fmt.Printf("Longitude DMS: %s\n", nmea.FormatDMS(m.Longitude))
	fmt.Printf("Speed: %f\n", m.Speed)
	fmt.Printf("Course: %f\n", m.Course)
	fmt.Printf("Date: %s\n", m.Date)
	fmt.Printf("Variation: %f\n", m.Variation)
}

Output:

$ go run main/main.go

Raw sentence: $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
Time: 22:05:16.0000
Validity: A
Latitude GPS: 5133.8200
Latitude DMS: 51° 33' 49.200000"
Longitude GPS: 042.2400
Longitude DMS: 0° 42' 14.400000"
Speed: 173.800000
Course: 231.800000
Date: 13/06/94
Variation: -4.200000

Contributions

Please, feel free to implement support for new sentences, fix bugs, refactor code, etc. and send a pull-request to update the library.

Documentation

Index

Constants

View Source
const (
	// PrefixGPGGA prefix
	PrefixGPGGA = "GPGGA"
	// Invalid fix quality.
	Invalid = "0"
	// GPS fix quality
	GPS = "1"
	// DGPS fix quality
	DGPS = "2"
	// PPS fix
	PPS = "3"
	// RTK real time kinematic fix
	RTK = "4"
	// FRTK float RTK fix
	FRTK = "5"
)
View Source
const (
	// PrefixGPGLL prefix for GPGLL sentence type
	PrefixGPGLL = "GPGLL"
	// ValidGLL character
	ValidGLL = "A"
	// InvalidGLL character
	InvalidGLL = "V"
)
View Source
const (
	// PrefixGPGSA prefix of GPGSA sentence type
	PrefixGPGSA = "GPGSA"
	// Auto - Field 1, auto or manual fix.
	Auto = "A"
	// Manual - Field 1, auto or manual fix.
	Manual = "M"
	// FixNone - Field 2, fix type.
	FixNone = "1"
	// Fix2D - Field 2, fix type.
	Fix2D = "2"
	// Fix3D - Field 2, fix type.
	Fix3D = "3"
)
View Source
const (
	// PrefixGPRMC prefix of GPRMC sentence type
	PrefixGPRMC = "GPRMC"
	// ValidRMC character
	ValidRMC = "A"
	// InvalidRMC character
	InvalidRMC = "V"
)
View Source
const (
	// PrefixPGRME prefix for PGRME sentence type
	PrefixPGRME = "PGRME"
	// ErrorUnit must be meters (M)
	ErrorUnit = "M"
)
View Source
const (
	// SentenceStart is the token to indicate the start of a sentence.
	SentenceStart = "$"

	// FieldSep is the token to delimit fields of a sentence.
	FieldSep = ","

	// ChecksumSep is the token to delimit the checksum of a sentence.
	ChecksumSep = "*"
)
View Source
const (
	// Degrees value
	Degrees = '\u00B0'
	// Minutes value
	Minutes = '\''
	// Seconds value
	Seconds = '"'
	// Point value
	Point = '.'
	// North value
	North = "N"
	// South value
	South = "S"
	// East value
	East = "E"
	// West value
	West = "W"
)
View Source
const (
	// PrefixGLGSV prefix
	PrefixGLGSV = "GLGSV"
)
View Source
const (
	// PrefixGNGGA prefix
	PrefixGNGGA = "GNGGA"
)
View Source
const (
	// PrefixGNRMC prefix of GNRMC sentence type
	PrefixGNRMC = "GNRMC"
)
View Source
const (
	// PrefixGPGSV prefix
	PrefixGPGSV = "GPGSV"
)
View Source
const (
	// PrefixGPVTG prefix
	PrefixGPVTG = "GPVTG"
)
View Source
const (
	// PrefixGPZDA prefix
	PrefixGPZDA = "GPZDA"
)

Variables

This section is empty.

Functions

func FormatDMS

func FormatDMS(l float64) string

FormatDMS returns the degrees, minutes, seconds format for the given LatLong.

func FormatGPS

func FormatGPS(l float64) string

FormatGPS formats a GPS/NMEA coordinate

func ParseDMS

func ParseDMS(s string) (float64, error)

ParseDMS parses a coordinate in degrees, minutes, seconds. - e.g. 33° 23' 22"

func ParseDecimal

func ParseDecimal(s string) (float64, error)

ParseDecimal parses a decimal format coordinate. e.g: 151.196019

func ParseGPS

func ParseGPS(s string) (float64, error)

ParseGPS parses a GPS/NMEA coordinate. e.g 15113.4322S

func ParseLatLong

func ParseLatLong(s string) (float64, error)

ParseLatLong parses the supplied string into the LatLong.

Supported formats are: - DMS (e.g. 33° 23' 22") - Decimal (e.g. 33.23454) - GPS (e.g 15113.4322S)

Types

type BaseSentence

type BaseSentence struct {
	Type     string   // The sentence type (e.g $GPGSA)
	Fields   []string // Array of fields
	Checksum string   // The Checksum
	Raw      string   // The raw NMEA sentence received
}

BaseSentence contains the information about the NMEA sentence

func (BaseSentence) Prefix

func (s BaseSentence) Prefix() string

Prefix returns the type of the message

func (BaseSentence) String

func (s BaseSentence) String() string

String formats the sentence into a string

type Date

type Date struct {
	Valid bool
	DD    int
	MM    int
	YY    int
}

Date type

func ParseDate

func ParseDate(ddmmyy string) (Date, error)

ParseDate field ddmmyy format

func (Date) String

func (d Date) String() string

String representation of date

type GLGSV

type GLGSV struct {
	BaseSentence
	TotalMessages   int64       // Total number of messages of this type in this cycle
	MessageNumber   int64       // Message number
	NumberSVsInView int64       // Total number of SVs in view
	Info            []GLGSVInfo // visible satellite info (0-4 of these)
}

GLGSV represents the GPS Satellites in view http://aprs.gids.nl/nmea/#glgsv

type GLGSVInfo

type GLGSVInfo struct {
	SVPRNNumber int64 // SV PRN number, pseudo-random noise or gold code
	Elevation   int64 // Elevation in degrees, 90 maximum
	Azimuth     int64 // Azimuth, degrees from true north, 000 to 359
	SNR         int64 // SNR, 00-99 dB (null when not tracking)
}

GLGSVInfo represents information about a visible satellite

type GNGGA

type GNGGA struct {
	BaseSentence
	Time          Time    // Time of fix.
	Latitude      float64 // Latitude.
	Longitude     float64 // Longitude.
	FixQuality    string  // Quality of fix.
	NumSatellites int64   // Number of satellites in use.
	HDOP          float64 // Horizontal dilution of precision.
	Altitude      float64 // Altitude.
	Separation    float64 // Geoidal separation
	DGPSAge       string  // Age of differential GPD data.
	DGPSId        string  // DGPS reference station ID.
}

GNGGA is the Time, position, and fix related data of the receiver.

type GNRMC

type GNRMC struct {
	BaseSentence
	Time      Time    // Time Stamp
	Validity  string  // validity - A-ok, V-invalid
	Latitude  float64 // Latitude
	Longitude float64 // Longitude
	Speed     float64 // Speed in knots
	Course    float64 // True course
	Date      Date    // Date
	Variation float64 // Magnetic variation
}

GNRMC is the Recommended Minimum Specific GNSS data. http://aprs.gids.nl/nmea/#rmc

type GPGGA

type GPGGA struct {
	BaseSentence
	Time          Time    // Time of fix.
	Latitude      float64 // Latitude.
	Longitude     float64 // Longitude.
	FixQuality    string  // Quality of fix.
	NumSatellites int64   // Number of satellites in use.
	HDOP          float64 // Horizontal dilution of precision.
	Altitude      float64 // Altitude.
	Separation    float64 // Geoidal separation
	DGPSAge       string  // Age of differential GPD data.
	DGPSId        string  // DGPS reference station ID.
}

GPGGA represents fix data. http://aprs.gids.nl/nmea/#gga

type GPGLL

type GPGLL struct {
	BaseSentence
	Latitude  float64 // Latitude
	Longitude float64 // Longitude
	Time      Time    // Time Stamp
	Validity  string  // validity - A-valid
}

GPGLL is Geographic Position, Latitude / Longitude and time. http://aprs.gids.nl/nmea/#gll

type GPGSA

type GPGSA struct {
	BaseSentence
	Mode    string   // The selection mode.
	FixType string   // The fix type.
	SV      []string // List of satellite PRNs used for this fix.
	PDOP    float64  // Dilution of precision.
	HDOP    float64  // Horizontal dilution of precision.
	VDOP    float64  // Vertical dilution of precision.
}

GPGSA represents overview satellite data. http://aprs.gids.nl/nmea/#gsa

type GPGSV

type GPGSV struct {
	BaseSentence
	TotalMessages   int64       // Total number of messages of this type in this cycle
	MessageNumber   int64       // Message number
	NumberSVsInView int64       // Total number of SVs in view
	Info            []GPGSVInfo // visible satellite info (0-4 of these)
}

GPGSV represents the GPS Satellites in view http://aprs.gids.nl/nmea/#gpgsv

type GPGSVInfo

type GPGSVInfo struct {
	SVPRNNumber int64 // SV PRN number, pseudo-random noise or gold code
	Elevation   int64 // Elevation in degrees, 90 maximum
	Azimuth     int64 // Azimuth, degrees from true north, 000 to 359
	SNR         int64 // SNR, 00-99 dB (null when not tracking)
}

GPGSVInfo represents information about a visible satellite

type GPRMC

type GPRMC struct {
	BaseSentence
	Time      Time    // Time Stamp
	Validity  string  // validity - A-ok, V-invalid
	Latitude  float64 // Latitude
	Longitude float64 // Longitude
	Speed     float64 // Speed in knots
	Course    float64 // True course
	Date      Date    // Date
	Variation float64 // Magnetic variation
}

GPRMC is the Recommended Minimum Specific GNSS data. http://aprs.gids.nl/nmea/#rmc

type GPVTG

type GPVTG struct {
	BaseSentence
	TrueTrack        float64
	MagneticTrack    float64
	GroundSpeedKnots float64
	GroundSpeedKPH   float64
}

GPVTG represents track & speed data. http://aprs.gids.nl/nmea/#vtg

type GPZDA

type GPZDA struct {
	BaseSentence
	Time          Time
	Day           int64
	Month         int64
	Year          int64
	OffsetHours   int64 // Local time zone offset from GMT, hours
	OffsetMinutes int64 // Local time zone offset from GMT, minutes
}

GPZDA represents date & time data. http://aprs.gids.nl/nmea/#zda

type PGRME

type PGRME struct {
	BaseSentence
	Horizontal float64 // Estimated horizontal position error (HPE) in metres
	Vertical   float64 // Estimated vertical position error (VPE) in metres
	Spherical  float64 // Overall spherical equivalent position error in meters
}

PGRME is Estimated Position Error (Garmin proprietary sentence) http://aprs.gids.nl/nmea/#rme

type Sentence

type Sentence interface {
	fmt.Stringer
	Prefix() string
}

Sentence interface for all NMEA sentence

func Parse

func Parse(raw string) (Sentence, error)

Parse parses the given string into the correct sentence type.

type Time

type Time struct {
	Valid       bool
	Hour        int
	Minute      int
	Second      int
	Millisecond int
}

Time type

func ParseTime

func ParseTime(s string) (Time, error)

ParseTime parses wall clock time. e.g. hhmmss.ssss An empty time string will result in an invalid time.

func (Time) String

func (t Time) String() string

String representation of Time

Jump to

Keyboard shortcuts

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