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
@@ -300,6 +300,15 @@ LEDS = Path("/sys/class/leds")
|
||||
#: the chip does its own reset after this.
|
||||
POWER_SETTLE_S = 0.1
|
||||
|
||||
#: How long the expander of a board gets to answer, after the header is powered on, and
|
||||
#: before MeshTerm says that no board is attached. The first read comes after
|
||||
#: :data:`POWER_SETTLE_S`, which is sufficient on the boards that we have. A board with a
|
||||
#: slower power rail answers a moment later, and that must not read as an absent board.
|
||||
#: :data:`PI4IO_RETRY_S` is the time between two tries, which is short, because a board
|
||||
#: that is ready answers at once.
|
||||
PI4IO_WAIT_S = 1.0
|
||||
PI4IO_RETRY_S = 0.05
|
||||
|
||||
#: ``I2C_SLAVE``: point the open ``/dev/i2c-*`` at one device. The kernel refuses it
|
||||
#: (``EBUSY``) while a kernel driver is bound to that address. This is the correct answer,
|
||||
#: because then the device is not ours to use.
|
||||
@@ -342,6 +351,43 @@ def restore_leds(previous: list[tuple[Path, str]]) -> None:
|
||||
log.warning("could not put %s back to %s: %s", path, before, exc)
|
||||
|
||||
|
||||
def _expander_id(fd: int, address: int, path: Path) -> int:
|
||||
"""Read the ID register of the expander at ``address``, and try again until it answers.
|
||||
|
||||
The caller powers the header of the board a short time before this read. A board whose
|
||||
power rail is slower than :data:`POWER_SETTLE_S` refuses the first read and answers
|
||||
correctly a moment later. For this reason the function tries again until
|
||||
:data:`PI4IO_WAIT_S` is spent, and calls the board absent only then.
|
||||
|
||||
The log line carries the error of the last try. The sentence that 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.
|
||||
|
||||
Args:
|
||||
fd: The open bus, already pointed at the address.
|
||||
address: The address of the expander, for the message.
|
||||
path: The bus device file, for the message.
|
||||
|
||||
Returns:
|
||||
The byte in the ID register.
|
||||
|
||||
Raises:
|
||||
NodeError: ``absent``, when nothing answered in the time above.
|
||||
"""
|
||||
deadline = time.monotonic() + PI4IO_WAIT_S
|
||||
while True:
|
||||
try:
|
||||
os.write(fd, bytes([_PI4IO_ID]))
|
||||
return os.read(fd, 1)[0]
|
||||
except OSError as exc:
|
||||
if time.monotonic() >= deadline:
|
||||
log.warning(
|
||||
"no answer at %#04x on %s after %.1fs: %s", address, path, PI4IO_WAIT_S, exc
|
||||
)
|
||||
raise NodeError("absent", f"nothing answers at {address:#04x} on {path}") from None
|
||||
time.sleep(PI4IO_RETRY_S)
|
||||
|
||||
|
||||
def drive_pi4io(bus: int, address: int, high: list[int], dev: Path = Path("/dev")) -> None:
|
||||
"""Drive the ``high`` pins of a PI4IOE5V6408 high as outputs, and keep the rest as inputs.
|
||||
|
||||
@@ -362,11 +408,7 @@ def drive_pi4io(bus: int, address: int, high: list[int], dev: Path = Path("/dev"
|
||||
fcntl.ioctl(fd, _I2C_SLAVE, address)
|
||||
except OSError as exc:
|
||||
raise NodeError("busy", f"{address:#04x} on {path} is held: {exc}") from None
|
||||
try:
|
||||
os.write(fd, bytes([_PI4IO_ID]))
|
||||
ident = os.read(fd, 1)[0]
|
||||
except OSError:
|
||||
raise NodeError("absent", f"nothing answers at {address:#04x} on {path}") from None
|
||||
ident = _expander_id(fd, address, path)
|
||||
if ident >> 5 != _PI4IO_MAKER:
|
||||
raise NodeError(
|
||||
"absent", f"{address:#04x} on {path} is not a PI4IOE5V6408 (ID {ident:#04x})"
|
||||
@@ -687,6 +729,10 @@ async def run_node(config: dict, report) -> int: # noqa: ANN001 - (dict) -> Non
|
||||
wiring = dict(config.get("wiring") or {})
|
||||
seed = dict(config.get("seed") or {})
|
||||
|
||||
# The log must say which wiring the node used. A board problem is reported with this
|
||||
# file, and the wiring can come from a profile that the reporter wrote.
|
||||
log.info("node wiring: %s", json.dumps(wiring, sort_keys=True))
|
||||
|
||||
bus, cs = int(wiring.get("bus_id", 0)), int(wiring.get("cs_id", 0))
|
||||
_check_device(f"/dev/spidev{bus}.{cs}", "no-spi", "SPI overlay")
|
||||
_check_device(f"/dev/gpiochip{int(wiring.get('gpio_chip', 0))}", "no-gpio", "GPIO chip")
|
||||
|
||||
@@ -63,7 +63,7 @@ from ..core.discovery import (
|
||||
tcp_device,
|
||||
)
|
||||
from ..core.spiradio import spi_radios, without_radio_ports
|
||||
from ..persistence.logging import log_file_for
|
||||
from ..persistence.logging import get_logger, log_file_for
|
||||
from .logo import load_logo
|
||||
from .menus import Lane, align_icons, column_header
|
||||
from .tui import Choice, DeleteRequest, KeyRequest, Separator
|
||||
@@ -332,7 +332,10 @@ async def _smoke_test(
|
||||
continue
|
||||
except DeviceCommandError as exc:
|
||||
# A different failure that the user can act on (not a PIN). Show its remedy, then
|
||||
# go back to the list.
|
||||
# go back to the list. The log keeps the failure also when the dialog says all
|
||||
# that the log would say, because a user who reports a problem sends the log file,
|
||||
# and the dialog is gone long before that.
|
||||
get_logger().warning("%s did not connect (%s): %s", name, type(exc).__name__, exc)
|
||||
notice = connect_failure_text(exc)
|
||||
notice.append("\nChoose another device.")
|
||||
await ui.notify_startup(notice, title="Can't connect yet", banner=load_logo())
|
||||
|
||||
Reference in new issue
Block a user