pynmeagps package

Submodules

pynmeagps.exceptions module

NMEA Custom Exception Types

Created on 04 Mar 2021

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

exception pynmeagps.exceptions.NMEAParseError[source]

Bases: Exception

NMEA Parsing error.

exception pynmeagps.exceptions.NMEAStreamError[source]

Bases: Exception

NMEA Streaming error.

exception pynmeagps.exceptions.NMEAMessageError[source]

Bases: Exception

NMEA Undefined message class/id. Essentially a prompt to add missing payload types to UBX_PAYLOADS.

exception pynmeagps.exceptions.NMEATypeError[source]

Bases: Exception

NMEA Undefined payload attribute type. Essentially a prompt to fix incorrect payload definitions to UBX_PAYLOADS.

pynmeagps.nmeahelpers module

Collection of NMEA helper methods which can be used outside the NMEAMessage or NMEAReader classes

Created on 04 Mar 2021

author:

semuadmin

copyright:

SEMU Consulting © 2021

license:

BSD 3-Clause

pynmeagps.nmeahelpers.get_parts(message: object) tuple[source]

Get content, talker, msgid, payload and checksum of raw NMEA message.

Parameters:

message (object) – entire message as bytes or string

Returns:

tuple of (content, talker, msgID, payload as list, checksum)

Return type:

tuple

Raises:

NMEAMessageError (if message is badly formed)

pynmeagps.nmeahelpers.calc_checksum(content: object) str[source]

Calculate checksum for raw NMEA message.

Parameters:

content (object) – NMEA message content (everything except checksum)

Returns:

checksum as hex string

Return type:

str

pynmeagps.nmeahelpers.generate_checksum(talker: str, msgID: str, payload: list) str[source]

Generate checksum for new NMEA message.

Parameters:
  • talker (str) – talker e.g. “GN”

  • msgID (str) – msgID e.g. “GLL”

  • payload (list) – payload as list

Returns:

checksum as hex string

Return type:

str

pynmeagps.nmeahelpers.dmm2ddd(pos: str) float[source]

Convert NMEA lat/lon string to (unsigned) decimal degrees.

Parameters:

pos (str) – (d)ddmm.mmmmm

Returns:

pos as decimal degrees

Return type:

float or str if invalid

pynmeagps.nmeahelpers.ddd2dmm(degrees: float, att: str, hpmode: bool = False) str[source]

Convert decimal degrees to native NMEA degrees decimal minutes string (NB: standard NMEA only supports 5dp minutes precision - a high precision mode offers 7dp precision but this may not be accepted by all NMEA parsers).

Parameters:
  • degrees (float) – degrees

  • att (str) – ‘LA’ (lat) or ‘LN’ (lon)

  • hpmode (bool) – high precision mode (7dp rather than 5dp)

Returns:

degrees as (d)ddmm.mmmmm(mm) formatted string

Return type:

str

pynmeagps.nmeahelpers.date2utc(dates: str, form: str = 'DT') date[source]

Convert NMEA Date to UTC datetime.

Parameters:
  • dates (str) – NMEA date

  • form (str) – date format DT = ddmmyy, DTL = ddmmyyyy, DM = mmddyy (DT)

Returns:

UTC date YYyy:mm:dd

Return type:

datetime.date

pynmeagps.nmeahelpers.time2utc(times: str) time[source]

Convert NMEA Time to UTC datetime.

Parameters:

times (str) – NMEA time hhmmss.ss

Returns:

UTC time hh:mm:ss.ss

Return type:

datetime.time

pynmeagps.nmeahelpers.time2str(tim: ~.datetime.time) str[source]

Convert datetime.time to NMEA formatted string.

Parameters:

tim (datetime.time) – time

Returns:

NMEA formatted time string hhmmss.ss

Return type:

str

pynmeagps.nmeahelpers.date2str(dat: ~.datetime.date, form: str = 'DT') str[source]

Convert datetime.date to NMEA formatted string.

Parameters:
  • dat (datetime.date) – date

  • form (str) – date format DT = ddmmyy, DTL = ddmmyyyy, DM = mmddyy (DT)

Returns:

NMEA formatted date string

Return type:

str

pynmeagps.nmeahelpers.knots2spd(knots: float, unit: str = 'MS') float[source]

Convert speed in knots to speed in specified units.

Parameters:
  • knots (float) – knots

  • str (unit) – ‘MS’ (default), ‘FS’, MPH’, ‘KMPH’

Returns:

speed in m/s, feet/s, mph or kmph

Return type:

float

pynmeagps.nmeahelpers.msgdesc(msgID: str) str[source]

Return descriptive string for NMEA msgId.

Parameters:

str (msgID) – message ID e.g. ‘GGA’

Returns:

description of message

Return type:

str

pynmeagps.nmeahelpers.latlon2dms(lat: float, lon: float) tuple[source]

Converts decimal lat/lon tuple to degrees minutes seconds.

Parameters:
  • lat (float) – lat

  • lon (float) – lon

Returns:

(lat,lon) in d.m.s. format

Return type:

tuple

