fix(minimateplus): a MiniMate that boots on connect is waited for, not given up on

BE9441 on a serial cable (bench, 2026-10-25) twice sent "Operating System"
~3 s after the port opened and ignored the POLL sent before it; the request
then failed at the full receive timeout (502 after 15 s on /device/info, 504
after 120 s on a download).  After a mid-download reboot it answered 8.8 s
after its banner -- the one measured readiness point.

startup()'s first POLL now stops waiting the moment the banner arrives (that
POLL will never be answered) and polls again every 2 s for up to 20 s.  Without
a banner nothing changes: a silent unit fails at the normal timeout, with no
re-polling.  Only SESSION_RESET and POLL are sent, so this is safe in front of
the change path too.

No codec, store or DB change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-25 18:17:09 -04:00
1 parent 36f4e5d985
commit d73a27d2e3
2 files changed
+129 -4

No files matched your search

+52 -4
View File
@@ -223,10 +223,9 @@ class MiniMateProtocol:
log.debug("startup: POLL probe")
self._send(POLL_PROBE)
probe_rsp = self._recv_one(
expected_sub=_expected_rsp_sub(SUB_POLL),
timeout=self._recv_timeout,
)
probe_rsp = self._await_poll_or_boot(self._recv_timeout)
if probe_rsp is None:
probe_rsp = self._poll_until_booted()
log.debug(
"startup: POLL probe response page_key=0x%04X", probe_rsp.page_key
)
@@ -1570,6 +1569,55 @@ class MiniMateProtocol:
f"Expected SUB=0x{expected_sub:02X}, got 0x{frame.sub:02X}"
)
# A MiniMate whose port has just opened may boot: it sends this banner a few
# seconds later and ignores a POLL sent before it. Measured on BE9441 over a
# serial cable (2026-10-25): banner ~3 s after the port opened, twice; after a
# mid-download reboot it answered 8.8 s after the banner.
_BOOT_BANNER = b"Operating System"
_BOOT_GRACE_S = 20.0
_BOOT_POLL_S = 2.0
def _await_poll_or_boot(self, timeout: float) -> Optional[S3Frame]:
"""The first POLL probe's reply -- or None the moment the unit sends its
boot banner, because a POLL sent before the banner is never answered."""
expected = _expected_rsp_sub(SUB_POLL)
deadline = time.monotonic() + timeout
tail = b""
while time.monotonic() < deadline:
chunk = self._transport.read(256)
if not chunk:
time.sleep(0.005)
continue
log.debug("RX %d bytes: %s", len(chunk), chunk.hex())
frames = self._parser.feed(chunk)
if frames:
self._pending_frames.extend(frames[1:])
self._validate_frame(frames[0], expected)
return frames[0]
tail = (tail + chunk)[-64:]
if self._BOOT_BANNER in tail:
return None
raise TimeoutError(
f"No S3 frame received within {timeout:.1f}s (expected SUB 0x{expected:02X})")
def _poll_until_booted(self) -> S3Frame:
"""The unit said it is booting: POLL again until it answers. A read --
nothing is ever sent but SESSION_RESET and POLL."""
log.info("startup: the unit is booting (it sent %r) -- polling again until it answers",
self._BOOT_BANNER.decode())
deadline = time.monotonic() + self._BOOT_GRACE_S
while time.monotonic() < deadline:
self._send(SESSION_RESET)
self._send(POLL_PROBE)
try:
return self._recv_one(expected_sub=_expected_rsp_sub(SUB_POLL),
timeout=self._BOOT_POLL_S)
except TimeoutError:
continue
raise TimeoutError(
f"the unit sent its boot message but did not answer a POLL within "
f"{self._BOOT_GRACE_S:.0f} s")
def _drain_boot_string(self, drain_ms: int = 200) -> None:
"""
Read and discard any boot-string bytes ("Operating System") the device