From a54e6115d2d3fc9b766f4a8fc27f3144f31c4474 Mon Sep 17 00:00:00 2001 From: Ishaan Samantray Date: Thu, 29 Oct 2026 13:59:41 -0400 Subject: [PATCH] fix(crsf_rc): send the flight mode telemetry frame again (#29446) * fix(crsf_rc): send the flight mode telemetry frame again The arming check added with the bind command (#26790) reads vehicle_status through the same subscription as the flight mode telemetry. Its copy() advances that subscription on every Run(), so the telemetry slot's update() never sees a new message and the flight mode frame (0x21) is never sent. Give the arming check its own vehicle_status subscription. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: devteamaegis * fix(crsf_rc): read vehicle_status once per cycle instead of a second subscription Per review: update the cached vehicle_status once at the top of Run(), use it for the arming state, and let the flight mode telemetry slot send from the cached copy when a new message arrived since its last send. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: devteamaegis --------- Signed-off-by: devteamaegis --- src/drivers/rc/crsf_rc/CrsfRc.cpp | 18 +++++++----------- src/drivers/rc/crsf_rc/CrsfRc.hpp | 2 ++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/drivers/rc/crsf_rc/CrsfRc.cpp b/src/drivers/rc/crsf_rc/CrsfRc.cpp index 50b408f96a3..5d5ebc004a2 100644 --- a/src/drivers/rc/crsf_rc/CrsfRc.cpp +++ b/src/drivers/rc/crsf_rc/CrsfRc.cpp @@ -212,12 +212,9 @@ void CrsfRc::Run() const hrt_abstime time_now_us = hrt_absolute_time(); perf_count_interval(_cycle_interval_perf, time_now_us); - if (_vehicle_status_sub.updated()) { - vehicle_status_s vehicle_status; - - if (_vehicle_status_sub.copy(&vehicle_status)) { - _armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED); - } + if (_vehicle_status_sub.update(&_vehicle_status)) { + _armed = (_vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED); + _vehicle_status_updated = true; } vehicle_command_s vcmd{}; @@ -359,12 +356,11 @@ void CrsfRc::Run() break; case 3: - vehicle_status_s vehicle_status; - - if (_vehicle_status_sub.update(&vehicle_status)) { + if (_vehicle_status_updated) { + _vehicle_status_updated = false; const char *flight_mode = "(unknown)"; - switch (vehicle_status.nav_state) { + switch (_vehicle_status.nav_state) { case vehicle_status_s::NAVIGATION_STATE_MANUAL: flight_mode = "Manual"; break; @@ -382,7 +378,7 @@ void CrsfRc::Run() break; case vehicle_status_s::NAVIGATION_STATE_POSCTL: - flight_mode = (vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING) ? "Cruise" : "Position"; + flight_mode = (_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING) ? "Cruise" : "Position"; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_RTL: diff --git a/src/drivers/rc/crsf_rc/CrsfRc.hpp b/src/drivers/rc/crsf_rc/CrsfRc.hpp index 30d6289c6a9..d8948c2e443 100644 --- a/src/drivers/rc/crsf_rc/CrsfRc.hpp +++ b/src/drivers/rc/crsf_rc/CrsfRc.hpp @@ -104,6 +104,8 @@ private: char _device[20] {}; ///< device / serial port path bool _is_singlewire{false}; bool _armed{false}; + vehicle_status_s _vehicle_status{}; + bool _vehicle_status_updated{false}; static constexpr size_t RC_MAX_BUFFER_SIZE{64}; uint8_t _rcs_buf[RC_MAX_BUFFER_SIZE] {};