pynmeagps.nmeahelpers.latlon2dmm(lat: float, lon: float) tuple[source]

Converts decimal lat/lon tuple to degrees decimal minutes.

Parameters:
  • lat (float) – lat

  • lon (float) – lon

Returns:

(lat,lon) in d.mm.m format

Return type:

tuple

pynmeagps.nmeahelpers.deg2dms(degrees: float, att: str) str[source]

Convert decimal degrees to degrees minutes seconds string e.g. ‘51°20′45.6″N’

Parameters:
  • degrees (float) – degrees

  • att (str) – ‘LA’ (lat) or ‘LN’ (lon)

Returns:

degrees as d.m.s formatted string

Return type:

str

pynmeagps.nmeahelpers.deg2dmm(degrees: float, att: str) str[source]

Convert decimal degrees to degrees decimal minutes string e.g. ‘51°20.76′S’.

Parameters:
  • degrees (float) – degrees

  • att (str) – ‘LA’ (lat) or ‘LN’ (lon)

Returns:

degrees as dm.m formatted string

Return type:

str

pynmeagps.nmeahelpers.llh2iso6709(lat: float, lon: float, alt: float, crs: str = 'WGS_84') str[source]

Convert decimal degrees and alt to ISO6709 format e.g. “+27.5916+086.5640+8850CRSWGS_84/”.

Parameters:
  • lat (float) – latitude

  • lon (float) – longitude

  • alt (float) – altitude (hMSL)

  • crs (float) – coordinate reference system (default = WGS_84)

Returns:

position in ISO6709 format

Return type:

str

pynmeagps.nmeahelpers.ecef2llh(x: float, y: float, z: float, a: float = 6378137.0, f: float = 298.257223563) tuple[source]

Convert ECEF coordinates to geodetic (LLH) using Olson algorithm.

Olson, D. K. (1996). Converting Earth-Centered, Earth-Fixed Coordinates to Geodetic Coordinates. IEEE Transactions on Aerospace and Electronic Systems, 32(1), 473-476. https://doi.org/10.1109/7.481290

Parameters:
  • x (float) – X coordinate

  • y (float) – Y coordinate

  • z (float) – Z coordinate

  • a (float) – semi-major axis (6378137.0 for WGS84)

  • f (float) – flattening (298.257223563 for WGS84)

Returns:

tuple of (lat, lon, ellipsoidal height in m) as floats

Return type:

tuple

pynmeagps.nmeahelpers.llh2ecef(lat: float, lon: float, height: float, a: float = 6378137.0, f: float = 298.257223563) tuple[source]

Convert geodetic coordinates (LLH) to ECEF.

Parameters:
  • lat (float) – lat in degrees

  • lon (float) – lon on degrees

  • height (float) – ellipsoidal height in metres

  • a (float) – semi-major axis (6378137.0 for WGS84)

  • f (float) – flattening (298.257223563 for WGS84)

Returns:

tuple of ECEF (X, Y, Z) as floats

Return type:

tuple

pynmeagps.nmeahelpers.haversine(lat1: float, lon1: float, lat2: float, lon2: float, radius: int = 6378.137) float[source]

Calculate spherical distance in km between two coordinates using haversine formula.

NB suitable for coordinates greater than around 50m apart. For smaller separations, use the planar approximation formula.

Parameters:
  • lat1 (float) – lat1

  • lon1 (float) – lon1

  • lat2 (float) – lat2

  • lon2 (float) – lon2

  • radius (float) – radius in km (Earth = 6378.137 km)

Returns:

spherical distance in km

Return type:

float

pynmeagps.nmeahelpers.planar(lat1: float, lon1: float, lat2: float, lon2: float, radius: int = 6378137.0) float[source]

Calculate planar distance between two coordinates using planar approximation formula.

NB suitable for coordinates less than around 50m apart. For larger separations, use the haversine great circle formula.

Parameters:
  • lat1 (float) – lat1

  • lon1 (float) – lon1

  • lat2 (float) – lat2

  • lon2 (float) – lon2

  • radius (float) – radius in m (Earth = 6378137 m)

Returns:

planar distance in m

Return type:

float

pynmeagps.nmeahelpers.bearing(lat1: float, lon1: float, lat2: float, lon2: float) float[source]

Calculate bearing between two coordinates.

Parameters:
  • lat1 (float) – lat1

  • lon1 (float) – lon1

  • lat2 (float) – lat2

  • lon2 (float) – lon2

Returns:

bearing in degrees

Return type:

float

pynmeagps.nmeahelpers.area(lat1: float, lon1: float, lat2: float, lon2: float, radius: int = 6378.137) float[source]

Calculate spherical area bounded by two coordinates.

Parameters:
  • lat1 (float) – lat1

  • lon1 (float) – lon1

  • lat2 (float) – lat2

  • lon2 (float) – lon2

  • radius (float) – radius in km (Earth = 6378.137 km)

Returns:

area in km²

Return type:

float

pynmeagps.nmeahelpers.get_gpswnotow(dat: datetime) tuple[source]

Get GPS Week number (Wno) and Time of Week (Tow) for midnight on given date.

