From 2d747a97c5bc5affb95d0d92df0a41e5e9cb5d1c Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Tue, 17 Feb 2026 15:12:50 -0500 Subject: [PATCH 1/2] Added comments and cleaned up binary_message_decode print order. --- python/examples/binary_message_decode.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/examples/binary_message_decode.py b/python/examples/binary_message_decode.py index f5b0cba7..0c69cb2e 100755 --- a/python/examples/binary_message_decode.py +++ b/python/examples/binary_message_decode.py @@ -82,20 +82,26 @@ logger.info("Header: " + str(header)) if isinstance(message, MessagePayload): logger.info("Payload: " + str(message)) + # Message decode failed -- see if we can decode manually. else: # If we didn't detect any complete messages, see if maybe they didn't provide enough bytes? if len(contents) < MessageHeader.calcsize(): - logger.warning("Warning: Specified byte string too small to contain a valid FusionEngine message. " + logger.warning("Warning: Specified byte array too small to contain a valid FusionEngine message. " "[size=%d B, minimum=%d B]" % (len(contents), MessageHeader.calcsize())) + # Or maybe there was a CRC failure or something? Try to decode the message anyway. else: try: + logger.warning('Warning: Error detected by FusionEngine decoder. Attempting to parse message manually.') + # Try to decode a message header anyway. header = MessageHeader() header.unpack(contents, validate_crc=False) + + logger.info("Header: " + str(header)) + if len(contents) < header.get_message_size(): - logger.warning('Warning: Specified byte string too small. [expected=%d B, got=%d B]' % + logger.warning('Warning: Specified byte array too small. [expected=%d B, got=%d B]' % (header.get_message_size(), len(contents))) - logger.info("Header: " + str(header)) # If that succeeds, try to determine the payload type and print out the expected size. If we have enough # bytes, try to decode the payload. From 1eb1ea772a3061c0c3b9934e75cdbfaae9f4054b Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Tue, 17 Feb 2026 15:13:51 -0500 Subject: [PATCH 2/2] Do a second CRC check if manually parsing the message. --- python/examples/binary_message_decode.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/examples/binary_message_decode.py b/python/examples/binary_message_decode.py index 0c69cb2e..5e02e52b 100755 --- a/python/examples/binary_message_decode.py +++ b/python/examples/binary_message_decode.py @@ -103,6 +103,19 @@ logger.warning('Warning: Specified byte array too small. [expected=%d B, got=%d B]' % (header.get_message_size(), len(contents))) + # Do a CRC check manually, _after_ calling unpack(), and warn on failure but try to continue. If there + # is a CRC mismatch, the FE decoder will already have printed a warning about it, assuming that is the + # reason the decoder rejected the message. We'll warn again here for good measure, or in case that was + # not the reason for the decode failure. + # + # Normally, unpack() does the CRC check internally. If it fails, it will raise an exception and not + # populate the rest of the MessageHeader object. In this application, we want to attempt to decode + # broken messages if possible for debugging purposes. + try: + header.validate_crc(contents) + except ValueError as e: + logger.warning(f'Warning: {str(e)}') + # If that succeeds, try to determine the payload type and print out the expected size. If we have enough # bytes, try to decode the payload. payload_cls = message_type_to_class.get(header.message_type, None)