Repository navigation
feat(system): report the health of each CAN bus - #43
Conversation
Add SystemState.can_bus_health (field 9): per bus id, a firmware-judged CanBusStatus over the last report window plus RX counters since boot (frames received and matched, RX errors, overruns, bus-offs) and whether the controller is listen-only. BLE only. A map keyed by bus id rather than a repeated field, so the app's mergeFromMessage replaces each bus's entry instead of appending. Part of OpenCarControls/firmware#12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiX4By1AMegtzFhVwNo
|
The latest Buf updates on your PR. Results from workflow Proto Check / check (pull_request).
|
Hardware test: WiCAN (ESP32-C3) + virtual-carTested together with OpenCarControls/firmware#115 and OpenCarControls/mobile-app#127. Setup
The PRs list no manual checks, so all tests come from reading the diffs. 1. [Analysis] The CAN buses row appears: passSettings → CAN buses shows "Bus 0 (listen-only) · Silent", "0 frames · 0 errors · 0 overruns · 0 bus-offs". This matches the serial log.
2. [Analysis] Bus health shown when Settings first opens: fail as submitted, pass with
|
| Time (UTC) | Event |
|---|---|
| 18:41:12.3 | Window report: listen-only |
| 18:41:14.8 | Write lock off: TWAI started in normal mode |
| 18:41:17.3 | Window report: (normal); the app updates, 2.5 s after the switch |
| 18:41:23.4 | Write lock on: TWAI started in listen-only mode |
| 18:41:27.3 | Window report: (listen-only); the app updates, 3.9 s after the switch |
Note on firmware#115:
- When the mode changes,
run_twai_sessionreturns without ending the RX window. The new mode reaches the app only when that window ends, up to 5 s later, rather than "right away". - The window that spans the switch is reported under the new mode.
- Neither blocks the PR. Ending the window on a mode change, as is done on bus-off, would make the update immediate.
4. [Analysis] No regression on the BLE link: pass
- About 20 minutes of serial log, including the extra bus health message every 5 s: no
BLE GATT TX dropped, queue-full or panic lines. - Car access and the dashboard kept updating.
5. [Analysis] Board reset with the app connected: pass
A watchdog reset while the app was on Settings. The row came back as soon as the app reconnected.
| Time (UTC) | Event |
|---|---|
| 18:43:21.8 | Boot: 1 bond, bus 0 in listen-only mode |
| 18:43:26.9 → | Bus 0 window reports every 5 s while the app is away |
| 18:43:56.3 | Phone reconnected (the app's 30 s retry gap) |
| 18:43:56.6 | Link encrypted |
| 18:43:57.6 | Subscribed; latest state resent and the row shows at once |
Unrelated observation
After adb install -r of the new APK, the BLE link seems to have stayed up. The log shows only a new subscribe at 18:38:44, with no new connect or encryption line.
Not tested
- The OK, Errors (degraded), No valid frames and Bus-off statuses, overruns, and the early report on bus-off. These need a live CAN bus; an in-car test with the E-GMP firmware is planned next.
- The PC SocketCAN path (no vcan here).
- MCP2515 (not implemented in this PR).
- The section being hidden over MQTT.
- iOS, a second phone, and ESP32-S3 (Xtensa) builds.
Hardware test in the car: WiCAN (ESP32-C3) + egmpTested together with OpenCarControls/firmware#115 and OpenCarControls/mobile-app#127. Setup
A. [Analysis] Car awake → OK: passThe app showed "Bus 0 (listen-only) · OK", "151409 frames · 0 errors · 0 overruns · 0 bus-offs" at 20:06:43 UTC. That matches the serial log's window sum exactly, up to the window that ended at 20:06:38.
About 2,160 frames/s, with 0 RX errors and 0 overruns. There were no B. [Analysis] Car going to sleep → Silent: skippedSkipped because the phone had to stay on USB in the car. The desk tests already showed Silent rendering correctly. C. [Analysis] Wrong bitrate (250 kbit/s, still listen-only) → No valid frames: failThe car was awake: about 10,800 frames per 5 s just before and just after the test. Bus 0 still reported Cause: the ESP TWAI driver never counts bus errors (bit, stuff, form, CRC, ACK). esp-hal 1.1.2's Follow-ups, in progress on this PR set:
Not tested in the car: bus-off (shouldn't be provoked on a car, and a listen-only controller can't go bus-off) and overruns (none seen). The WiCAN was flashed back to the 500 kbit/s build afterwards. |
The frame total only grows, so after a while in a car it no longer reads at a glance. The rate over the last report window does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a busy bus (about 2,000 frames/s on E-GMP M-CAN) a uint32 frame total saturates after a few weeks of the bus being awake, and the app doesn't need it. Drops frames_received and frames_matched and moves frames_per_second into field 3. CanBusHealth isn't released yet, so the numbers are reused rather than deprecated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Frames per second: changes and in-car retestTogether with OpenCarControls/firmware#115 and OpenCarControls/mobile-app#127. Changes after the in-car test
Checks: Retest in the car: pass
Before merging: the firmware and app pins point at the contracts PR branch ( |
|
🎉 This PR is included in version 0.15.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
What and why
Adds
SystemState.can_bus_health(field 9, the next free number), the last open item of OpenCarControls/firmware#12. Closes #21.map<uint32, CanBusHealth>keyed by bus id. I used a map rather than a repeated field so the app'smergeFromMessagereplaces each bus's entry instead of appending a new copy on every update.CommandAvailabilityuses a map for the same reason.CanBusHealth:CanBusStatusthe firmware works out from the last report window:OK,SILENT,DEGRADED,NO_VALID_FRAMESorBUS_OFFlisten_onlycan_access.Matching PRs: the firmware PR on OpenCarControls/firmware and the mobile-app PR on OpenCarControls/mobile-app, both from branch
claude/sweet-albattani-i9lueo.Checklist
buf format,buf lintandbuf breakingpass:bufisn't installed where I worked, so I couldn't run them; CI runs them. The schema does compile withprotocthrough the firmware'sprost-build.optional(a map can't be)u32::MAXcounters) fits inble.payload.max_message_bytesSource of the data
The firmware's own TWAI and SocketCAN RX counters, not vehicle signals.
Generated by Claude Code