pyrtcm package

Submodules

pyrtcm.exceptions module

RTCM Custom Exception Types

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

exception pyrtcm.exceptions.ParameterError[source]

Bases: Exception

Parameter Error Class.

exception pyrtcm.exceptions.RTCMParseError[source]

Bases: Exception

RTCM Parsing error.

exception pyrtcm.exceptions.RTCMStreamError[source]

Bases: Exception

RTCM Streaming error.

exception pyrtcm.exceptions.RTCMMessageError[source]

Bases: Exception

RTCM Undefined message class/id. Essentially a prompt to add missing payload types to rtcm_PAYLOADS.

exception pyrtcm.exceptions.RTCMTypeError[source]

Bases: Exception

RTCM Undefined payload attribute type. Essentially a prompt to fix incorrect payload definitions to rtcm_PAYLOADS.

pyrtcm.rtcmhelpers module

Collection of RTCM helper methods which can be used outside the RTCMMessage or RTCMReader classes

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

pyrtcm.rtcmhelpers.att2idx(att: str) int[source]

Get integer index corresponding to grouped attribute.

e.g. DF389_06 -> 6; DF406_103 -> 103

Parameters:

att (str) – grouped attribute name e.g. DF406_01

Returns:

index as integer, or 0 if not grouped

Return type:

int

pyrtcm.rtcmhelpers.att2name(att: str) str[source]

Get name of grouped attribute.

e.g. DF389_06 -> DF389; DF406_103 -> DF406

Parameters:

att (str) – grouped attribute name e.g. DF406_01

Returns:

name without index e.g. DF406

Return type:

str

pyrtcm.rtcmhelpers.calc_crc24q(message: bytes) int[source]

Perform CRC24Q cyclic redundancy check.

If the message includes the appended CRC bytes, the function will return 0 if the message is valid. If the message excludes the appended CRC bytes, the function will return the applicable CRC.

Parameters:

message (bytes) – message

Returns:

CRC or 0

Return type:

int

pyrtcm.rtcmhelpers.crc2bytes(message: bytes) bytes[source]

Generate CRC as 3 bytes, suitable for constructing RTCM message transport.

Parameters:

message (bytes) – message including header & length but _without_ CRC

Returns:

CRC as 3 bytes

Return type:

bytes

pyrtcm.rtcmhelpers.len2bytes(payload: bytes) bytes[source]

Generate payload length as 2 bytes, suitable for constructing RTCM message transport.

Parameters:

payload (bytes) – message payload (i.e. _without_ header, length or CRC)

Returns:

payload length as 2 bytes padded with leading zeros

Return type:

bytes

pyrtcm.rtcmhelpers.datadesc(datafield: str) str[source]

Get description of data field.

Parameters:

datafield (str) – datafield e.g. ‘DF234’

Returns:

datafield description

Return type:

str

pyrtcm.rtcmhelpers.get_bit(data: bytes, num: int) int[source]

Get specified bit from bytes.

Parameters:
  • data (bytes) – data

  • num (int) – bit position

Returns:

selected bit value

Return type:

int

pyrtcm.rtcmhelpers.tow2utc(tow: int) time[source]

Convert GPS Time Of Week to UTC time (UTC = GPS - 18 seconds; correct as from 1/1/2017).

Parameters:

tow (int) – GPS Time Of Week

Returns:

UTC time hh.mm.ss

Return type:

datetime.time

pyrtcm.rtcmhelpers.hextable(raw: bytes, cols: int = 8) str[source]

Formats raw (binary) message in tabular hexadecimal format e.g.

000: 2447 4e47 5341 2c41 2c33 2c33 342c 3233 | b’$GNGSA,A,3,34,23’ |

Parameters:
  • raw (bytes) – raw (binary) data

  • cols (int) – number of columns in hex table (8)

Returns:

table of hex data

Return type:

str

pyrtcm.rtcmhelpers.escapeall(val: bytes) str[source]

Escape all byte characters e.g. b’\x73’ rather than b`s`

Parameters:

val (bytes) – bytes

Returns:

string of escaped bytes

Return type:

str

pyrtcm.rtcmhelpers.parse_msm(msg: object) tuple[source]

Parse individual MSM message into iterable data arrays.

Parameters:

msg (RTCMMessage) – RTCM MSM Message

Returns:

tuple of (metadata, sat data array, cell data array)

Return type:

tuple

pyrtcm.rtcmhelpers.parse_4076_201(msg: object)[source]

Parse individual 4076_201 message into iterable data arrays.

Parameters:

parsed (RTCMMessage) – parsed 4076_201 message

Returns:

dict of {metadata, [cosine coefficients], [sine coefficients]} for each layer

Return type:

dict

pyrtcm.rtcmmessage module

Main RTCM Message Protocol Class.

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

class pyrtcm.rtcmmessage.RTCMMessage(payload: bytes = None, labelmsm: int = 1)[source]

Bases: object

RTCM Message Class.

__init__(payload: bytes = None, labelmsm: int = 1)[source]

Constructor.

