feat(micromate): get_setup() -- the setup block decoded, checksum-verified, and read off a real unit
MicromateClient.get_setup() reads SUB 0x1A once and returns a MicromateSetup: record mode, sample rate, histogram interval, pre-trigger, stop mode, record time, auto-stop, active sensors, trigger sources, the three geophone trigger levels, mic type and (linear) mic trigger, job number, scaled distance, and the four notes. MEASURED FIELDS ONLY -- everything graded inferred or unknown in the reference stays in .raw. micromate/setup_block.py holds the decode as pure functions (no I/O), plus crc_ok(): one checksum rule for 0x1A, 0x08 and 0x2E. A failed checksum raises SetupChecksumError (a ProtocolError) unless verify=False; a short block raises either way. Two things the decoder gets right that a naive one would not: - the mic comes from channel block 4 (the ACTIVE mic), never blocks 5/6, which hold the stored settings of whichever mic is NOT fitted; - distance and charge weight convert back with the unit's own 3.2808 and 2.21, so 45 lb entered on the unit reads 45.0, not 44.89. TESTS: 69 new. 15 real fixtures (2,103 B each) -- 14 UM20147 reads from the 10-17/10-19 keypad passes, chosen so every field takes at least two values, plus UM12947's read from Thor's 9-24 capture (other firmware line). Expected values are what the operator read off the unit's screen, never the decoder's own output. Fixtures force-added, per the tests/fixtures/ convention. Full suite 541 passed; the 16 pre-existing failures (test_bw_ascii_report.py 15, test_event_file_io.py 1) are unchanged. VERIFIED ON HARDWARE: bridges/mm_client_check.py now prints the decoded setup; against UM20147 every line matched the unit's screen (Brian, 10-19). Also: the scratch harness uses the library checksum and checks all three blocks; mm_client_check's stale labels fixed (0x06 content[4:8] is the likely monitor-log count, not "unexplained"; 11.0BD is no longer "the first one this code has met"). No codec, store or DB change; no backfill. 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
a74d3c9b00
commit
b3aff4ed66
22 files changed
+622
-35
No files matched your search
+10
-21
@@ -52,6 +52,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from bridges.mm_client_check import StdlibSerial # noqa: E402
|
||||
from micromate.client import MicromateClient # noqa: E402
|
||||
from micromate.setup_block import crc_ok # noqa: E402
|
||||
from minimateplus.transport import TcpTransport # noqa: E402
|
||||
|
||||
SNAP_ROOT = Path(__file__).resolve().parent / "mm_config_snaps"
|
||||
@@ -138,28 +139,16 @@ def _interps(a: bytes, b: bytes, off: int, run: int) -> list[str]:
|
||||
return out
|
||||
|
||||
|
||||
def crc16_aug_ccitt(data: bytes) -> int:
|
||||
"""CRC-16/AUG-CCITT: poly 0x1021, init 0x1D0F, no reflection, xorout 0."""
|
||||
c = 0x1D0F
|
||||
for x in data:
|
||||
c ^= x << 8
|
||||
for _ in range(8):
|
||||
c = ((c << 1) ^ 0x1021) & 0xFFFF if c & 0x8000 else (c << 1) & 0xFFFF
|
||||
return c
|
||||
# Blocks that carry the config checksum (micromate.setup_block.crc_ok): N =
|
||||
# content[0:2], CRC-16/AUG-CCITT over [0:N-2] stored at [N:N+2]. 0x2C has none.
|
||||
CRC_BLOCKS = {"1A_compliance", "08_event_index", "2E_trigger"}
|
||||
|
||||
|
||||
def crc_status_1a(raw: bytes) -> str:
|
||||
"""Check 0x1A's trailer: CRC over content[0:2088], stored BE at [2090:2092].
|
||||
|
||||
Found 2026-10-17 from one keypad diff and confirmed on 23 snapshots plus
|
||||
UM12947's 9-24 capture. A mismatch means a short or corrupt read -- or
|
||||
that the layout is not what this assumes, which is worth knowing too.
|
||||
"""
|
||||
def crc_status(raw: bytes) -> str:
|
||||
"""A mismatch means a short or corrupt read -- or a block this rule misses."""
|
||||
c = raw[CONTENT:]
|
||||
if len(c) < 2092:
|
||||
return f"CRC n/a (content {len(c)} B < 2092)"
|
||||
want, got = crc16_aug_ccitt(c[:2088]), int.from_bytes(c[2090:2092], "big")
|
||||
return f"CRC ok ({got:04x})" if want == got else f"CRC MISMATCH computed {want:04x}, stored {got:04x}"
|
||||
stored = c[int.from_bytes(c[0:2], "big"):][:2].hex() if len(c) >= 2 else "--"
|
||||
return f"CRC ok ({stored})" if crc_ok(c) else f"CRC MISMATCH (stored {stored})"
|
||||
|
||||
|
||||
def _runs(a: bytes, b: bytes, ignore: set[int]) -> list[tuple[int, int]]:
|
||||
@@ -314,8 +303,8 @@ def cmd_watch(mm: MicromateClient, serial: str, interval: float,
|
||||
f"{a[off:off + run].hex()} -> {b[off:off + run].hex()}")
|
||||
for line in _interps(a, b, off, run):
|
||||
print(f" {line}")
|
||||
if name == "1A_compliance":
|
||||
print(f" {crc_status_1a(cur[name])}")
|
||||
if name in CRC_BLOCKS:
|
||||
print(f" {crc_status(cur[name])}")
|
||||
print(flush=True)
|
||||
prev = cur
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in new issue
Block a user