Browse Source

AP_RCProtocol: allow switching between all protocols on IOMCU

this allows searching for uart protocols after losing a pulse based
protocol
mission-4.1.18
Andrew Tridgell 6 years ago
parent
commit
53b6f38027
  1. 16
      libraries/AP_RCProtocol/AP_RCProtocol.cpp

16
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) 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 // we're using byte inputs, discard pulses
return; return;
} }
uint32_t now = AP_HAL::millis();
// first try current protocol // 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); backend[_detected_protocol]->process_pulse(width_s0, width_s1);
if (backend[_detected_protocol]->new_input()) { if (backend[_detected_protocol]->new_input()) {
_new_input = true; _new_input = true;
@ -70,6 +71,7 @@ void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1)
} }
_new_input = true; _new_input = true;
_detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i; _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i;
memset(_good_frames, 0, sizeof(_good_frames));
_last_input_ms = now; _last_input_ms = now;
_detected_with_bytes = false; _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) 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 // we're using pulse inputs, discard bytes
return; return;
} }
uint32_t now = AP_HAL::millis();
// first try current protocol // 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); backend[_detected_protocol]->process_byte(byte, baudrate);
if (backend[_detected_protocol]->new_input()) { if (backend[_detected_protocol]->new_input()) {
_new_input = true; _new_input = true;
@ -128,6 +131,7 @@ void AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate)
} }
_new_input = true; _new_input = true;
_detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i; _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i;
memset(_good_frames, 0, sizeof(_good_frames));
_last_input_ms = now; _last_input_ms = now;
_detected_with_bytes = true; _detected_with_bytes = true;
} }

Loading…
Cancel
Save