Measured against every Blastware request on record: the uploaded Feb-Apr 2026
captures (3,869 frames, 3,869 re-encode exactly) and BE9441's two sends on
2026-10-26 (26 write frames). A write is the standard 16-byte request plus its
data, every 02/03/04/10 escaped, SUM8 checksum; the length field is the data's
length. A config block starts with its own length N and is written as N + 2
bytes: event index (68) and trigger (82) as read plus 02 00 / 00 00 (constant on
15 sends), waveform data (69) and the 2,092-byte compliance image (71) whole.
The compliance image goes in addressed chunks (params[2:4] = address): 512 bytes
tonight (Blastware 10.74), 1,024 in March.
- framing.build_bw_write_frame: uniform escaping, SUM8, length = len(data).
RETRACTED: 'only BW_CMD doubled', the 'DLE-aware checksum', 'offset = data[1]
+ 2' -- fitted to frames still holding their escape bytes ('data 91, offset 90'
was 90 bytes and one escape). It got 7 of every 13 frames in a write wrong.
- protocol.write_image(): unescapes (callers may pass the parser's form), adds
the trailing two bytes to an N-byte block, and REFUSES anything else before a
byte is sent -- an edit beside a kept escape byte (the old encoder's anc-9
hazard) leaves an image one byte long.
- write_compliance_config_raw: 512-byte addressed chunks, then confirm 72.
- read_event_index / read_waveform_data_raw unescape before slicing (a block
holding 02/03/04/10 came out short); new read_trigger_config (SUB 0x2E).
- apply_config reads the unit's trigger block. RETRACTED: the block
'hardcoded from 3-11-26 -- no read exists'. Blastware reads it; byte 5 has
been 01 / 03 / 04 by unit and session, and the March copy (03) would have
changed BE9441's (01).
- The call-home write (7E) goes through write_image: its 127-byte 'read + 00 00'
is the 126-byte image (N = 0x7C). No Blastware 7E is on record here -- that
one is inferred from the other 77 write frames.
Tests: tonight's 26 and every Feb-Apr write frame rebuilt byte for byte; each
block as read written exactly as Blastware wrote it; the parser's form; the
stray-byte refusal; the reads against the unit's recorded replies; apply_config
writes BE9441's own trigger block. Six mutants, each caught. The old
test_write_frames.py (25 tests that had been skipping) runs now that the
captures are here, rewritten to the measured model.
Not yet sent to a unit: a config push changes settings, so its first live use
is a bench session with Brian. No codec, store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
105 lines
3.5 KiB
Python
105 lines
3.5 KiB
Python
"""
|
||
test_write_frames.py — the 3-11-26/170151 Blastware config write, read correctly.
|
||
|
||
Frames 102–112 of raw_bw_20260311_170151.bin: 68, 73, 71×3, 72, 82, 83, 69, 74, 72.
|
||
|
||
⚠ REWRITTEN 2026-10-27 (#46). This file pinned a model of these frames that was
|
||
wrong: "only BW_CMD is doubled", a "DLE-aware checksum", compliance chunks of
|
||
1,027 / 1,055 bytes at "offset 0x1004", single-block "offset = data[1] + 2".
|
||
Every one of those read the frames with their escape bytes still in. Decoded
|
||
as every Blastware request decodes (each 02/03/04/10 escaped, SUM8 of the
|
||
payload), these frames are ordinary requests: a LENGTH at [4:6] equal to the
|
||
data's length, the compliance image in 1,024-byte chunks addressed by
|
||
params[2:4], and blocks of N + 2 bytes. tests/test_minimate_write_frames.py
|
||
covers every write on record, tonight's 26 frames included.
|
||
|
||
Skips when the capture is absent.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
|
||
import pytest
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
from minimateplus.framing import build_bw_write_frame, checksum
|
||
|
||
CAPTURE_PATH = os.path.join(
|
||
os.path.dirname(__file__), "..", "bridges", "captures", "3-11-26", "raw_bw_20260311_170151.bin",
|
||
)
|
||
|
||
|
||
def _unstuff(b: bytes) -> bytes:
|
||
out, k = bytearray(), 0
|
||
while k < len(b):
|
||
if b[k] == 0x10 and k + 1 < len(b):
|
||
out.append(b[k + 1]); k += 2
|
||
else:
|
||
out.append(b[k]); k += 1
|
||
return bytes(out)
|
||
|
||
|
||
def _frames(raw: bytes) -> list:
|
||
out, i = [], 0
|
||
while i < len(raw):
|
||
if raw[i:i + 2] == b"\x41\x03":
|
||
i += 2
|
||
continue
|
||
if raw[i:i + 2] != b"\x41\x02":
|
||
i += 1
|
||
continue
|
||
j = i + 2
|
||
while j < len(raw) and raw[j] != 0x03:
|
||
j += 2 if raw[j] == 0x10 else 1
|
||
out.append(raw[i:j + 1])
|
||
i = j + 1
|
||
return out
|
||
|
||
|
||
@pytest.fixture(scope="module")
|
||
def writes() -> list:
|
||
if not os.path.exists(CAPTURE_PATH):
|
||
pytest.skip(f"Capture file not found: {CAPTURE_PATH}")
|
||
frames = _frames(open(CAPTURE_PATH, "rb").read())
|
||
w = [f for f in frames if 0x68 <= _unstuff(f[2:-1])[2] <= 0x83]
|
||
assert [f"{_unstuff(f[2:-1])[2]:02X}" for f in w] == \
|
||
["68", "73", "71", "71", "71", "72", "82", "83", "69", "74", "72"]
|
||
return w
|
||
|
||
|
||
def _fields(frame: bytes):
|
||
p = _unstuff(frame[2:-1])
|
||
payload, chk = p[:-1], p[-1]
|
||
return payload[2], int.from_bytes(payload[4:6], "big"), payload[6:16], payload[16:], chk, payload
|
||
|
||
|
||
def test_every_frame_is_an_ordinary_request_with_a_sum8_checksum(writes):
|
||
for f in writes:
|
||
sub, length, params, data, chk, payload = _fields(f)
|
||
assert chk == checksum(payload)
|
||
assert build_bw_write_frame(sub, data, params=params) == f
|
||
|
||
|
||
def test_the_length_field_is_the_datas_length(writes):
|
||
for f in writes:
|
||
sub, length, params, data, chk, _ = _fields(f)
|
||
assert length == len(data)
|
||
|
||
|
||
def test_single_blocks_are_their_header_plus_two(writes):
|
||
for f in writes:
|
||
sub, length, params, data, chk, _ = _fields(f)
|
||
if sub in (0x68, 0x82, 0x69):
|
||
assert len(data) == int.from_bytes(data[:2], "big") + 2
|
||
|
||
|
||
def test_the_compliance_image_goes_in_1024_byte_chunks_addressed_by_params(writes):
|
||
chunks = [_fields(f) for f in writes if _fields(f)[0] == 0x71]
|
||
assert [(length, params[2:4].hex()) for _, length, params, *_ in chunks] == \
|
||
[(0x400, "0000"), (0x400, "0400"), (0x2C, "0800")]
|
||
image = b"".join(c[3] for c in chunks)
|
||
assert len(image) == 2092 and int.from_bytes(image[:2], "big") == 2090
|