Skip to content

Commit ec4ee76

Browse files
authored
Merge pull request #174 from semuconsulting/RC-1.2.49
Rc 1.2.49
2 parents 1227e03 + 6e48a39 commit ec4ee76

File tree

13 files changed

+94
-18
lines changed

13 files changed

+94
-18
lines changed

.github/workflows/checkpr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.9, "3.10", "3.11", "3.12", "3.13.0-rc.3"]
11+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
1212

1313
steps:
1414
- uses: actions/checkout@v4

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [3.9, "3.10", "3.11", "3.12", "3.13.0-rc.3"]
13+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
1414

1515
steps:
1616
- uses: actions/checkout@v4

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"editor.formatOnSave": true,
55
"modulename": "${workspaceFolderBasename}",
66
"distname": "${workspaceFolderBasename}",
7-
"moduleversion": "1.2.48",
7+
"moduleversion": "1.2.49",
88
}

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# pyubx2 Release Notes
22

3+
### RELEASE 1.2.49
4+
5+
ENHANCEMENTS:
6+
7+
1. Enhance pyubx2.config_set() exception handling - addresses #173.
8+
39
### RELEASE 1.2.48
410

511
ENHANCEMENTS:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "pyubx2"
77
authors = [{ name = "semuadmin", email = "semuadmin@semuconsulting.com" }]
88
maintainers = [{ name = "semuadmin", email = "semuadmin@semuconsulting.com" }]
99
description = "UBX protocol parser and generator"
10-
version = "1.2.48"
10+
version = "1.2.49"
1111
license = { file = "LICENSE" }
1212
readme = "README.md"
1313
requires-python = ">=3.9"

src/pyubx2/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
:license: BSD 3-Clause
99
"""
1010

11-
__version__ = "1.2.48"
11+
__version__ = "1.2.49"

src/pyubx2/ubxhelpers.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pyubx2.ubxtypes_configdb as ubcdb
2020
import pyubx2.ubxtypes_core as ubt
2121
from pyubx2.ubxtypes_core import (
22+
ATTTYPE,
2223
NMEA_PROTOCOL,
2324
POLL,
2425
RTCM3_PROTOCOL,
@@ -125,11 +126,13 @@ def attsiz(att: str) -> int:
125126
Helper function to return attribute size in bytes.
126127
127128
:param str: attribute type e.g. 'U002'
128-
:return: size of attribute in bytes
129+
:return: size of attribute in bytes, or -1 if variable length
129130
:rtype: int
130131
131132
"""
132133

134+
if att == "CH": # variable length
135+
return -1
133136
return int(att[1:4])
134137

135138

