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_SPortParser.h
Views: 1798
1
#pragma once
2
3
#include "AP_Frsky_SPort.h"
4
5
#if AP_FRSKY_SPORT_TELEM_ENABLED
6
7
#include <stdint.h>
8
9
// for SPort X protocol
10
#define FRAME_HEAD 0x7E
11
#define FRAME_DLE 0x7D
12
#define FRAME_XOR 0x20
13
// for SPort D protocol
14
#define START_STOP_D 0x5E
15
#define BYTESTUFF_D 0x5D
16
// for SPort packet parser
17
#define TELEMETRY_RX_BUFFER_SIZE 19U // 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1)
18
#define SPORT_PACKET_SIZE 9U
19
#define STUFF_MASK 0x20
20
#define SPORT_DATA_FRAME 0x10
21
#define SPORT_UPLINK_FRAME 0x30
22
#define SPORT_UPLINK_FRAME_RW 0x31
23
#define SPORT_DOWNLINK_FRAME 0x32
24
25
class AP_Frsky_SPortParser
26
{
27
public:
28
29
// packet parser helpers
30
bool process_byte(AP_Frsky_SPort::sport_packet_t &sport_packet, const uint8_t data);
31
32
private:
33
enum class ParseState : uint8_t {
34
IDLE,
35
START,
36
IN_FRAME,
37
XOR,
38
};
39
40
struct {
41
uint8_t rx_buffer_count;
42
uint8_t rx_buffer[TELEMETRY_RX_BUFFER_SIZE];
43
uint8_t last_packet[SPORT_PACKET_SIZE];
44
ParseState state;
45
} _parse_state;
46
47
bool should_process_packet(const uint8_t *packet, bool discard_duplicates);
48
bool get_packet(AP_Frsky_SPort::sport_packet_t &sport_packet, bool discard_duplicates);
49
};
50
51
#endif // AP_FRSKY_SPORT_TELEM_ENABLED
52
53