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
@@ -22,6 +22,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from micromate.client import CONTENT, MicromateClient, _content, _cstring
|
||||
from micromate.framing import ETX, STX, checksum, stuff
|
||||
from micromate.protocol import ProtocolError
|
||||
from micromate.setup_block import SetupChecksumError
|
||||
|
||||
FLAGS_CB, FLAGS_THOR = 0xC5, 0x03
|
||||
|
||||
@@ -491,3 +492,47 @@ def test_the_four_extra_bd_bytes_are_not_all_zero():
|
||||
"""
|
||||
assert _content(MS_BD_MONITORING)[44:] == bytes.fromhex("0fa00004")
|
||||
assert _content(MS_IDLE)[44:] == b"", "the CB block has no such tail"
|
||||
|
||||
|
||||
# ── get_setup() ───────────────────────────────────────────────────────────────
|
||||
# Decoding itself is covered field by field in test_micromate_setup.py; these
|
||||
# check the client's read, its framing round trip and the verify switch.
|
||||
|
||||
SETUP_FIXTURES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "micromate-setup")
|
||||
|
||||
|
||||
def _setup_read(name: str) -> bytes:
|
||||
with open(os.path.join(SETUP_FIXTURES, f"{name}.bin"), "rb") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def test_get_setup_is_one_read_of_0x1a():
|
||||
"""One frame -- not Series III's four-frame compliance sequence."""
|
||||
mm, t = client([frame(0xE5, _setup_read("um20147_baseline"))])
|
||||
mm.get_setup()
|
||||
assert [w[5] for w in t.written] == [0x1A]
|
||||
|
||||
|
||||
def test_get_setup_survives_a_literal_dle_through_the_framing():
|
||||
"""4096 sps puts 0x10 in the payload, which the unit must escape on the wire
|
||||
and the parser must unescape. Wrong either way and the rate reads wrong or
|
||||
the CRC fails."""
|
||||
mm, _ = client([frame(0xE5, _setup_read("um20147_4096sps"))])
|
||||
s = mm.get_setup()
|
||||
assert s.sample_rate == 4096
|
||||
assert s.raw == _setup_read("um20147_4096sps")[CONTENT:]
|
||||
|
||||
|
||||
def test_get_setup_raises_on_a_corrupt_read_by_default():
|
||||
data = bytearray(_setup_read("um20147_baseline"))
|
||||
data[CONTENT + 5] = 0x05
|
||||
mm, _ = client([frame(0xE5, bytes(data))])
|
||||
with pytest.raises(SetupChecksumError):
|
||||
mm.get_setup()
|
||||
|
||||
|
||||
def test_get_setup_verify_false_returns_the_corrupt_read():
|
||||
data = bytearray(_setup_read("um20147_baseline"))
|
||||
data[CONTENT + 5] = 0x05
|
||||
mm, _ = client([frame(0xE5, bytes(data))])
|
||||
assert mm.get_setup(verify=False).record_mode == 0x05
|
||||
Reference in new issue
Block a user