GPS Epoch 0 = 6th Jan 1980

Parameters:

dat (datetime) – calendar date

Returns:

tuple of (Wno, Tow)

Return type:

tuple

pynmeagps.nmeamessage module

Main NMEA GNSS/GPS Message Protocol Class.

Created on 04 Mar 2021

author:

semuadmin

copyright:

SEMU Consulting © 2021

license:

BSD 3-Clause

class pynmeagps.nmeamessage.NMEAMessage(talker: str, msgID: str, msgmode: int, hpnmeamode: bool = False, validate: int = 1, userdefined: dict = None, **kwargs)[source]

Bases: object

NMEA GNSS/GPS Message Class.

__init__(talker: str, msgID: str, msgmode: int, hpnmeamode: bool = False, validate: int = 1, userdefined: dict = None, **kwargs)[source]

Constructor.

If ‘payload’ is passed as a keyword arg, this is taken to contain the entire message content as a list of string values; any other keyword args are ignored.

Otherwise, any individual attributes passed as keyword args will be set to the value provided, all others will be assigned a nominal value according to type.

Parameters:
  • talker (str) – message talker e.g. “GP” or “P”

  • msgID (str) – message ID e.g. “GGA”

  • msgmode (int) – mode (0=GET, 1=SET, 2=POLL)

  • hpnmeamode (bool) – high precision lat/lon mode (7dp rather than 5dp) (False)

  • validate (int) – VALNONE (0), VALCKSUM (1), VALMSGID (2), (can be OR’d) (1)

  • userdefined (dict) – user-defined payload definition dictionary (None)

  • kwargs – keyword arg(s) representing all or some payload attributes

Raises:

NMEAMessageError

serialize() bytes[source]

Serialize message.

Returns:

serialized output

Return type:

bytes

property identity: str

Identity getter.

Returns:

message identity e.g. GNGSA

Return type:

str

property talker: str

Talker getter.

Returns:

talker e.g. GN

Return type:

str

property msgID: str

Message id getter.

Returns:

message id e.g. GSA

Return type:

str

property msgmode: int

Message mode getter.

Returns:

message mode

Return type:

int

property payload: list

Payload getter.

Returns:

raw payload as list of strings

Return type:

list

property checksum: str

Checksum getter.

Returns:

checksum as hex string

Return type:

str

static str2val(vals: str, att: str) object[source]

Convert NMEA string to typed value (this is the format that will be available to end users).

Parameters:
  • vals (str) – attribute value in NMEA protocol format

  • att (str) – attribute type e.g. ‘DE’

Returns:

attribute value

Return type:

object

Raises:

MMEATypeError

static val2str(val, att: str, hpmode: bool = False) str[source]

Convert typed value to NMEA string (this is the format used internally by the NMEA protocol).

Parameters:
  • val (object) – typed attribute value

  • att (str) – attribute type e.g. ‘IN’

  • hpmode (bool) – high precision lat/lon mode (7dp rather than 5dp)

Returns:

attribute value in NMEA protocol format

Return type:

str

Raises:

NMEATypeError

static nomval(att: str) object[source]

Return nominal value for specified attribute type

Parameters:

att (str) – attribute type e.g. ‘DE’

Returns:

nominal value for type

Return type:

object

Raises:

NMEATypeError

pynmeagps.nmeareader module

NMEAReader class.

Reads and parses individual NMEA GNSS/GPS messages from any stream which supports a read(n) -> bytes method.

Can also read from socket via SocketStream wrapper.

Returns both the raw binary data (as bytes) and the parsed data (as an NMEAMessage object).

Implements an iterator: for raw, parsed in NMEAReader(stream):

If the ‘nmeaonly’ kwarg is set to ‘True’, the reader will raise a NMEAParseError if it encounters any non-NMEA data. Otherwise, it will ignore the non-NMEA data and attempt to carry on.

Created on 4 Mar 2021

author:

semuadmin

copyright:

SEMU Consulting © 2021

license:

BSD 3-Clause

class pynmeagps.nmeareader.NMEAReader(stream, msgmode: int = 0, validate: int = 1, nmeaonly: bool = False, quitonerror: int = 1, bufsize: int = 4096, errorhandler: object = None, userdefined: dict = None)[source]

Bases: object

NMEAReader class.

__init__(stream, msgmode: int = 0, validate: int = 1, nmeaonly: bool = False, quitonerror: int = 1, bufsize: int = 4096, errorhandler: object = None, userdefined: dict = None)[source]

Constructor.

Parameters:
  • stream (stream) – input data stream (e.g. Serial or binary File)

  • msgmode (int) – 0=GET, 1=SET, 2=POLL (0)

  • validate (int) – VALNONE (0), VALCKSUM (1), VALMSGID (2), (can be OR’d) (1)

  • nmeaonly (bool) – True = error on non-NMEA data, False = ignore non-NMEA data

  • quitonerror (int) – ERR_IGNORE (0) = ignore errors, ERR_LOG (1) = log continue, ERR_RAISE (2) = (re)raise (1)

  • bufsize (int) – socket recv buffer size (4096)

  • errorhandler (object) – error handling object or function (None)

  • userdefined (dict) – user-defined payload definition dictionary (None)

