Skip to content

Commit 64a0fbb

Browse files
committed
update ubx_cfgval_frame for X types
1 parent 7fd4c48 commit 64a0fbb

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
### RELEASE 1.6.10
44

5-
1. Minor enhancements to UBX Config Dialog confirmation signalling. Clarify 'X' bitfields are little endian.
5+
1. Minor enhancements to UBX Config Dialog confirmation signalling.
6+
1. Amend CFG-VALSET/GET/DEL Configuration Interface panel; X-type attributes (`X004`, `X008`, etc.) are now entered in
7+
conventional hexadecimal integer notation rather than little-endian hex strings, consistent with values illustrated in the Interface
8+
Specifications e.g. value for CFG_SBAS_PRNSCANMASK (`X008`) would now be entered `0x000000000003ab88` rather than `88ab030000000000`.
69
1. Make 'Check for update on startup' 'opt-in' rather than 'opt-out'. Setting available via About dialog.
710

811
### RELEASE 1.6.9

src/pygpsclient/helpers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,23 @@ def valid_geom(geom: str) -> bool:
14831483
return regexgeom.match(geom) is not None
14841484

14851485

1486+
def valid_hex(val: str, *args) -> bool:
1487+
"""
1488+
Validate hex string in Entry field.
1489+
1490+
:param str val: hexadecimal value
1491+
:return: Valid/Invalid
1492+
:rtype: bool
1493+
"""
1494+
1495+
try:
1496+
atts = args[0]
1497+
int.to_bytes(int(val, 16), atts, "little")
1498+
return True
1499+
except (TypeError, ValueError, OverflowError):
1500+
return False
1501+
1502+
14861503
def xy2ll(width: int, height: int, bounds: Area, xy: tuple) -> Point | NoneType:
14871504
"""
14881505
Convert canvas x/y to lat/lon.

src/pygpsclient/ubx_cfgval_frame.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
TRACEMODE_WRITE,
5252
UBX_CFGVAL,
5353
VALBOOL,
54+
VALCUSTOM,
5455
VALFLOAT,
5556
VALINT,
5657
VALNONBLANK,
5758
)
59+
from pygpsclient.helpers import valid_hex
5860

5961
VALSET = 0
6062
VALDEL = 1
@@ -183,7 +185,6 @@ def _body(self):
183185
width=8,
184186
state=READONLY,
185187
)
186-
self._lbl_endian = Label(self, text="")
187188
self._lbl_val = Label(self, text="Value")
188189
self._ent_val = Entry(
189190
self,
@@ -223,7 +224,6 @@ def _do_layout(self):
223224
self._lbl_att.grid(column=4, row=13, sticky=W)
224225
self._lbl_layer.grid(column=1, row=14, sticky=E)
225226
self._spn_layer.grid(column=2, row=14, sticky=W)
226-
self._lbl_endian.grid(column=3, row=14, columnspan=2, sticky=E)
227227
self._lbl_val.grid(column=1, row=15, sticky=E)
228228
self._ent_val.grid(column=2, row=15, columnspan=3, sticky=EW)
229229

@@ -307,8 +307,6 @@ def _on_select_parm(self, *args, **kwargs): # pylint: disable=unused-argument
307307
self._cfgatt.set(att)
308308
self._cfgval.set("")
309309
self._lbl_send_command.config(image=self._img_blank)
310-
endian = "Little Endian" if att[0:1] == "X" and att[1:] > "001" else ""
311-
self._lbl_endian.config(text=endian)
312310
except TclError:
313311
pass
314312

@@ -352,12 +350,15 @@ def _do_valset(self):
352350
layers = 1
353351
try:
354352
if att in ("C", "X"): # byte or char
355-
self._ent_val.validate(VALNONBLANK)
356-
if len(val) == atts * 2: # 2 hex chars per byte
357-
val = bytearray.fromhex(val)
358-
else:
359-
valid = False
360-
353+
valid = self._ent_val.validate(
354+
VALCUSTOM,
355+
func=valid_hex,
356+
args=[
357+
atts,
358+
],
359+
)
360+
if valid:
361+
val = int.to_bytes(int(val, 16), atts, "little")
361362
elif att in ("E", "U"): # unsigned integer
362363
self._ent_val.validate(VALINT)
363364
val = int(val)
@@ -462,7 +463,9 @@ def update_status(self, msg: UBXMessage): # pylint: disable=unused-argument
462463
val = getattr(msg, self._cfgval_keyname, None)
463464
if val is not None:
464465
if isinstance(val, bytes):
465-
val = val.hex()
466+
atts = attsiz(self._cfgatt.get())
467+
vali = int.from_bytes(val, "little")
468+
val = f"0x{vali:0{atts*2}x}"
466469
self._cfgval.set(val)
467470
self.__container.status_label = ("CFG-VALGET GET message received", OKCOL)
468471

tests/test_static.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
unused_sats,
7878
val2sphp,
7979
valid_geom,
80+
valid_hex,
8081
xy2ll,
8182
)
8283
from pygpsclient.mapquest_handler import (
@@ -963,6 +964,15 @@ def testhdg2yaw(self):
963964
self.assertEqual(hdg2yaw(375.0),15.0)
964965
self.assertEqual(hdg2yaw(715.0),-5.0)
965966

967+
def testvalidhex(self):
968+
969+
self.assertTrue(valid_hex("0x11223344", 4))
970+
self.assertFalse(valid_hex("0x112233zz", 4))
971+
self.assertFalse(valid_hex("0x1122334455667788", 4))
972+
self.assertTrue(valid_hex("0x1122334455667788", 8))
973+
self.assertFalse(valid_hex("asdfttwergazz", 4))
974+
self.assertFalse(valid_hex("", 4))
975+
966976
if __name__ == "__main__":
967977
# import sys;sys.argv = ['', 'Test.testName']
968978
unittest.main()

0 commit comments

Comments
 (0)