fix(framing): an escaped checksum no longer leaves its 0x10 in a reply's data (#58)
A MiniMate sends a checksum of 02, 03 or 04 as `10 X`. S3FrameParser kept both bytes and _finalise took only the last as the checksum, so the frame's data ended in a stray 0x10. It now takes the pair. Measured on every recorded reply (60 captures, March to October 2026): SUM8 of the unescaped payload is the checksum on 7,747 of 7,747; 272 arrived escaped, all valid as an escape pair. What the stray byte did: - 1C status: battery and memory are counted from the end; 12 of 760 recorded status replies read 419.84 V / 251,654,656 bytes (6.76 V / 983,026). - 2C call-home read: one byte long, refused as "monitoring". - 1A, 09 reads: already trimmed (bench 2026-11-04); the trims stay as guards. - 5A file builder: compensated in _frame_body_bytes; that pairing is removed, else a real 0x10 ending a chunk (one in ten do) would be dropped. Stored .a5.pkl frames: A5_PICKLE_VERSION 2; load_a5 drops the stray 0x10 from version-1 frames. All 28 pickles on this box rebuild byte-identical to dev's build. Operational consequence: none for prod's stored events (S3 events arrive through save_imported_bw, which keeps no frames); no schema change, no TOOL_VERSION bump, no backfill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
d2fe675650
commit
89c5234ac0
6 files changed
+214
-71
No files matched your search
+19
-3
@@ -46,7 +46,19 @@ from sfm.shape_metrics import shape_from_h5, offset_from_h5
|
||||
|
||||
log = logging.getLogger("sfm.waveform_store")
|
||||
|
||||
A5_PICKLE_VERSION = 1
|
||||
# 2 (2026-11-06, #58): frames as the parser gives them since an escaped checksum
|
||||
# stopped leaving its 0x10 in `data`. A version-1 frame with a checksum of 02, 03
|
||||
# or 04 still ends in that 0x10; load_a5 drops it (_frame_from_v1).
|
||||
A5_PICKLE_VERSION = 2
|
||||
|
||||
|
||||
def _frame_from_v1(f: S3Frame) -> S3Frame:
|
||||
"""A frame pickled before #58, as the parser reads its reply now. Its 02/03/04
|
||||
checksum arrived as `10 X` (every recorded one did), and the 10 ended `data`."""
|
||||
if f.chk_byte in (0x02, 0x03, 0x04) and f.data[-1:] == b"\x10":
|
||||
return S3Frame(sub=f.sub, page_hi=f.page_hi, page_lo=f.page_lo, data=f.data[:-1],
|
||||
checksum_valid=f.checksum_valid, chk_byte=f.chk_byte)
|
||||
return f
|
||||
|
||||
|
||||
def _frame_to_dict(f: S3Frame) -> dict:
|
||||
@@ -801,7 +813,8 @@ class WaveformStore:
|
||||
|
||||
def load_a5(self, serial: str, filename: str) -> Optional[list[S3Frame]]:
|
||||
"""
|
||||
Re-hydrate the pickled A5 frame stream for a stored event.
|
||||
Re-hydrate the pickled A5 frame stream for a stored event, as the parser
|
||||
reads it now (a version-1 pickle's frames are converted).
|
||||
Returns None if the sidecar is missing.
|
||||
"""
|
||||
_, a5_path = self.paths_for(serial, filename)
|
||||
@@ -812,7 +825,10 @@ class WaveformStore:
|
||||
if not isinstance(payload, dict) or "frames" not in payload:
|
||||
log.warning("WaveformStore.load_a5: malformed sidecar at %s", a5_path)
|
||||
return None
|
||||
return [_dict_to_frame(d) for d in payload["frames"]]
|
||||
frames = [_dict_to_frame(d) for d in payload["frames"]]
|
||||
if payload.get("version", 1) < 2:
|
||||
frames = [_frame_from_v1(f) for f in frames]
|
||||
return frames
|
||||
|
||||
# ── modern .sfm.json sidecar accessors ──────────────────────────────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user