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_Backend.h
Views: 1798
1
#pragma once
2
3
#include "AP_Frsky_config.h"
4
5
#if AP_FRSKY_TELEM_ENABLED
6
7
#include <GCS_MAVLink/GCS_MAVLink.h>
8
9
class AP_Frsky_Backend
10
{
11
public:
12
13
AP_Frsky_Backend(AP_HAL::UARTDriver *port) :
14
_port(port) { }
15
16
virtual ~AP_Frsky_Backend() {}
17
18
virtual bool init();
19
virtual void send() = 0;
20
21
typedef union {
22
struct PACKED {
23
uint8_t sensor;
24
uint8_t frame;
25
uint16_t appid;
26
uint32_t data;
27
};
28
uint8_t raw[8];
29
} sport_packet_t;
30
31
// SPort is at 57600, D overrides this
32
virtual uint32_t initial_baud() const
33
{
34
return 57600;
35
}
36
37
// get next telemetry data for external consumers of SPort data
38
virtual bool get_telem_data(sport_packet_t* packet_array, uint8_t &packet_count, const uint8_t max_size)
39
{
40
return false;
41
}
42
43
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
44
virtual bool set_telem_data(const uint8_t frame, const uint16_t appid, const uint32_t data)
45
{
46
return false;
47
}
48
#endif
49
50
virtual void queue_text_message(MAV_SEVERITY severity, const char *text) { }
51
52
protected:
53
54
AP_HAL::UARTDriver *_port; // UART used to send data to FrSky receiver
55
56
virtual bool init_serial_port();
57
58
void calc_nav_alt(void);
59
void calc_gps_position(void);
60
bool calc_rpm(const uint8_t instance, int32_t &value) const;
61
62
float get_vspeed_ms(void);
63
64
// methods to convert flight controller data to FrSky D or SPort format
65
float format_gps(float dec);
66
67
struct {
68
int32_t vario_vspd;
69
char lat_ns, lon_ew;
70
uint16_t latdddmm;
71
uint16_t latmmmm;
72
uint16_t londddmm;
73
uint16_t lonmmmm;
74
uint16_t alt_gps_meters;
75
uint16_t alt_gps_cm;
76
uint16_t alt_nav_meters;
77
uint16_t alt_nav_cm;
78
int16_t speed_in_meter;
79
uint16_t speed_in_centimeter;
80
uint16_t yaw;
81
} _SPort_data;
82
83
/*
84
for FrSky D protocol (D-receivers)
85
*/
86
// FrSky sensor hub data IDs
87
static const uint8_t DATA_ID_GPS_ALT_BP = 0x01;
88
static const uint8_t DATA_ID_TEMP1 = 0x02;
89
static const uint8_t DATA_ID_FUEL = 0x04;
90
static const uint8_t DATA_ID_TEMP2 = 0x05;
91
static const uint8_t DATA_ID_GPS_ALT_AP = 0x09;
92
static const uint8_t DATA_ID_BARO_ALT_BP = 0x10;
93
static const uint8_t DATA_ID_GPS_SPEED_BP = 0x11;
94
static const uint8_t DATA_ID_GPS_LONG_BP = 0x12;
95
static const uint8_t DATA_ID_GPS_LAT_BP = 0x13;
96
static const uint8_t DATA_ID_GPS_COURS_BP = 0x14;
97
static const uint8_t DATA_ID_GPS_SPEED_AP = 0x19;
98
static const uint8_t DATA_ID_GPS_LONG_AP = 0x1A;
99
static const uint8_t DATA_ID_GPS_LAT_AP = 0x1B;
100
static const uint8_t DATA_ID_BARO_ALT_AP = 0x21;
101
static const uint8_t DATA_ID_GPS_LONG_EW = 0x22;
102
static const uint8_t DATA_ID_GPS_LAT_NS = 0x23;
103
static const uint8_t DATA_ID_CURRENT = 0x28;
104
static const uint8_t DATA_ID_VFAS = 0x39;
105
106
static const uint8_t START_STOP_D = 0x5E;
107
static const uint8_t BYTESTUFF_D = 0x5D;
108
109
/*
110
for FrSky X protocol (X-receivers)
111
*/
112
// FrSky 2 bytes DATA IDs;
113
static const uint16_t ALT_ID = 0x010F;
114
static const uint16_t VARIO_ID = 0x011F;
115
static const uint16_t CURR_ID = 0x020F;
116
static const uint16_t VFAS_ID = 0x021F;
117
static const uint16_t TEMP1_ID = 0x040F;
118
static const uint16_t TEMP2_ID = 0x041F;
119
static const uint16_t RPM1_ID = 0x050E;
120
static const uint16_t RPM2_ID = 0x050F;
121
static const uint16_t FUEL_ID = 0x060F;
122
static const uint16_t GPS_LONG_LATI_FIRST_ID = 0x0800;
123
static const uint16_t GPS_ALT_ID = 0x082F;
124
static const uint16_t GPS_SPEED_ID = 0x083F;
125
static const uint16_t GPS_COURS_ID = 0x084F;
126
static const uint16_t DIY_FIRST_ID = 0x5000;
127
128
static const uint8_t FRAME_HEAD = 0x7E;
129
static const uint8_t FRAME_DLE = 0x7D;
130
static const uint8_t FRAME_XOR = 0x20;
131
132
static const uint8_t SPORT_DATA_FRAME = 0x10;
133
134
// for FrSky SPort and SPort Passthrough (OpenTX) protocols (X-receivers)
135
static const uint8_t SENSOR_ID_VARIO = 0x00; // Sensor ID 0
136
static const uint8_t SENSOR_ID_FAS = 0x22; // Sensor ID 2
137
static const uint8_t SENSOR_ID_GPS = 0x83; // Sensor ID 3
138
static const uint8_t SENSOR_ID_RPM = 0xE4; // Sensor ID 4
139
static const uint8_t SENSOR_ID_SP2UR = 0xC6; // Sensor ID 6
140
141
enum frsky_options_e : uint8_t {
142
OPTION_AIRSPEED_AND_GROUNDSPEED = 1U<<0,
143
};
144
145
private:
146
147
void loop(void);
148
149
};
150
151
#endif // AP_FRSKY_TELEM_ENABLED
152
153