Raises:

NMEAParseError (if mode is invalid)

read() tuple[source]

Read the binary data from the stream buffer.

Returns:

tuple of (raw_data as bytes, parsed_data as NMEAMessage)

Return type:

tuple

Raises:

NMEAStreamError (if nmeaonly=True and stream includes non-NMEA data)

property datastream: object

Getter for stream.

Returns:

data stream

Return type:

object

static parse(message: bytes, msgmode: int = 0, validate: int = 1, userdefined: dict = None) object[source]

Parse NMEA byte stream to NMEAMessage object.

Parameters:
  • message (bytes) – bytes message to parse

  • msgmode (int) – 0=GET, 1=SET, 2=POLL (0)

  • validate (int) – VALNONE (0), VALCKSUM (1), VALMSGID (2), (can be OR’d) (1)

  • userdefined (dict) – user-defined payload definition dictionary (None)

Returns:

NMEAMessage object (or None if unknown message and VALMSGID is not set)

Return type:

NMEAMessage

Raises:

NMEAParseError (if data stream contains invalid data or unknown message type)

pynmeagps.nmeatypes_core module

NMEA Protocol core globals and constants

Created on 4 Mar 2021

While the NMEA 0183 © protocol is proprietary, the information here has been collated from public domain sources.

author:

semuadmin

pynmeagps.nmeatypes_core.INPUT = 1

Input message type

pynmeagps.nmeatypes_core.OUTPUT = 0

Output message type

pynmeagps.nmeatypes_core.GET = 0

GET (receive, response) message types

pynmeagps.nmeatypes_core.SET = 1

SET (command) message types

pynmeagps.nmeatypes_core.POLL = 2

POLL (query) message types

pynmeagps.nmeatypes_core.SETPOLL = 3

SETPOLL (SET or POLL) message types

pynmeagps.nmeatypes_core.VALNONE = 0

Do not validate checksum or msgid

pynmeagps.nmeatypes_core.VALCKSUM = 1

Validate checksum

pynmeagps.nmeatypes_core.VALMSGID = 2

Validate message id

pynmeagps.nmeatypes_core.NMEA_PROTOCOL = 1

NMEA Protocol

pynmeagps.nmeatypes_core.UBX_PROTOCOL = 2

UBX Protocol

pynmeagps.nmeatypes_core.RTCM3_PROTOCOL = 4

RTCM3 Protocol

pynmeagps.nmeatypes_core.ERR_RAISE = 2

Raise error and quit

pynmeagps.nmeatypes_core.ERR_LOG = 1

Log errors

pynmeagps.nmeatypes_core.ERR_IGNORE = 0

Ignore errors

pynmeagps.nmeatypes_core.DEF_STND = 0

Standard message definition

pynmeagps.nmeatypes_core.DEF_PROP = 1

Proprietary message definition

pynmeagps.nmeatypes_core.DEF_USER = 2

User-defined message definition

pynmeagps.nmeatypes_core.DEF_UNKN = 3

Unknown (not public domain) message definition

pynmeagps.nmeatypes_core.GNSSLIST = {0: 'GPS', 1: 'SBAS', 2: 'Galileo', 3: 'BeiDou', 4: 'IMES', 5: 'QZSS', 6: 'GLONASS', 7: 'NAVIC'}

GNSS code

pynmeagps.nmeatypes_core.FIXTYPE_GGA = {0: 'NO FIX', 1: '3D', 2: '3D', 4: 'RTK FIXED', 5: 'RTK FLOAT', 6: 'DR'}

Fix type from GGA

pynmeagps.nmeatypes_core.GPSEPOCH0 = datetime.datetime(1980, 1, 6, 0, 0)

GPS epoch base date

pynmeagps.nmeatypes_core.WGS84 = 'WGS_84'

WGS84 datum descriptor

pynmeagps.nmeatypes_core.WGS84_SMAJ_AXIS = 6378137.0

WGS84 semi-major axis

pynmeagps.nmeatypes_core.WGS84_FLATTENING = 298.257223563

WGS84 flattening

