Add additional checks on some fields.

pull/21/head v0.1.21
Mark Jessop 2021-01-30 10:44:46 +10:30
rodzic 975d50af51
commit 219c4e7686
4 zmienionych plików z 45 dodań i 5 usunięć

Wyświetl plik

@ -1 +1 @@
__version__ = "0.1.20"
__version__ = "0.1.21"

Wyświetl plik

@ -80,7 +80,7 @@ HORUS_LENGTH_TO_FORMAT = {
32: 'horus_binary_v2_32byte'
}
def decode_packet(data:bytes, packet_format:dict = None) -> dict:
def decode_packet(data:bytes, packet_format:dict = None, ignore_crc:bool = False) -> dict:
"""
Attempt to decode a set of bytes based on a provided packet format.
@ -113,7 +113,7 @@ def decode_packet(data:bytes, packet_format:dict = None) -> dict:
# Check the Checksum
_crc_ok = check_packet_crc(data, checksum=packet_format['checksum'])
if not _crc_ok:
if (not _crc_ok) and (not ignore_crc):
raise ValueError("Decoder - CRC Failure.")
else:
_output['crc_ok'] = True
@ -321,6 +321,32 @@ if __name__ == "__main__":
print(f"Input ({_format}): {str(_input)} - Caught Error: {str(e)}")
assert(_output == 'error')
# Binary packet tests that break various fields
tests = [
# ID Seq---| HH MM SS Lat----------| Lon-----------| Alt---|
['horus_binary_v1', b'\x01\x12\x00\x00\x00\x23\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', ''],
['horus_binary_v1', b'\x01\x12\x00\x18\x00\x23\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', 'error'],
['horus_binary_v1', b'\x01\x12\x00\x00\x3c\x23\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', 'error'],
['horus_binary_v1', b'\x01\x12\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', 'error'],
['horus_binary_v1', b'\x01\x12\x00\x00\x00\x23\x00\x00\x35\x43\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', 'error'],
['horus_binary_v1', b'\x01\x12\x00\x00\x00\x23\x00\x80\x34\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x1C\x9A\x95\x45', 'error'],
]
for _test in tests:
_format = _test[0]
_input = _test[1]
_output = _test[2]
try:
_decoded = decode_packet(_input, ignore_crc=True)
print(f"Input ({_format}): {str(_input)} - Output: {_decoded['ukhas_str']}")
print(_decoded)
# Insert assert checks here.
except ValueError as e:
print(f"Input ({_format}): {str(_input)} - Caught Error: {str(e)}")
assert(_output == 'error')
# RTTY Decoder Tests
tests = [
'$$HORUS,6,06:43:16,0.000000,0.000000,0,0,0,1801,20*1DA2',

Wyświetl plik

@ -40,8 +40,16 @@ def decode_time_hms(data: bytes) -> str:
raise ValueError(f"time_hms - Input has incorrect length ({len(data)}), should be 3.")
_hour = int(data[0])
if _hour >= 24:
raise ValueError(f"time_hms - Hour value ({_hour}) out of range 0-23.")
_minute = int(data[1])
if _minute >= 60:
raise ValueError(f"time_hms - Minute value ({_minute}) out of range 0-59.")
_second = int(data[2])
if _second >= 60:
raise ValueError(f"time_hms - Second value ({_second}) out of range 0-59.")
_str = f"{_hour:02d}:{_minute:02d}:{_second:02d}"
@ -65,7 +73,7 @@ def decode_time_biseconds(data:int) -> str:
raise ValueError("time_biseconds - Invalid input type.")
if (data < 0) or data > 43200:
raise ValueError("time_biseconds - Input of of range (0-43200)")
raise ValueError("time_biseconds - Input out of range (0-43200)")
_str = time.strftime("%H:%M:%S", time.gmtime(data*2))
@ -81,6 +89,9 @@ def decode_degree_float(data:float) -> str:
if type(data) != float:
raise ValueError("decimal_degrees - Invalid input type.")
if (data < -180.0) or (data > 180.0):
raise ValueError(f"decimal_degrees - Value ({data}) out of range -180 - 180.")
return (data, f"{data:.5f}")
@ -110,6 +121,9 @@ def decode_degree_fixed3(data:bytes) -> str:
_value = struct.unpack('<i', _temp)[0]
_value_degrees = _value * 1e-7
if (_value_degrees < -180.0) or (_value_degrees > 180.0):
raise ValueError(f"degree_fixed3 - Value ({_value_degrees}) out of range -180 - 180.")
return (_value_degrees, f"{_value_degrees:.5f}")

Wyświetl plik

@ -1,6 +1,6 @@
[tool.poetry]
name = "horusdemodlib"
version = "0.1.20"
version = "0.1.21"
description = "Project Horus HAB Telemetry Demodulators"
authors = ["Mark Jessop"]
license = "LGPL-2.1-or-later"