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
Using pip :
pip install sbf-parser
From source :
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.pyAnd somes tools inutils - Split sbf files :
split_sbf_file.py - Re-order sbd time of week :
replace_header_time.py - Speed benchmark :
benchmark.py - Compare result of SbfParser with Septentrio sbf2ascii :
comapre_with_ascii.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
Utils
You can also use some script in utils/ to edit your sbf files :
split_sbf_file: Split Sbf file using twoTOWreplace_herder_time: Change the value ofTOW, usefull when your receiver is not connected to satellites during recordingbenchmark: If you want to stress test SbfParsercompare_with_ascii: Compare Sbf block with ascii given by RxTools
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.
Metadata
Release files for sbf-parser 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sbf_parser-1.0.3.tar.gz | 536.4 kB | Without provenance | Details for sbf_parser-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sbf_parser-1.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ x86-64 | Details for sbf_parser-1.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
Total release size: 2.7 MB
Release files / sbf_parser-1.0.3.tar.gz
| Download URL | sbf_parser-1.0.3.tar.gz |
|---|---|
| Size | 536.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
066c41c085e5644bcff4af82f7a1f7ac95a2040cacd89dc5ad2a52c104b176a2
|
|
BLAKE2b-256 checksum How to use checksums |
d0af5216f38e7d7cf3e26572a21ac691579e5d7ffca5dade8cef778f657e585d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / sbf_parser-1.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | sbf_parser-1.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7d3aaec0a1ce10689b5246172daf84dddd980153b52b4a608330a3c79156428e
|
|
BLAKE2b-256 checksum How to use checksums |
2b92f3bd6775481db509936f315ea4cfb2a6fb3cea9c182cfce0206fe626e210
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for sbf-parser 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.