feat(sfm): Series-3 call-home state and audited enable/disable, live send gated until its frame is verified (phase 4)
- minimateplus.protocol: call_home_enabled(raw) reads byte 5 of the UNESCAPED 0x2C payload (0x01 on / 0x00 off, measured 2026-04-20; anything else None -- bench finding #1's lesson: an escaped byte before it would move the raw index); call_home_image(raw, enabled) is write_image's N + 2 image with byte 5 set and everything else as read, refusing a byte 5 never measured. - MiniMateClient.read_call_home_raw() / write_call_home_image(image) (0x7E then 0x7F, each ack checked, never retried). - Series3Adapter.call_home_state (wake, then 0x2C; no serial read, like status) and change_call_home: the shared change core with a connect() identity check, state 'enabled' / 'disabled' / 'unknown(0xNN)' (unknown sends nothing), the plan showing both exact frames, a snapshot of both unescaped images. - S3_CALL_HOME_FRAME_VERIFIED = False: a live change is refused (501) before any connection until the frame is reproduced from Blastware's (next commit). 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
eeb55effe9
commit
8612cd9df7
5 files changed
+267
-6
No files matched your search
+94
-5
@@ -10,14 +10,19 @@ from typing import Any, Callable, Optional
|
||||
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
|
||||
from minimateplus.protocol import SUB_START_MONITORING, SUB_STOP_MONITORING
|
||||
from minimateplus.framing import build_bw_write_frame, unescape_reply
|
||||
from minimateplus.protocol import (
|
||||
SUB_CALL_HOME_CONFIRM, SUB_CALL_HOME_WRITE, SUB_START_MONITORING, SUB_STOP_MONITORING,
|
||||
call_home_enabled, call_home_image, write_image,
|
||||
)
|
||||
from minimateplus.transport import TcpTransport
|
||||
|
||||
from .errors import DeviceError, EventNotFound, MalformedReply, NoAnswer, StaleEvent, WrongUnit, translate
|
||||
from .change import monitoring_change, run_change
|
||||
from .errors import (DeviceError, EventNotFound, MalformedReply, NoAnswer, NotSupported, StaleEvent,
|
||||
WrongUnit, translate)
|
||||
from .change import call_home_change, monitoring_change, run_change
|
||||
from .events import iso_of, make_event_id, stamp_of
|
||||
from .models import ChangeResult, DownloadedEvent, EventList, EventRef, UnitAddress, UnitInfo, UnitSettings, UnitStatus
|
||||
from .models import (CallHomeState, ChangeResult, DownloadedEvent, EventList, EventRef, UnitAddress,
|
||||
UnitInfo, UnitSettings, UnitStatus)
|
||||
|
||||
log = logging.getLogger("sfm.device_access")
|
||||
|
||||
@@ -27,6 +32,11 @@ S3_MODES = {0x00: "Single Shot", 0x01: "Continuous", 0x03: "Histogram", 0x04: "H
|
||||
|
||||
S3_EVENT_TIMEOUT = 120.0 # what the legacy event-download routes use
|
||||
|
||||
# A MiniMate call-home write goes out only once SFM's 0x7E / 0x7F frames are
|
||||
# reproduced from Blastware's own (tests/test_s3_call_home_bw_frames.py). Until
|
||||
# then a live change is refused before any connection; a dry run still works.
|
||||
S3_CALL_HOME_FRAME_VERIFIED = False
|
||||
|
||||
# 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.
|
||||
@@ -330,6 +340,85 @@ class Series3Adapter:
|
||||
)
|
||||
return self._run(address, op)
|
||||
|
||||
def call_home_state(self, address: UnitAddress, serial: str) -> CallHomeState:
|
||||
"""The unit's call-home switch and dial string (0x2C), after a wake. Like
|
||||
status, it reads no serial: the one shown is the one requested."""
|
||||
def op(client: Any) -> CallHomeState:
|
||||
client.wake(attempt_s=S3_WAKE_ATTEMPT_S, deadline_s=S3_WAKE_DEADLINE_S)
|
||||
raw = client.read_call_home_raw()
|
||||
image = unescape_reply(raw)
|
||||
dial = bytes(image[6:46]).split(b"\x00", 1)[0].decode("ascii", errors="replace") or None
|
||||
return CallHomeState(serial=serial, series=3, enabled=call_home_enabled(raw),
|
||||
dial_string=dial,
|
||||
detail={"byte5": f"0x{image[5]:02X}" if len(image) > 5 else None,
|
||||
"block": bytes(raw).hex(), "serial_verified": False})
|
||||
return self._run(address, op)
|
||||
|
||||
def change_call_home(self, address: UnitAddress, serial: str, *, enabled: bool, dry_run: bool,
|
||||
even_if_already: 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: read 0x2C, set byte 5 of the
|
||||
unescaped image, send it (0x7E) and confirm (0x7F), re-read. One attempt,
|
||||
never retried; refused live until the frame is verified against Blastware."""
|
||||
if not dry_run and not S3_CALL_HOME_FRAME_VERIFIED:
|
||||
raise NotSupported("a MiniMate call-home write waits until its frame has been "
|
||||
"reproduced from a Blastware capture -- nothing sent")
|
||||
what = "call-home " + ("enable" if enabled else "disable")
|
||||
|
||||
def op(client: Any) -> ChangeResult:
|
||||
reads: list = []
|
||||
images: 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)
|
||||
raw = client.read_call_home_raw()
|
||||
reads.append(raw)
|
||||
on = call_home_enabled(raw)
|
||||
if on is None:
|
||||
image = unescape_reply(raw)
|
||||
return f"unknown(0x{image[5]:02X})" if len(image) > 5 else "unknown(short)"
|
||||
return "enabled" if on else "disabled"
|
||||
|
||||
def describe_plan() -> dict:
|
||||
try:
|
||||
image = call_home_image(reads[-1], enabled)
|
||||
except ValueError as exc:
|
||||
images[:] = []
|
||||
return {"action": what, "steps": [], "warnings": [f"{exc}; nothing would be sent"]}
|
||||
images[:] = [image]
|
||||
warnings = []
|
||||
if image == write_image(SUB_CALL_HOME_WRITE, reads[-1]):
|
||||
warnings.append(f"the unit is already call-home {'enabled' if enabled else 'disabled'}"
|
||||
" -- this write changes nothing")
|
||||
return {"action": what, "warnings": warnings, "steps": [
|
||||
{"sub": f"0x{SUB_CALL_HOME_WRITE:02X}", "what": "call-home config write",
|
||||
"data_len": len(image), "frame": build_bw_write_frame(SUB_CALL_HOME_WRITE, image).hex()},
|
||||
{"sub": f"0x{SUB_CALL_HOME_CONFIRM:02X}", "what": "call-home config confirm",
|
||||
"data_len": 0, "frame": build_bw_write_frame(SUB_CALL_HOME_CONFIRM, b"").hex()}]}
|
||||
|
||||
def send() -> dict:
|
||||
client.write_call_home_image(images[0])
|
||||
return {"subs": [f"0x{0xFF - SUB_CALL_HOME_WRITE:02X}", f"0x{0xFF - SUB_CALL_HOME_CONFIRM:02X}"]}
|
||||
|
||||
def snapshot() -> dict:
|
||||
before = write_image(SUB_CALL_HOME_WRITE, reads[0])
|
||||
after = write_image(SUB_CALL_HOME_WRITE, reads[-1])
|
||||
return {"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=call_home_change(enabled), serial=serial, series=3, dry_run=dry_run,
|
||||
even_if_already=even_if_already, 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)
|
||||
return self._run(address, op, retry=False)
|
||||
|
||||
def settings(self, address: UnitAddress, serial: str) -> UnitSettings:
|
||||
def op(client: Any) -> UnitSettings:
|
||||
info = client.connect()
|
||||
|
||||
Reference in new issue
Block a user