pynmeagps.nmeatypes_core.NMEA_TALKERS = {'AB': 'Independent AIS Base Station', 'AD': 'Dependent AIS Base Station', 'AG': 'Heading Track Controller (Autopilot): General', 'AI': 'Mobile Class A or B AIS Station', 'AN': 'AIS Aids to Navigation Station', 'AP': 'Heading Track Controller (Autopilot): Magnetic', 'AR': 'AIS Receiving Station', 'AS': 'AIS Station (ITU_R M1371, (Limited Base Station))', 'AT': 'AIS Transmitting Station', 'AX': 'AIS Simplex Repeater Station', 'BD': 'BDS (BeiDou System)', 'BI': 'Bilge Systems', 'BN': 'Bridge Navigational Watch Alarm System', 'CA': 'Central Alarm Management', 'CD': 'Digital Selective Calling (DSC)', 'CR': 'Data Receiver', 'CS': 'Satellite', 'CT': 'Radio-Telephone (MF/HF)', 'CV': 'Radio-Telephone (VHF)', 'CX': 'Scanning Receiver', 'DE': 'DECCA Navigator', 'DF': 'Direction Finder', 'DP': 'Dynamic Position', 'DU': 'Duplex Repeater Station', 'EC': 'Electronic Chart System (ECS)', 'EI': 'Electronic Chart Display & Information System (ECDIS)', 'EP': 'Emergency Position Indicating Beacon (EPIRB)', 'ER': 'Engine Room Monitoring Systems', 'FD': 'Fire Door Controller/Monitoring Point', 'FE': 'Fire Extinguisher System', 'FR': 'Fire Detection Point', 'FS': 'Fire Sprinkler System', 'GA': 'Galileo Positioning System', 'GB': 'BDS (BeiDou System)', 'GI': 'NavIC (IRNSS)', 'GL': 'GLONASS Receiver', 'GN': 'Global Navigation Satellite System (GNSS)', 'GP': 'Global Positioning System (GPS)', 'GQ': 'QZSS', 'HC': 'Compass, Magnetic', 'HD': 'Hull Door Monitoring', 'HE': 'Gyro, North Seeking', 'HF': 'Fluxgate', 'HN': 'Gyro, Non-North Seeking', 'HS': 'Hull Stress Monitoring', 'IC': 'Integrated Communications System', 'II': 'Integrated Instrumentation', 'IN': 'Integrated Navigation', 'LC': 'Loran C', 'MP': 'Microprocessor  Controller', 'ND': 'Network Device', 'NL': 'Navigation Light Controller', 'P': 'Proprietary', 'RA': 'Radar and/or Radar Plotting', 'RC': 'Propulsion Machinery including Remote Control', 'SA': 'Physical Shore AIS Station', 'SC': 'Steering Control System/Device', 'SD': 'Sounder, Depth', 'SG': 'Steering Gear/Steering Engine', 'SI': 'Serial to Network Gateway Function', 'SN': 'Electronic Positioning System', 'SS': 'Sounder, Scanning', 'TC': 'Track Control System', 'TI': 'Turn Rate Indicator', 'U0': 'User-configured talker identifier', 'U1': 'User-configured talker identifier', 'U2': 'User-configured talker identifier', 'U3': 'User-configured talker identifier', 'U4': 'User-configured talker identifier', 'U5': 'User-configured talker identifier', 'U6': 'User-configured talker identifier', 'U7': 'User-configured talker identifier', 'U8': 'User-configured talker identifier', 'U9': 'User-configured talker identifier', 'UP': 'Microprocessor Controller', 'VD': 'Doppler', 'VM': 'Speed Log, Water, Magnetic', 'VR': 'Voyage Data Recorder', 'VW': 'Speed Log, Water, Mechanical', 'WD': 'Watertight Door Controller/Monitoring Panel', 'WI': 'Weather Instruments', 'WL': 'Water Level Detection Systems', 'YX': 'Transducer', 'ZA': 'Atomic Clock', 'ZC': 'Chronometer', 'ZQ': 'Quartz', 'ZV': 'Radio Update'}

Recognised NMEA Talkers.

