2018-01-17 15:31:11 -04:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-07-20 01:25:40 -03:00
|
|
|
*
|
2018-01-17 15:31:11 -04:00
|
|
|
* Code by Andrew Tridgell and Siddharth Bharat Purohit
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_RCProtocol.h"
|
2020-04-30 16:34:51 -03:00
|
|
|
#include <AP_HAL/utility/sparse-endian.h>
|
2018-01-17 15:31:11 -04:00
|
|
|
|
2018-07-20 01:25:40 -03:00
|
|
|
class AP_RCProtocol_Backend {
|
2018-01-17 15:31:11 -04:00
|
|
|
friend class AP_RCProtcol;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AP_RCProtocol_Backend(AP_RCProtocol &_frontend);
|
2018-11-04 23:56:37 -04:00
|
|
|
virtual ~AP_RCProtocol_Backend() {}
|
2018-07-12 11:49:32 -03:00
|
|
|
virtual void process_pulse(uint32_t width_s0, uint32_t width_s1) {}
|
2018-11-02 06:42:29 -03:00
|
|
|
virtual void process_byte(uint8_t byte, uint32_t baudrate) {}
|
2020-05-09 05:20:33 -03:00
|
|
|
virtual void process_handshake(uint32_t baudrate) {}
|
2018-01-17 15:31:11 -04:00
|
|
|
uint16_t read(uint8_t chan);
|
2020-01-28 22:16:54 -04:00
|
|
|
void read(uint16_t *pwm, uint8_t n);
|
2018-01-17 15:31:11 -04:00
|
|
|
bool new_input();
|
2021-02-01 12:26:33 -04:00
|
|
|
uint8_t num_channels() const;
|
2018-01-18 17:40:07 -04:00
|
|
|
|
2018-04-10 03:14:54 -03:00
|
|
|
// support for receivers that have FC initiated bind support
|
|
|
|
virtual void start_bind(void) {}
|
|
|
|
|
|
|
|
// allow for backends that need regular polling
|
|
|
|
virtual void update(void) {}
|
2018-07-12 11:49:32 -03:00
|
|
|
enum {
|
|
|
|
PARSE_TYPE_SIGREAD,
|
|
|
|
PARSE_TYPE_SERIAL
|
|
|
|
};
|
2018-11-05 02:13:46 -04:00
|
|
|
|
|
|
|
// get number of frames, ignoring failsafe
|
|
|
|
uint32_t get_rc_frame_count(void) const {
|
|
|
|
return rc_frame_count;
|
|
|
|
}
|
|
|
|
|
2020-08-13 00:28:42 -03:00
|
|
|
// reset valid rc frame count
|
|
|
|
void reset_rc_frame_count(void) {
|
|
|
|
rc_frame_count = 0;
|
|
|
|
}
|
|
|
|
|
2018-11-08 04:07:42 -04:00
|
|
|
// get number of frames, honoring failsafe
|
|
|
|
uint32_t get_rc_input_count(void) const {
|
|
|
|
return rc_input_count;
|
|
|
|
}
|
2019-12-02 03:47:12 -04:00
|
|
|
|
2020-05-09 05:20:33 -03:00
|
|
|
uint32_t get_rc_protocols_mask(void) const {
|
|
|
|
return frontend.rc_protocols_mask;
|
|
|
|
}
|
|
|
|
|
2019-12-02 03:47:12 -04:00
|
|
|
// get RSSI
|
|
|
|
int16_t get_RSSI(void) const {
|
|
|
|
return rssi;
|
|
|
|
}
|
2021-07-13 13:45:08 -03:00
|
|
|
int16_t get_rx_link_quality(void) const {
|
|
|
|
return rx_link_quality;
|
|
|
|
}
|
2019-12-02 23:22:44 -04:00
|
|
|
// get UART for RCIN, if available. This will return false if we
|
|
|
|
// aren't getting the active RC input protocol via the uart
|
|
|
|
AP_HAL::UARTDriver *get_UART(void) const {
|
|
|
|
return frontend._detected_with_bytes?frontend.added.uart:nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:46:46 -03:00
|
|
|
// get an available uart regardless of whether we have detected a protocol via it
|
|
|
|
AP_HAL::UARTDriver *get_available_UART(void) const {
|
|
|
|
return frontend.added.uart;
|
|
|
|
}
|
|
|
|
|
2019-12-02 23:22:44 -04:00
|
|
|
// return true if we have a uart available for protocol handling.
|
|
|
|
bool have_UART(void) const {
|
|
|
|
return frontend.added.uart != nullptr;
|
|
|
|
}
|
2022-01-15 11:26:47 -04:00
|
|
|
|
|
|
|
// is the receiver active, used to detect power loss and baudrate changes
|
|
|
|
virtual bool is_rx_active() const {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-08 04:07:42 -04:00
|
|
|
|
2018-01-17 15:31:11 -04:00
|
|
|
protected:
|
2020-10-26 03:32:36 -03:00
|
|
|
struct Channels11Bit_8Chan {
|
2020-04-30 16:34:51 -03:00
|
|
|
#if __BYTE_ORDER != __LITTLE_ENDIAN
|
|
|
|
#error "Only supported on little-endian architectures"
|
|
|
|
#endif
|
|
|
|
uint32_t ch0 : 11;
|
|
|
|
uint32_t ch1 : 11;
|
|
|
|
uint32_t ch2 : 11;
|
|
|
|
uint32_t ch3 : 11;
|
|
|
|
uint32_t ch4 : 11;
|
|
|
|
uint32_t ch5 : 11;
|
|
|
|
uint32_t ch6 : 11;
|
|
|
|
uint32_t ch7 : 11;
|
|
|
|
} PACKED;
|
|
|
|
|
2021-07-13 13:45:08 -03:00
|
|
|
void add_input(uint8_t num_channels, uint16_t *values, bool in_failsafe, int16_t rssi=-1, int16_t rx_link_quality=-1);
|
2020-03-23 16:20:00 -03:00
|
|
|
AP_RCProtocol &frontend;
|
2018-07-20 01:25:40 -03:00
|
|
|
|
2020-03-18 21:08:17 -03:00
|
|
|
void log_data(AP_RCProtocol::rcprotocol_t prot, uint32_t timestamp, const uint8_t *data, uint8_t len) const;
|
|
|
|
|
2020-04-30 16:34:51 -03:00
|
|
|
// decode channels from the standard 11bit format (used by CRSF and SBUS)
|
|
|
|
void decode_11bit_channels(const uint8_t* data, uint8_t nchannels, uint16_t *values, uint16_t mult, uint16_t div, uint16_t offset);
|
|
|
|
|
2018-01-18 17:40:07 -04:00
|
|
|
private:
|
2018-11-05 02:13:46 -04:00
|
|
|
uint32_t rc_input_count;
|
|
|
|
uint32_t last_rc_input_count;
|
|
|
|
uint32_t rc_frame_count;
|
2018-01-17 15:31:11 -04:00
|
|
|
|
2018-01-18 17:40:07 -04:00
|
|
|
uint16_t _pwm_values[MAX_RCIN_CHANNELS];
|
2018-01-17 15:31:11 -04:00
|
|
|
uint8_t _num_channels;
|
2019-12-02 03:47:12 -04:00
|
|
|
int16_t rssi = -1;
|
2021-07-13 13:45:08 -03:00
|
|
|
int16_t rx_link_quality = -1;
|
2018-01-18 17:40:07 -04:00
|
|
|
};
|