pysbf2 package

Submodules

pysbf2.exceptions module

SBF Custom Exception Types.

Created on 19 May 2025

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

exception pysbf2.exceptions.ParameterError[source]

Bases: Exception

Parameter Error Class.

exception pysbf2.exceptions.GNSSStreamError[source]

Bases: Exception

Generic Stream Error Class.

exception pysbf2.exceptions.SBFParseError[source]

Bases: Exception

SBF Parsing error.

exception pysbf2.exceptions.SBFStreamError[source]

Bases: Exception

SBF Streaming error.

exception pysbf2.exceptions.SBFMessageError[source]

Bases: Exception

SBF Undefined message class/id. Essentially a prompt to add missing payload types to SBF_PAYLOADS.

exception pysbf2.exceptions.SBFTypeError[source]

Bases: Exception

SBF Undefined payload attribute type. Essentially a prompt to fix incorrect payload definitions to SBF_PAYLOADS.

pysbf2.sbfhelpers module

sbfhelpers.py

Collection of SBF helper methods which can be used outside the SBFMessage or SBFReader classes.

Created on 19 May 2025

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

pysbf2.sbfhelpers.getpadding(length: int) bytes[source]

Generate specified number of padding bytes.

Parameters:

length – length in bytes

Returns:

bytes

Return type:

bytes

pysbf2.sbfhelpers.bytes2id(msgid: bytes) tuple[source]

Get message id and revision number from block ID.

Parameters:

msgid (bytes) – ID as bytes

Returns:

tuple of (msgid, revno)

Return type:

tuple

pysbf2.sbfhelpers.calc_crc(message: bytes) int[source]

Perform CRC-CCIT cyclic redundancy check.

Parameters:

message (bytes) – message

Returns:

CRC or 0

Return type:

int

pysbf2.sbfhelpers.crc2bytes(message: bytes) bytes[source]

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

Parameters:

message (bytes) – message including hdr and crc

Returns:

CRC as 2 bytes

Return type:

bytes

pysbf2.sbfhelpers.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

pysbf2.sbfhelpers.msgid2bytes(msgid: str) int[source]

Convert integer SBF message str to bytes.

Parameters:

msgid (str) – message id e.g. “PVTCartesian”

Returns:

message id as bytes e.g. b’¦’ (4006)

Return type:

bytes

Raises:

SBFMessageError

pysbf2.sbfhelpers.atttyp(att: str) str[source]

Helper function to return attribute type as string.

Parameters:

str – attribute type e.g. ‘U002’

Returns:

type of attribute as string e.g. ‘U’

Return type:

str

pysbf2.sbfhelpers.attsiz(att: str) int[source]

Helper function to return attribute size in bytes.

Parameters:

str – attribute type e.g. ‘U002’

Returns:

size of attribute in bytes

Return type:

int

pysbf2.sbfhelpers.val2bytes(val, att: str) bytes[source]

Convert value to bytes for given SBF attribute type.

Parameters:
  • val (object) – attribute value e.g. 25

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

Returns:

attribute value as bytes

Return type:

bytes

Raises:

SBFTypeError

pysbf2.sbfhelpers.bytes2val(valb: bytes, att: str) object[source]

Convert bytes to value for given SBF attribute type.

Parameters:
  • valb (bytes) – attribute value in byte format e.g. b’\x19\x00\x00\x00’

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

Returns:

attribute value as int, float, str or bytes

Return type:

object

Raises:

SBFTypeError

pysbf2.sbfhelpers.nomval(att: str) object[source]

Get nominal value for given SBF attribute type.

Parameters:

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

Returns:

attribute value as int, float, str or bytes

Return type:

object

Raises:

SBFTypeError

pysbf2.sbfhelpers.itow2utc(itow: int) time[source]

Convert GPS Time Of Week to UTC time

Parameters:

itow (int) – GPS Time Of Week in milliseconds

Returns:

UTC time hh.mm.ss

Return type:

datetime.time

