Merge pull request #10215 from iNavFlight/mmosca-mavlinkrc
[inav.git] / src / main / telemetry / telemetry.c
blobe0820234e659f4f72866d72498a8042bde39f00e
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <stdlib.h>
22 #include "platform.h"
24 #ifdef USE_TELEMETRY
26 #include "build/debug.h"
28 #include "common/utils.h"
30 #include "config/parameter_group.h"
31 #include "config/parameter_group_ids.h"
33 #include "drivers/serial.h"
35 #include "fc/config.h"
36 #include "fc/rc_controls.h"
37 #include "fc/rc_modes.h"
38 #include "fc/runtime_config.h"
39 #include "fc/settings.h"
41 #include "io/serial.h"
43 #include "rx/rx.h"
45 #include "telemetry/telemetry.h"
46 #include "telemetry/hott.h"
47 #include "telemetry/smartport.h"
48 #include "telemetry/ltm.h"
49 #include "telemetry/mavlink.h"
50 #include "telemetry/jetiexbus.h"
51 #include "telemetry/ibus.h"
52 #include "telemetry/crsf.h"
53 #include "telemetry/srxl.h"
54 #include "telemetry/sbus2.h"
55 #include "telemetry/sim.h"
56 #include "telemetry/ghst.h"
59 PG_REGISTER_WITH_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig, PG_TELEMETRY_CONFIG, 8);
61 PG_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig,
62 .telemetry_switch = SETTING_TELEMETRY_SWITCH_DEFAULT,
63 .telemetry_inverted = SETTING_TELEMETRY_INVERTED_DEFAULT,
64 .frsky_pitch_roll = SETTING_FRSKY_PITCH_ROLL_DEFAULT,
65 .frsky_use_legacy_gps_mode_sensor_ids = SETTING_FRSKY_USE_LEGACY_GPS_MODE_SENSOR_IDS_DEFAULT,
66 .report_cell_voltage = SETTING_REPORT_CELL_VOLTAGE_DEFAULT,
67 .hottAlarmSoundInterval = SETTING_HOTT_ALARM_SOUND_INTERVAL_DEFAULT,
68 .halfDuplex = SETTING_TELEMETRY_HALFDUPLEX_DEFAULT,
69 #if !defined(SETTING_SMARTPORT_FUEL_UNIT_DEFAULT) // SITL
70 .smartportFuelUnit = 1,
71 #else
72 .smartportFuelUnit = SETTING_SMARTPORT_FUEL_UNIT_DEFAULT,
73 #endif
74 .ibusTelemetryType = SETTING_IBUS_TELEMETRY_TYPE_DEFAULT,
75 .ltmUpdateRate = SETTING_LTM_UPDATE_RATE_DEFAULT,
77 #ifdef USE_TELEMETRY_SIM
78 .simTransmitInterval = SETTING_SIM_TRANSMIT_INTERVAL_DEFAULT,
79 .simTransmitFlags = SETTING_SIM_TRANSMIT_FLAGS_DEFAULT,
80 .simLowAltitude = SETTING_SIM_LOW_ALTITUDE_DEFAULT,
81 .simPin = SETTING_SIM_PIN_DEFAULT,
82 .simGroundStationNumber = SETTING_SIM_GROUND_STATION_NUMBER_DEFAULT,
84 .accEventThresholdHigh = SETTING_ACC_EVENT_THRESHOLD_HIGH_DEFAULT,
85 .accEventThresholdLow = SETTING_ACC_EVENT_THRESHOLD_LOW_DEFAULT,
86 .accEventThresholdNegX = SETTING_ACC_EVENT_THRESHOLD_NEG_X_DEFAULT,
87 #endif
89 .mavlink = {
90 .extended_status_rate = SETTING_MAVLINK_EXT_STATUS_RATE_DEFAULT,
91 .rc_channels_rate = SETTING_MAVLINK_RC_CHAN_RATE_DEFAULT,
92 .position_rate = SETTING_MAVLINK_POS_RATE_DEFAULT,
93 .extra1_rate = SETTING_MAVLINK_EXTRA1_RATE_DEFAULT,
94 .extra2_rate = SETTING_MAVLINK_EXTRA2_RATE_DEFAULT,
95 .extra3_rate = SETTING_MAVLINK_EXTRA3_RATE_DEFAULT,
96 .version = SETTING_MAVLINK_VERSION_DEFAULT,
97 .min_txbuff = SETTING_MAVLINK_MIN_TXBUFFER_DEFAULT,
98 .radio_type = SETTING_MAVLINK_RADIO_TYPE_DEFAULT
102 void telemetryInit(void)
105 #if defined(USE_TELEMETRY_HOTT)
106 initHoTTTelemetry();
107 #endif
109 #if defined(USE_TELEMETRY_SMARTPORT)
110 initSmartPortTelemetry();
111 #endif
113 #if defined(USE_TELEMETRY_LTM)
114 initLtmTelemetry();
115 #endif
117 #if defined(USE_TELEMETRY_MAVLINK)
118 initMAVLinkTelemetry();
119 #endif
121 #if defined(USE_TELEMETRY_JETIEXBUS)
122 initJetiExBusTelemetry();
123 #endif
125 #if defined(USE_TELEMETRY_IBUS)
126 initIbusTelemetry();
127 #endif
129 #if defined(USE_TELEMETRY_SIM)
130 initSimTelemetry();
131 #endif
133 #if defined(USE_SERIALRX_CRSF) && defined(USE_TELEMETRY_CRSF)
134 initCrsfTelemetry();
135 #endif
137 #ifdef USE_TELEMETRY_SRXL
138 initSrxlTelemetry();
139 #endif
141 #ifdef USE_TELEMETRY_GHST
142 initGhstTelemetry();
143 #endif
145 telemetryCheckState();
148 bool telemetryDetermineEnabledState(portSharing_e portSharing)
150 bool enabled = portSharing == PORTSHARING_NOT_SHARED;
152 if (portSharing == PORTSHARING_SHARED) {
153 if (telemetryConfig()->telemetry_switch)
154 enabled = IS_RC_MODE_ACTIVE(BOXTELEMETRY);
155 else
156 enabled = ARMING_FLAG(ARMED);
159 return enabled;
162 bool telemetryCheckRxPortShared(const serialPortConfig_t *portConfig)
164 return portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK;
167 serialPort_t *telemetrySharedPort = NULL;
169 void telemetryCheckState(void)
172 #if defined(USE_TELEMETRY_HOTT)
173 checkHoTTTelemetryState();
174 #endif
176 #if defined(USE_TELEMETRY_SMARTPORT)
177 checkSmartPortTelemetryState();
178 #endif
180 #if defined(USE_TELEMETRY_LTM)
181 checkLtmTelemetryState();
182 #endif
184 #if defined(USE_TELEMETRY_MAVLINK)
185 checkMAVLinkTelemetryState();
186 #endif
188 #if defined(USE_TELEMETRY_JETIEXBUS)
189 checkJetiExBusTelemetryState();
190 #endif
192 #if defined(USE_TELEMETRY_IBUS)
193 checkIbusTelemetryState();
194 #endif
196 #if defined(USE_TELEMETRY_SIM)
197 checkSimTelemetryState();
198 #endif
200 #if defined(USE_SERIALRX_CRSF) && defined(USE_TELEMETRY_CRSF)
201 checkCrsfTelemetryState();
202 #endif
204 #ifdef USE_TELEMETRY_SRXL
205 checkSrxlTelemetryState();
206 #endif
207 #ifdef USE_TELEMETRY_GHST
208 checkGhstTelemetryState();
209 #endif
212 void telemetryProcess(timeUs_t currentTimeUs)
214 UNUSED(currentTimeUs); // since not used by all the telemetry protocols
216 #if defined(USE_TELEMETRY_HOTT)
217 handleHoTTTelemetry(currentTimeUs);
218 #endif
220 #if defined(USE_TELEMETRY_SMARTPORT)
221 handleSmartPortTelemetry();
222 #endif
224 #if defined(USE_TELEMETRY_LTM)
225 handleLtmTelemetry();
226 #endif
228 #if defined(USE_TELEMETRY_MAVLINK)
229 handleMAVLinkTelemetry(currentTimeUs);
230 #endif
232 #if defined(USE_TELEMETRY_JETIEXBUS)
233 handleJetiExBusTelemetry();
234 #endif
236 #if defined(USE_SERIALRX_IBUS) && defined(USE_TELEMETRY_IBUS)
237 handleIbusTelemetry();
238 #endif
240 #if defined(USE_TELEMETRY_SIM)
241 handleSimTelemetry();
242 #endif
244 #if defined(USE_SERIALRX_CRSF) && defined(USE_TELEMETRY_CRSF)
245 handleCrsfTelemetry(currentTimeUs);
246 #endif
248 #ifdef USE_TELEMETRY_SRXL
249 handleSrxlTelemetry(currentTimeUs);
250 #endif
251 #ifdef USE_TELEMETRY_GHST
252 handleGhstTelemetry(currentTimeUs);
253 #endif
255 #ifdef USE_TELEMETRY_SBUS2
256 handleSbus2Telemetry(currentTimeUs);
257 #endif
260 #endif