pynmeagps.nmeatypes_core.NMEA_MSGIDS = {'AAM': 'Waypoint arrival alarm', 'ABK': 'AIS addressed and binary broadcast acknowledgement', 'ABM': 'AIS addressed binary and safety related message', 'ACA': 'AIS channel assignment message', 'ACK': 'Acknowledge alarm', 'ACN': 'Alert Command', 'ACS': 'AIS channel management information source', 'AIR': 'AIS interrogation request', 'AKD': 'Acknowledge detail alarm condition7', 'ALA': 'Report detailed alarm condition', 'ALC': 'Cyclic alert list', 'ALF': 'Alert sentence', 'ALR': 'Set alarm state', 'APA': 'Auto Pilot A sentence', 'APB': 'Heading/track controller (autopilot) sentence', 'ARC': 'Alert command refused', 'BBM': 'AIS broadcast binary message', 'BEC': 'Bearing and distance to waypoint - Dead reckoning', 'BOD': 'Bearing origin to destination', 'BWC': 'Bearing and distance to waypoint - Great circle', 'BWR': 'Bearing and distance to waypoint - Rhumb line', 'BWW': 'Bearing waypoint to waypoint', 'CUR': 'Water current layer - Multi-layer water current data', 'DBT': 'Depth below transducer', 'DDC': 'Display dimming control', 'DOR': 'Door status detection', 'DPT': 'Depth', 'DSC': 'Digital selective calling information', 'DSE': 'Expanded digital selective calling', 'DTM': 'Datum reference', 'EPV': 'Command or report equipment property value', 'ETL': 'Engine telegraph operation status', 'EVE': 'General event message', 'FIR': 'Fire detection', 'FOO': 'Dummy message', 'FSI': 'Frequency set information', 'GAQ': 'Poll Standard Message - Talker ID GA (Galileo)', 'GBQ': 'Poll Standard Message - Talker ID GB (BeiDou)', 'GBS': 'GNSS satellite fault detection', 'GEN': 'Generic binary information', 'GFA': 'GNSS fix accuracy and integrity', 'GGA': 'Global positioning system fix data', 'GLL': 'Geographic position - Latitude/longitude', 'GLQ': 'Poll Standard Message - Talker ID GL (GLONASS)', 'GMP': 'GNSS Map Projection Fix Data', 'GNQ': 'Poll Standard Message - Talker ID GN (Any GNSS)', 'GNS': 'GNSS Fix Data', 'GPQ': 'Poll Standard Message - Talker ID GP (GPS, SBAS)', 'GQQ': 'Poll Standard Message - Talker ID GQ (QZSS)', 'GRS': 'GNSS range residuals', 'GSA': 'GNSS DOP and active satellites', 'GST': 'GNSS pseudorange noise statistics', 'GSV': 'GNSS satellites in view', 'HBT': 'Heartbeat supervision sentence', 'HCR': 'Heading correction report', 'HDG': 'Heading, deviation and variation', 'HDM': 'Heading, Magnetic', 'HDT': 'Heading true', 'HMR': 'Heading monitor receive', 'HMS': 'Heading monitor set', 'HRM': 'heel angle, roll period and roll amplitude measurement device', 'HSC': 'Heading steering command', 'HSS': 'Hull stress surveillance systems', 'HTC': 'Heading/track control command', 'HTD': 'Heading /track control', 'LLQ': 'Leica local position and quality', 'LR1': 'AIS long-range reply sentence 1', 'LR2': 'AIS long-range reply sentence 2', 'LR3': 'AIS long-range reply sentence 3', 'LRF': 'AIS long-range function', 'LRI': 'AIS long-range interrogation', 'MOB': 'Man over board notification', 'MSK': 'MSK receiver interface', 'MSS': 'MSK receiver signal status', 'MTW': 'Water temperature', 'MWD': 'Wind direction and speed', 'MWV': 'Wind speed and angle', 'NAK': 'Negative acknowledgement', 'NRM': 'NAVTEX receiver mask', 'NRX': 'NAVTEX received message', 'NSR': 'Navigation status report', 'OSD': 'Own ship data', 'POS': 'Device position and ship dimensions report or configuration', 'PRC': 'Propulsion remote control status', 'RLM': 'Return link message', 'RMA': 'Recommended minimum specific LORAN-C data', 'RMB': 'Recommended minimum navigation information', 'RMC': 'Recommended minimum specific GNSS data', 'ROR': 'Rudder order status', 'ROT': 'Rate of turn', 'RPM': 'Revolutions', 'RRT': 'Report route transfer', 'RSA': 'Rudder sensor angle', 'RSD': 'Radar system data', 'RTE': 'Routes', 'SFI': 'Scanning frequency information', 'SM1': 'SafetyNET Message, All Ships/NavArea', 'SM2': 'SafetyNET Message, Coastal Warning Area', 'SM3': 'SafetyNET Message, Circular Area address', 'SM4': 'SafetyNET Message, Rectangular Area Address', 'SMB': 'IMO SafetyNET Message Body', 'SPW': 'Security password sentence', 'SSD': 'AIS ship static data', 'STN': 'Multiple data ID', 'THS': 'True heading and status', 'TLB': 'Target label', 'TLL': 'Target latitude and longitude', 'TRC': 'Thruster control data', 'TRD': 'Thruster response data', 'TRF': 'Transit Fix Data', 'TRL': 'AIS transmitter-non-functioning log', 'TTD': 'Tracked target data', 'TTM': 'Tracked target message', 'TUT': 'Transmission of multi-language text', 'TXT': 'Text transmission', 'UID': 'User identification code transmission', 'VBW': 'Dual ground/water speed', 'VDM': 'AIS VHF data-link message', 'VDO': 'AIS VHF data-link own-vessel report', 'VDR': 'Set and drift', 'VER': 'Version', 'VHW': 'Water speed and heading', 'VLW': 'Dual ground/water distance', 'VPW': 'Speed measured parallel to wind', 'VSD': 'AIS voyage static data', 'VTG': 'Course over ground and ground speed', 'WAT': 'Water level detection', 'WCV': 'Waypoint closure velocity', 'WNC': 'Distance waypoint to waypoint', 'WPL': 'Waypoint location', 'XDR': 'Transducer measurements', 'XTE': 'Cross-track error, measured', 'XTR': 'Cross-track error, dead reckoning', 'ZDA': 'Time and date', 'ZDL': 'Time and distance to variable point', 'ZFO': 'UTC and time from origin waypoint', 'ZTG': 'UTC and time to destination waypoint'}

Recognised Standard NMEA Message Identifiers.

Payload definitions for standard GET messages are defined in NMEA_PAYLOADS_GET. Standard POLL messages are defined in NMEA_PAYLOADS_POLL.