pysbf2.sbfhelpers.utc2itow(utc: datetime) tuple[source]

Convert UTC datetime to GPS Week Number, Time Of Week

Parameters:

utc (datetime) – datetime

Returns:

GPS Week Number, Time of Week in milliseconds

Return type:

tuple

pysbf2.sbfmessage module

SBFmessage.py

Main SBF Message Protocol Class.

Created on 19 May 2025

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

class pysbf2.sbfmessage.SBFMessage(msgid: object, revno: int = 0, crc: bytes = b'\x00\x00', length: int = 0, parsebitfield: bool = True, **kwargs)[source]

Bases: object

SBF Message Class.

__init__(msgid: object, revno: int = 0, crc: bytes = b'\x00\x00', length: int = 0, parsebitfield: bool = True, **kwargs)[source]

Constructor.

If no keyword parms are passed, the payload is taken to be empty.

If ‘payload’ is passed as a keyword parm, this is taken to contain the complete payload as a sequence of bytes; any other keyword parms are ignored.

Otherwise, any named attributes will be assigned the value given, all others will be assigned a nominal value according to type.

Parameters:
  • msgid (object) – message ID as str, int or bytes

  • revid (int) – revision number (0)

  • crc (bytes) – CRC16-CCIT as 2 bytes (if b”\x00\x00”, will be derived)

  • length (int) – length (if 0, will be derived)

  • parsebitfield (bool) – parse bitfields (‘X’ type attributes) Y/N

  • kwargs – optional payload keyword arguments

Raises:

SBFMessageError

serialize() bytes[source]

Serialize message.

Returns:

serialized output

Return type:

bytes

property identity: str

Returns message identity in plain text form.

Returns:

message identity e.g. ‘PVTCartesian’

Return type:

str

property payload: bytes

Payload getter - returns the raw payload bytes.

Returns:

raw payload as bytes

Return type:

bytes

pysbf2.sbfreader module

sbfreader.py

SBFReader class.

Reads and parses individual NMEA, SBF and RTCM messages from any viable data stream which supports a read(n) -> bytes method.

SBF message bit format (little-endian):

sync

crc

revno

msgid

length

payload

padding

0x2440

16 bits

3 bits

13 bits

16 bits

variable

0-24 bits

8 bytes

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

  • ‘protfilter’ governs which protocols (NMEA, SBF, RTCM) are processed

  • ‘quitonerror’ governs how errors are handled

Created on 19 May 2025

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

class pysbf2.sbfreader.SBFReader(datastream, validate: int = 1, protfilter: int = 7, quitonerror: int = 1, parsebitfield: bool = True, bufsize: int = 4096, parsing: bool = True, errorhandler: object = None)[source]

Bases: object

SBFReader class.

__init__(datastream, validate: int = 1, protfilter: int = 7, quitonerror: int = 1, parsebitfield: bool = True, bufsize: int = 4096, parsing: bool = True, errorhandler: object = None)[source]

Constructor.

Parameters:
  • stream (datastream) – input data stream

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

  • protfilter (int) – NMEA_PROTOCOL (1), SBF_PROTOCOL (2), RTCM3_PROTOCOL (4), Can be OR’d (7)

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

  • parsebitfield (bool) – 1 = parse bitfields, 0 = leave as bytes (1)

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

  • parsing (bool) – True = parse data, False = don’t parse data (output raw only) (True)

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

Raises:

SBFStreamError (if mode is invalid)

read() tuple[source]

Read a single NMEA, SBF or RTCM3 message from the stream buffer and return both raw and parsed data.

‘protfilter’ determines which protocols are parsed. ‘quitonerror’ determines whether to raise, log or ignore parsing errors.

Returns:

tuple of (raw_data as bytes, parsed_data as SBFMessage, NMEAMessage or RTCMMessage)

Return type:

tuple

Raises:

Exception (if invalid or unrecognised protocol in data stream)

property datastream: object

Getter for stream.

Returns:

data stream

Return type:

object

