From 189d6d6ed6ee92200056ff0ff764a48df9bda6a1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Oct 2021 09:33:18 +1100 Subject: [PATCH] AP_RCProtocol: check for RC protocol switching enable by default don't allow protocol switching after initial protocol is found --- libraries/AP_RCProtocol/AP_RCProtocol.cpp | 16 +++++++++++++--- libraries/AP_RCProtocol/AP_RCProtocol.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.cpp b/libraries/AP_RCProtocol/AP_RCProtocol.cpp index a722b0f59d..729c14d040 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol.cpp @@ -63,10 +63,20 @@ AP_RCProtocol::~AP_RCProtocol() } } +bool AP_RCProtocol::should_search(uint32_t now_ms) const +{ +#ifndef IOMCU_FW + if (_detected_protocol != AP_RCProtocol::NONE && !rc().allow_rc_protocol_switching()) { + return false; + } +#endif + return (now_ms - _last_input_ms >= 200); +} + void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1) { uint32_t now = AP_HAL::millis(); - bool searching = (now - _last_input_ms >= 200); + bool searching = should_search(now); #ifndef IOMCU_FW rc_protocols_mask = rc().enabled_protocols(); @@ -150,7 +160,7 @@ void AP_RCProtocol::process_pulse_list(const uint32_t *widths, uint16_t n, bool bool AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate) { uint32_t now = AP_HAL::millis(); - bool searching = (now - _last_input_ms >= 200); + bool searching = should_search(now); #ifndef IOMCU_FW rc_protocols_mask = rc().enabled_protocols(); @@ -234,7 +244,7 @@ void AP_RCProtocol::check_added_uart(void) return; } uint32_t now = AP_HAL::millis(); - bool searching = (now - _last_input_ms >= 200); + bool searching = should_search(now); if (!searching && !_detected_with_bytes) { // not using this uart return; diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.h b/libraries/AP_RCProtocol/AP_RCProtocol.h index 2a1575ffa5..e8e8c2e54b 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol.h @@ -49,6 +49,7 @@ public: { return _valid_serial_prot; } + bool should_search(uint32_t now_ms) const; void process_pulse(uint32_t width_s0, uint32_t width_s1); void process_pulse_list(const uint32_t *widths, uint16_t n, bool need_swap); bool process_byte(uint8_t byte, uint32_t baudrate);