pynmeagps.nmeatypes_core.NMEA_MSGIDS_PROP = {'ASHR': 'RT300 Roll and Pitch', 'ASHRALR': 'Alarms', 'ASHRARA': 'True Heading', 'ASHRARR': 'Vector & Accuracy', 'ASHRATT': 'True Heading', 'ASHRBTS': 'Bluetooth Status', 'ASHRCAP': 'Parameters of Antenna Used at Received Base', 'ASHRCPA': 'Height of Antenna Used at Received Base', 'ASHRCPO': 'Position of Received Base', 'ASHRDDM': 'Differential Decoder Message', 'ASHRDDS': 'Differential Decoder Status', 'ASHRHPR': 'True Heading', 'ASHRLTN': 'Latency', 'ASHRMDM': 'Modem State and Parameter', 'ASHRPBN': 'Position and Velocity Information', 'ASHRPOS': 'Position', 'ASHRPTT': 'PPS Time Tag', 'ASHRPWR': 'Power Status', 'ASHRRCS': 'Recording Status', 'ASHRSBD': 'BEIDOU Satellites Status', 'ASHRSGA': 'GALILEO Satellites Status (E1,E5a,E5b)', 'ASHRSGL': 'GLONASS Satellites Status', 'ASHRSGO': 'GALILEO Satellites Status (E1,E5a,E5b,E6)', 'ASHRSGP': 'GPS Satellites Status', 'ASHRSIR': 'IRNSS Satellites Status', 'ASHRSLB': 'L-Band Satellites Status', 'ASHRSQZ': 'QZSS Satellites Status', 'ASHRSSB': 'SBAS Satellites Status', 'ASHRTEM': 'Receiver Temperature', 'ASHRTHS': 'True Heading and Status', 'ASHRTTT': 'Event Marker', 'ASHRVCR': 'Vector and Accuracy', 'ASHRVCT': 'Vector and Accuracy', 'ASHRVEL': 'Velocity', 'FECGPATT': 'Attitude yaw, pitch, roll', 'FECGPHVE': 'Heave', 'FUGDP': 'Fugro Dynamic Positioning', 'GPPADV110': 'Position and satellite information for RTK network operations 110', 'GPPADV120': 'Position and satellite information for RTK network operations 120', 'GRMB': 'DGPS Beacon Information', 'GRMC': 'Set Sensor Configuration information', 'GRMC1': 'Set Additional Sensor Configuration Information', 'GRME': 'Estimated Error Information', 'GRMF': 'GPS Fix Data sentence', 'GRMH': 'Aviation Height and VNAV data', 'GRMI': 'Set Sensor Initialisation Information', 'GRMM': 'MapDatum', 'GRMO': 'Set Output Sentence Enable', 'GRMT': 'Sensor Status Information', 'GRMV': '3D Velocity Information', 'GRMW': 'Set Additional Waypoint Information', 'GRMZ': 'Altitude', 'INVCRES': 'Clear the NVM data', 'INVCSTR': 'Start session', 'INVMATTIT': 'ATTIT information', 'INVMIMU': 'MEMS RAW-DATA message information', 'INVMINR': 'Calibration status', 'INVMSLOPE': 'SLOPE information', 'INVMSTR': 'Session Status', 'KLDS': 'Position, Speed, Course', 'KLSH': 'FleetSync GNSS sentence', 'KNDS': 'Position, Speed, Course', 'KNSH': 'Position', 'KWDWPL': 'Waypoint Location', 'LSC': 'Set status/poll version', 'LSR': 'Set status response', 'LSVD': 'Attitude yaw, pitch, roll', 'MGNWPL': 'Waypoint Location', 'TNLAVR': 'Time, yaw, tilt/roll, range for moving baseline RTK', 'TNLBPQ': 'Base station position and quality indicator', 'TNLDG': 'L-band corrections and beacon signal strength and related information', 'TNLEVT': 'Event marker data', 'TNLGGK': 'Time, position, position type, DOP', 'TNLGGKx': 'GNSS Position Message', 'TNLPJK': 'Local coordinate position output', 'TNLPJT': 'Projection type', 'TNLREX': 'Rover Extended Output', 'TNLVGK': 'Vector information', 'TNLVHD': 'Heading information', 'UBX00': 'PUBX-POSITION Lat/Long Position Data', 'UBX03': 'PUBX-SVSTATUS Satellite Status', 'UBX04': 'PUBX-TIME Time of Day and Clock Information', 'UBX05': 'Lat/Long Position Data', 'UBX06': 'Lat/Long Position Data', 'UBX40': 'Set NMEA message output rate', 'UBX41': 'PUBX-CONFIG Set Protocols and Baudrate'}

Recognised Proprietary NMEA Message Identifiers.

Payload definitions for proprietary GET messages are defined in NMEA_PAYLOADS_GET_PROP. Proprietary SET and POLL messages are defined in NMEA_PAYLOADS_SET and NMEA_PAYLOADS_POLL.

pynmeagps.nmeatypes_core.NMEA_PREFIX_PROP = ('FEC', 'UBX', 'TNL', 'ASHR', 'GPPADV')

Proprietary NMEA Message Prefixes where msgId is part of payload.