Parameters:
  • payload (bytes) – message payload (mandatory)

  • labelmsm (int) – MSM NSAT and NCELL attribute label (1 = RINEX, 2 = freq)

Raises:

RTCMMessageError

serialize() bytes[source]

Serialize message.

Returns:

serialized output

Return type:

bytes

property identity: str

Getter for identity.

Returns:

message identity e.g. “1005”

Return type:

str

property payload: bytes

Payload getter - returns the raw payload bytes.

Returns:

raw payload as bytes

Return type:

bytes

property ismsm: bool

Check if message is Multiple Signal Message (MSM) type.

Returns:

True/False

Return type:

bool

pyrtcm.rtcmreader module

RTCMReader class.

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

RTCM3 transport layer bit format:

0xd3

000000

length

type

content

crc

8 bits

6 bits

10 bits

12 bits

variable

24 bits

payload; length x 8

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

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

class pyrtcm.rtcmreader.RTCMReader(datastream, validate: int = 1, quitonerror: int = 1, labelmsm: int = 1, bufsize: int = 4096, parsed: bool = True, errorhandler: object = None, encoding: int = 0)[source]

Bases: object

rtcmReader class.

__init__(datastream, validate: int = 1, quitonerror: int = 1, labelmsm: int = 1, bufsize: int = 4096, parsed: bool = True, errorhandler: object = None, encoding: int = 0)[source]

Constructor.

Parameters:
  • stream (datastream) – input data stream

  • validate (int) – 0 = ignore invalid checksum, 1 = validate checksum (1)

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

  • labelmsm (int) – MSM NSAT and NCELL attribute label (1 = RINEX, 2 = freq)

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

  • parsed (bool) – 1 = return raw and parsed data, 0 = return only raw data (parsed = None) (1)

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

  • encoding (int) – encoding for socket stream (0 = none, 1 = chunk, 2 = gzip, 4 = compress, 8 = deflate (can be OR’d)) (0)

Raises:

RTCMStreamError (if mode is invalid)

read() tuple[source]

Read a single RTCM message from the stream buffer and return both raw and parsed data.

‘quitonerror’ determines whether to raise, log or ignore parsing errors.

Returns:

tuple of (raw_data as bytes, parsed_data as RTCMMessage)

Return type:

tuple

Raises:

RTCMStreamError (if unrecognised protocol in data stream)

property datastream: object

Getter for stream.

Returns:

data stream

Return type:

object

static parse(message: bytes, validate: int = 1, labelmsm: int = 1) RTCMMessage[source]

Parse RTCM message to RTCMMessage object.

Parameters:
  • message (bytes) – RTCM raw message bytes

  • validate (int) – 0 = don’t validate CRC, 1 = validate CRC (1)

  • labelmsm (int) – MSM NSAT and NCELL attribute label (1 = RINEX, 2 = freq)

Returns:

RTCMMessage object

Return type:

RTCMMessage

Raises:

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

pyrtcm.rtcmtables module

RTCM Lookup and Decode Tables

Created on 7 Jul 2022

Information sourced from RTCM STANDARD 10403.3 © 2016 RTCM

author:

semuadmin

pyrtcm.rtcmtypes_core module

RTCM Protocol core globals and constants

Created on 14 Feb 2022

Information sourced from RTCM STANDARD 10403.3 © 2016 RTCM

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

pyrtcm.rtcmtypes_core.UBX_HDR = b'\xb5b'

UBX message header

pyrtcm.rtcmtypes_core.RTCM_HDR = b'\xd3'

RTCM3 message header

pyrtcm.rtcmtypes_core.GET = 0

GET (receive, response) message types

pyrtcm.rtcmtypes_core.SET = 1

SET (command) message types

pyrtcm.rtcmtypes_core.POLL = 2

POLL (query) message types

pyrtcm.rtcmtypes_core.SETPOLL = 3

SETPOLL (SET or POLL) message types

pyrtcm.rtcmtypes_core.VALNONE = 0

Do not validate checksum

pyrtcm.rtcmtypes_core.VALCKSUM = 1

Validate checksum

pyrtcm.rtcmtypes_core.NMEA_PROTOCOL = 1

NMEA Protocol

pyrtcm.rtcmtypes_core.UBX_PROTOCOL = 2

UBX Protocol

pyrtcm.rtcmtypes_core.RTCM3_PROTOCOL = 4

RTCM3 Protocol

pyrtcm.rtcmtypes_core.ERR_RAISE = 2

Raise error and quit

pyrtcm.rtcmtypes_core.ERR_LOG = 1

Log errors

pyrtcm.rtcmtypes_core.ERR_IGNORE = 0

Ignore errors

pyrtcm.rtcmtypes_core.DEFAULT_BUFSIZE = 4096

Default socket buffer size

pyrtcm.rtcmtypes_core.ENCODE_NONE = 0

No socket encoding

pyrtcm.rtcmtypes_core.ENCODE_CHUNKED = 1

chunked socket encoding

pyrtcm.rtcmtypes_core.ENCODE_GZIP = 2

gzip socket encoding

