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 @@ shrink or disappear.
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import math
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
|
||||
@@ -480,6 +481,81 @@ class MicromateState:
|
||||
return " ".join(bits)
|
||||
|
||||
|
||||
_RECORD_MODES = {0x01: "Waveform", 0x02: "Waveform Manual", 0x03: "Histogram", 0x04: "Histogram Combo"}
|
||||
|
||||
# The unit's OWN conversion constants, identified bit-exactly from what it
|
||||
# stored for keypad entries (2026-10-19). Not the textbook 3.28084 / 2.20462:
|
||||
# convert back with these, or 45 lb entered on the unit reads as 44.89 lb.
|
||||
_FT_PER_M = 3.2808
|
||||
_LB_PER_KG = 2.21
|
||||
_PA_PER_PSI = 6894.757
|
||||
_P_REF_PA = 20e-6 # dB re 20 µPa
|
||||
|
||||
|
||||
@dataclass
|
||||
class MicromateSetup:
|
||||
"""A unit's active setup, from ``SUB 0x1A`` — see ``micromate/setup_block.py``.
|
||||
|
||||
**Measured fields only.** Each was located by changing that one setting on a
|
||||
unit's keypad and watching the bytes; anything graded inferred or unknown in
|
||||
the protocol reference is left in ``raw`` rather than guessed at here.
|
||||
|
||||
⚠ This is what the unit is set to *right now* — including unsaved edits if
|
||||
someone is in its setup menu, because ``0x1A`` reads the keypad's edit
|
||||
buffer. Values are in the units the unit stores, whatever it displays:
|
||||
in/s, psi, metres, kilograms.
|
||||
"""
|
||||
|
||||
name: str # ⚠ ".MMB" after a keypad save, ".mmb" after a load
|
||||
record_mode: int # see record_mode_name
|
||||
sample_rate: int # samples per second
|
||||
histogram_interval_s: int
|
||||
pretrigger_s: float # positive; the unit stores it negative
|
||||
auto_record_stop: bool # False = Fixed record time
|
||||
record_time_s: float
|
||||
auto_stop_after_s: int # quiet time before an Auto stop
|
||||
geophones_active: bool
|
||||
mic_active: bool
|
||||
trigger_on_geophones: bool
|
||||
trigger_on_mic: bool
|
||||
geo_trigger_ips: Tuple[float, float, float] # Tran, Vert, Long
|
||||
mic_type: str # "linear" | "sound_level" | "unknown (<code>)"
|
||||
mic_trigger_psi: Optional[float] # linear mic only; SLM units not measured
|
||||
job_number_enabled: bool
|
||||
job_number: int # kept while switched off
|
||||
scaled_distance_enabled: bool
|
||||
distance_m: float
|
||||
charge_weight_kg: float
|
||||
notes: Dict[str, str] # label -> value, in the unit's order
|
||||
raw: bytes = field(default=b"", repr=False) # the 2,092-byte content
|
||||
|
||||
@property
|
||||
def record_mode_name(self) -> str:
|
||||
return _RECORD_MODES.get(self.record_mode, f"unknown (0x{self.record_mode:02x})")
|
||||
|
||||
@property
|
||||
def mic_trigger_db(self) -> Optional[float]:
|
||||
"""dB re 20 µPa. Matches the unit's screen to ±0.001 dB on 131 and 140."""
|
||||
if not self.mic_trigger_psi:
|
||||
return None
|
||||
return 20.0 * math.log10(self.mic_trigger_psi * _PA_PER_PSI / _P_REF_PA)
|
||||
|
||||
@property
|
||||
def distance_ft(self) -> float:
|
||||
return self.distance_m * _FT_PER_M
|
||||
|
||||
@property
|
||||
def charge_weight_lb(self) -> float:
|
||||
return self.charge_weight_kg * _LB_PER_KG
|
||||
|
||||
@property
|
||||
def scaled_distance(self) -> Optional[float]:
|
||||
"""ft / √lb, as the unit computes it for display. It is not stored."""
|
||||
if self.charge_weight_kg <= 0:
|
||||
return None
|
||||
return self.distance_ft / math.sqrt(self.charge_weight_lb)
|
||||
|
||||
|
||||
@dataclass
|
||||
class MicromateEventRef:
|
||||
"""One entry in a unit's event chain, from `1E`/`1F` and optionally `0x0C`.
|
||||
|
||||
Reference in new issue
Block a user