2016-02-17 21:25:26 -04:00
|
|
|
#pragma once
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2017-01-10 02:08:42 -04:00
|
|
|
#include <atomic>
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_Linux.h"
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2014-08-17 23:32:22 -03:00
|
|
|
#define LINUX_RC_INPUT_NUM_CHANNELS 16
|
2014-08-14 13:48:17 -03:00
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
namespace Linux {
|
|
|
|
|
|
|
|
class RCInput : public AP_HAL::RCInput {
|
2013-09-22 03:01:24 -03:00
|
|
|
public:
|
2015-10-20 18:13:25 -03:00
|
|
|
RCInput();
|
2015-09-13 15:28:02 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput *from(AP_HAL::RCInput *rcinput) {
|
|
|
|
return static_cast<RCInput*>(rcinput);
|
2015-09-13 15:28:02 -03:00
|
|
|
}
|
|
|
|
|
2019-02-21 19:08:12 -04:00
|
|
|
virtual void init() override;
|
|
|
|
bool new_input() override;
|
|
|
|
uint8_t num_channels() override;
|
2017-08-10 00:08:28 -03:00
|
|
|
void set_num_channels(uint8_t num);
|
2019-02-21 19:08:12 -04:00
|
|
|
uint16_t read(uint8_t ch) override;
|
|
|
|
uint8_t read(uint16_t* periods, uint8_t len) override;
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2017-06-20 00:12:40 -03:00
|
|
|
int16_t get_rssi(void) override {
|
|
|
|
return _rssi;
|
|
|
|
}
|
2019-06-17 09:10:18 -03:00
|
|
|
|
|
|
|
const char *protocol() const override { return "Unknown"; }
|
|
|
|
|
2014-08-19 00:37:10 -03:00
|
|
|
// default empty _timer_tick, this is overridden by board
|
|
|
|
// specific implementations
|
|
|
|
virtual void _timer_tick() {}
|
|
|
|
|
2015-12-13 23:19:54 -04:00
|
|
|
// add some DSM input bytes, for RCInput over a serial port
|
2016-10-14 02:22:47 -03:00
|
|
|
bool add_dsm_input(const uint8_t *bytes, size_t nbytes);
|
2016-06-07 02:06:35 -03:00
|
|
|
|
|
|
|
// add some SBUS input bytes, for RCInput over a serial port
|
|
|
|
void add_sbus_input(const uint8_t *bytes, size_t nbytes);
|
2016-07-29 16:14:02 -03:00
|
|
|
|
2016-09-16 05:20:22 -03:00
|
|
|
// add some SUMD input bytes, for RCInput over a serial port
|
2016-10-14 02:22:47 -03:00
|
|
|
bool add_sumd_input(const uint8_t *bytes, size_t nbytes);
|
2016-07-29 16:14:02 -03:00
|
|
|
|
2016-09-16 05:20:22 -03:00
|
|
|
// add some st24 input bytes, for RCInput over a serial port
|
2016-10-14 02:22:47 -03:00
|
|
|
bool add_st24_input(const uint8_t *bytes, size_t nbytes);
|
2016-10-14 02:14:07 -03:00
|
|
|
|
|
|
|
// add some srxl input bytes, for RCInput over a serial port
|
2016-10-14 02:22:47 -03:00
|
|
|
bool add_srxl_input(const uint8_t *bytes, size_t nbytes);
|
2017-01-10 02:08:42 -04:00
|
|
|
|
2016-07-29 20:26:07 -03:00
|
|
|
protected:
|
2016-01-18 18:04:14 -04:00
|
|
|
void _process_rc_pulse(uint16_t width_s0, uint16_t width_s1);
|
2015-09-04 13:37:09 -03:00
|
|
|
void _update_periods(uint16_t *periods, uint8_t len);
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2017-01-10 02:08:42 -04:00
|
|
|
std::atomic<unsigned int> rc_input_count;
|
|
|
|
std::atomic<unsigned int> last_rc_input_count;
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
uint16_t _pwm_values[LINUX_RC_INPUT_NUM_CHANNELS];
|
2014-10-08 19:19:35 -03:00
|
|
|
uint8_t _num_channels;
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2014-10-06 23:24:23 -03:00
|
|
|
void _process_ppmsum_pulse(uint16_t width);
|
|
|
|
void _process_sbus_pulse(uint16_t width_s0, uint16_t width_s1);
|
2014-10-07 22:49:42 -03:00
|
|
|
void _process_dsm_pulse(uint16_t width_s0, uint16_t width_s1);
|
2017-08-10 00:08:28 -03:00
|
|
|
void _process_pwm_pulse(uint16_t channel, uint16_t width_s0, uint16_t width_s1);
|
2014-10-06 23:24:23 -03:00
|
|
|
|
2014-10-08 19:19:35 -03:00
|
|
|
// state of ppm decoder
|
|
|
|
struct {
|
|
|
|
int8_t _channel_counter;
|
|
|
|
uint16_t _pulse_capt[LINUX_RC_INPUT_NUM_CHANNELS];
|
|
|
|
} ppm_state;
|
|
|
|
|
2014-10-06 23:24:23 -03:00
|
|
|
// state of SBUS bit decoder
|
|
|
|
struct {
|
|
|
|
uint16_t bytes[25]; // including start bit, parity and stop bits
|
|
|
|
uint16_t bit_ofs;
|
|
|
|
} sbus_state;
|
2014-10-07 22:49:42 -03:00
|
|
|
|
|
|
|
// state of DSM decoder
|
|
|
|
struct {
|
|
|
|
uint16_t bytes[16]; // including start bit and stop bit
|
|
|
|
uint16_t bit_ofs;
|
|
|
|
} dsm_state;
|
2015-12-13 23:19:54 -04:00
|
|
|
|
|
|
|
// state of add_dsm_input
|
|
|
|
struct {
|
|
|
|
uint8_t frame[16];
|
|
|
|
uint8_t partial_frame_count;
|
|
|
|
uint32_t last_input_ms;
|
|
|
|
} dsm;
|
2016-06-07 02:06:35 -03:00
|
|
|
|
|
|
|
// state of add_sbus_input
|
|
|
|
struct {
|
|
|
|
uint8_t frame[25];
|
|
|
|
uint8_t partial_frame_count;
|
|
|
|
uint32_t last_input_ms;
|
|
|
|
} sbus;
|
2017-06-20 00:12:40 -03:00
|
|
|
|
|
|
|
int16_t _rssi = -1;
|
2013-09-22 03:01:24 -03:00
|
|
|
};
|
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
}
|