telemetry: guard CRSF ESC RPM/temp against stale data#11536
telemetry: guard CRSF ESC RPM/temp against stale data#11536sensei-hacker wants to merge 3 commits intoiNavFlight:maintenance-9.xfrom
Conversation
ESC sensor slots are initialized with dataAge=ESC_DATA_INVALID (255) and age toward 255 when no frames arrive. The previous null-guard on getEscTelemetry() was dead code (it always returns a valid pointer), so stale last-seen RPM and temperature values were forwarded to CRSF regardless of data age — causing random values on disarm and when individual ESCs lose contact in multi-ESC setups. Check dataAge < ESC_DATA_INVALID before forwarding; send 0 / TEMPERATURE_INVALID_VALUE for stale or uninitialized slots instead. Fixes iNavFlight#11517
Review Summary by QodoGuard CRSF ESC telemetry against stale sensor data
WalkthroughsDescription• Guard CRSF ESC RPM/temperature against stale data • Check dataAge < ESC_DATA_INVALID before forwarding values • Send 0 for stale RPM; send TEMPERATURE_INVALID_VALUE for stale temperature • Fixes random/garbage values on disarm and multi-motor contact loss Diagramflowchart LR
A["ESC Sensor Data"] --> B["dataAge Check"]
B -->|Fresh| C["Forward RPM/Temp"]
B -->|Stale| D["Send Default Values"]
C --> E["CRSF Frame"]
D --> E
File Changes1. src/main/telemetry/crsf.c
|
Code Review by Qodo
1. crsfRpm() uses 0 sentinel
|
ESC_DATA_INVALID (255) is too lenient as a freshness threshold — with 50ms poll cycles it allows stale data to persist 12+ seconds (single motor) before being suppressed. All other ESC data consumers (OSD, battery, jetiexbus, sbus2) use ESC_DATA_MAX_AGE (10) as the freshness cutoff, giving a ~500ms window per motor. Switch CRSF RPM and temperature guards to match.
|
Test firmware build ready — commit Download firmware for PR #11536 234 targets built. Find your board's
|
In listenOnly mode only escSensorData[0] is ever populated. crsfRpm() and crsfTemperature() were using getMotorCount() to size their frames, emitting N-1 zero/invalid slots alongside the single real motor entry — confusing ground station displays. Export getTelemetryMotorCount() from esc_sensor and use it in both CRSF functions so the frame contains only the slots that the ESC sensor actually populates.
|
I gave it a quick flight test. It seems to occur less. However it still happens on the occasion. RPM.Telemetry.glitch.mp4 |
Summary
ESC RPM and temperature forwarded over CRSF showed random/garbage values when the FC was disarmed and when individual ESCs lost contact in multi-motor setups. The previous null-guard on
getEscTelemetry()was dead code — the function always returns a valid pointer into a static array — so stale last-seen values were unconditionally forwarded regardless of data age.Changes
crsfRpm(): checkescState->dataAge < ESC_DATA_INVALIDbefore forwarding RPM; send0for stale/uninitialized slotscrsfTemperature(): same check before forwarding temperature; sendTEMPERATURE_INVALID_VALUEfor stale/uninitialized slotsESC_DATA_INVALID(255) is already the initialization value set byescSensorInitialize()and is the value used consistently throughoutesc_sensor.cfor this purpose.Testing
dataAgeguard:dataAgecauses mixed fresh/stale values (now stale slots send 0)dataAgesaturates at 255 but was never checked (now checked)Related Issues
Fixes #11517