fix(minimateplus): read a MiniMate's settings by position, not the 'anchor' (#48)
The legacy SUB 1A decode found the record mode, sample rate, histogram interval and record time by searching for be 80 00 00 00 00, believed a stable anchor. It is the block's [12:18]: the pre-trigger (-0.25 s) and the stop mode (Fixed). A unit in Auto stop mode, or with another pre-trigger, has no such bytes, and all four read None -- in connect()'s legacy routes (/device/info without a serial, the legacy event download's sample rate). The serial-routed settings path already read by position. The block is now found by its own length field N = 2090 (08 2a, at unescaped[12] on every recorded reply) and read by position, Series IV's 0x1A layout. It never struck: every DL2 event file's setup copy has stop mode Fixed, 70,041 / 70,041, and Blastware's reports agree (7,631 / 7,631). Tested on recorded replies patched to Auto stop and to a -0.5 s pre-trigger (8 new tests; the 7 existing ones unchanged); not yet on a unit in Auto stop mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R9LdWawLzUxwewZGA1
This commit is contained in:
1 parent
621c836109
commit
71bd14156d
4 files changed
+90
-35
No files matched your search
+43
-34
@@ -55,6 +55,7 @@ from .protocol import (
|
||||
SUB_WRITE_CONFIRM_C,
|
||||
SUB_TRIGGER_CONFIRM,
|
||||
SUB_MONITOR_STATUS,
|
||||
COMPLIANCE_CONTENT_LEN,
|
||||
)
|
||||
from .transport import SerialTransport, BaseTransport
|
||||
|
||||
@@ -2012,6 +2013,9 @@ def _extract_project_strings(data: bytes) -> Optional[ProjectInfo]:
|
||||
)
|
||||
|
||||
|
||||
# The settings block starts with its own length N = 2090, uint16 BE (#48).
|
||||
_SETTINGS_BLOCK_HEAD = COMPLIANCE_CONTENT_LEN.to_bytes(2, "big") # 08 2a
|
||||
_SETTINGS_BLOCK_SEARCH = 40 # found at unescaped[12] on every recorded reply
|
||||
|
||||
|
||||
def _decode_compliance_config_into(data: bytes, info: DeviceInfo) -> None:
|
||||
@@ -2023,20 +2027,20 @@ def _decode_compliance_config_into(data: bytes, info: DeviceInfo) -> None:
|
||||
|
||||
Confirmed field locations (BE11529 with 3-step read, duplicate detection):
|
||||
- cfg[89] = setup_name: first long ASCII string in cfg[40:250] ✅
|
||||
- ANCHOR = b'\\xbe\\x80\\x00\\x00\\x00\\x00' in cfg[0:150] ✅ (revised 2026-04-07)
|
||||
- anchor - 6 = sample_rate uint16_BE (1024 normal / 2048 fast / 4096 faster)
|
||||
- anchor + 6 = record_time float32_BE
|
||||
- the settings block, found by its length field N = 2090 (`08 2a`) after
|
||||
unescaping, read by position (#48, 2026-12-01; see the comment in the body):
|
||||
mode [5], sample rate [6:8], histogram interval [8:10], record time [18:22]
|
||||
- "Project:" needle → project string
|
||||
- "Client:" needle → client string
|
||||
- "User Name:" needle → operator string
|
||||
- "Seis Loc:" needle → sensor_location string
|
||||
- "Extended Notes" needle → notes string
|
||||
|
||||
Anchor approach is required because a DLE byte in the sample_rate field
|
||||
(4096 = 0x1000 → stored as 10 10 00 in raw S3 frame → unstuffed to 10 00,
|
||||
1 byte shorter than 04 00 or 08 00) causes frame C to be 1 byte shorter
|
||||
for "faster" mode, shifting all subsequent offsets by 1. The 10-byte
|
||||
anchor is stable across all modes.
|
||||
⚠ Retracted 2026-12-01 (#48): the mode, rate, interval and record time were
|
||||
found by the "anchor" `be 80 00 00 00 00`, thought stable across all modes.
|
||||
It is the pre-trigger and the stop mode, so it is absent in Auto stop mode.
|
||||
Escapes are removed first (unescape_reply), so an escaped byte no longer
|
||||
shifts the positions.
|
||||
|
||||
Channel block layout (✅ confirmed 2026-04-02 from 3-11-26 E5 frame 78
|
||||
and 1-2-26 A5 frame 77):
|
||||
@@ -2076,47 +2080,52 @@ def _decode_compliance_config_into(data: bytes, info: DeviceInfo) -> None:
|
||||
# mode, sample rate or interval moves every field after it by one. BE9441 at
|
||||
# Histogram / 4096 sps / 2 s read 0 sps and a 4098 s interval (2026-10-29).
|
||||
#
|
||||
# Layout after unescaping, measured on every recorded reply (four settings,
|
||||
# two of them Blastware's own writes -- tests/test_s3_compliance_anchor_fields.py):
|
||||
# _anchor - 7 : recording_mode (uint8)
|
||||
# _anchor - 6 : sample_rate (uint16 BE)
|
||||
# _anchor - 4 : histogram_interval_sec (uint16 BE, seconds)
|
||||
# _anchor - 2 : 0x00 0x00 (padding)
|
||||
# _anchor : \xbe\x80\x00\x00\x00\x00
|
||||
# _anchor + 6 : record_time (float32 BE)
|
||||
# The block is the settings block Series 4's 0x1A shares (reference D.6.2,
|
||||
# micromate/setup_block.py), found by its own length field N = 2090 (`08 2a`)
|
||||
# and read by position -- at unescaped[12] on every recorded reply:
|
||||
# [5] recording_mode (uint8)
|
||||
# [6:8] sample_rate (uint16 BE)
|
||||
# [8:10] histogram_interval_sec (uint16 BE, seconds)
|
||||
# [12:16] pre-trigger (float32 BE, negative seconds)
|
||||
# [17] stop mode (0 Fixed)
|
||||
# [18:22] record_time (float32 BE)
|
||||
# ⚠ RETRACTED 2026-12-01 (#48): these were found by the "stable anchor"
|
||||
# `be 80 00 00 00 00`, which is [12:18] -- the pre-trigger (-0.25 s) and the
|
||||
# stop mode (Fixed), not a marker. A unit in Auto stop mode, or with another
|
||||
# pre-trigger, has no such bytes, and all four fields read None. No DL2 event
|
||||
# was recorded in Auto (70,041 / 70,041 Fixed), so it never struck.
|
||||
# ⚠ The old raw layout's "anchor - 7 = constant 0x10" was the escape in front
|
||||
# of `04` at 1024 sps (0x0400); it read right only at that rate.
|
||||
# Everything below this block (channel block, strings) still reads the RAW
|
||||
# bytes: its label-relative offsets were measured on them and are wrong
|
||||
# unescaped. A reply with no anchor (BE9441 answered 1A with its device-info
|
||||
# block while monitoring, 2026-10-29) leaves all four fields None.
|
||||
_ANCHOR = b'\xbe\x80\x00\x00\x00\x00'
|
||||
# unescaped. A reply with no settings block (BE9441 answered 1A with its
|
||||
# device-info block while monitoring, 2026-10-29) leaves all four fields None.
|
||||
logical = unescape_reply(data)
|
||||
_anchor = logical.find(_ANCHOR, 0, 150)
|
||||
_block = logical.find(_SETTINGS_BLOCK_HEAD, 0, _SETTINGS_BLOCK_SEARCH)
|
||||
|
||||
if _anchor < 0:
|
||||
if _block < 0:
|
||||
log.warning(
|
||||
"compliance_config: anchor %s not found in cfg[0:150] (len=%d) "
|
||||
"compliance_config: no settings block (N = 2090) in cfg[0:%d] (len=%d) "
|
||||
"— sample_rate, record_time and recording_mode will be None",
|
||||
_ANCHOR.hex(), len(data),
|
||||
_SETTINGS_BLOCK_SEARCH, len(data),
|
||||
)
|
||||
elif _anchor >= 7 and _anchor + 10 <= len(logical):
|
||||
log.info("_decode_compliance_config_into: anchor at unescaped[%d] data_len=%d",
|
||||
_anchor, len(data))
|
||||
config.recording_mode = logical[_anchor - 7]
|
||||
config.sample_rate = struct.unpack_from(">H", logical, _anchor - 6)[0]
|
||||
config.histogram_interval_sec = struct.unpack_from(">H", logical, _anchor - 4)[0]
|
||||
config.record_time = struct.unpack_from(">f", logical, _anchor + 6)[0]
|
||||
elif _block + 22 <= len(logical):
|
||||
log.info("_decode_compliance_config_into: settings block at unescaped[%d] data_len=%d",
|
||||
_block, len(data))
|
||||
config.recording_mode = logical[_block + 5]
|
||||
config.sample_rate = struct.unpack_from(">H", logical, _block + 6)[0]
|
||||
config.histogram_interval_sec = struct.unpack_from(">H", logical, _block + 8)[0]
|
||||
config.record_time = struct.unpack_from(">f", logical, _block + 18)[0]
|
||||
log.debug(
|
||||
"compliance_config: recording_mode=0x%02X sample_rate=%d histogram_interval=%d s "
|
||||
"record_time=%.3f s (anchor@%d unescaped)",
|
||||
"record_time=%.3f s (block@%d unescaped)",
|
||||
config.recording_mode, config.sample_rate, config.histogram_interval_sec,
|
||||
config.record_time, _anchor,
|
||||
config.record_time, _block,
|
||||
)
|
||||
else:
|
||||
log.warning("compliance_config: anchor at unescaped[%d] is too close to an end "
|
||||
log.warning("compliance_config: settings block at unescaped[%d] is too close to the end "
|
||||
"(len=%d) — mode, rate, interval and record time left None",
|
||||
_anchor, len(logical))
|
||||
_block, len(logical))
|
||||
|
||||
# ── Project strings ───────────────────────────────────────────────────────
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user