fix(minimateplus): a 5A request's checksum is DLE-escaped when it is a framing byte
BE9441 never answered 5A chunk 0x7D06 of event 01122f06 -- twice (bench
2026-10-25 and 2026-10-26), each time rebooting ~11 s later. The request ended
'... 02 03': build_5a_frame wrote the checksum bare, and 0x02 is STX. Sent with
the checksum escaped ('10 02 03') the unit answered in 28 ms; so did chunk
0x7F06 (checksum 0x04) and 0x8B06 (0x10, which bare reads as DLE+ETX), and the
event downloaded whole and verified (21,504 x 3, peaks equal to the unit's).
Escape set {02, 03, 04, 10}: a Micromate's, measured on 251/251 THOR requests;
the MiniMate's own de-stuffing keeps 10 02/03/04 literal. About 1 chunk
request in 64 has such a checksum, so roughly half of all multi-chunk downloads
hit one.
Not changed (no evidence either way): build_bw_frame escapes only 0x10 in its
checksum; a keyed read whose checksum is 02/03/04 is untested. The BW 5A
byte-perfect tests skip on this box (captures absent) -- worth running where
they exist. 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:
1 parent
f34f5c3376
commit
d56dde768d
2 files changed
+47
-1
No files matched your search
@@ -183,7 +183,14 @@ def build_5a_frame(offset_word: int, raw_params: bytes) -> bytes:
|
||||
chk = (chk + s[i]) & 0xFF
|
||||
i += 1
|
||||
|
||||
return bytes([ACK, STX]) + bytes(s) + bytes([chk, ETX])
|
||||
# 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:
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
"""A 5A request's checksum is DLE-escaped when it lands on 02 / 03 / 04 / 10.
|
||||
|
||||
BE9441 (bench, 2026-10-25/26) never answered the request for chunk 0x7D06 of
|
||||
event 01122f06 -- twice, each time rebooting ~11 s later -- because the frame
|
||||
ended `... 02 03`: a bare 0x02 checksum, the STX byte, before ETX. Sent with
|
||||
the checksum escaped (`10 02 03`) it answered in 28 ms, as did chunks 0x7F06
|
||||
(checksum 0x04) and 0x8B06 (0x10), and the event downloaded whole and verified.
|
||||
The escape set is the one a Micromate uses for every byte (measured on 251/251
|
||||
THOR requests); the MiniMate's own de-stuffing keeps `10 02/03/04` literal.
|
||||
"""
|
||||
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_5a_frame, bulk_waveform_params # noqa: E402
|
||||
|
||||
KEY = bytes.fromhex("01122f06")
|
||||
CHUNK_OFFSET = 0x1002
|
||||
|
||||
|
||||
def chunk(counter: int) -> str:
|
||||
return build_5a_frame(CHUNK_OFFSET, bulk_waveform_params(KEY, counter)).hex()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("counter,wire", [
|
||||
# the wire bytes BE9441 answered, checksum escaped
|
||||
(0x7D06, "41021010005a0010020001127d06000000000000100203"), # checksum 0x02
|
||||
(0x7F06, "41021010005a0010020001127f06000000000000100403"), # checksum 0x04
|
||||
(0x8B06, "41021010005a0010020001128b06000000000000101003"), # checksum 0x10
|
||||
# an ordinary checksum is untouched
|
||||
(0x7B06, "41021010005a0010020001127b060000000000000003"),
|
||||
])
|
||||
def test_the_checksum_is_escaped_only_when_it_is_a_framing_byte(counter, wire):
|
||||
assert chunk(counter) == wire
|
||||
Reference in new issue
Block a user