CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Frsky_Telem/AP_Frsky_MAVlite_SPortToMAVlite.h
Views: 1798
1
#pragma once
2
3
#include "AP_Frsky_MAVlite_Message.h"
4
#include "AP_Frsky_SPort.h"
5
6
#include <stdint.h>
7
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.
16
*
17
* See AP_Frsky_MAVlite.h for a description of the encoding of a
18
* MAVlite message in SPort packets.
19
*/
20
class AP_Frsky_MAVlite_SPortToMAVlite {
21
public:
22
23
bool process(AP_Frsky_MAVlite_Message &rxmsg,
24
const AP_Frsky_SPort::sport_packet_t &packet) WARN_IF_UNUSED;
25
26
private:
27
28
void reset();
29
30
uint8_t expected_seq;
31
uint8_t payload_next_byte;
32
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,
41
};
42
State parse_state = State::IDLE;
43
44
AP_Frsky_MAVlite_Message _rxmsg;
45
void parse(const uint8_t byte);
46
47
int16_t checksum; // sent at end of packet
48
void update_checksum(const uint8_t c);
49
};
50
#endif
51