fix(protocol): correct A5 frame classification and chunk counter formula

This commit is contained in:
2026-04-24 17:25:29 -04:00
parent 43c8158493
commit 35c3f4f945
4 changed files with 48 additions and 27 deletions
+15 -5
View File
@@ -527,7 +527,7 @@ def classify_frame(frame: S3Frame) -> str:
Returns one of:
"terminator" — page_key == 0x0000
"probe_or_strt" — data contains b"STRT" (the initial probe response)
"probe_or_strt" — data contains b"STRT\xff\xfe" (the initial probe response)
"metadata" — data contains ASCII compliance-config markers
"waveform" — predominantly binary (< 20 % printable ASCII)
"unknown" — none of the above criteria matched
@@ -539,7 +539,7 @@ def classify_frame(frame: S3Frame) -> str:
if frame.page_key == 0x0000:
return "terminator"
data = bytes(frame.data)
if b"STRT" in data:
if b"STRT\xff\xfe" in data:
return "probe_or_strt"
if any(m in data for m in _METADATA_FRAME_MARKERS):
return "metadata"
@@ -677,6 +677,7 @@ def write_blastware_file(
term_frame = None
all_bytes = bytearray()
seen_metadata = False
for fi, frame in enumerate(body_frames):
ftype = classify_frame(frame)
@@ -686,11 +687,20 @@ def write_blastware_file(
# Probe frame: always process regardless of classification.
# It holds the STRT record; probe_skip positions us past it.
skip = probe_skip
elif ftype == "waveform":
elif seen_metadata:
# Drop all frames that come after the compliance/metadata block.
# (e.g. extra waveform chunks fetched after stop_after_metadata)
log.debug(
"write_blastware_file: frame %d after metadata — skipping", fi
)
continue
elif ftype in ("waveform", "metadata"):
skip = 13 if fi == 1 else 12
if ftype == "metadata":
seen_metadata = True
else:
# Skip metadata, probe_or_strt, and unknown frames.
if b"STRT" in bytes(frame.data):
# Skip probe_or_strt and unknown frames.
if b"STRT\xff\xfe" in bytes(frame.data):
log.warning(
"write_blastware_file: frame %d (%s) contains STRT — skipping",
fi, ftype,