From 47da0ddef0ab72ba2955a592c93721154f306a87 Mon Sep 17 00:00:00 2001 From: serversdown Date: Fri, 6 Nov 2026 14:54:45 -0500 Subject: [PATCH] fix(framing): checksum_valid sums the reply's payload unescaped S3FrameParser summed its payload with the kept `10` of each `10 02/03/04` still in, so checksum_valid was False on about a third of good replies (the old "S3 checksums frequently fail" belief). SUM8 of the unescaped payload is the unit's checksum on 7,747 of 7,747 recorded replies; the test pins it on the 2,509 in the committed October fixtures (62 with an escaped checksum), which also proves #58's split of data from checksum on real replies. Nothing decides on checksum_valid; seismo_lab's display stops crying wolf. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- minimateplus/framing.py | 4 +++- tests/test_s3_escaped_checksum.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/minimateplus/framing.py b/minimateplus/framing.py index 2c803b2..cab24be 100644 --- a/minimateplus/framing.py +++ b/minimateplus/framing.py @@ -764,7 +764,9 @@ class S3FrameParser: n_chk = 2 if body[-2] == DLE and body[-1] in (STX, ETX, 0x04) else 1 raw_payload = body[:-n_chk] # everything except the checksum chk_received = body[-1] - chk_computed = checksum(raw_payload) + # SUM8 of the payload unescaped: the kept `10` of a `10 02/03/04` is not + # summed (7,747 of 7,747 recorded replies check this way). + chk_computed = checksum(unescape_reply(raw_payload)) if len(raw_payload) < 5: return None diff --git a/tests/test_s3_escaped_checksum.py b/tests/test_s3_escaped_checksum.py index e8b699e..1493362 100644 --- a/tests/test_s3_escaped_checksum.py +++ b/tests/test_s3_escaped_checksum.py @@ -75,6 +75,20 @@ def test_a_last_data_byte_of_0x10_survives_an_escaped_checksum(chk): assert (unescape_reply(f.data), f.chk_byte) == (data, chk) +REPLY_RECORDINGS = ["minimate-bench-10-25-26/BE9441_event0_01110000_rx.bin", + "minimate-bench-10-25-26/BE9441_event1_0111646a_rx.bin", + "minimate-bench-10-26-26-blastware/unit_replies.bin", + "minimate-bench-10-26-26-histogram/unit_replies.bin"] + + +@pytest.mark.parametrize("name", REPLY_RECORDINGS) +def test_every_recorded_reply_checks(name): + # BE9441, October 2026: 2,509 replies, 62 with an escaped checksum. + frames = S3FrameParser().feed((FIX / name).read_bytes()) + assert frames + assert [i for i, f in enumerate(frames) if not f.checksum_valid] == [] + + @pytest.mark.parametrize("chk", [0x10, 0x00, 0x55]) def test_any_other_checksum_reads_as_before(chk): data = data_for(chk, last=0x10)