optimise mavlink SS packet size (#3029)
[ExpressLRS.git] / src / lib / StubbornSender / stubborn_sender.h
blobf79caa678e2cb5ead5024bb9ca71d9a6b69a32e7
1 #pragma once
3 #include <cstdint>
5 // The number of times to resend the same package index before going to RESYNC
6 #define SSENDER_MAX_MISSED_PACKETS 20
8 typedef enum {
9 SENDER_IDLE = 0,
10 SEND_PENDING,
11 SENDING,
12 WAIT_UNTIL_NEXT_CONFIRM,
13 RESYNC,
14 RESYNC_THEN_SEND, // perform a RESYNC then go to SENDING
15 } stubborn_sender_state_e;
17 class StubbornSender
19 public:
20 StubbornSender();
21 void setMaxPackageIndex(uint8_t maxPackageIndex);
22 void ResetState();
23 void UpdateTelemetryRate(uint16_t airRate, uint8_t tlmRatio, uint8_t tlmBurst);
24 void SetDataToTransmit(uint8_t* dataToTransmit, uint8_t lengthToTransmit);
25 uint8_t GetCurrentPayload(uint8_t *outData, uint8_t maxLen);
26 void ConfirmCurrentPayload(bool telemetryConfirmValue);
27 bool IsActive() const { return senderState != SENDER_IDLE; }
28 uint16_t GetMaxPacketsBeforeResync() const { return maxWaitCount; }
29 private:
30 uint8_t *data;
31 uint8_t length;
32 uint8_t currentOffset;
33 uint8_t bytesLastPayload;
34 uint8_t currentPackage;
35 bool telemetryConfirmExpectedValue;
36 uint16_t waitCount;
37 uint16_t maxWaitCount;
38 uint8_t maxPackageIndex;
39 stubborn_sender_state_e senderState;