Second start through SFM, BE9441 2026-10-26 23:54:41: acked 0x69, and Brian saw 'starting, performing sensor check, recording' -- but the read-back's single SESSION_RESET + POLL went out 2.3 s after the ack, inside the ~30 s sensor check, and was never answered or re-sent (504 after 120 s, audit ca7b5b42). Brian: every unit is set to sensor-check before monitoring, ~30 s, then 'Recording...'. - MiniMateProtocol.wake(attempt_s, deadline_s): SESSION_RESET + POLL re-sent every attempt_s until the unit answers, then the POLL data step; a named timeout at the deadline. Reads only. MiniMateClient.wake() wraps it. - The Series-3 change: after a START, the first read waits S3_SENSOR_CHECK_S (30 s) before asking; every read then wakes with retries (every 5 s, up to 60 s). A stop is unchanged -- its read-back was confirmed three times tonight. Tests: a unit deaf for 4 probes is asked a 5th time and answers; a unit that never answers ends in the named timeout after ~6 probes; a start's first read waits the sensor check, a stop's does not; every read is preceded by a wake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
"""Waking a MiniMate that is busy right after a start (BE9441, 2026-10-26).
|
|
|
|
A start makes the unit run its sensor check (~30 s, Brian; ~40 s on BE11529,
|
|
2026-04-08) before 'Recording...'. Twice tonight a read-back sent 2 s after the
|
|
start's ack -- a bare 0x1C, then SESSION_RESET + POLL -- got no answer, and with
|
|
nothing re-sent the read waited out 120 s. wake() re-sends SESSION_RESET + POLL
|
|
until the unit answers or the deadline passes.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
import minimateplus.protocol as mp # noqa: E402
|
|
from minimate_replay import fast_clock # noqa: E402
|
|
from minimateplus.framing import POLL_DATA, POLL_PROBE, SESSION_RESET # noqa: E402
|
|
|
|
# BE9441's own POLL replies, recorded 2026-10-26 (probe ack, then the data reply)
|
|
PROBE_ACK = bytes.fromhex("1002001010a400000030000000000000000000000000d403")
|
|
|
|
|
|
def _poll_data_reply() -> bytes:
|
|
from pathlib import Path
|
|
from minimateplus.framing import S3FrameParser
|
|
raw = (Path(__file__).parent / "fixtures" / "minimate-bench-10-26-26-histogram"
|
|
/ "unit_replies.bin").read_bytes()
|
|
p, start = S3FrameParser(), 0
|
|
for i in range(len(raw)):
|
|
for f in p.feed(raw[i:i + 1]):
|
|
w = raw[start:i + 1]
|
|
if f.sub == 0xA4 and len(f.data) > 20:
|
|
return w[w.index(b"\x10\x02"):]
|
|
start = i + 1
|
|
raise AssertionError("no POLL data reply in the fixture")
|
|
|
|
|
|
class Busy:
|
|
"""Ignores the first `deaf` POLL probes (a sensor check), then answers."""
|
|
|
|
def __init__(self, deaf: int):
|
|
self.deaf, self.sent, self._buf = deaf, [], b""
|
|
self.data_reply = _poll_data_reply()
|
|
|
|
def write(self, data):
|
|
data = bytes(data)
|
|
self.sent.append(data)
|
|
if data == POLL_PROBE:
|
|
if self.deaf:
|
|
self.deaf -= 1
|
|
else:
|
|
self._buf += PROBE_ACK
|
|
elif data == POLL_DATA:
|
|
self._buf += self.data_reply
|
|
|
|
def read(self, n):
|
|
out, self._buf = self._buf[:n], self._buf[n:]
|
|
return out
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _fast(monkeypatch):
|
|
fast_clock(monkeypatch)
|
|
|
|
|
|
def test_the_probe_ack_is_real():
|
|
from minimateplus.framing import S3FrameParser
|
|
f = S3FrameParser().feed(PROBE_ACK)
|
|
assert len(f) == 1 and f[0].sub == 0xA4
|
|
|
|
|
|
def test_a_busy_unit_is_asked_again_until_it_answers():
|
|
t = Busy(deaf=4)
|
|
mp.MiniMateProtocol(t).wake(attempt_s=5.0, deadline_s=60.0)
|
|
probes = [i for i, d in enumerate(t.sent) if d == POLL_PROBE]
|
|
assert len(probes) == 5 # 4 ignored, the 5th answered
|
|
assert all(t.sent[i - 1] == SESSION_RESET for i in probes)
|
|
assert t.sent[-2:] == [SESSION_RESET, POLL_DATA]
|
|
|
|
|
|
def test_a_unit_that_never_answers_ends_in_a_named_timeout():
|
|
t = Busy(deaf=10 ** 6)
|
|
with pytest.raises(mp.TimeoutError, match="did not answer a POLL"):
|
|
mp.MiniMateProtocol(t).wake(attempt_s=5.0, deadline_s=30.0)
|
|
assert 5 <= t.sent.count(POLL_PROBE) <= 7 # every ~5 s for 30 s
|