fix(minimateplus): a non-first event's 5A stream has no metadata pages -- stop cutting 2 bytes

extract_body_bytes() and write_blastware_file() skipped 13 bytes on A5 frames
1 and 2 unconditionally, as if they were the global metadata pages (0x1002,
0x1004).  Only the event-1 walk fetches those; a non-first event goes straight
from the probe to sample chunks (skip 12), so every non-first event SFM built
lost two bytes and decoded truncated (BE9441 event 1: 1,024 / 2,782 / 512
samples instead of 21,504, peaks far low).  Frames now say which they are: each
A5 reply echoes its address, and both 0x1002 at frame 1 and 0x1004 at frame 2
must match.  Rebuilt from the bench's logged bytes, event 1 decodes 21,504 x 3
with peaks equal to the unit's own 0C values.

Fixtures: BE9441's raw replies for events 0 and 1 (force-added).

Operational: affects only Series-3 files SFM assembled itself (live downloads,
bridges/ach_server.py) for non-first events -- not Blastware's own files, which
is what the production store ingests.  Such files are two bytes short; their
.a5.pkl sidecars can rebuild them.  No DB or schema change; codec unchanged
(TOOL_VERSION not bumped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-25 18:05:44 -04:00
1 parent a8cc516601
commit 352f6944e7
5 files changed
+99 -5

No files matched your search

+22 -5
View File
@@ -552,6 +552,21 @@ def classify_frame(frame: S3Frame) -> str:
# ── Waveform file writer ───────────────────────────────────────────────────────────
def _has_metadata_pages(a5_frames) -> bool:
"""Whether A5 frames 1 and 2 are the global metadata pages.
Only the event-1 walk (start_key[2:4] == 0) fetches them, at 0x1002 and
0x1004; a non-first event's stream goes straight from the probe to sample
chunks. Each A5 reply echoes its address at data[2:6], so the frames say
which they are. Both must match: a sample chunk can sit at 0x1002, but then
the next one is at 0x1202, never 0x1004. (Assuming metadata pages in every
stream lost two bytes from every non-first event -- BE9441, 2026-10-25.)
"""
return (len(a5_frames) > 2
and bytes(a5_frames[1].data[4:6]) == b"\x10\x02"
and bytes(a5_frames[2].data[4:6]) == b"\x10\x04")
def extract_body_bytes(a5_frames):
"""Reconstruct the Blastware-file body bytes from a list of A5 frames.
@@ -612,11 +627,12 @@ def extract_body_bytes(a5_frames):
body_frames = a5_frames
term_frame = None
meta = _has_metadata_pages(body_frames)
all_bytes = bytearray()
for fi, frame in enumerate(body_frames):
if fi == 0:
skip = probe_skip
elif fi in (1, 2):
elif fi in (1, 2) and meta:
skip = 13 # metadata pages
else:
skip = 12 # sample chunks
@@ -786,8 +802,8 @@ def write_blastware_file(
# Frame contribution loop (v0.14.0 BW-exact walk).
# Skip values:
# probe (fi=0): probe_skip
# meta@0x1002 (fi=1): 13 (6-byte inner header)
# meta@0x1004 (fi=2): 13 (6-byte inner header)
# meta@0x1002 (fi=1): 13 (6-byte inner header) -- event-1 walk only
# meta@0x1004 (fi=2): 13 (6-byte inner header) -- event-1 walk only
# sample chunks (fi=3+): 12 (5-byte inner header)
last_fi = len(body_frames) - 1
@@ -796,13 +812,14 @@ def write_blastware_file(
len(body_frames), last_fi,
)
meta = _has_metadata_pages(body_frames)
all_bytes = bytearray()
for fi, frame in enumerate(body_frames):
if fi == 0:
skip = probe_skip
elif fi in (1, 2):
skip = 13 # metadata pages
elif fi in (1, 2) and meta:
skip = 13 # metadata pages (event-1 walk only)
else:
skip = 12 # sample chunks