Skip to content

Commit

Permalink
add getinputmode helper
Browse files Browse the repository at this point in the history
  • Loading branch information
semuadmin committed Feb 14, 2024
1 parent fb56ac3 commit 8da5894
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGES:

1. Add val2sphp helper method to convert high precision (9dp) coordinate to separate standard and high precision components, as required by some CFG and NAV messages.
1. Add utc2itow helper method to convert utc datetime to GPS week number and time of week.
1. Add getinputmode helper to determinate mode of input UBX message (SET or POLL)

### RELEASE 1.2.37

Expand Down
29 changes: 28 additions & 1 deletion src/pyubx2/ubxhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pyubx2.exceptions as ube
import pyubx2.ubxtypes_configdb as ubcdb
import pyubx2.ubxtypes_core as ubt
from pyubx2.ubxtypes_core import UBX_HDR
from pyubx2.ubxtypes_core import POLL, SET, UBX_HDR
from pyubx2.ubxtypes_decodes import FIXTYPE, GNSSLIST

EPOCH0 = datetime(1980, 1, 6) # EPOCH start date
Expand Down Expand Up @@ -529,3 +529,30 @@ def val2sphp(val: float, scale: float = 1e-7) -> tuple:
val_sp = trunc(val)
val_hp = round((val - val_sp) * 100)
return val_sp, val_hp


def getinputmode(data: bytes) -> int:
"""
Return input message mode (SET or POLL).
:param bytes data: raw UBX input message
:return: message mode (1 = SET, 2 = POLL)
:rtype: int
"""

if (
len(data) == 8
or data[2:4] == b"\x06\x8b" # CFG-VALGET
or (
data[2:4]
in (
b"\x06\x01",
b"\x06\x02",
b"\x06\x03",
b"\x06\x31",
) # CFG-INF, CFG-MSG, CFG-PRT, CFG-TP5
and len(data) <= 10
)
):
return POLL
return SET
14 changes: 13 additions & 1 deletion tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import unittest
from datetime import datetime
import pyubx2.ubxtypes_core as ubt
from pyubx2 import POLL, UBX_CLASSES, UBXMessage, UBXReader
from pyubx2 import SET, POLL, UBX_CLASSES, UBXMessage, UBXReader
from pyubx2.ubxhelpers import (
att2idx,
att2name,
Expand All @@ -25,6 +25,7 @@
dop2str,
escapeall,
get_bits,
getinputmode,
gnss2str,
gpsfix2str,
hextable,
Expand Down Expand Up @@ -290,6 +291,17 @@ def testval2sphp(self):
res = val2sphp(5.9876543)
self.assertEqual(res, (59876543,0))

def testgetinputmode(self):
res = getinputmode(UBXMessage("CFG","CFG-ODO", POLL).serialize())
self.assertEqual(res, POLL)
res = getinputmode(UBXMessage.config_poll(0,0,["CFG_UART1_BAUDRATE", 0x40530001]).serialize())
self.assertEqual(res, POLL)
res = getinputmode(UBXMessage.config_set(0,0,[("CFG_UART1_BAUDRATE", 9600), (0x40530001, 115200)]).serialize())
self.assertEqual(res, SET)
res = getinputmode(UBXMessage.config_del(0,0,["CFG_UART1_BAUDRATE", 0x40530001]).serialize())
self.assertEqual(res, SET)
res = getinputmode(UBXMessage("CFG","CFG-INF", POLL, protocolID=1).serialize())
self.assertEqual(res, POLL)

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

0 comments on commit 8da5894

Please sign in to comment.