Line data Source code
1 : /* 2 : * This file is free software: you can redistribute it and/or modify it 3 : * under the terms of the GNU General Public License as published by the 4 : * Free Software Foundation, either version 3 of the License, or 5 : * (at your option) any later version. 6 : * 7 : * This file is distributed in the hope that it will be useful, but 8 : * WITHOUT ANY WARRANTY; without even the implied warranty of 9 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 : * See the GNU General Public License for more details. 11 : * 12 : * You should have received a copy of the GNU General Public License along 13 : * with this program. If not, see <http://www.gnu.org/licenses/>. 14 : * 15 : * Code by Andrew Tridgell and Siddharth Bharat Purohit 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "AP_RCProtocol_config.h" 21 : 22 : #if AP_RCPROTOCOL_SUMD_ENABLED 23 : 24 : #include "AP_RCProtocol_Backend.h" 25 : #include "SoftSerial.h" 26 : 27 : #define SUMD_MAX_CHANNELS 32 28 : #define SUMD_FRAME_MAXLEN 40 29 : class AP_RCProtocol_SUMD : public AP_RCProtocol_Backend { 30 : public: 31 2094 : AP_RCProtocol_SUMD(AP_RCProtocol &_frontend) : AP_RCProtocol_Backend(_frontend) {} 32 : void process_pulse(uint32_t width_s0, uint32_t width_s1) override; 33 : void process_byte(uint8_t byte, uint32_t baudrate) override; 34 : 35 : private: 36 : void _process_byte(uint32_t timestamp_us, uint8_t byte); 37 : 38 : typedef struct { 39 : uint8_t status; ///< 0x01 valid and live SUMD data frame / 0x00 = SUMH / 0x81 = Failsafe 40 : uint8_t length; ///< Channels 41 : uint8_t sumd_data[(SUMD_MAX_CHANNELS+1) * 2]; ///< ChannelData (High Byte/ Low Byte) 42 : uint8_t crc16_high; ///< High Byte of 16 Bit CRC 43 : } ReceiverFcPacketHoTT; 44 : 45 : 46 : enum SUMD_DECODE_STATE { 47 : SUMD_DECODE_STATE_UNSYNCED = 0, 48 : SUMD_DECODE_STATE_GOT_HEADER, 49 : SUMD_DECODE_STATE_GOT_STATE, 50 : SUMD_DECODE_STATE_GOT_LEN, 51 : SUMD_DECODE_STATE_GOT_DATA, 52 : SUMD_DECODE_STATE_GOT_CRC, 53 : }; 54 : 55 : enum SUMD_DECODE_STATE _decode_state = SUMD_DECODE_STATE_UNSYNCED; 56 : uint8_t _rxlen; 57 : ReceiverFcPacketHoTT _rxpacket; 58 : uint16_t _crc16; 59 : uint32_t last_packet_us; 60 : 61 : SoftSerial ss{115200, SoftSerial::SERIAL_CONFIG_8N1}; 62 : }; 63 : 64 : #endif // AP_RCPROTOCOL_SUMD_ENABLED