static parse(message: bytes, validate: int = 1, parsebitfield: bool = True) object[source]

Parse SBF byte stream to SBFMessage object.

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

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

  • parsebitfield (bool) – 1 = parse bitfields, 0 = leave as bytes (1)

Returns:

SBFMessage object

Return type:

SBFMessage

Raises:

SBFMessageError (if data stream contains invalid CRC)

pysbf2.sbftypes_blocks module

sbftypes_blocks.py

SBF Protocol output payload definitions.

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

Created on 19 May 2025

Info sourced from mosaic-X5 Reference Guide v4.14.10 © 2000-2024 Septentrio NV/SA

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

pysbf2.sbftypes_core module

sbftypes_core.py

SBF Protocol core globals, constants, datatypes and message identifiers.

Created on 19 May 2025

Info sourced from mosaic-X5 Reference Guide v4.14.10 © 2000-2024 Septentrio NV/SA

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

pysbf2.sbftypes_core.SBF_HDR = b'$@'

SBF message header

pysbf2.sbftypes_core.ERR_RAISE = 2

Raise error and quit

pysbf2.sbftypes_core.ERR_LOG = 1

Log errors

pysbf2.sbftypes_core.ERR_IGNORE = 0

Ignore errors

pysbf2.sbftypes_core.NMEA_PROTOCOL = 1

NMEA Protocol

pysbf2.sbftypes_core.RTCM3_PROTOCOL = 4

RTCM3 Protocol

pysbf2.sbftypes_core.SBF_PROTOCOL = 2

SBF Protocol

pysbf2.sbftypes_core.VALNONE = 0

Do not validate checksum

pysbf2.sbftypes_core.VALCKSUM = 1

Validate checksum

pysbf2.sbftypes_core.ATTTYPE = {'C': (<class 'bytes'>, <class 'str'>), 'F': (<class 'int'>, <class 'float'>), 'I': <class 'int'>, 'P': <class 'bytes'>, 'U': <class 'int'>, 'V': <class 'bytes'>, 'X': <class 'bytes'>}

Permissible attribute types

pysbf2.sbftypes_decodes module

sbftypes_decodes.py

SBF Protocol attribute value decode constants.

Created on 19 May 2025

Info sourced from mosaic-X5 Reference Guide v4.14.10 © 2000-2024 Septentrio NV/SA

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause

pysbf2.sbftypes_decodes.SIGNAL_TYPE = {0: ('L1CA', 'GPS', 1575.4, '1C'), 1: ('L1P', 'GPS', 1575.42, '1W'), 2: ('L2P', 'GPS', 1227.6, '2W'), 3: ('L2C', 'GPS', 1227.6, '2L'), 4: ('L5', 'GPS', 1176.45, '5Q'), 5: ('L1C', 'GPS', 1575.42, '1L'), 6: ('L1CA', 'QZSS', 1575.42, '1C'), 7: ('L2C', 'QZSS', 1227.6, '2L'), 8: ('L1CA', 'GLONASS', 1602.0, '1C'), 9: ('L1P', 'GLONASS', 1602.0, '1P'), 10: ('L2P', 'GLONASS', 1246.0, '2P'), 11: ('L2CA', 'GLONASS', 1246.0, '2C'), 12: ('L3', 'GLONASS', 1202.025, '3Q'), 13: ('B1C', 'BeiDou', 1575.42, '1P'), 14: ('B2a', 'BeiDou', 1176.45, '5P'), 15: ('L5', 'NavIC', 1176.45, '5A'), 16: ('Reserved', '', 0, ''), 17: ('E1', 'Galileo', 1575.42, '1C'), 18: ('Reserved', '', 0, ''), 19: ('E6', 'Galileo', 1278.75, '6C/6B'), 20: ('E5a', 'Galileo', 1176.45, '5Q'), 21: ('E5b', 'Galileo', 1207.14, '7Q'), 22: ('E5 AltBOC', 'Galileo', 1191.795, '8Q'), 23: ('LBand', 'MSS', 0, 'NA'), 24: ('L1CA', 'SBAS', 1575.42, '1C'), 25: ('L5', 'SBAS', 1176.45, '5I'), 26: ('L5', 'QZSS', 1176.45, '5Q'), 27: ('L6', 'QZSS', 1278.75, ''), 28: ('B1I', 'BeiDou', 1561.098, '2I'), 29: ('B2I', 'BeiDou', 1207.14, '7I'), 30: ('B3I', 'BeiDou', 1268.52, '6I'), 31: ('Reserved', '', 0, ''), 32: ('L1C', 'QZSS', 1575.42, '1L'), 33: ('L1S', 'QZSS', 1575.42, '1Z'), 34: ('B2b', 'BeiDou', 1207.14, '7D'), 35: ('Reserved', '', 0, ''), 36: ('Reserved', '', 0, ''), 37: ('Reserved', '', 0, ''), 38: ('L1CB', 'QZSS', 1575.42, '1E'), 39: ('L5S', 'QZSS', 1176.45, '5P')}