pyrtcm.rtcmtypes_core.ENCODE_COMPRESS = 4

compress socket encoding

pyrtcm.rtcmtypes_core.ENCODE_DEFLATE = 8

deflate socket encoding

pyrtcm.rtcmtypes_core.GNSSMAP = {'107': ('GPS', 'DF004'), '108': ('GLONASS', 'DF034'), '109': ('GALILEO', 'DF248'), '110': ('SBAS', 'DF004'), '111': ('QZSS', 'DF428'), '112': ('BEIDOU', 'DF427'), '113': ('NAVIC', 'DF546')}

Map of MSM message identity prefix to GNSS name & epoch attribute name

pyrtcm.rtcmtypes_core.SSR_SPHER_COEFFS = {'1264': {0: ('DF476', 'Cosine Coefficients'), 1: ('DF477', 'Sine Coefficients')}, '4076_201': {0: ('IDF039', 'Cosine Coefficients'), 1: ('IDF040', 'Sine Coefficients')}}

Map of 4076_201 and 1264 spherical coefficient data attributes

pyrtcm.rtcmtypes_core.SSR_COEFF = {'DF475': ('DF474', 'DF475'), 'IDF038': ('IDF037', 'IDF038')}

Map of 4076_201 and 1264 special coefficient attributes

pyrtcm.rtcmtypes_get module

RTCM Protocol Standard payload definitions

Created on 14 Feb 2022

Information sourced from RTCM STANDARD 10403.3 © 2016 RTCM

Message definitions 1240-1264 sourced from from: - Proposal of new RTCM SSR Messages SSR Stage 1: Galileo, QZSS, SBAS, BDS - Proposal of new RTCM SSR Messages SSR Stage 2: Vertical TEC (VTEC)

Payload definitions are contained in a series of dictionaries. Repeating and conditional elements are defined as a tuple of (element size/presence designator, element dictionary). The element size/presence designator can take one of the following forms:

Repeating elements:
  • an integer representing the fixed size of the repeating element N.

  • a string representing the name of a preceding attribute containing the size of the repeating element N e.g.

"groupsat": (
    "IDF010",
    {
        "IDF011": "GNSS Satellite ID",
        etc ...
    },
),
Conditional elements:
  • a tuple containing a string and a value, representing the name of a preceding attribute and the value it must take in order for the optional element to be present e.g.

"optL1CA": (
    ("DF422_1", 1),  # if DF422_1 = 1
    {
        "DF423": "GLONASS L1 C/A Code-Phase Bias",
    },
),

A ‘+1’ or ‘+2’ suffix indicates that the attribute name must be suffixed with the specified number of nested element indices e.g. ‘“IDF023+1”’ -> ‘“IDF023_01”’

In some instances, the size of the repeating element is derived from multiple attributes. In these cases the element size is denoted by a composite attribute name which is calculated within rtcmmessage.py e.g. ‘NHARMCOEFFC’

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

pyrtcm.rtcmtypes_get_igs module

RTCM Protocol IGS payload definitions

Information sourced from https://files.igs.org/pub/data/format/igs_ssr_v1.pdf

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

pyrtcm.rtcmtypes_get_msm module

RTCM Protocol MSM payload definitions

Information sourced from RTCM STANDARD 10403.3 © 2016 RTCM

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause

pyrtcm.socketwrapper module

socketwrapper.py

Socket stream wrapper providing read(n) and readline() methods.

Supports chunked and compressed transfer-encoded datastreams.

Created on 12 Feb 2023

author:

semuadmin

copyright:

SEMU Consulting © 2023

license:

BSD 3-Clause

class pyrtcm.socketwrapper.SocketWrapper(sock: <module 'socket' from '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py'>, encoding=0, bufsize=4096)[source]

Bases: object

Socket stream wrapper providing read(n) and readline() methods.

Supports chunked transfer-encoded datastreams.

__init__(sock: <module 'socket' from '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py'>, encoding=0, bufsize=4096)[source]

Constructor.

Parameters:
  • socket (sock) – socket object

  • encoding (int) – transfer-encoding values (0 = none, 1 = chunk, 2 = gzip, 4 = compress, 8 = deflate (can be OR’d) (0)

  • bufsize (int) – internal buffer size

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 CRLF reached. NB: always check that return data terminator is CRLF.

Returns:

bytes

Return type:

bytes

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

Write bytes to socket.

Parameters:
  • data (bytes) – data

  • kwargs (dict) – kwargs

in_waiting() int[source]

Return number of bytes in buffer.

Returns:

length of buffer

Return type:

int

dechunk(segment: bytes) tuple[source]

Parse segment of chunked transfer-encoded byte stream.

Returns complete chunks in this segment and any partial chunk, which should be prepended to next segment read.

Parameters:

segment – segment of byte stream

Returns:

tuple of (chunks, partial)

Return type:

tuple

property buffer: bytearray

Getter for buffer.

Returns:

buffer

Return type:

bytearray

Module contents

Created on 14 Feb 2022

author:

semuadmin

copyright:

SEMU Consulting © 2022

license:

BSD 3-Clause