merge: an escaped checksum is the checksum, not data (#58)
S3FrameParser kept the 10 of a checksum sent as `10 02/03/04` as the reply's last data byte. It now takes the pair: 7,747 / 7,747 recorded replies check, 272 of them with an escaped checksum. Fixes the 1C battery/memory misread (419.84 V on 12 of 760 recorded status replies) and the 2C call-home read; the 5A file builder's own compensation is removed with it, and pre-fix .a5.pkl frames are converted on load (A5_PICKLE_VERSION 2). checksum_valid now sums the unescaped payload. Conflict: the reference's changelog table (dev's own 2026-11-06 row); #58's row kept as 2026-11-06 (2). Suite on the merge: 1,693 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
commit
ff705ebf87
8 files changed
+248
-82
No files matched your search
@@ -104,17 +104,11 @@ M529LIY6 (example event) using raw_s3_20260403_153508.bin capture):
|
||||
DLE strip rule (applied AFTER slicing):
|
||||
Strip any 0x10 byte that is immediately followed by 0x02, 0x03, or 0x04.
|
||||
This undoes the DLE-escape that S3FrameParser preserves as literal pairs.
|
||||
Applied to frame.data[skip:] + bytes([frame.chk_byte]) together, then
|
||||
conditionally exclude the trailing chk_byte from the output.
|
||||
|
||||
chk_byte absorption:
|
||||
When frame.data[-1] == 0x10 AND frame.chk_byte ∈ {0x02, 0x03, 0x04},
|
||||
the last byte of frame.data is the DLE prefix of a split DLE+chk pair.
|
||||
Including chk_byte in the strip buffer allows the pair to be stripped as
|
||||
a unit. After stripping, the trailing chk_byte is ALWAYS removed — because
|
||||
_strip_inner_frame_dles keeps the byte after the DLE (the chk_byte value),
|
||||
and that value is the checksum, never payload. This applies to all three
|
||||
cases (chk ∈ {0x02, 0x03, 0x04}) identically.
|
||||
chk_byte absorption (retired 2026-11-06, #58):
|
||||
The escape 0x10 of a checksum sent as `10 02/03/04` used to stay at the end
|
||||
of frame.data, and this builder dropped it here. The parser now drops it,
|
||||
so a 0x10 ending frame.data is real data (one A5 chunk in ten ends in one).
|
||||
|
||||
MLG CRC:
|
||||
The algorithm that produces the 2-byte CRC at the start of each MLG record
|
||||
@@ -297,29 +291,16 @@ def _frame_body_bytes(frame: S3Frame, skip: int) -> bytes:
|
||||
Extract the waveform body contribution from one A5 S3Frame.
|
||||
|
||||
The contribution is frame.data[skip:] with inner-frame DLE pairs stripped
|
||||
per _strip_inner_frame_dles(). The chk_byte is temporarily appended before
|
||||
stripping to handle the split-pair edge case where a DLE at the end of
|
||||
frame.data is paired with chk_byte.
|
||||
per _strip_inner_frame_dles().
|
||||
|
||||
Split-pair edge case (confirmed for A5[8] of M529LIY6 (example event), 2026-04-21):
|
||||
|
||||
S3FrameParser appends DLE+XX pairs as two literal bytes when XX ∉ {DLE, ETX}.
|
||||
When the LAST occurrence of such a pair straddles the payload/checksum boundary
|
||||
(i.e., DLE is the last byte of raw_payload and XX is the checksum), the parser
|
||||
splits them:
|
||||
- DLE ends up as the last byte of frame.data (frame.data[-1] == 0x10)
|
||||
- XX is stored as frame.chk_byte
|
||||
|
||||
To strip the pair correctly, we reunite the bytes before calling the strip
|
||||
function. Since chk_byte is the checksum (not payload data), it is excluded
|
||||
from the final output regardless of whether it was part of a pair.
|
||||
|
||||
Post-strip chk_byte removal (ALL cases):
|
||||
_strip_inner_frame_dles strips the 0x10 and KEEPS chk_byte in all cases.
|
||||
Chk_byte is always the checksum (not payload), so always strip it off.
|
||||
Until #58 (2026-11-06) an escaped checksum (`10 02/03/04`) left its 0x10 as
|
||||
the last byte of frame.data, and this function dropped it by pairing it with
|
||||
chk_byte (first seen on A5[8] of M529LIY6, 2026-04-21). The parser drops it
|
||||
now, so a 0x10 here is data and is kept.
|
||||
|
||||
Args:
|
||||
frame: S3Frame with frame.data and frame.chk_byte populated.
|
||||
frame: S3Frame from S3FrameParser (or a store pickle loaded by
|
||||
WaveformStore.load_a5, which converts pre-#58 frames).
|
||||
skip: Number of leading bytes in frame.data to exclude (frame header).
|
||||
|
||||
Returns:
|
||||
@@ -327,28 +308,7 @@ def _frame_body_bytes(frame: S3Frame, skip: int) -> bytes:
|
||||
"""
|
||||
if skip >= len(frame.data):
|
||||
return b""
|
||||
|
||||
relevant = frame.data[skip:]
|
||||
|
||||
# Detect split DLE+chk pair at the frame boundary.
|
||||
has_split_pair = (
|
||||
len(relevant) > 0
|
||||
and relevant[-1] == 0x10
|
||||
and frame.chk_byte in {0x02, 0x03, 0x04}
|
||||
)
|
||||
|
||||
if has_split_pair:
|
||||
# Reunite the split pair so the strip function sees both bytes together.
|
||||
buf = relevant + bytes([frame.chk_byte])
|
||||
stripped = _strip_inner_frame_dles(buf)
|
||||
# _strip_inner_frame_dles strips the DLE (0x10) and KEEPS chk_byte.
|
||||
# chk_byte is the received checksum — never payload — so remove it.
|
||||
# This is correct for all values in {0x02, 0x03, 0x04}.
|
||||
if stripped:
|
||||
stripped = stripped[:-1]
|
||||
return stripped
|
||||
else:
|
||||
return _strip_inner_frame_dles(relevant)
|
||||
return _strip_inner_frame_dles(frame.data[skip:])
|
||||
|
||||
|
||||
# ── Filename helper ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -2354,8 +2354,9 @@ def _decode_monitor_status(data: bytes) -> MonitorStatus:
|
||||
header, so field offsets below are relative to data[11]).
|
||||
|
||||
NOTE: frame.data has the checksum byte already stripped by S3FrameParser
|
||||
(_finalise returns raw_payload[5:] where raw_payload = body[:-1]).
|
||||
There is NO trailing checksum byte in section.
|
||||
(_finalise returns raw_payload[5:], the checksum and, since #58, the 10 of
|
||||
an escaped checksum removed). There is NO trailing checksum byte in section;
|
||||
before #58 one status reply in 63 kept that 10 and read 419.84 V.
|
||||
|
||||
Monitoring flag (confirmed 4-8-26/2ndtry, byte diff of all 144 data frames):
|
||||
section[1] == 0x00 → idle
|
||||
|
||||
+17
-12
@@ -534,11 +534,13 @@ STRT_MARKER = b"STRT"
|
||||
def unescape_reply(data: bytes) -> bytes:
|
||||
"""A reply's data with each kept escape removed: `10 02/03/04` → `02/03/04`.
|
||||
|
||||
The unit escapes 02, 03, 04 and 10 in its replies exactly as requests do
|
||||
(748/748 replies, 2026-10-26). S3FrameParser collapses `10 10` but keeps the
|
||||
`10` of `10 02/03/04` (inner-frame markers to it), so its `.data` carries an
|
||||
extra byte before each 02/03/04 value -- harmless for fields read before the
|
||||
escape, one byte off for any read after it, or counted from the end."""
|
||||
The unit escapes 02, 03, 04 and 10 in its replies exactly as requests do,
|
||||
the checksum included (748/748 replies, 2026-10-26; 7,747 / 7,747 across every
|
||||
recording, March to October 2026, #58). S3FrameParser collapses `10 10` but
|
||||
keeps the `10` of `10 02/03/04` (inner-frame markers to it) everywhere but the
|
||||
checksum, so its `.data` carries an extra byte before each 02/03/04 value --
|
||||
harmless for fields read before the escape, one byte off for any read after it,
|
||||
or counted from the end."""
|
||||
out, i = bytearray(), 0
|
||||
while i < len(data):
|
||||
if data[i] == DLE and i + 1 < len(data) and data[i + 1] in (STX, ETX, 0x04):
|
||||
@@ -632,11 +634,8 @@ class S3Frame:
|
||||
page_lo: int # PAGE_LO from header
|
||||
data: bytes # payload data section (payload[5:], checksum already stripped)
|
||||
checksum_valid: bool
|
||||
chk_byte: int = 0 # actual checksum byte received from wire (body[-1])
|
||||
# needed for waveform file reconstruction: when the last data byte
|
||||
# is 0x10 and chk_byte ∈ {0x02, 0x03, 0x04}, the DLE+chk pair
|
||||
# must be included in the DLE-strip operation to correctly
|
||||
# reconstruct the Blastware binary body.
|
||||
chk_byte: int = 0 # actual checksum byte received from wire (body[-1]); an
|
||||
# escaped one (`10 02/03/04`) leaves no 10 in `data` (#58)
|
||||
|
||||
@property
|
||||
def page_key(self) -> int:
|
||||
@@ -759,9 +758,15 @@ class S3FrameParser:
|
||||
if len(body) < 6:
|
||||
return None
|
||||
|
||||
raw_payload = body[:-1] # everything except the trailing checksum byte
|
||||
# A checksum of 02, 03 or 04 arrives escaped, `10 X`, and _step keeps both
|
||||
# bytes; that 10 is the escape, never data (#58: 272 of 7,747 recorded
|
||||
# replies, every one an escape pair). Any other checksum is one byte.
|
||||
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
|
||||
|
||||
@@ -196,10 +196,11 @@ def assemble_compliance_content(frames: "list[bytes]", lengths: "Optional[tuple]
|
||||
|
||||
`lengths`: the content each frame was asked for (SFM's read: 1024, 1024, 42).
|
||||
Each frame then gives exactly that. Measured at the bench 2026-11-04 (BE9441):
|
||||
when a frame's checksum byte is itself escaped (02 / 03 / 04), the parser keeps
|
||||
the escape's 0x10 and strips only the byte after it, so the frame arrives one
|
||||
byte long, ending in a lone 0x10. That one byte is dropped; any other leftover
|
||||
is kept, and the block then fails is_compliance_content."""
|
||||
when a frame's checksum byte was itself escaped (02 / 03 / 04), the parser kept
|
||||
the escape's 0x10, so the frame arrived one byte long, ending in a lone 0x10.
|
||||
The parser drops it since #58; this trim stays as a guard. That one byte is
|
||||
dropped; any other leftover is kept, and the block then fails
|
||||
is_compliance_content."""
|
||||
parts = [unescape_reply(bytes(f))[11:] for f in frames]
|
||||
parts = [p[1:] for p in parts[:-1]] + parts[-1:]
|
||||
if lengths is not None and len(lengths) == len(parts):
|
||||
@@ -633,8 +634,9 @@ class MiniMateProtocol:
|
||||
data_rsp = self._recv_one(expected_sub=rsp_sub)
|
||||
|
||||
raw = unescape_reply(data_rsp.data)[11:] # unescaped, as read_event_index
|
||||
# An escaped checksum byte leaves its 0x10 behind (bench 2026-11-04; see
|
||||
# assemble_compliance_content): one stray byte beyond what was asked is dropped.
|
||||
# An escaped checksum byte left its 0x10 behind until #58 (bench 2026-11-04;
|
||||
# see assemble_compliance_content): kept as a guard, one stray byte beyond
|
||||
# what was asked is dropped.
|
||||
if len(raw) == length + 1 and raw[-1:] == b"\x10":
|
||||
raw = raw[:-1]
|
||||
log.debug("read_waveform_data_raw: got %d bytes", len(raw))
|
||||
|
||||
Reference in new issue
Block a user