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_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
|
2018-07-12 11:49:32 -03:00
|
|
|
#define MAX_RCIN_CHANNELS 32
|
2018-01-17 15:31:11 -04:00
|
|
|
#define MIN_RCIN_CHANNELS 5
|
|
|
|
|
|
|
|
class AP_RCProtocol_Backend;
|
2018-10-31 21:21:03 -03:00
|
|
|
|
2018-01-17 15:31:11 -04:00
|
|
|
class AP_RCProtocol {
|
|
|
|
public:
|
2018-10-31 21:21:03 -03:00
|
|
|
AP_RCProtocol() {
|
2019-02-10 01:05:11 -04:00
|
|
|
_singleton = this;
|
2018-10-31 21:21:03 -03:00
|
|
|
}
|
2018-11-04 23:56:37 -04:00
|
|
|
~AP_RCProtocol();
|
2018-11-05 01:44:00 -04:00
|
|
|
|
2018-07-20 01:25:40 -03:00
|
|
|
enum rcprotocol_t {
|
2018-01-17 15:31:11 -04:00
|
|
|
PPM = 0,
|
|
|
|
SBUS,
|
2018-05-23 19:00:16 -03:00
|
|
|
SBUS_NI,
|
2018-01-17 15:31:11 -04:00
|
|
|
DSM,
|
2018-07-12 11:49:32 -03:00
|
|
|
SUMD,
|
2018-07-13 11:49:42 -03:00
|
|
|
SRXL,
|
|
|
|
ST24,
|
2018-01-17 15:31:11 -04:00
|
|
|
NONE //last enum always is None
|
|
|
|
};
|
|
|
|
void init();
|
2018-07-20 01:25:40 -03:00
|
|
|
bool valid_serial_prot()
|
|
|
|
{
|
|
|
|
return _valid_serial_prot;
|
|
|
|
}
|
2018-01-17 15:31:11 -04:00
|
|
|
void process_pulse(uint32_t width_s0, uint32_t width_s1);
|
2018-11-03 02:52:57 -03:00
|
|
|
void process_pulse_list(const uint32_t *widths, uint16_t n, bool need_swap);
|
2018-11-02 06:42:29 -03:00
|
|
|
void process_byte(uint8_t byte, uint32_t baudrate);
|
2018-11-02 08:25:05 -03:00
|
|
|
|
|
|
|
void disable_for_pulses(enum rcprotocol_t protocol) {
|
|
|
|
_disabled_for_pulses |= (1U<<(uint8_t)protocol);
|
|
|
|
}
|
|
|
|
|
2018-11-02 19:49:17 -03:00
|
|
|
// for protocols without strong CRCs we require 3 good frames to lock on
|
|
|
|
bool requires_3_frames(enum rcprotocol_t p) {
|
|
|
|
return (p == DSM || p == SBUS || p == SBUS_NI || p == PPM);
|
|
|
|
}
|
|
|
|
|
2018-07-20 01:25:40 -03:00
|
|
|
enum rcprotocol_t protocol_detected()
|
|
|
|
{
|
|
|
|
return _detected_protocol;
|
|
|
|
}
|
2018-01-17 15:31:11 -04:00
|
|
|
uint8_t num_channels();
|
|
|
|
uint16_t read(uint8_t chan);
|
|
|
|
bool new_input();
|
2018-04-10 03:14:54 -03:00
|
|
|
void start_bind(void);
|
2018-07-20 01:25:40 -03:00
|
|
|
|
2018-11-05 01:44:00 -04:00
|
|
|
// return protocol name as a string
|
|
|
|
static const char *protocol_name_from_protocol(rcprotocol_t protocol);
|
|
|
|
|
2018-11-02 19:49:56 -03:00
|
|
|
// return protocol name as a string
|
|
|
|
const char *protocol_name(void) const;
|
|
|
|
|
2018-11-05 01:44:00 -04:00
|
|
|
// return protocol name as a string
|
|
|
|
enum rcprotocol_t protocol_detected(void) const {
|
|
|
|
return _detected_protocol;
|
|
|
|
}
|
|
|
|
|
2018-10-31 21:21:03 -03:00
|
|
|
// access to singleton
|
2019-02-10 01:05:11 -04:00
|
|
|
static AP_RCProtocol *get_singleton(void) {
|
|
|
|
return _singleton;
|
2018-10-31 21:21:03 -03:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:31:11 -04:00
|
|
|
private:
|
|
|
|
enum rcprotocol_t _detected_protocol = NONE;
|
2018-11-02 08:25:05 -03:00
|
|
|
uint16_t _disabled_for_pulses;
|
2018-11-01 00:44:55 -03:00
|
|
|
bool _detected_with_bytes;
|
2018-01-17 15:31:11 -04:00
|
|
|
AP_RCProtocol_Backend *backend[NONE];
|
|
|
|
bool _new_input = false;
|
2018-01-17 19:12:16 -04:00
|
|
|
uint32_t _last_input_ms;
|
2018-07-12 11:49:32 -03:00
|
|
|
bool _valid_serial_prot = false;
|
2018-11-02 19:49:17 -03:00
|
|
|
uint8_t _good_frames[NONE];
|
2018-10-31 21:21:03 -03:00
|
|
|
|
2019-02-10 01:05:11 -04:00
|
|
|
static AP_RCProtocol *_singleton;
|
2018-01-17 15:31:11 -04:00
|
|
|
};
|
|
|
|
|
2018-01-17 19:12:16 -04:00
|
|
|
#include "AP_RCProtocol_Backend.h"
|