Skip to content

Commit

Permalink
update SEC-SIG definitions - Fixes #156
Browse files Browse the repository at this point in the history
  • Loading branch information
semuadmin committed Sep 2, 2024
1 parent 93ebc13 commit db9780d
Show file tree
Hide file tree
Showing 6 changed files with 60 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 @@ -5,6 +5,7 @@
FIXES:

1. Fix SEC-SIGLOG payload definition - thanks to @Niederb for contribution.
1. Cater for alternate (v1, v2) versions of SEC-SIG message = Fixes [#156](https://github.com/semuconsulting/pyubx2/issues/156).

### RELEASE 1.2.44

Expand Down
2 changes: 1 addition & 1 deletion src/pyubx2/ubxtypes_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
# ***************************************************************
# Security messages
# ***************************************************************
b"\x27\x09": "SEC-SIG",
b"\x27\x09": "SEC-SIG", # 2 versions
b"\x27\x10": "SEC-SIGLOG",
b"\x27\x01": "SEC-SIGN",
b"\x27\x03": "SEC-UNIQID",
Expand Down
16 changes: 15 additions & 1 deletion src/pyubx2/ubxtypes_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@
# ********************************************************************
# Security Feature Messages
# Messages in the SEC class are used for security features of the receiver.
"SEC-SIG": {
"SEC-SIG-V1": {
"version": U1, # 0x01
"reserved0": U3,
"jamFlags": (
Expand All @@ -3424,6 +3424,20 @@
),
"reserved2": U3,
},
"SEC-SIG-V2": {
"version": U1, # 0x02
"sigSecFlags": (
X1,
{
"jamDetEnabled": U1,
"jammingState": U2,
"spfDetEnabled": U1,
"spoofingState": U3,
},
),
"reserved0": U1,
"jamNumCentFreqs": U1,
},
"SEC-SIGLOG": {
"version": U1, # 0x00
"numEvents": U1,
Expand Down
25 changes: 25 additions & 0 deletions src/pyubx2/ubxvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,30 @@ def get_cfgdat_dict(**kwargs) -> dict:
return UBX_PAYLOADS_SET["CFG-DAT"] # manual datum set


def get_secsig_dict(**kwargs) -> dict:
"""
Select appropriate CFG-DAT SET payload definition by checking
presence of datumNum keyword or payload length of 2 bytes.
:param kwargs: optional payload key/value pairs
:return: dictionary representing payload definition
:rtype: dict
"""

if "version" in kwargs:
ver = val2bytes(kwargs["version"], U1)
elif "payload" in kwargs:
ver = kwargs["payload"][0:1]
else:
raise UBXMessageError(
"SEC-SIG message definitions must include version or payload keyword"
)
if ver == b"\x01":
return UBX_PAYLOADS_GET["SEC-SIG-V1"]
return UBX_PAYLOADS_GET["SEC-SIG-V2"]


VARIANTS = {
POLL: {b"\x06\x31": get_cfgtp5_dict}, # CFG-TP5
SET: {
Expand All @@ -287,5 +311,6 @@ def get_cfgdat_dict(**kwargs) -> dict:
b"\x06\x17": get_cfgnmea_dict, # CFG-NMEA
b"\x01\x60": get_aopstatus_dict, # NAV-AOPSTATUS
b"\x01\x3C": get_relposned_dict, # NAV-RELPOSNED
b"\x27\x09": get_secsig_dict, # SEC-SIG
},
}
Binary file added tests/pygpsdata-SEC.log
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ def testMONLOG(
i += 1
self.assertEqual(i, 12)

def testSEC(
self,
): # test stream of UBX MON messages
EXPECTED_RESULTS = (
"<UBX(SEC-SIGLOG, version=1, numEvents=0, reserved0=132701618176)>",
"<UBX(SEC-SIG, version=2, jamDetEnabled=1, jammingState=1, spfDetEnabled=1, spoofingState=1, reserved0=0, jamNumCentFreqs=6)>",
"<UBX(SEC-SIGLOG, version=1, numEvents=0, reserved0=132767154176)>",
"<UBX(SEC-SIG, version=1, reserved0=0, jamDetEnabled=1, jammingState=2, reserved1=0, spfDetEnabled=1, spoofingState=3, reserved2=0)>",
)
i = 0
with open(os.path.join(DIRNAME, "pygpsdata-SEC.log"), "rb") as stream:
ubr = UBXReader(stream)
for raw, parsed in ubr:
# print(f'"{parsed}",')
self.assertEqual(str(parsed), EXPECTED_RESULTS[i])
i += 1
self.assertEqual(i, 4)

def testCFGLOG(
self,
): # test stream of UBX CFG messages
Expand Down

0 comments on commit db9780d

Please sign in to comment.