feat(s3): change a MiniMate's settings by serial on the shared codec
Series3Adapter.settings reads the 1A block assembled into its 2,090 logical bytes and decodes it with micromate.setup_fields (a monitoring unit's device-info answer is refused with 'stop monitoring first'). change_settings runs the shared change core: read the four settings blocks, patch the settings block's fields, send Blastware's sequence through push_config_raw with the event index, trigger and waveform blocks as read, re-read. Refused before sending: monitoring, a value the unit does not allow, a stale preview. push_config_raw's pre-check now raises ImageRefused, so a refused image is audited as nothing sent. 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
c082f72d62
commit
66bb29b9d4
5 files changed
+346
-36
No files matched your search
+116
-21
@@ -11,15 +11,22 @@ from minimateplus import MiniMateClient
|
||||
from minimateplus.blastware_file import blastware_file_bytes, blastware_filename, with_type_letter
|
||||
from minimateplus.event_file_io import _GEO_INT16_FS
|
||||
from minimateplus.framing import build_bw_write_frame, unescape_reply
|
||||
from micromate.setup_block import decode_setup
|
||||
from micromate.setup_fields import (
|
||||
SettingsValueError, check_changes, editable_fields, encode_setup, field_rows, field_values,
|
||||
settings_state,
|
||||
)
|
||||
from micromate.setup_fields import revision as settings_revision
|
||||
from minimateplus.protocol import (
|
||||
SUB_CALL_HOME_CONFIRM, SUB_CALL_HOME_WRITE, SUB_START_MONITORING, SUB_STOP_MONITORING,
|
||||
ImageRefused, call_home_enabled, call_home_image, is_call_home_block, write_image,
|
||||
ImageRefused, call_home_enabled, call_home_image, is_call_home_block, is_compliance_content,
|
||||
write_image,
|
||||
)
|
||||
from minimateplus.transport import TcpTransport
|
||||
|
||||
from .errors import (DeviceError, EventNotFound, MalformedReply, NoAnswer, NotSupported, StaleEvent,
|
||||
UnitStateUnknown, WrongUnit, translate)
|
||||
from .change import call_home_change, monitoring_change, run_change
|
||||
from .errors import (BadRequest, DeviceError, EventNotFound, MalformedReply, NoAnswer, NotSupported,
|
||||
SettingsChanged, StaleEvent, UnitStateUnknown, WrongUnit, translate)
|
||||
from .change import call_home_change, monitoring_change, run_change, settings_change
|
||||
from .events import iso_of, make_event_id, stamp_of
|
||||
from .models import (CallHomeState, ChangeResult, DownloadedEvent, EventList, EventRef, UnitAddress,
|
||||
UnitInfo, UnitSettings, UnitStatus)
|
||||
@@ -49,6 +56,19 @@ S3_CALL_HOME_WHILE_MONITORING = ("did not return its call-home settings -- a Min
|
||||
# The 0x1C flag byte (section[1]): the only values ever measured. 0x10 is
|
||||
# BE11529 monitoring (2026-04-08); 0x0B is BE9441 recording a histogram,
|
||||
# confirmed at the unit (2026-10-26). Anything else is refused for a change.
|
||||
# Measured 2026-11-03 (BE9441's 10-26 recording, 5 / 5 reads): while monitoring, a
|
||||
# MiniMate answers the 1A settings read with its device-info block.
|
||||
S3_SETTINGS_WHILE_MONITORING = ("did not return its settings -- a MiniMate answers this way "
|
||||
"while monitoring; stop monitoring first")
|
||||
# Blastware's settings write, in its order (push_config_raw): event index, the
|
||||
# settings block in addressed chunks, trigger, waveform data, with their confirms.
|
||||
_S3_SETTINGS_STEPS = ((0x68, "event index (as read)"), (0x73, "confirm B"),
|
||||
(0x71, "settings block"), (0x72, "confirm A"),
|
||||
(0x82, "trigger block (as read)"), (0x83, "trigger confirm"),
|
||||
(0x69, "waveform data (as read)"), (0x74, "confirm C"), (0x72, "confirm A"))
|
||||
_S3_TAIL_WARNING = ("the two bytes after the settings block go out as 00 00 (Blastware sends "
|
||||
"its own constant; effect unmeasured)")
|
||||
|
||||
S3_RUN_STATES = {0x00: "idle", 0x10: "monitoring", 0x0B: "monitoring"}
|
||||
|
||||
|
||||
@@ -435,29 +455,104 @@ class Series3Adapter:
|
||||
is_refusal=lambda e: isinstance(e, ImageRefused))
|
||||
return self._run(address, op, retry=False)
|
||||
|
||||
def change_settings(self, address: UnitAddress, serial: str, *, changes: dict,
|
||||
revision: Optional[str], dry_run: bool, audit: Any, caller: str,
|
||||
sleep: Callable[[float], None], verify_timeout_s: float,
|
||||
verify_interval_s: float) -> ChangeResult:
|
||||
"""Series-3 pieces for the shared core (phase 5): read the four settings
|
||||
blocks, patch the settings block's fields (micromate.setup_fields), send
|
||||
Blastware's sequence through push_config_raw with the other three blocks
|
||||
as read, re-read the settings. One attempt, never retried.
|
||||
|
||||
Refused before anything is sent: a monitoring unit (it answers 1A with its
|
||||
device-info block); a value the unit does not allow (BadRequest); a live
|
||||
call whose `revision` is not this read's (SettingsChanged)."""
|
||||
def op(client: Any) -> ChangeResult:
|
||||
st: dict = {}
|
||||
reads: list = []
|
||||
|
||||
def read_serial() -> str:
|
||||
return client.connect().serial or "" # a fresh connection: the 0x15 read
|
||||
|
||||
def read_state() -> str:
|
||||
client.wake(attempt_s=S3_WAKE_ATTEMPT_S, deadline_s=S3_WAKE_DEADLINE_S)
|
||||
if st:
|
||||
now = client.read_compliance_content()
|
||||
if not is_compliance_content(now):
|
||||
raise MalformedReply("the read-back did not return the settings block")
|
||||
reads.append(now)
|
||||
return settings_state(st["setup"], st["image"], now, series=3)
|
||||
blocks = client.read_settings_blocks()
|
||||
setup = blocks["compliance"]
|
||||
if not is_compliance_content(setup):
|
||||
raise UnitStateUnknown(f"{serial} {S3_SETTINGS_WHILE_MONITORING} -- nothing sent")
|
||||
try:
|
||||
normal = check_changes(setup, 3, changes)
|
||||
except SettingsValueError as exc:
|
||||
raise BadRequest(f"{exc} -- nothing sent") from exc
|
||||
rev = settings_revision([blocks["event_index"], setup, blocks["trigger"], blocks["waveform"]])
|
||||
if not dry_run and revision != rev:
|
||||
raise SettingsChanged(f"{serial}'s settings changed since the preview -- "
|
||||
"preview again; nothing sent")
|
||||
image = encode_setup(setup, 3, normal)
|
||||
st.update(blocks=blocks, setup=setup, image=image, changes=normal, revision=rev)
|
||||
reads.append(setup)
|
||||
return settings_state(setup, image, setup, series=3)
|
||||
|
||||
def describe_plan() -> dict:
|
||||
b = st["blocks"]
|
||||
lens = {0x68: len(b["event_index"]), 0x71: len(st["image"]) + 2,
|
||||
0x82: len(b["trigger"]), 0x69: len(b["waveform"])}
|
||||
return {"action": "settings write", "blocked": [],
|
||||
"steps": [{"sub": f"0x{sub:02X}", "what": what, "data_len": lens.get(sub, 0)}
|
||||
for sub, what in _S3_SETTINGS_STEPS],
|
||||
"fields": field_rows(st["setup"], st["image"], 3, st["changes"]),
|
||||
"revision": st["revision"], "warnings": [_S3_TAIL_WARNING]}
|
||||
|
||||
def send() -> dict:
|
||||
b = st["blocks"]
|
||||
client.push_config_raw(b["event_index"], st["image"], b["trigger"], b["waveform"])
|
||||
return {"subs": [f"0x{0xFF - sub:02X}" for sub, _ in _S3_SETTINGS_STEPS]}
|
||||
|
||||
def snapshot() -> dict:
|
||||
before, after = st["setup"], reads[-1]
|
||||
return {"fields": field_rows(before, st["image"], 3, st["changes"], now=after),
|
||||
"before": before.hex(), "after": after.hex(),
|
||||
"changed_offsets": [i for i in range(min(len(before), len(after)))
|
||||
if before[i] != after[i]]}
|
||||
|
||||
return run_change(
|
||||
kind=settings_change(), serial=serial, series=3, dry_run=dry_run,
|
||||
even_if_already=False, audit=audit, address=address, caller=caller, sleep=sleep,
|
||||
verify_timeout_s=verify_timeout_s, verify_interval_s=verify_interval_s,
|
||||
read_serial=read_serial, read_state=read_state, describe_plan=describe_plan,
|
||||
send=send, snapshot=snapshot,
|
||||
# raised before the first frame goes out: audited as nothing sent
|
||||
is_refusal=lambda e: isinstance(e, ImageRefused))
|
||||
return self._run(address, op, retry=False)
|
||||
|
||||
def settings(self, address: UnitAddress, serial: str) -> UnitSettings:
|
||||
"""The 1A read assembled into the logical block and decoded by the shared
|
||||
settings codec (phase 5)."""
|
||||
def op(client: Any) -> UnitSettings:
|
||||
info = client.connect()
|
||||
self._check(info.serial, serial, address)
|
||||
cc = info.compliance_config
|
||||
if cc is None:
|
||||
raise MalformedReply("could not read the unit's settings (SUB 0x1A)")
|
||||
mode = None
|
||||
if cc.recording_mode is not None:
|
||||
mode = S3_MODES.get(cc.recording_mode, f"unknown (0x{cc.recording_mode:02x})")
|
||||
notes = {
|
||||
label: value for label, value in (
|
||||
("Project", cc.project), ("Client", cc.client), ("User Name", cc.operator),
|
||||
("Seis Loc", cc.sensor_location), ("Extended Notes", cc.notes),
|
||||
) if value is not None
|
||||
}
|
||||
content = client.read_compliance_content()
|
||||
if not is_compliance_content(content):
|
||||
raise UnitStateUnknown(f"{serial} {S3_SETTINGS_WHILE_MONITORING}")
|
||||
v = field_values(content, 3)
|
||||
name = decode_setup(content + bytes(2), verify=False).name # Series 3 reads no CRC
|
||||
labels = {d["field"]: d["label"] for d in editable_fields(content, 3)}
|
||||
notes = {labels[f]: v[f] for f in ("note_1", "note_2", "note_3", "note_4")}
|
||||
code = content[5]
|
||||
return UnitSettings(
|
||||
serial=info.serial, series=3, setup_name=cc.setup_name, record_mode=mode,
|
||||
sample_rate=cc.sample_rate, record_time_s=cc.record_time,
|
||||
histogram_interval_s=cc.histogram_interval_sec, geo_trigger_ips=cc.trigger_level_geo,
|
||||
serial=info.serial, series=3, setup_name=name or None,
|
||||
record_mode=S3_MODES.get(code, f"unknown (0x{code:02x})"),
|
||||
sample_rate=v["sample_rate"], record_time_s=v["record_time_s"],
|
||||
histogram_interval_s=v["histogram_interval_s"], geo_trigger_ips=v["geo_trigger_ips"],
|
||||
notes=notes,
|
||||
detail={"record_mode_code": cc.recording_mode, "alarm_level_geo": cc.alarm_level_geo,
|
||||
"geo_range": cc.geo_range},
|
||||
detail={"record_mode_code": code, "alarm_level_geo": v["geo_alarm_ips"],
|
||||
"geo_range": v["geo_range"], "editable": editable_fields(content, 3)},
|
||||
)
|
||||
return self._run(address, op)
|
||||
|
||||
|
||||
Reference in new issue
Block a user