listen_pod.py 串口EIO异常不再崩栈并给出排查提示

Pi板载UART典型故障(errno 5): 捕获后打印串口控制台占用/mini-UART不稳的
排查指引与改用USB转串口建议, 退出码1; 打桩复现验证通过
This commit is contained in:
keita
2026-09-24 15:42:04 +08:00
parent 50372e6623
commit 11131e26c5
+20 -1
View File
@@ -45,8 +45,15 @@ def main() -> int:
t0 = time.monotonic() t0 = time.monotonic()
n_tele, n_tgt, n_other = 0, 0, 0 n_tele, n_tgt, n_other = 0, 0, 0
link_error = None
while time.monotonic() - t0 < args.seconds: while time.monotonic() - t0 < args.seconds:
for frame in pod.poll(): try:
frames = pod.poll()
except OSError as exc:
# Pi 板载 UART 典型故障(errno 5 EIO):控制台抢占 / mini-UART 不稳
link_error = exc
break
for frame in frames:
if isinstance(frame, Telemetry): if isinstance(frame, Telemetry):
n_tele += 1 n_tele += 1
if n_tele == 1: if n_tele == 1:
@@ -65,7 +72,19 @@ def main() -> int:
else: else:
n_other += 1 n_other += 1
time.sleep(0.005) time.sleep(0.005)
try:
pod.close() pod.close()
except OSError:
pass
if link_error is not None:
print(f"[listen] 链路中途断开: {link_error}")
print("[listen] 排查: ① 串口控制台是否仍占用 "
"(systemctl disable --now serial-getty@ttyS0/ttyAMA0) → 重启; "
"② /dev/serial0 是否指向 mini-UART(ttyS0 不稳定) → 加 "
"dtoverlay=disable-bt 换到 PL011(ttyAMA0),或改用 USB 转串口("
"/dev/ttyUSB0,推荐)")
return 1
expected = _TELEMETRY_NOMINAL_HZ * args.seconds expected = _TELEMETRY_NOMINAL_HZ * args.seconds
rate = n_tele / args.seconds if args.seconds > 0 else 0.0 rate = n_tele / args.seconds if args.seconds > 0 else 0.0