A silent expander gets more tries, and a failed start says more in the log
A user on a Cardputer Zero could not connect his Cap. MeshTerm stopped with "nothing answers at 0x43 on /dev/i2c-1", and no log said more than the dialog did. His Cap is the older Cap LoRa868, which carries no expander at all. Support for that board follows separately. What this commit changes is what MeshTerm knows when the next board stays silent. The expander gets more than one try. The first read still comes after POWER_SETTLE_S, which is sufficient on the boards we have. A board with a slower power rail refuses that read and answers a moment later, and that must not read as an absent board. The node now tries again until PI4IO_WAIT_S is spent. A board that is ready still answers at once, so nothing waits. The log of that failure carries the error of the bus. The sentence the user reads cannot carry it, because a refused address and a broken bus are the same thing to that user. They are not the same thing to us, and only the log can tell them apart afterwards. The node also writes its wiring to its own log. A board problem is reported with that file, and the wiring can come from a profile that the reporter wrote, so the file must say which pins the node used. The startup picker writes a failed connection to meshterm.log at WARNING. It wrote nothing before, on the reasoning that the dialog already says all that the log would say. That holds while the dialog is up. A user who reports a problem sends the log file long after it is gone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63e31c334b
commit
bf79f9975c
3 files changed
+110
-7
No files matched your search
@@ -16,6 +16,7 @@ import ast
|
||||
import asyncio
|
||||
import dataclasses
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -183,6 +184,59 @@ def test_an_expander_on_a_missing_bus_is_named(tmp_path: Path) -> None:
|
||||
assert err.value.kind == "no-i2c"
|
||||
|
||||
|
||||
#: A number that stands for the open I2C bus in the two tests below. The tests put their
|
||||
#: own ``os.write`` and ``os.read`` in front of the real ones, and those answer for this
|
||||
#: number alone. Each other file in the process, the capture of pytest included, goes
|
||||
#: through to the real function.
|
||||
_BUS_FD = 9001
|
||||
|
||||
|
||||
def test_a_slow_expander_gets_more_than_one_try(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""A board whose power rail is slow answers a later read, and is attached after all."""
|
||||
real_write, real_read = os.write, os.read
|
||||
tries: list[bytes] = []
|
||||
|
||||
def write(fd: int, data: bytes) -> int:
|
||||
if fd != _BUS_FD:
|
||||
return real_write(fd, data)
|
||||
tries.append(data)
|
||||
return len(data)
|
||||
|
||||
def read(fd: int, count: int) -> bytes:
|
||||
if fd != _BUS_FD:
|
||||
return real_read(fd, count)
|
||||
if len(tries) < 3:
|
||||
raise OSError(121, "Remote I/O error")
|
||||
return bytes([0xA2])
|
||||
|
||||
monkeypatch.setattr(os, "write", write)
|
||||
monkeypatch.setattr(os, "read", read)
|
||||
monkeypatch.setattr(radionode, "PI4IO_RETRY_S", 0)
|
||||
assert radionode._expander_id(_BUS_FD, 0x43, Path("/dev/i2c-1")) == 0xA2
|
||||
assert len(tries) == 3, "it read the ID register again until the board answered"
|
||||
|
||||
|
||||
def test_an_expander_that_never_answers_is_absent_and_the_log_says_why(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""The user reads that nothing is there. Only the log says what the bus answered."""
|
||||
real_write = os.write
|
||||
|
||||
def write(fd: int, data: bytes) -> int:
|
||||
if fd != _BUS_FD:
|
||||
return real_write(fd, data)
|
||||
raise OSError(121, "Remote I/O error")
|
||||
|
||||
monkeypatch.setattr(os, "write", write)
|
||||
monkeypatch.setattr(radionode, "PI4IO_WAIT_S", 0)
|
||||
with caplog.at_level(logging.WARNING, logger="radionode"):
|
||||
with pytest.raises(radionode.NodeError) as err:
|
||||
radionode._expander_id(_BUS_FD, 0x43, Path("/dev/i2c-1"))
|
||||
assert err.value.kind == "absent"
|
||||
assert "nothing answers at 0x43" in str(err.value), "the sentence of the user is unchanged"
|
||||
assert "Remote I/O error" in caplog.text, "the log keeps the error of the bus"
|
||||
|
||||
|
||||
def test_a_board_with_no_switches_prepares_nothing() -> None:
|
||||
"""The wiring of the AIO has neither, and its node starts the same as it always did."""
|
||||
assert radionode.prepare_board({"bus_id": 1, "pi4io_bus": -1}) == []
|
||||
|
||||
Reference in new issue
Block a user