From 91554fd552cd7832e62686bdda4b44c81e56fba9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 15:53:31 +0000 Subject: [PATCH 1/3] feat(system): report the health of each CAN bus 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 Claude-Session: https://claude.ai/code/session_01XkZEiX4By1AMegtzFhVwNo --- opencar/core/v1/system.proto | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/opencar/core/v1/system.proto b/opencar/core/v1/system.proto index b69c756..3bf5f59 100644 --- a/opencar/core/v1/system.proto +++ b/opencar/core/v1/system.proto @@ -38,6 +38,14 @@ message SystemState { // transport.toml, so the topics this device's MQTT clients must use. BLE only. // Sent with can_access. Unset when the device has no MQTT. optional string mqtt_client_id = 8; + + // The health of each CAN bus the device listens on, by bus id (the 0-based + // index of the bus in the device's hardware config). BLE only. Sent in a + // state update of its own (with no vehicle_state) whenever a bus's status + // changes, every few seconds while frames arrive, and when the app + // subscribes. Each update carries every bus the device reports on; a bus + // whose driver doesn't report its health is absent. + map can_bus_health = 9; } // This contains a single system command. @@ -508,3 +516,48 @@ message SystemCommandResult { PhoneValidationRefusal validation_refusal = 4; } } + +// The health of one CAN bus. The counters are totals since the device booted, +// so an update lost on the way doesn't lose counts; they saturate instead of +// wrapping. +message CanBusHealth { + // The firmware's summary of the bus over its last report window (a few + // seconds). + optional CanBusStatus status = 1; + + // The controller is in listen-only mode: it never drives the bus (no ACKs, + // no error frames, no transmission). True while the device is read-only. + optional bool listen_only = 2; + + // Frames received. + optional uint32 frames_received = 3; + + // Frames received that the vehicle's filters accepted. + optional uint32 frames_matched = 4; + + // Receive errors (bit, stuff, form, CRC or acknowledge errors). + optional uint32 rx_errors = 5; + + // Times the receive queue overflowed and frames were dropped. + optional uint32 overruns = 6; + + // Times the controller went bus-off and was restarted. + optional uint32 bus_offs = 7; +} + +// The firmware's summary of a CAN bus over its last report window. +enum CanBusStatus { + // Unknown (not reported yet, or an older firmware). + CAN_BUS_STATUS_UNSPECIFIED = 0; + // Frames arrive with no errors. + CAN_BUS_STATUS_OK = 1; + // No frames and no errors: the car is asleep, or the bus isn't connected. + CAN_BUS_STATUS_SILENT = 2; + // Frames arrive, but with receive errors or overruns. + CAN_BUS_STATUS_DEGRADED = 3; + // Receive errors and no frames: usually a wrong bitrate, a CAN FD bus or a + // wiring fault. + CAN_BUS_STATUS_NO_VALID_FRAMES = 4; + // The controller went bus-off and is being restarted. + CAN_BUS_STATUS_BUS_OFF = 5; +} From 68ea89d7c1e2f8204068535b7afd8e4188574667 Mon Sep 17 00:00:00 2001 From: Tichael <13114338+Tichael@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:23:07 +0000 Subject: [PATCH 2/3] feat(system): report each CAN bus's frames per second 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 --- opencar/core/v1/system.proto | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opencar/core/v1/system.proto b/opencar/core/v1/system.proto index 3bf5f59..3671b63 100644 --- a/opencar/core/v1/system.proto +++ b/opencar/core/v1/system.proto @@ -543,6 +543,10 @@ message CanBusHealth { // Times the controller went bus-off and was restarted. optional uint32 bus_offs = 7; + + // Frames received per second over the last report window, rounded down. Unlike + // the totals, it doesn't grow with time, so it reads at a glance. + optional uint32 frames_per_second = 8; } // The firmware's summary of a CAN bus over its last report window. From ed013d79d425b125d39836b39c1dfc8f7ee6f82f Mon Sep 17 00:00:00 2001 From: Tichael <13114338+Tichael@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:31:07 +0000 Subject: [PATCH 3/3] refactor(system): send a CAN bus's frames as a rate only 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 --- opencar/core/v1/system.proto | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/opencar/core/v1/system.proto b/opencar/core/v1/system.proto index 3671b63..2e4f00f 100644 --- a/opencar/core/v1/system.proto +++ b/opencar/core/v1/system.proto @@ -517,9 +517,9 @@ message SystemCommandResult { } } -// The health of one CAN bus. The counters are totals since the device booted, -// so an update lost on the way doesn't lose counts; they saturate instead of -// wrapping. +// The health of one CAN bus. The error counters are totals since the device +// booted, so an update lost on the way doesn't lose counts; they saturate +// instead of wrapping. message CanBusHealth { // The firmware's summary of the bus over its last report window (a few // seconds). @@ -529,24 +529,19 @@ message CanBusHealth { // no error frames, no transmission). True while the device is read-only. optional bool listen_only = 2; - // Frames received. - optional uint32 frames_received = 3; - - // Frames received that the vehicle's filters accepted. - optional uint32 frames_matched = 4; + // Frames received per second over the last report window, rounded down. A + // rate rather than a total: on a busy bus a total would saturate after a few + // weeks of the bus being awake. + optional uint32 frames_per_second = 3; // Receive errors (bit, stuff, form, CRC or acknowledge errors). - optional uint32 rx_errors = 5; + optional uint32 rx_errors = 4; // Times the receive queue overflowed and frames were dropped. - optional uint32 overruns = 6; + optional uint32 overruns = 5; // Times the controller went bus-off and was restarted. - optional uint32 bus_offs = 7; - - // Frames received per second over the last report window, rounded down. Unlike - // the totals, it doesn't grow with time, so it reads at a glance. - optional uint32 frames_per_second = 8; + optional uint32 bus_offs = 6; } // The firmware's summary of a CAN bus over its last report window.