From 67fd862a8c9d70b40c819f733d0e74ef8e3135c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <andrew@tridgell.net> 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 1744146201..05f30d7fbe 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().multiple_receiver_support()) { + 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 ed084dcb70..5fa1a5a66f 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);