A lightweight python library for translating UBX packets
Project description
ubxtranslator
Overview
This module provides a simple way to decode messages from uBlox GPS devices in the UBX format.
Like the high accuracy NEO-M8U module that I have created,
click here for more info.
This package has no dependencies! This is written in pure python using only the standard lib and supports any
standard byte stream. The predefined messages are not added to the parser by default, this allows
you to have tight control over what messages can be parsed.
Is this the fastest implementation of a UBX parser? Probably not. If speed is critical then you probably need to go write something in C. If you want something that is fast enough and easy to use, you are in the right place. Keep reading.
Supports Python 3.5 and up.
Quickstart
Install the package with pip
pip install ubxtranslator
Import the core module
from ubxtranslator import core
If the message class you want has already been defined simply import it.
If not you will need to construct the messages and classes yourself, see the examples for more information.
from ubxtranslator import predefined
Construct the parser
parser = core.Parser([
predefined.CLS_ACK,
predefined.CLS_NAV
])
Then you can use the parser to decode messages from any byte stream.
cls_name, msg_name, payload = parser.receive_from(port)
The result is a tuple which can be unpacked as shown above.
The variables cls_name
and msg_name
are strings, ie. 'NAV'
, 'PVT'
.
The payload is the namedtuple of the message and can be accessed like an object. The attributes share the names of the fields.
print(cls_name, msg_name, payload.lat, payload.lng)
Bitfields are also returned as namedtuples and can be accessed the same way.
print(payload.flags.channel)
Repeated Blocks are returned as a list of blocks, the fields within each block are also named tuples. All of the repeated blocks in the predefined messages are name RB
.
for i in range(len(payload.RB)):
print(payload.RB[i].gnssId, payload.RB[i].flags.health)
The best way to look at what fields are available is where the fields are defined. However, if you want to inspect on the fly you can either help(payload)
and look at the attributes, or use the named tuple protected method payload._asdict()
which will return an ordered dict of all of the attributes.
Examples
For full examples see the examples directory.
TODO's
Want to contribute? Please feel free to submit issues or pull requests. Nothing in this package is very complicated, please have a crack and help me to improve this.
- Add the ability to pack messages into packets for two way communications
- Add more and better tests
- Add Field type RU1_3
- Add async support
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
Built Distribution
File details
Details for the file ubxtranslator-0.2.5.tar.gz
.
File metadata
- Download URL: ubxtranslator-0.2.5.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a9b1608df1cc482491328abcaab7aa8b700ef2705f40d3931735c78c462e817 |
|
MD5 | 9c681f48797c09c3ac28889c14e45acc |
|
BLAKE2b-256 | 0b342771f21d156c59093911281b744f0ae165720e5d7016be513d544e86666b |
File details
Details for the file ubxtranslator-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: ubxtranslator-0.2.5-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e47eb64e815669fe0ebe905b98b2972de779a9bccd05f2f2f8336afdb6edb633 |
|
MD5 | b7eefd190a9005c88cfec412921b36c0 |
|
BLAKE2b-256 | aa9ffc0c89d259f5101cbaf3606c44cc40b14e4f0d000a812c1201e56b8f0035 |