From cebfef3ead15c13ae2463adf45b8fc384955c5a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 9 Oct 2014 09:19:35 +1100 Subject: [PATCH] HAL_Linux: don't accept less than 5 input channels --- libraries/AP_HAL_Linux/RCInput.cpp | 50 +++++++++++++++++++----------- libraries/AP_HAL_Linux/RCInput.h | 13 +++++--- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/libraries/AP_HAL_Linux/RCInput.cpp b/libraries/AP_HAL_Linux/RCInput.cpp index 528630c771..2946785090 100644 --- a/libraries/AP_HAL_Linux/RCInput.cpp +++ b/libraries/AP_HAL_Linux/RCInput.cpp @@ -23,9 +23,10 @@ extern const AP_HAL::HAL& hal; using namespace Linux; LinuxRCInput::LinuxRCInput() : - new_rc_input(false), - _channel_counter(-1) -{} + new_rc_input(false) +{ + ppm_state._channel_counter = -1; +} void LinuxRCInput::init(void* machtnichts) { @@ -47,8 +48,10 @@ uint16_t LinuxRCInput::read(uint8_t ch) if (_override[ch]) { return _override[ch]; } - - return _pulse_capt[ch]; + if (ch >= _num_channels) { + return 0; + } + return _pwm_values[ch]; } uint8_t LinuxRCInput::read(uint16_t* periods, uint8_t len) @@ -106,14 +109,17 @@ void LinuxRCInput::_process_ppmsum_pulse(uint16_t width_usec) if (width_usec >= 4000) { // a long pulse indicates the end of a frame. Reset the // channel counter so next pulse is channel 0 - if (_channel_counter != -1) { + if (ppm_state._channel_counter >= 5) { + for (uint8_t i=0; i 700 && width_usec < 2300) { // take a reading for the current channel - _pulse_capt[_channel_counter] = width_usec; + // buffer these + ppm_state._pulse_capt[ppm_state._channel_counter] = width_usec; // move to next channel - _channel_counter++; + ppm_state._channel_counter++; } // if we have reached the maximum supported channels then // mark as unsynchronised, so we wait for a wide pulse - if (_channel_counter >= LINUX_RC_INPUT_NUM_CHANNELS) { + if (ppm_state._channel_counter >= LINUX_RC_INPUT_NUM_CHANNELS) { + for (uint8_t i=0; i= 5) { for (i=0; i 12) { @@ -268,11 +280,13 @@ void LinuxRCInput::_process_dsm_pulse(uint16_t width_s0, uint16_t width_s1) } uint16_t values[8]; uint16_t num_values=0; - if (dsm_decode(hal.scheduler->micros64(), bytes, values, &num_values, 8)) { + if (dsm_decode(hal.scheduler->micros64(), bytes, values, &num_values, 8) && + num_values >= 5) { for (i=0; i