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_MAVliteToSPort.h
Views: 1798
1
#pragma once
2
3
#include "AP_Frsky_config.h"
4
5
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
6
7
#include "AP_Frsky_MAVlite_Message.h"
8
#include "AP_Frsky_SPort.h"
9
10
#include <AP_HAL/utility/RingBuffer.h>
11
12
#include <stdint.h>
13
14
/*
15
* An instance of this class encodes a MAVlite message into several
16
* SPort packets, and pushes them onto the supplied queue.
17
*
18
* process() will return false if there is insufficient room in the
19
* queue for all SPort packets.
20
*
21
* See AP_Frsky_MAVlite.h for a description of the encoding of a
22
* MAVlite message in SPort packets.
23
*/
24
25
class AP_Frsky_MAVlite_MAVliteToSPort {
26
public:
27
28
// insert sport packets calculated from mavlite msg into queue
29
bool process(ObjectBuffer_TS<AP_Frsky_SPort::sport_packet_t> &queue,
30
const AP_Frsky_MAVlite_Message &msg) WARN_IF_UNUSED;
31
32
private:
33
34
enum class State : uint8_t {
35
WANT_LEN,
36
WANT_MSGID,
37
WANT_PAYLOAD,
38
WANT_CHECKSUM,
39
DONE,
40
};
41
State state = State::WANT_LEN;
42
43
void reset();
44
45
void process_byte(uint8_t byte, ObjectBuffer_TS<AP_Frsky_SPort::sport_packet_t> &queue);
46
47
AP_Frsky_SPort::sport_packet_t packet {};
48
uint8_t packet_offs = 0;
49
50
uint8_t next_seq = 0;
51
uint8_t payload_count = 0;
52
uint8_t payload_len;
53
54
int16_t checksum; // sent at end of packet
55
void update_checksum(const uint8_t c);
56
};
57
58
#endif // HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
59
60