|
80 | 80 | 32: 'horus_binary_v2_32byte'
|
81 | 81 | }
|
82 | 82 |
|
83 |
| -def decode_packet(data:bytes, packet_format:dict = None) -> dict: |
| 83 | +def decode_packet(data:bytes, packet_format:dict = None, ignore_crc:bool = False) -> dict: |
84 | 84 | """
|
85 | 85 | Attempt to decode a set of bytes based on a provided packet format.
|
86 | 86 |
|
@@ -113,7 +113,7 @@ def decode_packet(data:bytes, packet_format:dict = None) -> dict:
|
113 | 113 | # Check the Checksum
|
114 | 114 | _crc_ok = check_packet_crc(data, checksum=packet_format['checksum'])
|
115 | 115 |
|
116 |
| - if not _crc_ok: |
| 116 | + if (not _crc_ok) and (not ignore_crc): |
117 | 117 | raise ValueError("Decoder - CRC Failure.")
|
118 | 118 | else:
|
119 | 119 | _output['crc_ok'] = True
|
@@ -321,6 +321,32 @@ def parse_ukhas_string(sentence:str) -> dict:
|
321 | 321 | print(f"Input ({_format}): {str(_input)} - Caught Error: {str(e)}")
|
322 | 322 | assert(_output == 'error')
|
323 | 323 |
|
| 324 | + # Binary packet tests that break various fields |
| 325 | + tests = [ |
| 326 | + # ID Seq---| HH MM SS Lat----------| Lon-----------| Alt---| |
| 327 | + ['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', ''], |
| 328 | + ['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'], |
| 329 | + ['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'], |
| 330 | + ['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'], |
| 331 | + ['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'], |
| 332 | + ['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'], |
| 333 | + ] |
| 334 | + |
| 335 | + for _test in tests: |
| 336 | + _format = _test[0] |
| 337 | + _input = _test[1] |
| 338 | + _output = _test[2] |
| 339 | + |
| 340 | + try: |
| 341 | + _decoded = decode_packet(_input, ignore_crc=True) |
| 342 | + print(f"Input ({_format}): {str(_input)} - Output: {_decoded['ukhas_str']}") |
| 343 | + print(_decoded) |
| 344 | + # Insert assert checks here. |
| 345 | + |
| 346 | + except ValueError as e: |
| 347 | + print(f"Input ({_format}): {str(_input)} - Caught Error: {str(e)}") |
| 348 | + assert(_output == 'error') |
| 349 | + |
324 | 350 | # RTTY Decoder Tests
|
325 | 351 | tests = [
|
326 | 352 | '$$HORUS,6,06:43:16,0.000000,0.000000,0,0,0,1801,20*1DA2',
|
|
0 commit comments