For proprietary messages with these prefixes, the msgId is defined as the first element of the payload. The unique payload dictionary key is therefore a combination of prefix + msgId.

NB: There are some exceptions which require special handling e.g. PASHR.

pynmeagps.nmeatypes_get module

NMEA Protocol Output payload definitions

THESE ARE THE PAYLOAD DEFINITIONS FOR _GET_ MESSAGES _FROM_ THE RECEIVER (e.g. Periodic Navigation Data; Poll Responses; Info messages).

NB: Attribute names must be unique within each message id. NB: Avoid reserved names ‘msgID’, ‘talker’, ‘payload’, ‘checksum’.

NB: Repeating groups must be defined as a tuple thus

‘group’: (‘numr’, {dict}) where - ‘numr’ is either:

  1. an integer representing a fixed number of repeats e.g 32

  2. a string representing the name of a preceding attribute containing the number of repeats e.g. ‘numCh’

  3. ‘None’ for an indeterminate repeating group (only one such group is permitted per message type)

  • {dict} is the nested dictionary containing the repeating attributes

Created on 4 Mar Sep 2021

While the NMEA 0183 © protocol is proprietary, the information here has been collated from public domain sources.

author:

semuadmin

pynmeagps.nmeatypes_get_prop module

NMEA Protocol Proprietary Output payload definitions

THESE ARE THE PAYLOAD DEFINITIONS FOR PROPRIETARY _GET_ MESSAGES _FROM_ THE RECEIVER (e.g. Periodic Navigation Data; Poll Responses; Info messages).

NB: Attribute names must be unique within each message id. NB: Avoid reserved names ‘msgID’, ‘talker’, ‘payload’, ‘checksum’.

NB: Repeating groups must be defined as a tuple thus

‘group’: (‘numr’, {dict}) where - ‘numr’ is either:

  1. an integer representing a fixed number of repeats e.g 32

  2. a string representing the name of a preceding attribute containing the number of repeats e.g. ‘numCh’

  3. ‘None’ for an indeterminate repeating group (only one such group is permitted per message type)

  • {dict} is the nested dictionary containing the repeating attributes

Created on 4 Mar Sep 2021

While the NMEA 0183 © protocol is proprietary, the information here has been collated from public domain sources.

author:

semuadmin

pynmeagps.nmeatypes_poll module

NMEA Protocol Poll payload definitions

THESE ARE THE PAYLOAD DEFINITIONS FOR _POLL_ MESSAGES _TO_ THE RECEIVER (e.g. Message Poll requests).

NB: Attribute names must be unique within each message id. NB: Avoid reserved names ‘msgID’, ‘talker’, ‘payload’, ‘checksum’.

Created on 4 Mar Sep 2021

While the NMEA 0183 © protocol is proprietary, the information here has been collated from public domain sources.

author:

semuadmin

pynmeagps.nmeatypes_set module

NMEA Protocol Set payload definitions

THESE ARE THE PAYLOAD DEFINITIONS FOR _SET_ MESSAGES _TO_ THE RECEIVER (e.g. Configuration commands).

NB: Attribute names must be unique within each message id. NB: Avoid reserved names ‘msgID’, ‘talker’, ‘payload’, ‘checksum’.

NB: Repeating groups must be defined as a tuple thus

‘group’: (‘numr’, {dict}) where - ‘numr’ is either:

  1. an integer representing a fixed number of repeats e.g 32

  2. a string representing the name of a preceding attribute containing the number of repeats e.g. ‘numCh’

  3. ‘None’ for an indeterminate repeating group (only one such group is permitted per message type)

  • {dict} is the nested dictionary containing the repeating attributes

Created on 4 Mar Sep 2021

While the NMEA 0183 © protocol is proprietary, the information here has been collated from public domain sources.

author:

semuadmin

pynmeagps.socket_wrapper module

socket_wrapper class.

A skeleton socket wrapper which provides basic stream-like read(bytes) and readline() methods.

NB: this will read from a socket indefinitely. It is the responsibility of the calling application to monitor data returned and implement appropriate socket error, timeout or inactivity procedures.

Created on 4 Apr 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

class pynmeagps.socket_wrapper.SocketWrapper(sock: socket, **kwargs)[source]

Bases: object

socket stream class.

__init__(sock: socket, **kwargs)[source]

Constructor.

Parameters:
  • socket (sock) – socket object

  • bufsize (int) – (kwarg) internal buffer size (4096)

property buffer: bytearray

Getter for buffer.

Returns:

buffer

Return type:

bytearray

read(num: int) bytes[source]

Read specified number of bytes from buffer. NB: always check length of return data.

Parameters:

num (int) – number of bytes to read

Returns:

bytes read (which may be less than num)

Return type:

bytes

readline() bytes[source]

Read bytes from buffer until LF reached. NB: always check that return data terminator is LF.

Returns:

bytes

Return type:

bytes

write(data: bytes, **kwargs)[source]

Write bytes to socket.

Parameters:

data (bytes) – data

Returns:

None if successful

Return type:

Nonetype

Module contents

Created on 4 Mar 2021

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause