Skip to main content

A Python module (in Cython) to parse SBF stream generated by Septentrio receivers.

Project description

SBF Parser Logo

SbfParser

A Python module to parse output of Septentrio receiver, including Septentrio Binary Format (SBF) & more !

This project is an update of PySbf made by Jashandeep-Sohi & Nodd and SbfParser made by MJeanneRose.

Install

# Install build dependencies
sudo apt install gcc python3 python3-pip python3-venv

# Clone project
git clone https://github.com/septentrio-gnss/SbfParser
cd SbfParser

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate

# Install package
pip install -e .

Release Notes

  • 2x faster than SbfParser (12mo/s)
  • Parsing based on SBF v4.14.10.1, including more than 35 blocks
  • Can encode sbf message
  • Lossless decoding, get raw binary of decoded messages

Usage

Parsing input stream

You have many examples in example directory :

  • Decoding input streaming : decode.py, decode_with_memory.py
  • Save parser state between calls : memory_manipulation.py
  • Encoding of sbf blocks : create_complex_block.py, create_simple_block.py
import serial
from sbf_parser import SbfParser, load

# Open your files 
with open("sbf_files/log_0000.sbf", "rb") as fobj:
    for block_type, infos in load(fobj.read()):
        print(block_type, infos)


# or read directly from serial connection
parser = SbfParser()
ser = serial.Serial(
    port='COM5', baudrate=115200,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
)

while True:
    for binary in ser.read(100):
        for block_type, infos in parser.parse(binary):
            print(block_type, infos)

You can call read(path), load(fobj) or parse(binary), directly or with SbfParser to use memory between calls. infos use this structure for SBF block:

{
    'TOW': 49638143, 
    'WNc': 2368, 
    .... 
    'AGCState': [
        {'FrontendID': 1, 'Gain': 2, 'SampleVar': 4, 'BlankingStat': 8}, 
        {'FrontendID': 16, 'Gain': 32, 'SampleVar': 64, 'BlankingStat': 128}
    ], 
    
    'blockName': 'ReceiverStatus',
    'blockType': 'SBF',
    'payload': bytearray(b'$@.......')
}

block_type can be etheir, the name of the SBF block or "Replie", "Transmission", "Description", "Snmp", "BadSBF".

Encode block

Encode a basic block; for more examples, check example.py (block with sub-block or working with files).

from sbf_parser import encode
    
event_block = {
    'TOW': 123456789,  # Time of Week in milliseconds
    'WNc': 2120,       # Week number (continuous)
    'Source': 1,       # Source identifier
    'Polarity': 0,     # Polarity (0 = rising edge)
    'Offset': 0.005,   # Time offset in seconds
    'RxClkBias': 0.0,  # Receiver clock bias
    'PVTAge': 0,        # Age of PVT in ms

    'BlockType':'SBF',
    'BlockName':'ExtEvent'
}

block_bytes = encode(event_block)

with open('ext_event.sbf', 'wb') as f:
    f.write(block_bytes)

If you don't modify block, payload is the original binary representation of the block from the parser. You can set payload_priority of encode to theses values :

PAYLOAD_PRIORITY_ALWAYS = 0 # Use payload has soon we have one
PAYLOAD_PRIORITY_ONLY_ON_FAIL = -1 # Use payload for not implemented block and when encoding failed
PAYLOAD_PRIORITY_ONLY_NOT_IMPLEMENTED = -2 # Use payload only for not implemented block
PAYLOAD_PRIORITY_NO_PAYLOAD = -3 # Never use payload

FAQ

Can I call sbf parser from C/C++ project ?

Cython allows you to call cdef functions directly from C. You may need to make minor changes to _parse function from parser.pyx to make it accessible from C, check this tutorial.

Why this code is faster even if it has more feature ?

SbfParser was using fread to parse block from files, whereas this project loads the file directly into memory and casts the blocks in the correct structure rather than reading them.

Can I read a block larger than 1 MB ?

The actual implementation uses a structure memory with a uint_8[1000000] buffer, hence the limits of 1 MB. If needed, you can fork this project and increase this memory; otherwise, larger blocks will be split in smaller unknown blocks.

For your information, large sbf blocks can be up to 4096 bytes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sbf_parser-1.0.tar.gz (531.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sbf_parser-1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (882.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

File details

Details for the file sbf_parser-1.0.tar.gz.

File metadata

  • Download URL: sbf_parser-1.0.tar.gz
  • Upload date:
  • Size: 531.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sbf_parser-1.0.tar.gz
Algorithm Hash digest
SHA256 52af1d275359aa30842e9afa94b79bf94a87570139fc161e736856da724bb75e
MD5 4d8a0a74204d81ef29234d5c88637cb0
BLAKE2b-256 7bcc0f1ad8806429866ecd2b86139224128284a5d305fa6ee784d3ba6aa32ee6

See more details on using hashes here.

File details

Details for the file sbf_parser-1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for sbf_parser-1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d500bb2befcb250d66f8240f0093c4fb9c5943712ad19d3bffd250106bcedc14
MD5 863ce6586bf0a3e2c655a62c66a263b1
BLAKE2b-256 22ed9fb7dba4e8aac935805702489015efc3b8d867cd28f843fe8eb603d605c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page