test: remove test_5a_protocol.py and the retracted 5A helpers only it used

Its 19 tests pinned the May 2026 5A model -- a raw offset_hi 0x10,
11-byte params, metadata pages at 0x1002 / 0x1004 -- retracted on
2026-10-26, and the 5-1-26 capture they read no longer exists on the dev
box, so they skipped everywhere.  tests/test_5a_blastware_walk.py
replaced them: all 540 of Blastware's 5A requests rebuilt from tracked
fixtures.  Removed with them, from framing.py, the four helpers marked
'superseded, no production caller, kept for test_5a_protocol.py':
build_5a_frame, bulk_waveform_params, bulk_waveform_term_params,
bulk_waveform_term_v2.  parse_strt_end_offset stays: test_5a_blastware_
walk.py uses it to show the old misread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-20 13:39:23 -05:00
1 parent 20b1581e37
commit 646da046b7
2 files changed
+7 -517

No files matched your search

+7 -265
View File
@@ -124,118 +124,17 @@ def build_5a_request(address: int, length: int) -> bytes:
crossing a 64 KB page): a 5A request is an ORDINARY 16-byte request --
`[10 00 5A 00][length BE][address BE 4][zeros 6]`, SUM8 checksum, every
02/03/04/10 escaped -- and this rebuilds all 540 of Blastware's 5A requests
byte for byte. The older model below (`build_5a_frame`: a raw "offset_hi
0x10", an "11-byte params", "metadata pages at 0x1002 / 0x1004") was the
same bytes misread: `10 02 00` is the length 0x0200 escaped, and the
"metadata pages" are the first event's chunks at 0x0200 and 0x0400.
byte for byte. The older model (`build_5a_frame` and the
`bulk_waveform_*` helpers, removed 2026-11-20: a raw "offset_hi 0x10", an
"11-byte params", "metadata pages at 0x1002 / 0x1004") was the same bytes
misread: `10 02 00` is the length 0x0200 escaped, and the "metadata pages"
are the first event's chunks at 0x0200 and 0x0400.
"""
if not 0 <= address <= 0xFFFFFFFF:
raise ValueError(f"address must fit in 32 bits, got {address:#x}")
return build_bw_frame(SUB_5A, length, address.to_bytes(4, "big") + bytes(6))
def build_5a_frame(offset_word: int, raw_params: bytes) -> bytes:
"""
⛔ SUPERSEDED 2026-10-26 by `build_5a_request` -- no production caller. Kept
because tests/test_5a_protocol.py pins its bytes against the 5-1-26 captures;
for in-page requests it emits the same bytes. Its model (below) is retracted.
Build a BW→S3 frame for SUB 5A (BULK_WAVEFORM_STREAM) that exactly
matches Blastware's wire output.
SUB 5A uses a DIFFERENT frame format from all other read commands:
1. The offset field (bytes [4:6]) is written RAW — the 0x10 in
offset_hi=0x10 is NOT DLE-stuffed, unlike build_bw_frame().
2. The checksum uses a DLE-aware sum: for each 0x10 XX pair in the
stuffed section, only XX contributes; lone bytes contribute normally.
This differs from the standard SUM8 checksum on the unstuffed payload.
Both differences are confirmed from the 1-2-26 BW TX capture (all 10 frames
verified against this algorithm on 2026-04-02).
Args:
offset_word: 16-bit offset. For probe/chunks/metadata pages this is
`0x1002`. For the proper TERM frame this is computed by
`bulk_waveform_term_v2()` from the STRT-derived
`end_offset`.
raw_params: 10, 11, or 12 params bytes (from `bulk_waveform_params`
for probes/samples, `bulk_waveform_term_v2` for TERM, or
a manually-built 12-byte block for the metadata pages
0x1002 / 0x1004). See gotcha #3 below — params region
uses partial DLE stuffing of 0x10 bytes.
Returns:
Complete frame bytes: [ACK][STX][stuffed_section][chk][ETX]
"""
if len(raw_params) not in (10, 11, 12):
# 10 = termination params; 11 = regular probe / chunk params;
# 12 = metadata-page params (extra trailing 0x00 — BW byte-perfect quirk
# for the two fixed metadata reads at counter=0x1002 and 0x1004).
raise ValueError(f"raw_params must be 10/11/12 bytes, got {len(raw_params)}")
# Build stuffed section between STX and checksum
s = bytearray()
s += b"\x10\x10" # DLE-stuffed BW_CMD
s += b"\x00" # flags
s += bytes([SUB_5A]) # sub = 0x5A
s += b"\x00" # field3
s += bytes([(offset_word >> 8) & 0xFF, # offset_hi — raw, NOT stuffed
offset_word & 0xFF]) # offset_lo
# Params — partial DLE stuffing of 0x10 bytes (CONFIRMED 2026-05-05).
#
# The device's de-stuffing rule for params is:
# • `10 10` → de-stuffs to `10`
# • `10 02/03/04` → kept literal (these are inner-frame markers)
# • `10 X` other → de-stuffs to just `X` (drops the 0x10)
#
# So for any 0x10 byte in the *logical* params that is followed by a
# byte NOT in {0x02, 0x03, 0x04, 0x10}, we must double the 0x10 on the
# wire (`10 X` → `10 10 X`) so the device's de-stuffer reproduces the
# original `10 X` pair. Without this, counter values with `0x10` in
# the high byte (e.g. counter=0x1000 has params bytes `10 00`) are
# silently corrupted to `0x__00` on the device side, and the device
# responds for the wrong address — for counter=0x1000 it returns the
# probe response (counter=0x0000), which contains the file header +
# STRT. That STRT block then lands in the assembled file body and
# Blastware rejects the file as malformed.
#
# Confirmed against BW capture 5-1-26 / bwcap3sec frame 20: params
# logical bytes `00 01 11 10 00 00 00 00 00 00 00` (counter=0x1000)
# are encoded on the wire as `00 01 11 10 10 00 00 00 00 00 00 00`.
# BW frames 13/14 (meta @ 0x1002 / 0x1004) leave `10 02` and `10 04`
# raw — the device handles those literal pairs correctly.
i = 0
while i < len(raw_params):
b = raw_params[i]
s.append(b)
if (
b == 0x10
and i + 1 < len(raw_params)
and raw_params[i + 1] not in (0x02, 0x03, 0x04, 0x10)
):
s.append(0x10) # double the 0x10 so it survives device de-stuffing
i += 1
# DLE-aware checksum: for 0x10 XX pairs count XX; for lone bytes count them
chk, i = 0, 0
while i < len(s):
if s[i] == DLE and i + 1 < len(s):
chk = (chk + s[i + 1]) & 0xFF
i += 2
else:
chk = (chk + s[i]) & 0xFF
i += 1
# A checksum that is itself a framing byte is DLE-escaped. Sent bare, a
# 0x02 before ETX reads as a new STX: BE9441 never answered chunk 0x7D06
# (`... 02 03`) and rebooted ~11 s later, twice; escaped (`10 02 03`) it
# answered in 28 ms, as did checksums 0x04 and 0x10 (bench, 2026-10-26).
# The set is a Micromate's escape set (251/251 THOR requests); the MiniMate's
# de-stuffing keeps `10 02/03/04` literal and turns `10 10` into 0x10.
tail = bytes([DLE, chk]) if chk in (STX, ETX, 0x04, DLE) else bytes([chk])
return bytes([ACK, STX]) + bytes(s) + tail + bytes([ETX])
def build_bw_frame(sub: int, offset: int = 0, params: bytes = bytes(10)) -> bytes:
"""
Build a BW→S3 read-command frame.
@@ -368,164 +267,6 @@ def token_params(token: int = 0) -> bytes:
return bytes(p)
def bulk_waveform_params(key4: bytes, counter: int, *, is_probe: bool = False) -> bytes:
"""
⛔ SUPERSEDED 2026-10-26 by `build_5a_request` / `parse_strt_end_key` -- no
production caller; kept for tests/test_5a_protocol.py. See build_5a_request.
Build the 10-byte params block for SUB 5A (BULK_WAVEFORM_STREAM) requests.
Confirmed 2026-04-02 from 1-2-26 BW TX capture analysis:
Probe / first request (is_probe=True, counter=0):
params[0] = 0x00
params[1:5] = key4 (all 4 key bytes; counter overlaps key4[2:4] = 0x0000)
params[5:] = zeros
Regular chunk requests (is_probe=False):
params[0] = 0x00
params[1:3] = key4[0:2] (first 2 key bytes as session handle)
params[3:5] = counter (BE uint16) (chunk position, increments by 0x0400)
params[5:] = zeros
Termination request: DO NOT use this helper — see bulk_waveform_term_params().
Args:
key4: 4-byte waveform key from EVENT_HEADER (1E) response.
counter: Chunk position counter (uint16 BE). Pass 0 for probe.
is_probe: If True, embed full key4 (probe step only).
Returns:
11-byte params block. (BW confirmed: chunk frames carry 11 params bytes,
not 10; the extra trailing 0x00 was confirmed from 1-2-26 wire capture
on 2026-04-02.)
"""
if len(key4) != 4:
raise ValueError(f"waveform key must be 4 bytes, got {len(key4)}")
p = bytearray(11) # 11 bytes confirmed from BW wire capture
p[0] = 0x00
p[1] = key4[0]
p[2] = key4[1]
if is_probe:
# Full key4; counter=0 is implied (overlaps with key4[2:4] which must be 0x0000)
p[3] = key4[2]
p[4] = key4[3]
else:
p[3] = (counter >> 8) & 0xFF
p[4] = counter & 0xFF
return bytes(p)
def bulk_waveform_term_params(key4: bytes, counter: int) -> bytes:
"""
⛔ SUPERSEDED 2026-10-26 by `build_5a_request` / `parse_strt_end_key` -- no
production caller; kept for tests/test_5a_protocol.py. See build_5a_request.
⛔ DEPRECATED — DO NOT USE IN NEW CODE.
This is the v1 termination params helper, paired with the broken
`_BULK_TERM_OFFSET = 0x005A` magic offset_word. Together they produce a
~100-byte device-side terminator response that does NOT contain the
partial-last-chunk waveform tail or the 26-byte file footer. Files
reconstructed using this terminator are missing their last ~512 bytes of
waveform data and have a synthesized footer that disagrees with what BW
would have written.
**For new code, use `bulk_waveform_term_v2(key4, end_offset, last_chunk_counter)`**
which computes the correct offset_word + params from the STRT-derived
`end_offset`. v2 produces wire bytes that match BW exactly across all
tested events (4-27-26 / 5-1-26 / 5-4-26 captures).
This function is retained ONLY for the defensive fallback path in
`read_bulk_waveform_stream()` that triggers when STRT parsing fails or no
chunks are fetched (= a malformed event or an unexpected device state).
The fallback already logs a WARNING when it activates; if you see that
warning, the bug is upstream — STRT should have been parseable.
"""
if len(key4) != 4:
raise ValueError(f"waveform key must be 4 bytes, got {len(key4)}")
p = bytearray(10)
p[0] = key4[0]
p[1] = key4[1]
p[2] = (counter >> 8) & 0xFF
return bytes(p)
def bulk_waveform_term_v2(
key4: bytes,
end_offset: int,
last_chunk_counter: int,
) -> tuple[int, bytes]:
"""
⛔ SUPERSEDED 2026-10-26 by `build_5a_request` / `parse_strt_end_key` -- no
production caller; kept for tests/test_5a_protocol.py. See build_5a_request.
Compute the SUB 5A TERM frame's offset_word and 10-byte params block.
Confirmed across 3 events (4-27-26 + 5-1-26 captures):
next_boundary = last_chunk_counter + 0x0200
offset_word = end_offset - next_boundary (residual byte count)
params[0] = key4[0] (= 0x01 on every observed device)
params[1] = key4[1] (= 0x11)
params[2] = (next_boundary >> 8) & 0xFF
params[3] = next_boundary & 0xFF
params[4:10] = zeros
Verification:
| end_offset | last_chunk | next_boundary | offset_word | params[2:4] |
| 0x1ABE | 0x1800 | 0x1A00 | 0x00BE | 1A 00 |
| 0x21F2 | 0x1E00 | 0x2000 | 0x01F2 | 20 00 |
| 0x417E | 0x3E38 | 0x4038 | 0x0146 | 40 38 |
The device receives `requested_address = (params[2] << 8) | offset_word`
and replies with `(end_offset - next_boundary)` bytes of waveform tail
starting at `next_boundary` — including the 26-byte file footer.
Args:
key4: 4-byte waveform key for this event.
end_offset: Event-end pointer (= `(end_key[2] << 8) | end_key[3]`
from the STRT record at data[23:27] of A5[0]).
last_chunk_counter: Counter of the last full 0x0200-byte chunk fetched
(the chunk that covers [last_chunk_counter,
last_chunk_counter + 0x0200)).
Returns:
(offset_word, params10) tuple. Pass as
`build_5a_frame(offset_word, params)`.
Raises:
ValueError: on inconsistent inputs.
"""
if len(key4) != 4:
raise ValueError(f"waveform key must be 4 bytes, got {len(key4)}")
next_boundary = last_chunk_counter + 0x0200
if next_boundary > 0xFFFF:
raise ValueError(
f"next_boundary 0x{next_boundary:04X} exceeds uint16; check inputs"
)
if end_offset <= last_chunk_counter:
raise ValueError(
f"end_offset 0x{end_offset:04X} must be > "
f"last_chunk_counter 0x{last_chunk_counter:04X}"
)
offset_word = end_offset - next_boundary
if offset_word < 0:
# Last chunk overshot end_offset; caller should have stopped one chunk
# earlier. Treat as zero residual.
offset_word = 0
if offset_word > 0xFFFF:
raise ValueError(
f"offset_word 0x{offset_word:04X} exceeds uint16"
)
p = bytearray(10)
p[0] = key4[0]
p[1] = key4[1]
p[2] = (next_boundary >> 8) & 0xFF
p[3] = next_boundary & 0xFF
return offset_word, bytes(p)
# ── End-offset extraction from STRT record ────────────────────────────────────
STRT_MARKER = b"STRT"
@@ -567,7 +308,8 @@ def parse_strt_end_offset(a5_data: bytes) -> Optional[int]:
"""
⛔ SUPERSEDED 2026-10-26 by `parse_strt_end_key`: this keeps only the low 16
bits (the 64 KB page bug) and misreads an end whose low bytes hold an escaped
02/03/04. No production caller; kept for tests/test_5a_protocol.py.
02/03/04. No production caller; tests/test_5a_blastware_walk.py keeps it
to show that misread.
Extract the event-end offset from the STRT record in an A5 response payload.