@@ -274,11 +277,22 @@ def val2bytes(val, att: str) -> bytes:
274277
275278
"""
276279

277-
if att == ubt.CH: # single variable-length string (e.g. INF-NOTICE)
278-
return val.encode("utf-8", "backslashreplace")
280+
try:
281+
if not isinstance(val, ATTTYPE[atttyp(att)]):
282+
raise TypeError(
283+
f"Attribute type {att} value {val} must be {ATTTYPE[atttyp(att)]}, not {type(val)}"
284+
)
285+
except KeyError as err:
286+
raise ube.UBXTypeError(f"Unknown attribute type {att}") from err
287+
279288
atts = attsiz(att)
280-
if atttyp(att) in ("C", "X"): # byte or char
289+
if atttyp(att) == "X": # byte
281290
valb = val
291+
elif atttyp(att) == "C": # char
292+
if isinstance(val, str):
293+
valb = val.encode("utf-8", "backslashreplace")
294+
else: # byte
295+
valb = val
282296
elif atttyp(att) in ("E", "L", "U"): # unsigned integer
283297
valb = val.to_bytes(atts, byteorder="little", signed=False)
284298
elif atttyp(att) == "A": # array of unsigned integers
@@ -289,11 +303,9 @@ def val2bytes(val, att: str) -> bytes:
289303
elif atttyp(att) == "I": # signed integer
290304
valb = val.to_bytes(atts, byteorder="little", signed=True)
291305
elif att == ubt.R4: # single precision floating point
292-
valb = struct.pack("<f", val)
306+
valb = struct.pack("<f", float(val))
293307
elif att == ubt.R8: # double precision floating point
294-
valb = struct.pack("<d", val)
295-
else:
296-
raise ube.UBXTypeError(f"Unknown attribute type {att}")
308+
valb = struct.pack("<d", float(val))
297309
return valb
298310

299311

src/pyubx2/ubxmessage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,11 @@ def config_set(layers: int, transaction: int, cfgData: list) -> object:
734734
att = ""
735735
(key, val) = cfgItem
736736
if isinstance(key, str): # if key is a string (keyname)
737-
(key, att) = cfgname2key(key) # lookup keyID & attribute type
737+
(kid, att) = cfgname2key(key) # lookup keyID & attribute type
738738
else:
739-
(_, att) = cfgkey2name(key) # lookup attribute type
740-
keyb = val2bytes(key, U4)
739+
kid = key
740+
(key, att) = cfgkey2name(key) # lookup attribute type
741+
keyb = val2bytes(kid, U4)
741742
valb = val2bytes(val, att)
742743
lis = lis + keyb + valb
743744

src/pyubx2/ubxtypes_core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@
9696
R4 = "R004" # Float (IEEE 754) Single Precision 4 bytes
9797
R8 = "R008" # Float (IEEE 754) Double Precision 8 bytes
9898

99+
ATTTYPE = {
100+
"A": type([0, 1]),
101+
"C": (type(b"0"), type("0")),
102+
"E": type(0),
103+
"I": type(0),
104+
"L": type(0),
105+
"R": (type(0), type(0.1)),
106+
"U": type(0),
107+
"X": type(b"0"),
108+
}
109+
"""Permissible attribute types"""
110+
99111
# ***********************************************
100112
# THESE ARE THE UBX PROTOCOL CORE MESSAGE CLASSES
101113
# ***********************************************

src/pyubx2/ubxtypes_poll.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
UBX Protocol POLL payload definitions.
33
44
THESE ARE THE PAYLOAD DEFINITIONS FOR _POLL_ MESSAGES _TO_ THE RECEIVER
5-
(e.g. query configuration; request monitoring, receiver management, logging or sensor fusion status).
5+
(e.g. query configuration; request monitoring, receiver management,
6+
logging or sensor fusion status).
7+
68
Response payloads are defined in UBX_PAYLOADS_GET.
79
810
NB: Attribute names must be unique within each message class/id

tests/test_configdb.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import unittest
1313

14-
from pyubx2 import UBXMessage, SET, POLL
14+
from pyubx2 import UBXMessage, SET, POLL, SET_LAYER_FLASH, TXN_NONE
1515
from pyubx2.ubxtypes_configdb import UBX_CONFIG_DATABASE
1616
from tests.configdb_baseline import UBX_CONFIG_DATABASE_BASELINE
1717

@@ -63,6 +63,16 @@ def testFill_CFGVALSET(self): # test CFG-VALSET SET constructor
6363
)
6464
self.assertEqual(str(res), EXPECTED_RESULT)
6565

66+
def testGOODConfigSet(self):
67+
EXPECTED_RESULT = "<UBX(CFG-VALSET, version=0, ram=0, bbr=0, flash=1, action=0, reserved0=0, CFG_NAVSPG_USRDAT_ROTZ=0.0, CFG_NAVSPG_USRDAT_ROTY=0.10000000149011612)>"
68+
msg = UBXMessage.config_set(
69+
layers=SET_LAYER_FLASH,
70+
transaction=TXN_NONE,
71+
cfgData=[(0x40110069, 0), (0x40110068, 0.1)],
72+
)
73+
# print(msg)
74+
self.assertEqual(str(msg), EXPECTED_RESULT)
75+
6676

6777
if __name__ == "__main__":
6878
# import sys;sys.argv = ['', 'Test.testName']

tests/test_exceptions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
VALCKSUM,
2929
ERR_LOG,
3030
ERR_RAISE,
31+
SET_LAYER_FLASH,
32+
TXN_NONE,
3133
)
3234
from pyubx2.ubxhelpers import (
3335
cfgkey2name,
@@ -399,6 +401,32 @@ def testNMEABADEND(self): # test truncated NMEA file
399401
# print(f'"{parsed}",')
400402
i += 1
401403

404+
def testBADConfigSet(self): # test invalid configuration database value type
405+
with self.assertRaises(TypeError):
406+
UBXMessage.config_set(
407+
layers=SET_LAYER_FLASH,
408+
transaction=TXN_NONE,
409+
cfgData=[(0x20920006, 0)],
410+
)
411+
with self.assertRaises(TypeError):
412+
UBXMessage.config_set(
413+
layers=SET_LAYER_FLASH,
414+
transaction=TXN_NONE,
415+
cfgData=[(0x209100E0, b"\x00")],
416+
)
417+
with self.assertRaises(TypeError):
418+
UBXMessage.config_set(
419+
layers=SET_LAYER_FLASH,
420+
transaction=TXN_NONE,
421+
cfgData=[(0x5005002A, b"\x00")],
422+
)
423+
with self.assertRaises(TypeError):
424+
UBXMessage.config_set(
425+
layers=SET_LAYER_FLASH,
426+
transaction=TXN_NONE,
427+
cfgData=[(0x40110069, 0.1), (0x40110068, "0")],
428+
)
429+
402430

403431
if __name__ == "__main__":
404432
# import sys;sys.argv = ['', 'Test.testName']

tests/test_static.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import pyubx2.ubxtypes_core as ubt
1818
from pyubx2 import POLL, SET, UBX_CLASSES, UBXMessage, UBXReader
1919
from pyubx2.ubxhelpers import (
20+
attsiz,
2021
att2idx,
2122
att2name,
2223
bytes2val,
@@ -258,6 +259,10 @@ def testhextable(self): # test hextable*( method)
258259
res = hextable(b"$GNGLL,5327.04319,S,00214.41396,E,223232.00,A,A*68\r\n", 8)
259260
self.assertEqual(res, EXPECTED_RESULT)
260261

262+
def testattsiz(self): # test attsiz
263+
self.assertEqual(attsiz("CH"), -1)
264+
self.assertEqual(attsiz("C032"), 32)
265+
261266
def testatt2idx(self): # test att2idx
262267
EXPECTED_RESULT = [4, 16, 101, 0, (3, 6), 0]
263268
atts = ["svid_04", "gnssId_16", "cno_101", "gmsLon", "gnod_03_06", "dodgy_xx"]

0 commit comments

Comments
 (0)