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
|
|
|
|
|
2023-04-27 21:38:54 -03:00
|
|
|
#include "AP_RCProtocol_config.h"
|
|
|
|
|
|
|
|
#if AP_RCPROTOCOL_SBUS_ENABLED
|
|
|
|
|
2018-01-17 15:31:11 -04:00
|
|
|
#include "AP_RCProtocol.h"
|
2018-11-04 22:01:17 -04:00
|
|
|
#include "SoftSerial.h"
|
2018-01-17 15:31:11 -04:00
|
|
|
|
|
|
|
class AP_RCProtocol_SBUS : public AP_RCProtocol_Backend {
|
|
|
|
public:
|
2021-11-05 02:39:56 -03:00
|
|
|
AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool inverted, uint32_t configured_baud);
|
2018-01-17 15:31:11 -04:00
|
|
|
void process_pulse(uint32_t width_s0, uint32_t width_s1) override;
|
2018-11-02 06:42:29 -03:00
|
|
|
void process_byte(uint8_t byte, uint32_t baudrate) override;
|
2020-10-26 03:32:36 -03:00
|
|
|
|
2023-10-03 21:08:25 -03:00
|
|
|
static bool sbus_decode(const uint8_t frame[25], uint16_t *values, uint16_t *num_values,
|
|
|
|
bool &sbus_failsafe, uint16_t max_values);
|
|
|
|
|
2018-01-17 15:31:11 -04:00
|
|
|
private:
|
2018-11-04 22:01:17 -04:00
|
|
|
void _process_byte(uint32_t timestamp_us, uint8_t byte);
|
|
|
|
|
|
|
|
bool inverted;
|
2021-11-05 02:39:56 -03:00
|
|
|
SoftSerial ss;
|
2018-11-04 22:01:17 -04:00
|
|
|
uint32_t saved_width;
|
2018-11-02 06:42:29 -03:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint8_t buf[25];
|
|
|
|
uint8_t ofs;
|
2018-11-04 22:01:17 -04:00
|
|
|
uint32_t last_byte_us;
|
2018-11-02 06:42:29 -03:00
|
|
|
} byte_input;
|
|
|
|
};
|
2023-04-27 21:38:54 -03:00
|
|
|
|
|
|
|
#endif // AP_RCPROTOCOL_SBUS_ENABLED
|