Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / rx / expresslrs_telemetry.h
blob8027d2981c66c2de4c2c9d8cf9feda7e573a896f
1 /*
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)
8 * any later version.
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/>.
21 #pragma once
23 #include <stdbool.h>
24 #include <stdint.h>
26 #define ELRS_TELEMETRY_SHIFT 2
27 #define ELRS_TELEMETRY_BYTES_PER_CALL 5
28 #define ELRS_TELEMETRY_MAX_PACKAGES (255 >> ELRS_TELEMETRY_SHIFT)
29 #define ELRS_TELEMETRY_MAX_MISSED_PACKETS 20
31 #define ELRS_MSP_BYTES_PER_CALL 5
32 #define ELRS_MSP_BUFFER_SIZE 65
33 #define ELRS_MSP_MAX_PACKAGES ((ELRS_MSP_BUFFER_SIZE / ELRS_MSP_BYTES_PER_CALL) + 1)
34 #define ELRS_MSP_PACKET_OFFSET 5
35 #define ELRS_MSP_COMMAND_INDEX 7
37 typedef enum {
38 ELRS_SENDER_IDLE = 0,
39 ELRS_SENDING,
40 ELRS_WAIT_UNTIL_NEXT_CONFIRM,
41 ELRS_RESYNC,
42 ELRS_RESYNC_THEN_SEND, // perform a RESYNC then go to SENDING
43 } stubbornSenderState_e;
45 void initTelemetry(void);
46 bool getNextTelemetryPayload(uint8_t *nextPayloadSize, uint8_t **payloadData);
48 void setTelemetryDataToTransmit(const uint8_t lengthToTransmit, uint8_t* dataToTransmit, const uint8_t bpc);
49 bool isTelemetrySenderActive(void);
50 void getCurrentTelemetryPayload(uint8_t *packageIndex, uint8_t *count, uint8_t **currentData);
51 void confirmCurrentTelemetryPayload(const bool telemetryConfirmValue);
52 void updateTelemetryRate(const uint16_t airRate, const uint8_t tlmRatio, const uint8_t tlmBurst);
54 void mspReceiverResetState(void);
55 bool getCurrentMspConfirm(void);
56 void setMspDataToReceive(const uint8_t maxLength, uint8_t* dataToReceive, const uint8_t bpc);
57 void receiveMspData(const uint8_t packageIndex, const volatile uint8_t* receiveData);
58 bool hasFinishedMspData(void);
59 void mspReceiverUnlock(void);
60 void processMspPacket(uint8_t *packet);