Trying to set configuration from configuration file #145
-
Hi, I use many Ublox GPS ZED-F9P and I want to configure them automatically. For instance, I use U-Center to 1-"Update the firmware" from a file on my computer, 2-"Load configuration" from a configuration file on my computer generated by U-Center in a .txt format. I use an Ubuntu 18.04.5 version with python 3.6.9 so I use an old version of pyubx2 (1.2.14). I have already check examples "ubxconfigdb.py" and "ubxfile.py" but I don't really understand how they work and how I can use them to achieve my goal. It's important to precise that I just discover the UBX protocol so I don't really understand all its specifications. I think there is already someone who make something similar, but I can't find him. Thanks by advanced ! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hi @MelvinWarnet I'm converting this issue to a Discussion as it's not a code issue in |
Beta Was this translation helpful? Give feedback.
-
Firstly, please be aware that neither PyGPSClient nor pyubx2 can update the firmware on any u-blox device. This involves the use of private, proprietary message types and procedures which u-blox will not permit me to include in these open source libraries. I have tried to remonstrate with u-blox, but they are adamant that this functionality be excluded. |
Beta Was this translation helpful? Give feedback.
-
To clarify, it's perfectly possible to create a u-blox firmware update utility using Python, but you'd have to obtain the information directly from u-blox and they'll probably ask you to sign a Non-Disclosure Agreement (NDA). I'm not permitted to publish the information myself here. |
Beta Was this translation helpful? Give feedback.
-
I can't help you with firmware updates, but here's a simple python3 load_txt_config.py port="/dev/ttyACM0" baud=38400 infile="ucenter.txt" """
load_txt_config.py
Loads contents of u-center *.txt configuration file into u-blox
receiver via designed serial port.
Usage:
python3 load_txt_config.py port="/dev/ttyACM0" baud=38400 infile="ucenter.txt"
or, for dry run without updating receiver:
python3 load_txt_config.py infile="ucenter.txt" dryrun=1
"""
from sys import argv
from serial import Serial
from pyubx2 import (
POLL_LAYER_BBR,
POLL_LAYER_FLASH,
SET,
SET_LAYER_BBR,
SET_LAYER_FLASH,
SET_LAYER_RAM,
TXN_NONE,
U1,
UBXMessage,
bytes2val,
val2bytes,
)
CFG = b"\x06"
VALGET = b"\x8b"
VALSET = b"\x8a"
def load_txt(fname: str, output: Serial) -> int:
"""
Load u-center format text configuration file.
Any messages other than CFG-MSG, CFG-PRT or CFG-VALGET are discarded.
The CFG-VALGET messages are converted into CFG-VALGET.
:param str fname: fully qualified input file name
:param Serial output: output serial stream
:return: no of items read
:rtype: int
"""
# pylint: disable=too-many-locals, broad-exception-caught
try:
with open(fname, "r", encoding="utf-8") as file:
i = 0
for line in file:
parts = line.replace(" ", "").split("-")
data = bytes.fromhex(parts[-1])
cls = data[0:1]
mid = data[1:2]
if cls != CFG:
continue
if mid == VALGET: # config database command
version = data[4:5]
layer = bytes2val(data[5:6], U1)
if layer == POLL_LAYER_BBR:
layers = SET_LAYER_BBR
elif layer == POLL_LAYER_FLASH:
layers = SET_LAYER_FLASH
else:
layers = SET_LAYER_RAM
layers = val2bytes(layers, U1)
transaction = val2bytes(TXN_NONE, U1) # not transactional
reserved0 = b"\x00"
cfgdata = data[8:]
payload = version + layers + transaction + reserved0 + cfgdata
parsed = UBXMessage(CFG, VALSET, SET, payload=payload)
else: # legacy CFG command
parsed = UBXMessage(CFG, mid, SET, payload=data[4:])
if parsed is not None:
# send CFG message to receiver
print(parsed)
if output is not None:
output.write(parsed.serialize())
i += 1
except Exception:
print(f"ERROR parsing {fname}!")
return 0
print(f"{i} configuration commands processed")
return i
def main(**kwargs):
"""
Main routine.
"""
infile = kwargs.get("infile", "ucenter.txt")
port = kwargs.get("port", "/dev/ttyACM0")
baud = int(kwargs.get("baud", 38400))
dryrun = int(kwargs.get("dryrun", 0))
if dryrun:
load_txt(infile, None)
else:
with Serial(port, baud, timeout=5) as stream:
load_txt(infile, stream)
if __name__ == "__main__":
main(**dict(arg.split("=") for arg in argv[1:])) |
Beta Was this translation helpful? Give feedback.
I can't help you with firmware updates, but here's a simple
pyubx2
code snippet you could run at the Ubuntu command line which uploads the contents of a u-center *.txt configuration file to a u-blox receiver at a designated serial port: