From 53b6f3802784ca45fefe8b642ddff866f1957d6b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 4 Nov 2018 11:09:29 +1100 Subject: [PATCH] AP_RCProtocol: allow switching between all protocols on IOMCU this allows searching for uart protocols after losing a pulse based protocol --- libraries/AP_RCProtocol/AP_RCProtocol.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.cpp b/libraries/AP_RCProtocol/AP_RCProtocol.cpp index 8d1b93a049..4954938cd9 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol.cpp @@ -40,13 +40,14 @@ void AP_RCProtocol::init() void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1) { - if (_detected_protocol != AP_RCProtocol::NONE && _detected_with_bytes) { + uint32_t now = AP_HAL::millis(); + bool searching = (now - _last_input_ms >= 200); + if (_detected_protocol != AP_RCProtocol::NONE && _detected_with_bytes && !searching) { // we're using byte inputs, discard pulses return; } - uint32_t now = AP_HAL::millis(); // first try current protocol - if (_detected_protocol != AP_RCProtocol::NONE && now - _last_input_ms < 200) { + if (_detected_protocol != AP_RCProtocol::NONE && !searching) { backend[_detected_protocol]->process_pulse(width_s0, width_s1); if (backend[_detected_protocol]->new_input()) { _new_input = true; @@ -70,6 +71,7 @@ void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1) } _new_input = true; _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i; + memset(_good_frames, 0, sizeof(_good_frames)); _last_input_ms = now; _detected_with_bytes = false; } @@ -102,13 +104,14 @@ void AP_RCProtocol::process_pulse_list(const uint32_t *widths, uint16_t n, bool void AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate) { - if (_detected_protocol != AP_RCProtocol::NONE && !_detected_with_bytes) { + uint32_t now = AP_HAL::millis(); + bool searching = (now - _last_input_ms >= 200); + if (_detected_protocol != AP_RCProtocol::NONE && !_detected_with_bytes && !searching) { // we're using pulse inputs, discard bytes return; } - uint32_t now = AP_HAL::millis(); // first try current protocol - if (_detected_protocol != AP_RCProtocol::NONE && now - _last_input_ms < 200) { + if (_detected_protocol != AP_RCProtocol::NONE && !searching) { backend[_detected_protocol]->process_byte(byte, baudrate); if (backend[_detected_protocol]->new_input()) { _new_input = true; @@ -128,6 +131,7 @@ void AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate) } _new_input = true; _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i; + memset(_good_frames, 0, sizeof(_good_frames)); _last_input_ms = now; _detected_with_bytes = true; }