From 9bbecea70fc4ae07b8b668920ad2ec05d735fdf6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 26 Apr 2026 20:23:18 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(parser):=20correct=20S3=20frame=20termi?= =?UTF-8?q?nator=20=E2=80=94=20bare=20ETX,=20not=20DLE+ETX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parse_s3 had the S3 terminator logic inverted vs the real S3FrameParser in framing.py. It was terminating on DLE+ETX and treating bare ETX as payload, which caused every bare 0x03 to be swallowed — bundling multiple real S3 frames into one giant body until a DLE+ETX sequence happened to appear. Result: 583-byte POLL_RESPONSE 'frames' containing many real frames concatenated, all showing BAD CHK. Fix: mirror S3FrameParser exactly — - Bare ETX (0x03) = real frame terminator - DLE+ETX (0x10 0x03) = inner-frame literal data (A4/E5 sub-frames), appended to body and parsing continues https://claude.ai/code/session_014NczSHUz9uTzCAf4cVASTJ --- parsers/s3_parser.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/parsers/s3_parser.py b/parsers/s3_parser.py index 2f32933..4b8a2bc 100644 --- a/parsers/s3_parser.py +++ b/parsers/s3_parser.py @@ -33,7 +33,7 @@ STX = 0x02 ETX = 0x03 ACK = 0x41 -__version__ = "0.2.3" +__version__ = "0.2.4" @dataclass @@ -184,9 +184,9 @@ def validate_bw_body_auto(body: bytes) -> Optional[Tuple[bytes, bytes, str]]: def parse_s3(blob: bytes, trailer_len: int) -> List[Frame]: frames: List[Frame] = [] - IDLE = 0 - IN_FRAME = 1 - AFTER_DLE = 2 + IDLE = 0 + IN_FRAME = 1 + IN_FRAME_DLE = 2 # saw DLE inside frame — waiting for next byte state = IDLE body = bytearray() @@ -206,22 +206,15 @@ def parse_s3(blob: bytes, trailer_len: int) -> List[Frame]: state = IN_FRAME i += 2 continue + # ACK bytes, boot strings, garbage — silently ignored elif state == IN_FRAME: if b == DLE: - state = AFTER_DLE + state = IN_FRAME_DLE i += 1 continue - body.append(b) - - else: # AFTER_DLE - if b == DLE: - body.append(DLE) - state = IN_FRAME - i += 1 - continue - if b == ETX: + # Bare ETX = real S3 frame terminator (confirmed from S3FrameParser) end_offset = i + 1 trailer_start = i + 1 trailer_end = trailer_start + trailer_len @@ -259,13 +252,27 @@ def parse_s3(blob: bytes, trailer_len: int) -> List[Frame]: state = IDLE i = trailer_end continue + body.append(b) + else: # IN_FRAME_DLE + if b == DLE: + # DLE DLE → literal 0x10 in payload + body.append(DLE) + state = IN_FRAME + i += 1 + continue + if b == ETX: + # DLE+ETX inside a frame = inner-frame terminator (A4/E5 sub-frames). + # Treat as literal data, NOT the outer frame end. + body.append(DLE) + body.append(ETX) + state = IN_FRAME + i += 1 + continue # Unexpected DLE + byte → treat as literal data body.append(DLE) body.append(b) state = IN_FRAME - i += 1 - continue i += 1 From e1150b30aad7142ff8b0afc49cf5742020ee63ea Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 26 Apr 2026 20:40:45 +0000 Subject: [PATCH 2/2] fix(analyzer): name A5/5A frames; revert S3 checksum validation Add 0x5A (BULK_WAVEFORM_STREAM) and 0xA5 (BULK_WAVEFORM_RESPONSE) to SUB_TABLE so they display with real names instead of UNKNOWN_5A/A5. Revert S3 checksum validation to checksum_valid=None (the original intentional behavior). Large S3 frames (A5 bulk waveform, E5 compliance config) embed inner DLE+ETX sub-frame delimiters; the trailing 0x03 of the last inner delimiter can land where the parser expects the SUM8 checksum byte, causing false BAD CHK on every valid A5 frame. protocol.py _validate_frame documents and ignores exactly this issue. https://claude.ai/code/session_014NczSHUz9uTzCAf4cVASTJ --- parsers/s3_analyzer.py | 2 ++ parsers/s3_parser.py | 32 +++++++++++--------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/parsers/s3_analyzer.py b/parsers/s3_analyzer.py index c86477d..6feb32b 100644 --- a/parsers/s3_analyzer.py +++ b/parsers/s3_analyzer.py @@ -53,7 +53,9 @@ SUB_TABLE: dict[int, tuple[str, str, str]] = { 0x82: ("TRIGGER_CONFIG_WRITE", "BW→S3", "0x1C bytes; trigger config block; mirrors SUB 1C"), 0x83: ("TRIGGER_WRITE_CONFIRM", "BW→S3", "Short frame; commit step after 0x82"), # S3→BW responses + 0x5A: ("BULK_WAVEFORM_STREAM", "BW→S3", "Bulk waveform chunk request; response is A5 stream"), 0xA4: ("POLL_RESPONSE", "S3→BW", "Response to SUB 5B poll"), + 0xA5: ("BULK_WAVEFORM_RESPONSE", "S3→BW", "Response to SUB 5A; waveform chunks + metadata"), 0xFE: ("FULL_CONFIG_RESPONSE", "S3→BW", "Response to SUB 01"), 0xF9: ("CHANNEL_CONFIG_RESPONSE", "S3→BW", "Response to SUB 06"), 0xF7: ("EVENT_INDEX_RESPONSE", "S3→BW", "Response to SUB 08; contains backlight/power-save"), diff --git a/parsers/s3_parser.py b/parsers/s3_parser.py index 4b8a2bc..2bb3de1 100644 --- a/parsers/s3_parser.py +++ b/parsers/s3_parser.py @@ -33,7 +33,7 @@ STX = 0x02 ETX = 0x03 ACK = 0x41 -__version__ = "0.2.4" +__version__ = "0.2.5" @dataclass @@ -220,32 +220,22 @@ def parse_s3(blob: bytes, trailer_len: int) -> List[Frame]: trailer_end = trailer_start + trailer_len trailer = blob[trailer_start:trailer_end] - chk_valid = None - chk_type = None - chk_hex = None - payload = bytes(body) - - if len(body) >= 1: - received_chk = body[-1] - computed_chk = checksum8_sum(bytes(body[:-1])) - if computed_chk == received_chk: - chk_valid = True - chk_type = "SUM8" - chk_hex = f"{received_chk:02x}" - payload = bytes(body[:-1]) - else: - chk_valid = False - + # S3 checksums are deliberately not validated here. + # Large S3 responses (A5 bulk waveform, E5 compliance) embed + # inner DLE+ETX sub-frame terminators whose trailing 0x03 byte + # lands where the parser would expect the SUM8 checksum, causing + # false failures. The live protocol (protocol.py _validate_frame) + # also skips S3 checksum enforcement for the same reason. frames.append(Frame( index=idx, start_offset=start_offset, end_offset=end_offset, payload_raw=bytes(body), - payload=payload, + payload=bytes(body), trailer=trailer, - checksum_valid=chk_valid, - checksum_type=chk_type, - checksum_hex=chk_hex + checksum_valid=None, + checksum_type=None, + checksum_hex=None )) idx += 1