Copter: free allocations in case of allocation failure
[ardupilot.git] / libraries / AP_Frsky_Telem / AP_Frsky_MAVlite_SPortToMAVlite.h
blob36d7bf8c52d055d4c4dbee793dd36ce06bfe7ba2
1 #pragma once
3 #include "AP_Frsky_MAVlite_Message.h"
4 #include "AP_Frsky_SPort.h"
6 #include <stdint.h>
8 #if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
9 /*
10 * An instance of this class decodes a stream of SPort packets into a
11 * MAVlite message (see AP_Frsky_MAVlite_Message.h). It is expected
12 * that the same rxmsg is passed into process() multiple times, each
13 * time with a new sport packet. If a packet is successfully decodes
14 * then process() will return true and rxmsg can be used as a MAVlite
15 * message.
17 * See AP_Frsky_MAVlite.h for a description of the encoding of a
18 * MAVlite message in SPort packets.
20 class AP_Frsky_MAVlite_SPortToMAVlite {
21 public:
23 bool process(AP_Frsky_MAVlite_Message &rxmsg,
24 const AP_Frsky_SPort::sport_packet_t &packet) WARN_IF_UNUSED;
26 private:
28 void reset();
30 uint8_t expected_seq;
31 uint8_t payload_next_byte;
33 enum class State : uint8_t {
34 IDLE=0,
35 ERROR,
36 WANT_LEN,
37 WANT_MSGID,
38 WANT_PAYLOAD,
39 WANT_CHECKSUM,
40 MESSAGE_RECEIVED,
42 State parse_state = State::IDLE;
44 AP_Frsky_MAVlite_Message _rxmsg;
45 void parse(const uint8_t byte);
47 int16_t checksum; // sent at end of packet
48 void update_checksum(const uint8_t c);
50 #endif