fix(minimateplus): size the 5A chunk cap from STRT, refuse a misread STRT, TERM only a tail

Follow-ups from the review of 887e75d (verdict: keep, with fixes; no critical).

- The cap: a caller's max_chunks (client.py passes 128) now bounds only a walk
  whose end is unknown.  With STRT it cut every event past ~66 KB short --
  2,545 of 63,500 archived histograms are bigger (the review's count, DL2).
  Strict raised; legacy sent a TERM for most of the event, or a bare ValueError.
- A STRT claiming less than one 0x200 chunk, or more than 4 MiB (a sanity bound,
  not a measured limit), is refused as a misread, in both modes -- once a bare
  ValueError and a 500.
- TERM is sent only for a true tail (< 0x200).  After an early end the legacy
  walk returns what arrived and sends none.
- build_5a_request wraps build_bw_frame; the old 5A helpers are marked
  superseded (kept for tests/test_5a_protocol.py) and their imports dropped.

Tests: all 8 recorded events (were 4) walk exactly as Blastware and rebuild its
own files; an end key holding escaped bytes; a 300 KB event past a 128 cap; both
misread-STRT refusals; the 1A frames BE9441 answered post-fix; the checksum
vectors retargeted.  Mutants the review saw survive (no STRT un-escape; a
standard-request escape revert) and 3 new ones are each caught.

Measured on the way: a reply's checksum is SUM8 of its unescaped payload,
748/748.  The 'S3 checksums frequently fail' note was the parser summing its
own kept escape bytes; noted, parser unchanged.

Docs: the crossing count corrected to four (events 1, 3, 5, 7); the remaining
stale 5A sections in CLAUDE.md annotated; the write-frame suspicion recorded as
inferred only.  No codec, store or DB change.

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-26 15:16:10 -04:00
1 parent f61fc3cc78
commit 8acb9512a9
15 files changed
+285 -73

No files matched your search

+48 -12
View File
@@ -10,7 +10,7 @@ pair — lives in `../terra-view/docs/tmi-stack.md`, which is also loaded as
--- ---
## Where things stand (updated 2026-10-25) ## Where things stand (updated 2026-10-26)
Read this first when picking the project back up. Read this first when picking the project back up.
@@ -150,11 +150,14 @@ Read this first when picking the project back up.
Series-3 downloads are now checked against the unit's own 0C peaks before Series-3 downloads are now checked against the unit's own 0C peaks before
being stored. **Re-run 2026-10-26:** every event that does not cross a being stored. **Re-run 2026-10-26:** every event that does not cross a
64 KB page downloaded whole and verified (events 0, 1, 3, 4, 10). The two 64 KB page downloaded whole and verified (events 0, 1, 3, 4, 10). ~~The two
that cross one (events 2, 19) are refused by name. Stale id gives 409, a that cross one (events 2, 19) are refused by name.~~ **Later the same day the
repeat gives `already_stored`. ⚠ Still owed before merge: a histogram event, page bug was fixed** (see the ✅ FIXED entry below): a fresh 8 events, 4 of them
`already_stored` against Blastware's copy, and start/stop through the new path crossing a page, all downloaded byte-identical to Blastware's own files. Stale
(spec, phase 1b). Next: 1c (webapp). id gives 409, a repeat gives `already_stored`, also against Blastware's imported
copy. ⚠ Still owed before merge: a histogram event (and one over ~66 KB, the
size a 128-chunk cap used to cut short; now sized from STRT, untested on a unit)
and start/stop through the new path (spec, phase 1b). Next: 1c (webapp).
- **✅ Phase 3: start / stop monitoring by serial (2026-10-23) — built, - **✅ Phase 3: start / stop monitoring by serial (2026-10-23) — built,
reviewed, and bench-verified on UM20147 (2026-10-25).** Start acked in reviewed, and bench-verified on UM20147 (2026-10-25).** Start acked in
0.46 s and read back as monitoring at the first 2 s poll (during the sensor 0.46 s and read back as monitoring at the first 2 s poll (during the sensor
@@ -246,7 +249,7 @@ Read this first when picking the project back up.
relative), so do NOT retune `_GEO_LSB_IPS`. relative), so do NOT retune `_GEO_LSB_IPS`.
- **✅ FIXED 2026-10-26 (`887e75d`) — was: "KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB."** - **✅ FIXED 2026-10-26 (`887e75d`) — was: "KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB."**
Kept below as history. The fix came from a recording of Blastware downloading all 8 of Kept below as history. The fix came from a recording of Blastware downloading all 8 of
BE9441's events, 3 crossing a page (`tests/fixtures/minimate-bench-10-26-26-blastware/`): BE9441's events, 4 crossing a page (`tests/fixtures/minimate-bench-10-26-26-blastware/`):
- **Every MiniMate request DLE-escapes 02, 03, 04 and 10**, payload and checksum alike - **Every MiniMate request DLE-escapes 02, 03, 04 and 10**, payload and checksum alike
(748/748 re-encode). `build_bw_frame` had escaped only 0x10. (748/748 re-encode). `build_bw_frame` had escaped only 0x10.
- **A 5A request is an ordinary request carrying a LENGTH and a 4-byte linear ADDRESS.** - **A 5A request is an ordinary request carrying a LENGTH and a 4-byte linear ADDRESS.**
@@ -260,6 +263,20 @@ Read this first when picking the project back up.
⚠ Sections below that describe "partial DLE stuffing", "11-byte params", "offset_hi ⚠ Sections below that describe "partial DLE stuffing", "11-byte params", "offset_hi
0x10 raw" and "metadata pages 0x1002/0x1004" are that misreading. They are retracted 0x10 raw" and "metadata pages 0x1002/0x1004" are that misreading. They are retracted
here, not deleted. here, not deleted.
**Review follow-ups (2026-10-26):** the walk's chunk cap is now sized from STRT (a
caller's 128 cut every event past ~66 KB; 2,545 of 63,500 archived histograms are
bigger); a STRT claiming less than one chunk or more than 4 MiB is refused as a
misread; a TERM is sent only for a true tail. Still open, none measured: an event
ending exactly on a chunk step sends a zero-length TERM (as the old code did; 1 in
512, never seen); with no STRT the legacy walk still reads `max_chunks` blind.
🔶 **Inferred only, do not act on it without a capture:** `build_bw_write_frame`
("raw except BW_CMD", "DLE-aware checksum") carries the same fingerprints as the
retracted 5A model: SUB 71's "offset 0x1004" reads as length 0x0400 escaped, and
Blastware escapes `03` in write data. A write whose payload holds a bare
02/03/04/10 may be malformed. One Blastware config-write capture settles it.
🔑 **Replies follow the same rule (measured, 748/748):** every 02/03/04/10 escaped,
checksum = SUM8 of the unescaped payload. The "S3 checksums frequently fail" belief
is `S3FrameParser` summing its output with the `10` of `10 02/03/04` still in it.
~~**⚠ KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB.**~~ ~~**⚠ KNOWN BUG — the 5A walk breaks once a unit's buffer crosses 64 KB.**~~
`parse_strt_end_offset()` returns only `(end_key[2] << 8) | end_key[3]`, `parse_strt_end_offset()` returns only `(end_key[2] << 8) | end_key[3]`,
discarding the key's page byte. An event starting at `0x0111F2A2` and ending discarding the key's page byte. An event starting at `0x0111F2A2` and ending
@@ -530,7 +547,7 @@ Full read pipeline + write pipeline + erase pipeline + monitor log + call home c
| Event header / first key | 1E | ✅ | | Event header / first key | 1E | ✅ |
| Waveform header | 0A | ✅ | | Waveform header | 0A | ✅ |
| Waveform record (peaks, timestamp, project) | 0C | ✅ | | Waveform record (peaks, timestamp, project) | 0C | ✅ |
| **Bulk waveform stream (event-time metadata + full waveform)** | **5A** | ✅ **byte-perfect against BW captures (v0.14.3, 2026-05-05)** — STRT-bounded chunk walk + correct event-N probe counter + DLE-stuffed `0x10` bytes in params + concatenate-only file body assembly. All 17 5A request frames in the 5-1-26 3-sec capture reproduce byte-for-byte. | | **Bulk waveform stream (event-time metadata + full waveform)** | **5A** | ✅ **(2026-10-26: a LENGTH read at a 32-bit ADDRESS, every 02/03/04/10 escaped — the model in the rest of this cell is retracted, see "✅ FIXED 2026-10-26")** byte-perfect against BW captures (v0.14.3, 2026-05-05) — STRT-bounded chunk walk + correct event-N probe counter + DLE-stuffed `0x10` bytes in params + concatenate-only file body assembly. All 17 5A request frames in the 5-1-26 3-sec capture reproduce byte-for-byte. |
| Event advance / next key | 1F | ✅ | | Event advance / next key | 1F | ✅ |
| **Write commands (push config to device)** | **68–83** | ✅ new v0.8.0 | | **Write commands (push config to device)** | **68–83** | ✅ new v0.8.0 |
| **Erase all events** | **0xA3 → 0x1C → 0x06 → 0xA2** | ✅ new v0.9.0 | | **Erase all events** | **0xA3 → 0x1C → 0x06 → 0xA2** | ✅ new v0.9.0 |
@@ -994,6 +1011,11 @@ several events should read 0x1002/0x1004 only once at the start.
`read_bulk_waveform_stream`. `read_bulk_waveform_stream`.
### SUB 5A — STRT record encodes end_offset (NEW 2026-05-01) ### SUB 5A — STRT record encodes end_offset (NEW 2026-05-01)
> ⚠ **SUPERSEDED 2026-10-26:** the end is the FULL 32-bit `end_key`
> (`parse_strt_end_key`), read after removing the reply's escape bytes. The 16-bit
> `end_offset` below was the 64 KB page bug, and misread any end whose low bytes held
> an escaped 02/03/04.
The first A5 response (probe response, or the first chunk for event 2+) contains a STRT The first A5 response (probe response, or the first chunk for event 2+) contains a STRT
record at byte offset 17 of the `data` field. Layout: record at byte offset 17 of the `data` field. Layout:
@@ -1023,6 +1045,11 @@ Verified across 3 events:
| 5-1-26 "copy 2nd address" / DA event 2 | `011121F2` | `0111417E` | `0x417E` (event 2 span 0x1F8C = 8,076 B) | | 5-1-26 "copy 2nd address" / DA event 2 | `011121F2` | `0111417E` | `0x417E` (event 2 span 0x1F8C = 8,076 B) |
### SUB 5A — TERM frame formula (FINALIZED 2026-05-01) ### SUB 5A — TERM frame formula (FINALIZED 2026-05-01)
> ⚠ **SUPERSEDED 2026-10-26:** TERM is `build_5a_request(next_boundary, end -
> next_boundary)`: a read of the remainder at the next 32-bit boundary. "offset_word"
> is that length; "params[2:4]" are the address's low bytes. The tables below still
> hold as numbers.
The TERM frame fetches the partial last chunk *and* the file footer. It is **not** a simple The TERM frame fetches the partial last chunk *and* the file footer. It is **not** a simple
"goodbye" frame — its response payload contains the bytes between the last full 0x0200-aligned "goodbye" frame — its response payload contains the bytes between the last full 0x0200-aligned
@@ -1096,6 +1123,9 @@ confirmed from the BW wire capture. `bulk_waveform_term_params()` returns 10 byt
Do not swap them. Do not swap them.
### SUB 5A — event-time metadata source (FINALIZED 2026-05-05) ### SUB 5A — event-time metadata source (FINALIZED 2026-05-05)
> ⚠ **AMENDED 2026-10-26:** the strings come from the first event's chunks at 0x0200 and
> 0x0400, not from "global pages read once per session" (see the retraction above).
The metadata strings come from the two fixed metadata pages at counter `0x1002` and The metadata strings come from the two fixed metadata pages at counter `0x1002` and
`0x1004` (see "SUB 5A — fixed metadata pages 0x1002 and 0x1004" above). These pages `0x1004` (see "SUB 5A — fixed metadata pages 0x1002 and 0x1004" above). These pages
@@ -1137,6 +1167,11 @@ that's an old-walk artifact (the broken `0x0400`-step formula occasionally caugh
pages instead. pages instead.
### SUB 5A — end-of-stream (FINALIZED 2026-05-01) ### SUB 5A — end-of-stream (FINALIZED 2026-05-01)
> ⚠ **AMENDED 2026-10-26:** a reply's `page_key` is not a page. It is the echoed
> length plus an escape byte the parser keeps: all 532 chunk replies read `0x0010` and
> the 8 TERMs `0x0000`/`0x0001`. The walk relies on it only for the mid-stream
> terminator check, and now sends TERM only for a tail (< 0x200).
Under the v0.14.0+ STRT-bounded walk the stream ends cleanly: Under the v0.14.0+ STRT-bounded walk the stream ends cleanly:
@@ -1302,6 +1337,7 @@ Confirmed from the 5-1-26 "Download All" capture:
1F → null sentinel 1F → null sentinel
``` ```
(⚠ 2026-10-26: the walk starts at the 0x46 key itself, as a plain 32-bit address.)
This is why event 2's first 5A chunk is at `start_key + 0x46` — that's the address of the This is why event 2's first 5A chunk is at `start_key + 0x46` — that's the address of the
"real start" 0x46-record, distinct from the `0x2C`-record at the raw boundary. Use the "real start" 0x46-record, distinct from the `0x2C`-record at the raw boundary. Use the
`0x46` keys as the input to `read_bulk_waveform_stream`, not the `0x2C` keys. `0x46` keys as the input to `read_bulk_waveform_stream`, not the `0x2C` keys.
@@ -1563,12 +1599,12 @@ All DB endpoints are read-only except `PATCH /db/events/{id}/false_trigger`.
| Capture | Location | Contents | | Capture | Location | Contents |
|---|---|---| |---|---|---|
| 1-2-26 | `bridges/captures/1-2-26/` | SUB 5A BW TX frames — confirmed 5A frame format, 11-byte params, DLE-aware checksum | | 1-2-26 | `bridges/captures/1-2-26/` | SUB 5A BW TX frames — confirmed 5A frame format, 11-byte params, DLE-aware checksum (⚠ that model retracted 2026-10-26: a standard frame, length + 32-bit address) |
| 3-11-26 | `bridges/captures/3-11-26/` | Full compliance setup write, Aux Trigger capture | | 3-11-26 | `bridges/captures/3-11-26/` | Full compliance setup write, Aux Trigger capture |
| 3-31-26 | `bridges/captures/3-31-26/` | Complete event download cycle (148 BW / 147 S3 frames) — confirmed 1E/0A/0C/1F sequence; only 1 event stored so token=0xFE appeared to work | | 3-31-26 | `bridges/captures/3-31-26/` | Complete event download cycle (148 BW / 147 S3 frames) — confirmed 1E/0A/0C/1F sequence; only 1 event stored so token=0xFE appeared to work |
| 4-3-26 | `bridges/captures/4-3-26/` | Browse-mode S3 capture with 2+ events — confirmed all-zero params for 1F, 1F response layout, null sentinel, 0A context requirement | | 4-3-26 | `bridges/captures/4-3-26/` | Browse-mode S3 capture with 2+ events — confirmed all-zero params for 1F, 1F response layout, null sentinel, 0A context requirement |
| 4-27-26 | `bridges/captures/4-27-26/` | BW "open 2sec waveform" + "copy event to disk" + paired SFM "seismo_dl" — first proof that SFM was over-reading 5× past event end. BW reads 14 chunks at 0x0200 increments + TERM at end_offset; SFM was reading 37 chunks at 0x0400 increments. STRT end_key field located. | | 4-27-26 | `bridges/captures/4-27-26/` | BW "open 2sec waveform" + "copy event to disk" + paired SFM "seismo_dl" — first proof that SFM was over-reading 5× past event end. BW reads 14 chunks at 0x0200 increments + TERM at end_offset; SFM was reading 37 chunks at 0x0400 increments. STRT end_key field located. |
| 5-1-26 | `bridges/captures/5-1-26/comcheck/` | Three sub-captures: SFM 3-sec download (`seismo_dl_…`), BW comms-check + 3-sec download (`bwcap3sec/`), BW second-event download + "Download All" (`raw_*_170945`/`_171216`). Confirmed: TERM frame formula across 3 events; metadata pages 0x1002/0x1004 are global (read once per session); event-1 vs event-N chunk-pattern split; WAVEHDR length 0x46 vs 0x2C disambiguates real events from boundaries. | | 5-1-26 | `bridges/captures/5-1-26/comcheck/` | Three sub-captures: SFM 3-sec download (`seismo_dl_…`), BW comms-check + 3-sec download (`bwcap3sec/`), BW second-event download + "Download All" (`raw_*_170945`/`_171216`). Confirmed: TERM frame formula across 3 events; metadata pages 0x1002/0x1004 are global (read once per session) (⚠ retracted 2026-10-26: event 1's chunks at 0x0200/0x0400); event-1 vs event-N chunk-pattern split; WAVEHDR length 0x46 vs 0x2C disambiguates real events from boundaries. |
--- ---
@@ -2184,7 +2220,7 @@ body) because writing a dial string may require DLE escaping for embedded contro
| Folder / File | Contents | | Folder / File | Contents |
|---|---| |---|---|
| `1-2-26/` | First SUB 5A BW TX capture — established 5A frame format (raw offset_hi, DLE-aware checksum). 10 frames verified. | | `1-2-26/` | First SUB 5A BW TX capture — established 5A frame format (raw offset_hi, DLE-aware checksum). 10 frames verified. (⚠ model retracted 2026-10-26) |
| `3-11-26/raw_bw_20260311_170151.bin` | Full compliance write + event download (SUBs 68→83 confirmed, frames 102–112) | | `3-11-26/raw_bw_20260311_170151.bin` | Full compliance write + event download (SUBs 68→83 confirmed, frames 102–112) |
| `3-31-26/` | Single-event download (148 BW / 147 S3 frames) — 1E/0A/0C/1F sequence confirmed (single event so token=0xFE appeared to work in either branch) | | `3-31-26/` | Single-event download (148 BW / 147 S3 frames) — 1E/0A/0C/1F sequence confirmed (single event so token=0xFE appeared to work in either branch) |
| `4-2-26/` | Download-mode BW TX capture — POLL×3 requirement confirmed (frames 68-73 between 1F and first 5A) | | `4-2-26/` | Download-mode BW TX capture — POLL×3 requirement confirmed (frames 68-73 between 1F and first 5A) |
@@ -2196,7 +2232,7 @@ body) because writing a dial string may require DLE escaping for embedded contro
| `4-20-26/geo sensitivity/` | Geo sensitivity changes: 1.25 in/s (Sensitive), 10 in/s (Normal) | | `4-20-26/geo sensitivity/` | Geo sensitivity changes: 1.25 in/s (Sensitive), 10 in/s (Normal) |
| `4-20-26/call home settings/` | Call home config read/write captures | | `4-20-26/call home settings/` | Call home config read/write captures |
| `4-27-26/` | BW "open 2sec waveform" + "copy event to disk" + paired SFM "seismo_dl" — first proof of 5× SFM over-read. STRT end_key field located. | | `4-27-26/` | BW "open 2sec waveform" + "copy event to disk" + paired SFM "seismo_dl" — first proof of 5× SFM over-read. STRT end_key field located. |
| **`5-1-26/comcheck/`** | **Triplet of captures that nailed the v0.14.0 walk:** SFM 3-sec download (`seismo_dl_…`), BW comms-check + 3-sec download (`bwcap3sec/`), BW second-event download + "Download All" (`raw_*_170945` / `_171216`). Confirmed: TERM frame formula across 3 events, metadata pages 0x1002/0x1004 are global session metadata, event-1 vs event-N chunk pattern split, WAVEHDR off=0x46 vs 0x2C disambiguates real events from boundaries. | | **`5-1-26/comcheck/`** | **Triplet of captures that nailed the v0.14.0 walk:** SFM 3-sec download (`seismo_dl_…`), BW comms-check + 3-sec download (`bwcap3sec/`), BW second-event download + "Download All" (`raw_*_170945` / `_171216`). Confirmed: TERM frame formula across 3 events, metadata pages 0x1002/0x1004 are global session metadata (⚠ retracted 2026-10-26: event 1's chunks at 0x0200/0x0400), event-1 vs event-N chunk pattern split, WAVEHDR off=0x46 vs 0x2C disambiguates real events from boundaries. |
| **`5-1-26/comcheck/bwcap3sec/`** | **The byte-perfect reference for v0.14.3.** All 17 BW 5A request frames (probe, 2 metadata, 13 samples, TERM) reproduce byte-for-byte from SFM's framing helpers — including the `10 10 00` DLE-stuffed counter for sample @ 0x1000 that was the long-standing failure mode. | | **`5-1-26/comcheck/bwcap3sec/`** | **The byte-perfect reference for v0.14.3.** All 17 BW 5A request frames (probe, 2 metadata, 13 samples, TERM) reproduce byte-for-byte from SFM's framing helpers — including the `10 10 00` DLE-stuffed counter for sample @ 0x1000 that was the long-standing failure mode. |
| `5-4-26/` | BW MITM captures of "copy 3sec / 2sec / Download All" + paired SFM session (`seismo_dl_20260504_145701`) showing the +0x46 event-N probe bug producing 110-chunk runaway walk. Cross-references against 5-1-26 confirmed device behavior is identical. | | `5-4-26/` | BW MITM captures of "copy 3sec / 2sec / Download All" + paired SFM session (`seismo_dl_20260504_145701`) showing the +0x46 event-N probe bug producing 110-chunk runaway walk. Cross-references against 5-1-26 confirmed device behavior is identical. |
+2 -1
View File
@@ -11,7 +11,8 @@
| Date | Section | Change | | Date | Section | Change |
|---|---|---| |---|---|---|
| 2026-10-26 (3) | §3, §7.8, §10 | **⚠ RETRACTS the 5A "non-standard frame" model; the 64 KB page bug is FIXED (measured).** A bridge recorded Blastware downloading all 8 of BE9441's events, 3 crossing a 64 KB page (`tests/fixtures/minimate-bench-10-26-26-blastware/`). **Every request** is the standard 16-byte payload with a SUM8 checksum and **every 02, 03, 04 and 10 DLE-escaped**, payload and checksum alike: 748/748 re-encode byte-identically. §10's "only 0x10 is stuffed" is half the rule. **A 5A request is an ordinary request** `[10 00 5A 00][length BE 2][address BE 4][zeros 6]`, where length is 0x0200 per chunk and the remainder for TERM. The walk: the event's start address, +0x200 at a time as plain 32-bit addresses (carrying into the page byte), then TERM at the next boundary for exactly the remainder, ending at STRT's full 32-bit end key. **Misreadings retracted:** the fixed "offset 0x1002" is length 0x0200 escaped (`10 02 00`); the "metadata pages at 0x1002 / 0x1004, global, read once per session" are the first event's own chunks at 0x0200 and 0x0400; the "11-byte params" counted the length's low byte; the "partial DLE stuffing" carve-outs were the escape rule seen half; the 16-bit counter is why a walk could not leave its page. **Verified live on BE9441:** all 8 events downloaded whole, the 4 crossings included, each matching the unit's own 0C peaks. Code `887e75d`. | | 2026-10-26 (4) | §3, §10 | **Replies follow the request rule; a write-frame suspicion (inferred).** Measured on all 748 reply frames of the 10-26 recording: the unit escapes exactly 02/03/04/10 with a `10`, and the checksum is **SUM8 of the unescaped payload**, 748/748. The long-held "S3 response checksums frequently fail SUM8" (`protocol._validate_frame`) is `S3FrameParser`'s own doing: it keeps the `10` of `10 02/03/04` in its output (consumers rely on that) and sums it, so 502/540 A5 replies read invalid. 🔶 **Inferred only:** `build_bw_write_frame`'s model ("raw except BW_CMD", "DLE-aware checksum") shows the same fingerprints as the retracted 5A model -- SUB 71's "offset 0x1004" reads as length 0x0400 escaped, and Blastware escapes `03` in write data (§3 note, 2026-04-20). A write whose payload holds a bare 02/03/04/10 may be malformed; one Blastware config-write capture settles it. Not acted on. |
| 2026-10-26 (3) | §3, §7.8, §10 | **⚠ RETRACTS the 5A "non-standard frame" model; the 64 KB page bug is FIXED (measured).** A bridge recorded Blastware downloading all 8 of BE9441's events, 4 crossing a 64 KB page (`tests/fixtures/minimate-bench-10-26-26-blastware/`). **Every request** is the standard 16-byte payload with a SUM8 checksum and **every 02, 03, 04 and 10 DLE-escaped**, payload and checksum alike: 748/748 re-encode byte-identically. §10's "only 0x10 is stuffed" is half the rule. **A 5A request is an ordinary request** `[10 00 5A 00][length BE 2][address BE 4][zeros 6]`, where length is 0x0200 per chunk and the remainder for TERM. The walk: the event's start address, +0x200 at a time as plain 32-bit addresses (carrying into the page byte), then TERM at the next boundary for exactly the remainder, ending at STRT's full 32-bit end key. **Misreadings retracted:** the fixed "offset 0x1002" is length 0x0200 escaped (`10 02 00`); the "metadata pages at 0x1002 / 0x1004, global, read once per session" are the first event's own chunks at 0x0200 and 0x0400; the "11-byte params" counted the length's low byte; the "partial DLE stuffing" carve-outs were the escape rule seen half; the 16-bit counter is why a walk could not leave its page. **Verified live on BE9441:** all 8 events downloaded whole, the 4 crossings included, each matching the unit's own 0C peaks. Code `887e75d`. |
| 2026-10-26 (2) | §7.8 | **The 64 KB page bug, narrowed (measured, BE9441).** Blastware's own downloads of all 20 events (Brian, `example-events/10-25-26 - thumps`) give byte-exact ground truth. SFM's downloads of events 0, 1, 3, 4 and 10 are **byte-identical** to Blastware's. Importing Blastware's files first (the watcher route) makes SFM's downloads of the same events return `already_stored`: the unit's 0C and Blastware's file agree on (serial, timestamp). For an event that crosses a page (event 2, `0111c92c` → STRT end key `01122f06`, full 32 bits) a read-only test walk with the page byte carried (params `00 01 12 01 2c`) got a proper A5 reply for the first chunk in page 0x12, echoing `01 12 01 2c`. The second chunk, `00 01 12 03 2c`, got no reply frame: a raw 0x03 (ETX) inside the params. Page 0x11 never shows this, because event 1 skips 0x0000–0x05FF, so no counter there has a 02/03/04 byte. Every later page does. ⚠ How Blastware encodes a lone 02/03/04 inside params is unknown: §7.8 says `10 02/03/04` is kept as a literal pair, which would shift the address. A wire capture of Blastware downloading BE9441 event 2 or 19 settles it. Blastware's files are fixtures (`tests/fixtures/minimate-bench-10-25-26/blastware/`). | | 2026-10-26 (2) | §7.8 | **The 64 KB page bug, narrowed (measured, BE9441).** Blastware's own downloads of all 20 events (Brian, `example-events/10-25-26 - thumps`) give byte-exact ground truth. SFM's downloads of events 0, 1, 3, 4 and 10 are **byte-identical** to Blastware's. Importing Blastware's files first (the watcher route) makes SFM's downloads of the same events return `already_stored`: the unit's 0C and Blastware's file agree on (serial, timestamp). For an event that crosses a page (event 2, `0111c92c` → STRT end key `01122f06`, full 32 bits) a read-only test walk with the page byte carried (params `00 01 12 01 2c`) got a proper A5 reply for the first chunk in page 0x12, echoing `01 12 01 2c`. The second chunk, `00 01 12 03 2c`, got no reply frame: a raw 0x03 (ETX) inside the params. Page 0x11 never shows this, because event 1 skips 0x0000–0x05FF, so no counter there has a 02/03/04 byte. Every later page does. ⚠ How Blastware encodes a lone 02/03/04 inside params is unknown: §7.8 says `10 02/03/04` is kept as a literal pair, which would shift the address. A wire capture of Blastware downloading BE9441 event 2 or 19 settles it. Blastware's files are fixtures (`tests/fixtures/minimate-bench-10-25-26/blastware/`). |
| 2026-10-26 | §7.8 | **5A requests must DLE-escape a checksum that is a framing byte (measured, BE9441).** The request for chunk 0x7D06 of event 01122f06 ends `… 02 03`: a bare 0x02 checksum (STX) before ETX. BE9441 never answered it, twice on two days, and rebooted ~11 s later each time; that was the 'mid-download reboot' of 2026-10-25 (row below). Sent as `… 10 02 03` it answered in 28 ms. So did chunk 0x7F06 (checksum 0x04 → `10 04`) and 0x8B06 (checksum 0x10 → `10 10`; sent bare, that reads as DLE+ETX), and the event downloaded whole and matched the unit's peaks. Escape set {02, 03, 04, 10}: a Micromate's for every byte (251/251 THOR requests), and consistent with §7.8's de-stuffing rule (`10 02/03/04` literal). About 1 chunk request in 64 has such a checksum. ⚠ Not known: whether standard (non-5A) requests need the same. No such keyed-read checksum has been sent. Also measured on the re-run: events that end in the next 64 KB page (BE9441 events 2 and 19) read an end offset lower than their start (the known page bug); every other event downloaded whole and verified. | | 2026-10-26 | §7.8 | **5A requests must DLE-escape a checksum that is a framing byte (measured, BE9441).** The request for chunk 0x7D06 of event 01122f06 ends `… 02 03`: a bare 0x02 checksum (STX) before ETX. BE9441 never answered it, twice on two days, and rebooted ~11 s later each time; that was the 'mid-download reboot' of 2026-10-25 (row below). Sent as `… 10 02 03` it answered in 28 ms. So did chunk 0x7F06 (checksum 0x04 → `10 04`) and 0x8B06 (checksum 0x10 → `10 10`; sent bare, that reads as DLE+ETX), and the event downloaded whole and matched the unit's peaks. Escape set {02, 03, 04, 10}: a Micromate's for every byte (251/251 THOR requests), and consistent with §7.8's de-stuffing rule (`10 02/03/04` literal). About 1 chunk request in 64 has such a checksum. ⚠ Not known: whether standard (non-5A) requests need the same. No such keyed-read checksum has been sent. Also measured on the re-run: events that end in the next 64 KB page (BE9441 events 2 and 19) read an end offset lower than their start (the known page bug); every other event downloaded whole and verified. |
| 2026-10-25 | §7.2, §7.8, §6 | **MiniMate bench check, BE9441 (S338.17, mic disabled, serial cable). SFM read its 24-entry event index, listed 20 events, and downloaded 4.** Measured: (1) **§7.2: the 0x15 serial is a C string.** `"BE9441\x00?"`: a six-character serial leaves a stray byte after its NUL. (2) **§7.8: every A5 reply echoes the address it answers at `data[2:6]`.** The metadata pages come back as `01 11 10 02` and `01 11 10 04`; sample chunks as their own address, e.g. `01 11 66 6a`. The event-1 walk fetches the metadata pages as frames 1 and 2. A non-first event's walk fetches none and goes straight from the probe to sample chunks. SFM's body builder assumed metadata pages in every stream, so every non-first event it assembled was 2 bytes short and decoded truncated; it now checks the echoed addresses. The bug was in SFM's assembly; the protocol was as already documented. (3) **§6: the unit boots when its serial port opens.** It sent `Operating System` ~3 s after the port opened (twice) and ignored a POLL sent before that. After a mid-download reboot it answered 8.8 s after its banner (one data point). (4) **The unit rebooted once mid-download.** The chunk at 0x7D06 got one stray `0x41`, then silence, then the banner 11 s later. Cause unknown, inferred not measured: battery 6.33–6.37 V, a firmware reset. ⚠ **RETRACTED 2026-10-26:** the cause is measured, and it was our request. The chunk request had a bare 0x02 checksum. See the 2026-10-26 row. (5) The event index said 24 while the header walk listed 20 full records. **Inferred:** the other 4 are monitor-log entries. Single-shot events at 4096 sps with a 5 s record give **21,504 samples per channel** (5 s record + 0.25 s pre-trigger = 5.25 s at 4096 sps), all three channels equal, peaks equal to the unit's own 0C values. | | 2026-10-25 | §7.2, §7.8, §6 | **MiniMate bench check, BE9441 (S338.17, mic disabled, serial cable). SFM read its 24-entry event index, listed 20 events, and downloaded 4.** Measured: (1) **§7.2: the 0x15 serial is a C string.** `"BE9441\x00?"`: a six-character serial leaves a stray byte after its NUL. (2) **§7.8: every A5 reply echoes the address it answers at `data[2:6]`.** The metadata pages come back as `01 11 10 02` and `01 11 10 04`; sample chunks as their own address, e.g. `01 11 66 6a`. The event-1 walk fetches the metadata pages as frames 1 and 2. A non-first event's walk fetches none and goes straight from the probe to sample chunks. SFM's body builder assumed metadata pages in every stream, so every non-first event it assembled was 2 bytes short and decoded truncated; it now checks the echoed addresses. The bug was in SFM's assembly; the protocol was as already documented. (3) **§6: the unit boots when its serial port opens.** It sent `Operating System` ~3 s after the port opened (twice) and ignored a POLL sent before that. After a mid-download reboot it answered 8.8 s after its banner (one data point). (4) **The unit rebooted once mid-download.** The chunk at 0x7D06 got one stray `0x41`, then silence, then the banner 11 s later. Cause unknown, inferred not measured: battery 6.33–6.37 V, a firmware reset. ⚠ **RETRACTED 2026-10-26:** the cause is measured, and it was our request. The chunk request had a bare 0x02 checksum. See the 2026-10-26 row. (5) The event index said 24 while the header walk listed 20 full records. **Inferred:** the other 4 are monitor-log entries. Single-shot events at 4096 sps with a 5 s record give **21,504 samples per channel** (5 s record + 0.25 s pre-trigger = 5.25 s at 4096 sps), all three channels equal, peaks equal to the unit's own 0C values. |
@@ -394,8 +394,12 @@ Each safety piece arrives with its first real use, so nothing sits untested.
request escapes 02/03/04/10, and that a 5A request is an ordinary one request escapes 02/03/04/10, and that a 5A request is an ordinary one
carrying a length and a 32-bit linear address. Live on BE9441, all 8 carrying a length and a 32-bit linear address. Live on BE9441, all 8
events downloaded whole and verified, the 4 crossings included. events downloaded whole and verified, the 4 crossings included.
Review follow-ups: the chunk cap is sized from STRT (a caller's 128
cut events past ~66 KB short, e.g. large histograms), a misread STRT
is refused, TERM only for a true tail.
- Still owed: - Still owed:
- a histogram event (this unit records single shot); - a histogram event (this unit records single shot), ideally one
over ~66 KB, which only the new cap sizing lets through;
- start/stop through the new path, with Brian present; - start/stop through the new path, with Brian present;
- a dropped reply via fault injection. It happened for real on - a dropped reply via fault injection. It happened for real on
10-25, but that was our checksum bug, not a lossy link; 10-25, but that was our checksum bug, not a lossy link;
+4 -2
View File
@@ -130,8 +130,10 @@ def build_request(sub: int, offset: int = 0, params: bytes = bytes(10), data: by
"""Build a host→unit command frame. """Build a host→unit command frame.
⚠ Do **not** substitute `minimateplus.framing.build_bw_frame()` here, even ⚠ Do **not** substitute `minimateplus.framing.build_bw_frame()` here, even
though the payload layout is identical. That builder escapes only `0x10`, though the payload layout is identical. That builder escaped only `0x10`,
so it reproduces just **161 of Thor's 218** captured read frames. The 57 it so it reproduced just **161 of Thor's 218** captured read frames. (Since
2026-10-26 it escapes the same four values -- a MiniMate wants them too -- but
the Micromate framing differs in other ways; keep the two builders apart.) The 57 it
gets wrong are not edge cases: gets wrong are not edge cases:
* every `SUB 0x5A` bulk download — `offset = 0x0400` puts a literal * every `SUB 0x5A` bulk download — `offset = 0x0400` puts a literal
+21 -11
View File
@@ -112,18 +112,15 @@ def checksum(payload: bytes) -> int:
# ── BW→S3 frame builder ─────────────────────────────────────────────────────── # ── BW→S3 frame builder ───────────────────────────────────────────────────────
# SUB byte for 5A — used by build_5a_frame below (protocol.py has the full # SUB byte for 5A (protocol.py has the full constant set; defined here to
# constant set; defined here to avoid a circular import). # avoid a circular import).
SUB_5A = 0x5A SUB_5A = 0x5A
_BULK_CHUNK = 0x0200 # bytes per 5A read; a TERM reads the remainder
def build_5a_request(address: int, length: int) -> bytes: def build_5a_request(address: int, length: int) -> bytes:
"""A SUB 5A read of `length` bytes at the unit's 32-bit `address`. """A SUB 5A read of `length` bytes at the unit's 32-bit `address`.
Measured 2026-10-26 from Blastware downloading all 8 of BE9441's events (three Measured 2026-10-26 from Blastware downloading all 8 of BE9441's events (four
crossing a 64 KB page): a 5A request is an ORDINARY 16-byte request -- 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 `[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 02/03/04/10 escaped -- and this rebuilds all 540 of Blastware's 5A requests
@@ -134,15 +131,15 @@ def build_5a_request(address: int, length: int) -> bytes:
""" """
if not 0 <= address <= 0xFFFFFFFF: if not 0 <= address <= 0xFFFFFFFF:
raise ValueError(f"address must fit in 32 bits, got {address:#x}") raise ValueError(f"address must fit in 32 bits, got {address:#x}")
if not 0 <= length <= 0xFFFF: return build_bw_frame(SUB_5A, length, address.to_bytes(4, "big") + bytes(6))
raise ValueError(f"length must fit in 16 bits, got {length:#x}")
payload = (bytes([BW_CMD, 0x00, SUB_5A, 0x00, (length >> 8) & 0xFF, length & 0xFF])
+ address.to_bytes(4, "big") + bytes(6))
return bytes([ACK, STX]) + s3_stuff(payload + bytes([checksum(payload)])) + bytes([ETX])
def build_5a_frame(offset_word: int, raw_params: bytes) -> bytes: 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 Build a BW→S3 frame for SUB 5A (BULK_WAVEFORM_STREAM) that exactly
matches Blastware's wire output. matches Blastware's wire output.
@@ -442,6 +439,9 @@ def token_params(token: int = 0) -> bytes:
def bulk_waveform_params(key4: bytes, counter: int, *, is_probe: bool = False) -> bytes: 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. 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: Confirmed 2026-04-02 from 1-2-26 BW TX capture analysis:
@@ -487,6 +487,9 @@ def bulk_waveform_params(key4: bytes, counter: int, *, is_probe: bool = False) -
def bulk_waveform_term_params(key4: bytes, counter: int) -> bytes: 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. ⛔ DEPRECATED — DO NOT USE IN NEW CODE.
This is the v1 termination params helper, paired with the broken This is the v1 termination params helper, paired with the broken
@@ -523,6 +526,9 @@ def bulk_waveform_term_v2(
last_chunk_counter: int, last_chunk_counter: int,
) -> tuple[int, bytes]: ) -> 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. 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): Confirmed across 3 events (4-27-26 + 5-1-26 captures):
@@ -615,6 +621,10 @@ def parse_strt_end_key(a5_data: bytes) -> Optional[int]:
def parse_strt_end_offset(a5_data: bytes) -> Optional[int]: 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.
Extract the event-end offset from the STRT record in an A5 response payload. Extract the event-end offset from the STRT record in an A5 response payload.
The first A5 response (the probe response, or the first chunk for events The first A5 response (the probe response, or the first chunk for events
+42 -30
View File
@@ -29,14 +29,9 @@ from .framing import (
S3Frame, S3Frame,
S3FrameParser, S3FrameParser,
build_bw_frame, build_bw_frame,
build_5a_frame,
build_bw_write_frame, build_bw_write_frame,
waveform_key_params, waveform_key_params,
token_params, token_params,
bulk_waveform_params,
bulk_waveform_term_params,
bulk_waveform_term_v2,
parse_strt_end_offset,
parse_strt_end_key, parse_strt_end_key,
build_5a_request, build_5a_request,
POLL_PROBE, POLL_PROBE,
@@ -125,23 +120,15 @@ DATA_LENGTHS: dict[int, int] = {
# NOT handled here — requires specialised read logic. # NOT handled here — requires specialised read logic.
} }
# SUB 5A (BULK_WAVEFORM_STREAM) protocol constants. # SUB 5A (BULK_WAVEFORM_STREAM) walk constants. A 5A request is a read of a
# # LENGTH at a 32-bit ADDRESS (measured 2026-10-26 against Blastware; see
# 2026-05-01 minimal-fix: the chunk-counter walk is now bounded by the event's # read_bulk_waveform_stream and framing.build_5a_request).
# `end_offset` extracted from the STRT record at data[23:27] of the probe _BULK_TERM_OFFSET = 0x005A # TERM length when the end is unknown (legacy fallback only)
# response. Without this bound the loop kept asking for chunks past the event _BULK_COUNTER_STEP = 0x0200 # bytes per chunk read, and the step between addresses
# end and the device responded with post-event circular-buffer garbage, # A sanity bound on the size STRT claims, not a measured limit: BE units report
# corrupting reconstructed Blastware files for events ≥ 2 sec. # 983,026 bytes of memory (SUB 1C) and the largest archived event is ~850 KB. A
# # claim past this is a misread STRT, refused before walking megabytes of garbage.
# We keep the OLD 0x0400 chunk step here (BW actually uses 0x0200 — see §7.8.5 _BULK_MAX_EVENT_BYTES = 0x400000 # 4 MiB
# of the protocol reference for the corrected understanding) because the
# existing blastware_file.py builder relies on the 0x0400-step frame structure
# to produce valid files. Switching to BW's 0x0200 step is a separate task
# that also requires updating the file builder.
# BW-exact protocol values (v0.14.0). Verified against 4-27-26 + 5-1-26 captures.
_BULK_CHUNK_OFFSET = 0x1002 # offset_word for probe + all chunk requests
_BULK_TERM_OFFSET = 0x005A # offset_word for the legacy terminator (fallback only)
_BULK_COUNTER_STEP = 0x0200 # chunk counter increment (matches chunk payload size)
# Default timeout values (seconds). # Default timeout values (seconds).
# MiniMate Plus is a slow device — keep these generous. # MiniMate Plus is a slow device — keep these generous.
@@ -561,7 +548,7 @@ class MiniMateProtocol:
tolerance stands: an early end proceeds to TERM and returns what arrived. tolerance stands: an early end proceeds to TERM and returns what arrived.
The walk (measured 2026-10-26: Blastware downloading all 8 of BE9441's The walk (measured 2026-10-26: Blastware downloading all 8 of BE9441's
events, three crossing a 64 KB page -- tests/test_5a_blastware_walk.py events, four crossing a 64 KB page -- tests/test_5a_blastware_walk.py
rebuilds its requests byte for byte): rebuilds its requests byte for byte):
1. Read 0x200 bytes at the event's own 32-bit address (the key). The 1. Read 0x200 bytes at the event's own 32-bit address (the key). The
@@ -634,6 +621,16 @@ class MiniMateProtocol:
"before its start -- not downloaded") "before its start -- not downloaded")
log.warning("5A STRT end 0x%08X is not after the start 0x%08X -- ignored", end, start) log.warning("5A STRT end 0x%08X is not after the start 0x%08X -- ignored", end, start)
end = None end = None
if end is not None and end - start < _BULK_COUNTER_STEP:
# The walk's first read is a whole chunk, so a smaller event cannot be
# bounded -- and no event is that small (the header alone is longer).
raise ProtocolError(
f"5A STRT for {key4.hex()} says the event is {end - start} bytes, less than "
"one 0x200 chunk -- a misread STRT; not downloaded")
if end is not None and end - start > _BULK_MAX_EVENT_BYTES:
raise ProtocolError(
f"5A STRT for {key4.hex()} says the event is {end - start:,} bytes, more than "
f"any unit holds ({_BULK_MAX_EVENT_BYTES:,}) -- a misread STRT; not downloaded")
have_end = end is not None have_end = end is not None
if not have_end: if not have_end:
log.warning( log.warning(
@@ -644,13 +641,18 @@ class MiniMateProtocol:
end = start + (max_chunks + 2) * _BULK_COUNTER_STEP # the cap bounds the loop end = start + (max_chunks + 2) * _BULK_COUNTER_STEP # the cap bounds the loop
else: else:
log.info("5A STRT start=0x%08X end=0x%08X size=0x%X", start, end, end - start) log.info("5A STRT start=0x%08X end=0x%08X size=0x%X", start, end, end - start)
# With the end known, STRT bounds the walk and the cap must not cut it short:
# a histogram can be several hundred KB (2,545 of 63,500 in the DL2 archive
# exceed the 128-chunk / ~66 KB a caller's cap allowed). The cap still
# bounds a walk whose end is unknown.
chunk_cap = max(max_chunks, (end - start) // _BULK_COUNTER_STEP) if have_end else max_chunks
# ── Step 3: chunks at +0x200, plain 32-bit addresses ───────────────── # ── Step 3: chunks at +0x200, plain 32-bit addresses ─────────────────
address = start + _BULK_COUNTER_STEP address = start + _BULK_COUNTER_STEP
last = start last = start
chunks_fetched = 0 chunks_fetched = 0
while chunks_fetched < max_chunks: while chunks_fetched < chunk_cap:
# Stop when the next chunk would straddle the event end. # Stop when the next chunk would straddle the event end.
if address + _BULK_COUNTER_STEP > end: if address + _BULK_COUNTER_STEP > end:
log.debug( log.debug(
@@ -709,17 +711,27 @@ class MiniMateProtocol:
else: else:
if strict: if strict:
raise ProtocolError( raise ProtocolError(
f"5A reached the {max_chunks}-chunk cap at 0x{address:08X} before the " f"5A reached the {chunk_cap}-chunk cap at 0x{address:08X} before the "
f"event's end 0x{end:08X} -- the event was not kept") f"event's end 0x{end:08X} -- the event was not kept")
log.warning( log.warning(
"5A reached max_chunks=%d at address=0x%08X (end=0x%08X)", "5A reached max_chunks=%d at address=0x%08X (end=0x%08X)",
max_chunks, address, end, chunk_cap, address, end,
) )
# ── Step 4: TERM -- the remainder, from the next boundary ─────────── # ── Step 4: TERM -- the remainder, from the next boundary ───────────
boundary = last + _BULK_COUNTER_STEP boundary = last + _BULK_COUNTER_STEP
if have_end: if have_end:
term_length = end - boundary term_length = end - boundary
if not 0 <= term_length < _BULK_COUNTER_STEP:
# Only after an early end (the legacy tolerance): what is left is not a
# tail but most of the event, and a TERM for it is no TERM at all.
if strict:
raise ProtocolError(
f"5A TERM for {key4.hex()} would read 0x{term_length:X} bytes from "
f"0x{boundary:08X}, not a tail -- the event was not kept")
log.warning("5A stream ended 0x%X bytes before the event's end; no TERM sent",
term_length)
return frames_data
log.debug("5A TERM address=0x%08X length=0x%04X end=0x%08X", log.debug("5A TERM address=0x%08X length=0x%04X end=0x%08X",
boundary, term_length, end) boundary, term_length, end)
else: else:
@@ -1466,10 +1478,10 @@ class MiniMateProtocol:
def _validate_frame(frame: S3Frame, expected_sub: Optional[int]) -> None: def _validate_frame(frame: S3Frame, expected_sub: Optional[int]) -> None:
"""Validate SUB; log but do not raise on bad checksum. """Validate SUB; log but do not raise on bad checksum.
S3 response checksums frequently fail SUM8 validation due to inner-frame A reply's checksum is SUM8 of its unescaped payload (748/748, measured
delimiter bytes being captured as the checksum byte. The original 2026-10-26). `checksum_valid` is usually False only because S3FrameParser
s3_parser.py deliberately never validates S3 checksums for exactly this sums its output with the `10` of each kept `10 02/03/04` pair still in it
reason. We log a warning and continue. -- the parser's doing, not the unit's. We log and continue.
""" """
if not frame.checksum_valid: if not frame.checksum_valid:
# S3 checksums frequently fail SUM8 due to inner-frame delimiter bytes # S3 checksums frequently fail SUM8 due to inner-frame delimiter bytes
+11 -1
View File
@@ -9,7 +9,7 @@ to disk. Both directions, raw:
| `blastware_requests.bin` | Blastware → unit (748 requests, each after a `41 03` SESSION_RESET) | 17,757 B | | `blastware_requests.bin` | Blastware → unit (748 requests, each after a `41 03` SESSION_RESET) | 17,757 B |
| `unit_replies.bin` | unit → Blastware | 364,972 B | | `unit_replies.bin` | unit → Blastware | 364,972 B |
Events (key → end), from Blastware's 5A walks. Three cross a 64 KB page: Events (key → end), from Blastware's 5A walks. Four cross a 64 KB page (1, 3, 5, 7):
| event | start key | end (STRT) | 5A requests | | event | start key | end (STRT) | 5A requests |
|---|---|---|---| |---|---|---|---|
@@ -35,8 +35,18 @@ its chunks at 0x0200 and 0x0400, escaped (`10 02 00`, `10 04 00`).
|---|---|---| |---|---|---|
| `K441LTOF.ZI0` | 0 (`01110000`) | no | | `K441LTOF.ZI0` | 0 (`01110000`) | no |
| `K441LTOF.ZQ0` | 1 (`01118a2c`) | yes, into 0x12 | | `K441LTOF.ZQ0` | 1 (`01118a2c`) | yes, into 0x12 |
| `K441LTOF.ZV0` | 2 (`011216c4`) | no |
| `K441LTOG.000` | 3 (`0112a0b6`) | yes, into 0x13 | | `K441LTOG.000` | 3 (`0112a0b6`) | yes, into 0x13 |
| `K441LTOG.050` | 4 (`011329d2`) | no |
| `K441LTOG.0A0` | 5 (`0113b072`) | yes, into 0x14 |
| `K441LTOG.0L0` | 6 (`01143046`) | no |
| `K441LTOG.0S0` | 7 (`0114b0b2`) | yes, into 0x15 | | `K441LTOG.0S0` | 7 (`0114b0b2`) | yes, into 0x15 |
After the fix (887e75d), SFM's own live downloads of all 8 events were byte-identical to After the fix (887e75d), SFM's own live downloads of all 8 events were byte-identical to
Blastware's files (sha256), the 4 crossings included. Blastware's files (sha256), the 4 crossings included.
The unit's replies (measured on all 748): every 02/03/04/10 is escaped with a `10`, exactly as
in requests, and the checksum is SUM8 of the **unescaped** payload, 748/748. `S3FrameParser`
keeps the escape bytes of `10 02/03/04` in its output and sums those too, which is why its
`checksum_valid` is False on 502 of the 540 A5 replies. The "S3 checksums frequently fail"
note in `protocol._validate_frame` describes the parser, not the unit.
+3 -2
View File
@@ -11,8 +11,9 @@ import minimateplus.protocol as mp
from minimateplus.framing import S3FrameParser from minimateplus.framing import S3FrameParser
_DIR = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26" _DIR = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26"
FIX = _DIR / "BE9441_event1_0111646a_rx.bin" # event 1 (non-first): no metadata pages FIX = _DIR / "BE9441_event1_0111646a_rx.bin" # event 1 (non-first)
FIX_EVENT0 = _DIR / "BE9441_event0_01110000_rx.bin" # event 0: metadata pages 0x1002 / 0x1004 FIX_EVENT0 = _DIR / "BE9441_event0_01110000_rx.bin" # event 0 (its chunks at 0x0200 / 0x0400 were
# once read as "metadata pages 0x1002 / 0x1004")
KEY = bytes.fromhex("0111646a") KEY = bytes.fromhex("0111646a")
STAMP = "2026-10-25T14:10:49" STAMP = "2026-10-25T14:10:49"
UNIT_PEAKS = {"Tran": 0.030, "Vert": 0.095, "Long": 0.020} # the unit's own 0C peaks, in/s UNIT_PEAKS = {"Tran": 0.030, "Vert": 0.095, "Long": 0.020} # the unit's own 0C peaks, in/s
+125 -5
View File
@@ -1,6 +1,6 @@
"""SFM's MiniMate requests and 5A walk, against Blastware's own (recorded 2026-10-26). """SFM's MiniMate requests and 5A walk, against Blastware's own (recorded 2026-10-26).
Blastware downloaded all 8 of BE9441's events -- three of which cross a 64 KB page Blastware downloaded all 8 of BE9441's events -- four of which cross a 64 KB page
-- while a bridge recorded both directions (fixture README). Every one of its 748 -- while a bridge recorded both directions (fixture README). Every one of its 748
requests is the standard 16-byte payload with a SUM8 checksum and every 02 / 03 / requests is the standard 16-byte payload with a SUM8 checksum and every 02 / 03 /
04 / 10 byte DLE-escaped; a 5A request carries a length (0x0200, or the remainder 04 / 10 byte DLE-escaped; a 5A request carries a length (0x0200, or the remainder
@@ -23,7 +23,8 @@ import minimateplus.protocol as mp # noq
from minimate_replay import fast_clock # noqa: E402 from minimate_replay import fast_clock # noqa: E402
from minimateplus.blastware_file import extract_body_bytes, write_blastware_file # noqa: E402 from minimateplus.blastware_file import extract_body_bytes, write_blastware_file # noqa: E402
from minimateplus.models import Event # noqa: E402 from minimateplus.models import Event # noqa: E402
from minimateplus.framing import S3FrameParser, build_5a_request, build_bw_frame, waveform_key_params # noqa: E402 from minimateplus.framing import (S3FrameParser, build_5a_request, build_bw_frame, # noqa: E402
parse_strt_end_key, parse_strt_end_offset, waveform_key_params)
from minimateplus.waveform_codec import STREAM_END_ID, decode_waveform_v2, walk_records # noqa: E402 from minimateplus.waveform_codec import STREAM_END_ID, decode_waveform_v2, walk_records # noqa: E402
FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-26-26-blastware" FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-26-26-blastware"
@@ -140,7 +141,19 @@ def _fast(monkeypatch):
fast_clock(monkeypatch) fast_clock(monkeypatch)
@pytest.mark.parametrize("key", ["01110000", "01118a2c", "0112a0b6", "0114b0b2"]) # BE9441's 8 events; 1, 3, 5 and 7 cross into the next 64 KB page.
EVENTS = [("01110000", "K441LTOF.ZI0"), ("01118a2c", "K441LTOF.ZQ0"), ("011216c4", "K441LTOF.ZV0"),
("0112a0b6", "K441LTOG.000"), ("011329d2", "K441LTOG.050"), ("0113b072", "K441LTOG.0A0"),
("01143046", "K441LTOG.0L0"), ("0114b0b2", "K441LTOG.0S0")]
def test_the_crossing_events_are_the_ones_named():
ends = {k: addr_len(blastware_walk(int(k, 16))[-1]) for k, _ in EVENTS}
crossing = [k for k, (a, n) in ends.items() if (a + n) >> 16 != int(k, 16) >> 16]
assert crossing == ["01118a2c", "0112a0b6", "0113b072", "0114b0b2"]
@pytest.mark.parametrize("key", [k for k, _ in EVENTS])
def test_the_walk_sends_exactly_blastwares_requests_and_the_event_is_whole(key): def test_the_walk_sends_exactly_blastwares_requests_and_the_event_is_whole(key):
t = ByAddress() t = ByAddress()
frames = mp.MiniMateProtocol(t).read_bulk_waveform_stream( frames = mp.MiniMateProtocol(t).read_bulk_waveform_stream(
@@ -155,8 +168,7 @@ def test_the_walk_sends_exactly_blastwares_requests_and_the_event_is_whole(key):
assert len({len(dec[c]) for c in ("Tran", "Vert", "Long")}) == 1 assert len({len(dec[c]) for c in ("Tran", "Vert", "Long")}) == 1
@pytest.mark.parametrize("key,bw", [("01110000", "K441LTOF.ZI0"), ("01118a2c", "K441LTOF.ZQ0"), @pytest.mark.parametrize("key,bw", EVENTS)
("0112a0b6", "K441LTOG.000"), ("0114b0b2", "K441LTOG.0S0")])
def test_the_file_built_from_the_walk_is_blastwares_own(key, bw, tmp_path): def test_the_file_built_from_the_walk_is_blastwares_own(key, bw, tmp_path):
frames = mp.MiniMateProtocol(ByAddress()).read_bulk_waveform_stream( frames = mp.MiniMateProtocol(ByAddress()).read_bulk_waveform_stream(
bytes.fromhex(key), stop_after_metadata=False, include_terminator=True, strict=True) bytes.fromhex(key), stop_after_metadata=False, include_terminator=True, strict=True)
@@ -165,3 +177,111 @@ def test_the_file_built_from_the_walk_is_blastwares_own(key, bw, tmp_path):
path = tmp_path / bw path = tmp_path / bw
write_blastware_file(ev, frames, path) write_blastware_file(ev, frames, path)
assert path.read_bytes() == (FIX / "blastware" / bw).read_bytes() assert path.read_bytes() == (FIX / "blastware" / bw).read_bytes()
# -- the requests BE9441 answered after the escape fix ---------------------------
def test_the_compliance_reads_be9441_answered_with_the_escaped_0x04():
# SUB 1A frames B and C are the only fixed requests whose bytes the fix changed
# (their 0x0400 length went out bare). These exact frames got full replies,
# 2,125 bytes, decoded correctly (bench 2026-10-26 14:38:43).
assert build_bw_frame(0x1A, 0x0400, bytes(7) + b"\x64\x00\x00").hex() == \
"41021010001a00100400000000000000006400009203"
assert build_bw_frame(0x1A, 0x0400, bytes([0, 0, 4, 0, 0, 0, 0, 0x64, 0, 0])).hex() == \
"41021010001a0010040000001004000000006400009603"
# -- synthetic replies: the unit's own encoding, with a chosen STRT end ----------
def _escape(b: bytes) -> bytes:
"""The unit's encoding (measured on 748 replies): 10 before 02, 03, 04 and 10."""
return b"".join(bytes([0x10, x]) if x in (0x02, 0x03, 0x04, 0x10) else bytes([x]) for x in b)
def _parse(wire: bytes):
frames = S3FrameParser().feed(wire)
assert len(frames) == 1
return frames[0]
def _logical(reply: bytes) -> bytes:
"""A recorded reply's payload, unescaped and without its checksum. Each
recorded reply opens with the unit's `41 03 41` before its `10 02`."""
return _unstuff(reply[reply.index(b"\x10\x02") + 2:-1])[:-1]
def first_reply_ending_at(end: int, event: int = 1) -> bytes:
"""A recorded first-chunk reply with STRT's end key set to `end`, re-encoded."""
q = FIVE_A.index(blastware_walk(int(EVENTS[event][0], 16))[0])
payload = bytearray(_logical(unit_a5_replies()[q]))
i = payload.find(b"STRT")
payload[i + 6:i + 10] = end.to_bytes(4, "big")
return b"\x10\x02" + _escape(bytes(payload) + bytes([sum(payload) & 0xFF])) + b"\x03"
def test_the_reply_encoder_is_the_units():
q = FIVE_A.index(blastware_walk(0x01118a2c)[0])
recorded = unit_a5_replies()[q]
payload = _logical(recorded)
i = payload.find(b"STRT")
end = int.from_bytes(payload[i + 6:i + 10], "big")
assert _parse(first_reply_ending_at(end)).data == _parse(recorded).data
def test_an_end_key_holding_escaped_bytes_reads_whole():
# None of the 8 recorded end keys holds a 02/03/04/10; this one holds 03 and 10.
data = _parse(first_reply_ending_at(0x01120310)).data
assert parse_strt_end_key(data) == 0x01120310
assert parse_strt_end_offset(data) != 0x0310 # the old reader's misread
class Synthetic:
"""Answers the first 5A request with `first`, each chunk with a recorded chunk
reply and the TERM with a recorded TERM reply; records (address, length)."""
def __init__(self, first: bytes):
replies = unit_a5_replies()
walk = blastware_walk(0x01118a2c)
self.first, self.sent, self._buf = first, [], b""
self.chunk = replies[FIVE_A.index(walk[1])]
self.term = replies[FIVE_A.index(walk[-1])]
def write(self, data):
a, n = addr_len(bytes(data))
self.sent.append((a, n))
self._buf += self.first if len(self.sent) == 1 else (self.chunk if n == 0x200 else self.term)
def read(self, n):
out, self._buf = self._buf[:n], self._buf[n:]
return out
def walk(first: bytes, start: int = 0x01118a2c, **kw):
t = Synthetic(first)
frames = mp.MiniMateProtocol(t).read_bulk_waveform_stream(
start.to_bytes(4, "big"), stop_after_metadata=False, include_terminator=True, **kw)
return t.sent, frames
def test_the_walk_ends_on_an_escaped_end_key():
sent, _ = walk(first_reply_ending_at(0x01120310), strict=True)
# chunks step from the start (...8a2c), so the TERM is at 0x0112022C for 0xE4
assert sent[-1] == (0x0112022C, 0x01120310 - 0x0112022C) # TERM: the tail, exactly
def test_a_large_event_walks_whole_past_the_callers_cap():
# 2,545 of 63,500 archived histograms exceed the ~66 KB a 128-chunk cap allowed.
start, end = 0x01118a2c, 0x01118a2c + 300_000
sent, frames = walk(first_reply_ending_at(end), start, strict=True, max_chunks=128)
n = (end - start) // 0x200
assert sent[:-1] == [(start + 0x200 * k, 0x200) for k in range(n)]
assert sent[-1] == (start + 0x200 * n, (end - start) % 0x200)
assert len(frames) == len(sent)
@pytest.mark.parametrize("strict", [True, False])
@pytest.mark.parametrize("size,why", [(0x100, "less than one 0x200 chunk"),
(0x500000, "more than any unit holds")])
def test_a_misread_strt_is_refused_in_both_modes(size, why, strict):
with pytest.raises(mp.ProtocolError, match=why):
walk(first_reply_ending_at(0x01118a2c + size), strict=strict)
+3 -5
View File
@@ -17,14 +17,12 @@ import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from minimateplus.framing import build_5a_frame, bulk_waveform_params # noqa: E402 from minimateplus.framing import build_5a_request # noqa: E402
KEY = bytes.fromhex("01122f06")
CHUNK_OFFSET = 0x1002
def chunk(counter: int) -> str: def chunk(counter: int) -> str:
return build_5a_frame(CHUNK_OFFSET, bulk_waveform_params(KEY, counter)).hex() # Event 01122f06's chunk reads, length 0x0200 (once read as an "offset 0x1002")
return build_5a_request(0x01120000 + counter, 0x0200).hex()
@pytest.mark.parametrize("counter,wire", [ @pytest.mark.parametrize("counter,wire", [
+21 -3
View File
@@ -84,9 +84,17 @@ def test_strict_raises_on_a_terminator_mid_stream():
stream(r, strict=True) stream(r, strict=True)
def test_strict_raises_at_the_chunk_cap(): def test_a_known_end_is_not_cut_short_by_the_callers_chunk_cap():
with pytest.raises(mp.ProtocolError, match="chunk cap"): # STRT bounds the walk; a cap (client.py passes 128) once cut every event past
stream(a5_replies(), max_chunks=5, strict=True) # ~66 KB short -- a large histogram, say. It now bounds only a walk with no end.
assert len(stream(a5_replies(), max_chunks=5, strict=True)) == 51
def test_the_cap_still_bounds_a_legacy_walk_with_no_strt():
r = a5_replies()
r[0] = r[0].replace(b"STRT", b"XXXX")
frames = stream(r, max_chunks=5)
assert len(frames) == 1 + 5 + 1 # first chunk, 5 capped chunks, TERM
def test_strict_raises_when_the_probe_has_no_strt(): def test_strict_raises_when_the_probe_has_no_strt():
@@ -114,3 +122,13 @@ def test_strict_refuses_a_strt_whose_end_is_not_after_its_start():
p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True, p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True,
strict=True) strict=True)
assert p._transport.sent == 1 # the first chunk, and nothing after assert p._transport.sent == 1 # the first chunk, and nothing after
def test_the_legacy_walk_sends_no_term_for_most_of_an_event():
# After an early end, the "remainder" is most of the event, not a tail; a TERM
# for it once asked for kilobytes (or, past 64 KB, raised a bare ValueError).
t = Replay(a5_replies(), silent_from=40)
frames = mp.MiniMateProtocol(t).read_bulk_waveform_stream(
KEY, stop_after_metadata=False, include_terminator=True)
assert len(frames) == 40
assert t.sent == 41 # 40 answered, the one met by silence, and no TERM