You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
elifatt==ubt.R4: # single precision floating point
valb=struct.pack("<f", val)
elifatt==ubt.R8: # double precision floating point
valb=struct.pack("<d", val)
else:
raiseube.UBXTypeError(f"Unknown attribute type {att}")
returnvalb
which returns integer instead of bytes in case of bitmask attribute.
Adding to_bytes() conversion fixes the issue.
This is especially critical for X8 type, where little-endian conversion is a must.
I don't see why X1/2/4/8 attributes need to be treated differently from U1/2/4/8 ones
fronders
changed the title
UBXMessage.config_set() throws ValueType exception for config item of X1 type
UBXMessage.config_set() throws TypeError for config item of X1 type
Dec 27, 2024
This is expected behaviour for X type attributes. The UBX protocol makes an intentional distinction between U (unsigned integer) and X (byte) types, and pyubx2 has to observe this distinction. Not all X type attributes can be interpreted as unsigned integers (the majority are actually character strings), so a .to_bytes() conversion would not be appropriate in all cases.
In this case the issue can be simply resolved by supplying the value as bytes, i.e.:
As to why some config database values are defined as X when a U (or C) type would seem more intuitive - I'm afraid you'll have to ask u-blox that question!
OK, fair enough, I see many X8 ones are char sequences, while X1, X2 and X4 mostly are bitmasks (which should be treated as unsigned imo). But at least the fact that you need to pass little-endian bytes to cfgData needs to be documented somewhere :) The val2bytes(val, att) behavior is a bit inconsistent then, as one would expect it to return bytes. Maybe check for incoming val type and raise an exception telling user to pass bytes instead of dying silently?
Describe the bug
UBXMessage.config_set() tries to lookup attribute types and fails because of
val2bytes()
function foratt
tovalb
conversionIssue is caused by code on line 281:
pyubx2/src/pyubx2/ubxhelpers.py
Lines 265 to 297 in 1227e03
which returns integer instead of bytes in case of bitmask attribute.
Adding
to_bytes()
conversion fixes the issue.This is especially critical for
X8
type, where little-endian conversion is a must.I don't see why
X1/2/4/8
attributes need to be treated differently fromU1/2/4/8
onesInfo
To Reproduce
Steps to reproduce the behaviour:
Desktop:
GNSS/GPS Device:
The text was updated successfully, but these errors were encountered: