2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
29 #include "common/utils.h"
30 #include "common/unit.h"
33 #include "pg/pg_ids.h"
36 #include "drivers/timer.h"
37 #include "drivers/serial.h"
38 #include "drivers/serial_softserial.h"
40 #include "io/serial.h"
42 #include "config/config.h"
43 #include "fc/rc_modes.h"
44 #include "fc/runtime_config.h"
46 #include "msp/msp_serial.h"
50 #include "telemetry/telemetry.h"
51 #include "telemetry/frsky_hub.h"
52 #include "telemetry/hott.h"
53 #include "telemetry/smartport.h"
54 #include "telemetry/ltm.h"
55 #include "telemetry/jetiexbus.h"
56 #include "telemetry/mavlink.h"
57 #include "telemetry/crsf.h"
58 #include "telemetry/ghst.h"
59 #include "telemetry/srxl.h"
60 #include "telemetry/ibus.h"
61 #include "telemetry/msp_shared.h"
63 PG_REGISTER_WITH_RESET_TEMPLATE(telemetryConfig_t
, telemetryConfig
, PG_TELEMETRY_CONFIG
, 5);
65 PG_RESET_TEMPLATE(telemetryConfig_t
, telemetryConfig
,
66 .telemetry_inverted
= false,
68 .gpsNoFixLatitude
= 0,
69 .gpsNoFixLongitude
= 0,
70 .frsky_coordinate_format
= FRSKY_FORMAT_DMS
,
71 .frsky_unit
= UNIT_METRIC
,
72 .frsky_vfas_precision
= 0,
73 .hottAlarmSoundInterval
= 5,
74 .pidValuesAsTelemetry
= 0,
75 .report_cell_voltage
= false,
77 IBUS_SENSOR_TYPE_TEMPERATURE
,
78 IBUS_SENSOR_TYPE_RPM_FLYSKY
,
79 IBUS_SENSOR_TYPE_EXTERNAL_VOLTAGE
81 .disabledSensors
= ESC_SENSOR_ALL
| SENSOR_CAP_USED
,
82 .mavlink_mah_as_heading_divisor
= 0,
85 void telemetryInit(void)
87 #ifdef USE_TELEMETRY_FRSKY_HUB
88 initFrSkyHubTelemetry();
90 #ifdef USE_TELEMETRY_HOTT
93 #ifdef USE_TELEMETRY_SMARTPORT
94 initSmartPortTelemetry();
96 #ifdef USE_TELEMETRY_LTM
99 #ifdef USE_TELEMETRY_JETIEXBUS
100 initJetiExBusTelemetry();
102 #ifdef USE_TELEMETRY_MAVLINK
103 initMAVLinkTelemetry();
105 #ifdef USE_TELEMETRY_GHST
108 #ifdef USE_TELEMETRY_CRSF
110 #if defined(USE_MSP_OVER_TELEMETRY)
114 #ifdef USE_TELEMETRY_SRXL
117 #ifdef USE_TELEMETRY_IBUS
120 #if defined(USE_MSP_OVER_TELEMETRY)
124 telemetryCheckState();
127 bool telemetryDetermineEnabledState(portSharing_e portSharing
)
129 bool enabled
= portSharing
== PORTSHARING_NOT_SHARED
;
131 if (portSharing
== PORTSHARING_SHARED
) {
132 if (isModeActivationConditionPresent(BOXTELEMETRY
))
133 enabled
= IS_RC_MODE_ACTIVE(BOXTELEMETRY
);
135 enabled
= ARMING_FLAG(ARMED
);
141 bool telemetryCheckRxPortShared(const serialPortConfig_t
*portConfig
, const SerialRXType serialrxProvider
)
143 if (portConfig
->functionMask
& FUNCTION_RX_SERIAL
&& portConfig
->functionMask
& TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK
&&
144 (serialrxProvider
== SERIALRX_SPEKTRUM1024
||
145 serialrxProvider
== SERIALRX_SPEKTRUM2048
||
146 serialrxProvider
== SERIALRX_SBUS
||
147 serialrxProvider
== SERIALRX_SUMD
||
148 serialrxProvider
== SERIALRX_SUMH
||
149 serialrxProvider
== SERIALRX_XBUS_MODE_B
||
150 serialrxProvider
== SERIALRX_XBUS_MODE_B_RJ01
||
151 serialrxProvider
== SERIALRX_IBUS
)) {
155 #ifdef USE_TELEMETRY_IBUS
156 if (portConfig
->functionMask
& FUNCTION_TELEMETRY_IBUS
157 && portConfig
->functionMask
& FUNCTION_RX_SERIAL
158 && serialrxProvider
== SERIALRX_IBUS
) {
159 // IBUS serial RX & telemetry
163 #if defined(USE_MSP_OVER_TELEMETRY) && defined(USE_VTX_MSP)
164 if (portConfig
->functionMask
& FUNCTION_RX_SERIAL
&& portConfig
->functionMask
& FUNCTION_VTX_MSP
) {
171 serialPort_t
*telemetrySharedPort
= NULL
;
173 void telemetryCheckState(void)
175 #ifdef USE_TELEMETRY_FRSKY_HUB
176 checkFrSkyHubTelemetryState();
178 #ifdef USE_TELEMETRY_HOTT
179 checkHoTTTelemetryState();
181 #ifdef USE_TELEMETRY_SMARTPORT
182 checkSmartPortTelemetryState();
184 #ifdef USE_TELEMETRY_LTM
185 checkLtmTelemetryState();
187 #ifdef USE_TELEMETRY_JETIEXBUS
188 checkJetiExBusTelemetryState();
190 #ifdef USE_TELEMETRY_MAVLINK
191 checkMAVLinkTelemetryState();
193 #ifdef USE_TELEMETRY_CRSF
194 checkCrsfTelemetryState();
196 #ifdef USE_TELEMETRY_GHST
197 checkGhstTelemetryState();
199 #ifdef USE_TELEMETRY_SRXL
200 checkSrxlTelemetryState();
202 #ifdef USE_TELEMETRY_IBUS
203 checkIbusTelemetryState();
207 void telemetryProcess(uint32_t currentTime
)
209 #ifdef USE_TELEMETRY_FRSKY_HUB
210 handleFrSkyHubTelemetry(currentTime
);
214 #ifdef USE_TELEMETRY_HOTT
215 handleHoTTTelemetry(currentTime
);
219 #ifdef USE_TELEMETRY_SMARTPORT
220 handleSmartPortTelemetry();
222 #ifdef USE_TELEMETRY_LTM
223 handleLtmTelemetry();
225 #ifdef USE_TELEMETRY_JETIEXBUS
226 handleJetiExBusTelemetry();
228 #ifdef USE_TELEMETRY_MAVLINK
229 handleMAVLinkTelemetry();
231 #ifdef USE_TELEMETRY_CRSF
232 handleCrsfTelemetry(currentTime
);
234 #ifdef USE_TELEMETRY_GHST
235 handleGhstTelemetry(currentTime
);
237 #ifdef USE_TELEMETRY_SRXL
238 handleSrxlTelemetry(currentTime
);
240 #ifdef USE_TELEMETRY_IBUS
241 handleIbusTelemetry();
245 bool telemetryIsSensorEnabled(sensor_e sensor
)
247 return ~(telemetryConfig()->disabledSensors
) & sensor
;