feat(sfm): start/stop monitoring for Series 3 through the same safety layer
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
78c3d568d5
commit
ce5d2cb0d6
5 files changed
+332
-106
No files matched your search
+42
-5
@@ -9,11 +9,14 @@ from typing import Any, Callable, Optional
|
||||
|
||||
from minimateplus import MiniMateClient
|
||||
from minimateplus.blastware_file import blastware_filename
|
||||
from minimateplus.framing import build_bw_write_frame
|
||||
from minimateplus.protocol import SUB_START_MONITORING, SUB_STOP_MONITORING
|
||||
from minimateplus.transport import TcpTransport
|
||||
|
||||
from .errors import DeviceError, EventNotFound, MalformedReply, NoAnswer, NotSupported, StaleEvent, WrongUnit, translate
|
||||
from .change import run_change
|
||||
from .events import iso_of, make_event_id, stamp_of
|
||||
from .models import DownloadedEvent, EventList, EventRef, UnitAddress, UnitInfo, UnitSettings, UnitStatus
|
||||
from .models import ChangeResult, DownloadedEvent, EventList, EventRef, UnitAddress, UnitInfo, UnitSettings, UnitStatus
|
||||
|
||||
log = logging.getLogger("sfm.device_access")
|
||||
|
||||
@@ -85,10 +88,44 @@ class Series3Adapter:
|
||||
def __init__(self, client_factory: Callable[..., Any] = default_s3_client_factory) -> None:
|
||||
self._factory = client_factory
|
||||
|
||||
def change_monitoring(self, address: UnitAddress, serial: str, **kw: Any) -> Any:
|
||||
raise NotSupported("Series 3 start/stop through DeviceAccess arrives in Task 5")
|
||||
def change_monitoring(self, address: UnitAddress, serial: str, *, start: 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 in change.py. One attempt, never
|
||||
retried: `retry=False` stops _run's cold-boot second attempt, and the
|
||||
core calls the write once."""
|
||||
sub = SUB_START_MONITORING if start else SUB_STOP_MONITORING
|
||||
ack_sub = 0xFF - sub
|
||||
|
||||
def _run(self, address: UnitAddress, fn: Callable[[Any], Any], timeout: Optional[float] = None) -> Any:
|
||||
def op(client: Any) -> ChangeResult:
|
||||
def read_serial() -> str:
|
||||
info = client.connect() # a fresh connection: connect() is the fresh 0x15 read
|
||||
return info.serial or ""
|
||||
|
||||
def describe_plan() -> dict:
|
||||
what = "start monitoring" if start else "stop monitoring"
|
||||
return {"action": what, "sends_nothing": True, "warnings": [],
|
||||
"steps": [{"sub": f"0x{sub:02X}", "what": what, "offset": "0x0000",
|
||||
"data_len": 0, "expect_ack": f"0x{ack_sub:02X}",
|
||||
"frame": build_bw_write_frame(sub, b"").hex()}]}
|
||||
|
||||
def send() -> dict:
|
||||
# The client validates the ack SUB; it returns nothing else, so none is claimed.
|
||||
(client.start_monitoring if start else client.stop_monitoring)()
|
||||
return {"subs": [f"0x{ack_sub:02X}"]}
|
||||
|
||||
return run_change(
|
||||
serial=serial, series=3, start=start, 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=lambda: "monitoring" if client.get_monitor_status().is_monitoring else "idle",
|
||||
describe_plan=describe_plan, send=send)
|
||||
return self._run(address, op, timeout=S3_EVENT_TIMEOUT, retry=False)
|
||||
|
||||
def _run(self, address: UnitAddress, fn: Callable[[Any], Any], timeout: Optional[float] = None,
|
||||
retry: bool = True) -> Any:
|
||||
def attempt() -> Any:
|
||||
client = self._factory(address) if timeout is None else self._factory(address, timeout=timeout)
|
||||
try:
|
||||
@@ -114,7 +151,7 @@ class Series3Adapter:
|
||||
# server._run_with_retry (any protocol error): retrying a
|
||||
# MalformedReply would also retry "no settings block", which a
|
||||
# reconnect cannot fix.
|
||||
if not address.host:
|
||||
if not retry or not address.host:
|
||||
raise
|
||||
log.info("Series 3 at %s: no clean answer, retrying once (unit may be cold)", address.key)
|
||||
return attempt()
|
||||
|
||||
Reference in new issue
Block a user