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
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""A MiniMate that boots when its port opens is waited for, not given up on.
|
|
|
|
BE9441 on a serial cable (bench, 2026-10-25) twice sent its boot banner
|
|
("Operating System") ~3 s after the port opened and ignored the POLL sent
|
|
before it; the request then failed at the full receive timeout (15 s, or 120 s
|
|
on the download path). After a mid-download reboot it answered 8.8 s after its
|
|
banner. startup() now stops waiting on the moment it sees the banner and polls
|
|
again until the unit answers (up to 20 s); with no banner, nothing changes.
|
|
"""
|
|
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.client as mc # noqa: E402
|
|
import minimateplus.protocol as mp # noqa: E402
|
|
from minimate_replay import SessionReplay, fast_clock, recorded_replies # noqa: E402
|
|
|
|
BANNER = b"Operating System"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _fast(monkeypatch):
|
|
fast_clock(monkeypatch)
|
|
|
|
|
|
class Booting(SessionReplay):
|
|
"""Banner instead of an answer to the first POLL; then `deaf` more POLL probes
|
|
go unanswered (still booting); after that, the recorded session as normal."""
|
|
|
|
def __init__(self, replies, deaf=2, banner=True):
|
|
super().__init__(replies)
|
|
self.deaf, self.banner, self.polls = deaf, banner, 0
|
|
|
|
def write(self, data):
|
|
data = bytes(data)
|
|
if data[:2] == b"\x41\x02" and data[5] == 0x5B and data[8] == 0x00: # the POLL probe
|
|
self.polls += 1
|
|
if self.polls == 1:
|
|
if self.banner:
|
|
self._buf += BANNER
|
|
return
|
|
if self.polls <= 1 + self.deaf:
|
|
return
|
|
super().write(data)
|
|
|
|
|
|
def connect(transport):
|
|
client = mc.MiniMateClient(transport=transport)
|
|
client.open()
|
|
return client, client.connect()
|
|
|
|
|
|
def test_a_unit_booting_on_connect_is_waited_for():
|
|
t = Booting(recorded_replies(), deaf=2)
|
|
_client, info = connect(t)
|
|
assert info.serial == "BE9441"
|
|
assert t.polls == 4 # the lost one, two while booting, the answered one
|
|
|
|
|
|
def test_a_unit_that_boots_but_never_answers_says_so():
|
|
t = Booting(recorded_replies(), deaf=10_000)
|
|
with pytest.raises(mp.TimeoutError, match="boot"):
|
|
connect(t)
|
|
|
|
|
|
def test_a_silent_unit_without_a_banner_fails_as_before():
|
|
t = Booting(recorded_replies(), deaf=10_000, banner=False)
|
|
with pytest.raises(mp.TimeoutError) as e:
|
|
connect(t)
|
|
assert "boot" not in str(e.value)
|
|
assert t.polls == 1 # no re-polling without the banner
|