Signal Type Decode, aka “SigIdxLo” or “SigIdxHi” with offset 32.

Number: (Signal Code, Constellation, Base Frequency, RINEX Code)

pysbf2.sbftypes_decodes.PVT_TYPE = {0: 'No GNSS PVT available', 1: 'Stand-Alone PVT', 2: 'Differential PVT', 3: 'Fixed location', 4: 'RTK with fixed ambiguities', 5: 'RTK with float ambiguities', 6: 'SBAS aided PVT', 7: 'Moving-base RTK with fixed ambiguities', 8: 'Moving-base RTK with float ambiguities', 9: 'Reserved', 10: 'Precise Point Positioning (PPP)', 12: 'Reserved'}

PVT Type (bits 0-3 of Mode) decode

pysbf2.sbftypes_decodes.PVT_ERROR = {0: 'No Error', 1: 'Not enough measurements', 2: 'Not enough ephemerides available', 3: 'DOP too large (larger than 15)', 4: 'Sum of squared residuals too large', 5: 'No convergence', 6: 'Not enough measurements after outlier rejection', 7: 'Position output prohibited due to export laws', 8: 'Not enough differential corrections available', 9: 'Base station coordinates unavailable', 10: 'Ambiguities not fixed and user requested to only output RTKfixed'}

PVT Error decode

pysbf2.sbftypes_decodes.PVT_TIMESYSTEM = {0: 'GPS time', 1: 'Galileo time', 3: 'GLONASS time', 4: 'BeiDou time', 5: 'QZSS time', 100: 'Fugro AtomiChron time'}

PVT Timesystem decode

pysbf2.sbftypes_decodes.PVT_DATUM = {0: 'WGS84/ITRS', 19: 'Datum equal to that used by the DGNSS/RTK base station', 30: 'ETRS89 (ETRF2000 realization)', 31: 'NAD83(2011), North American Datum (2011)', 32: 'NAD83(PA11), North American Datum, Pacific plate (2011)', 33: 'NAD83(MA11), North American Datum, Marianas plate (2011)', 34: 'GDA94(2010), Geocentric Datum of Australia (2010)', 35: 'GDA2020, Geocentric Datum of Australia 2020', 36: 'JGD2011, Japanese Geodetic Datum 2011', 250: 'First user-defined datum', 251: 'Second user-defined datum'}

PVT Datum decode

pysbf2.sbftypes_decodes.PVT_RTK_TYPE = {0: 'unknown or not in differential positioning mode(DGNSS or RTK)', 1: 'corrections from a physical base', 2: 'corrections from a virtual base (VRS)', 3: 'SSR corrections (RTK using SSR corrections is often referred to as RTK-SSR or PPP-RTK)'}

PVT RTK Type from WACorrInfo aka Corr_RTKType

Module contents

Created on 19 May 2025

author:

semuadmin

copyright:

SEMU Consulting © 2020

license:

BSD 3-Clause