Communicate Rx available antenna mode to the Tx (#3039)
[ExpressLRS.git] / src / lib / CRSF2MSP / crsf2msp.h
blobe4f82a45b65cd32af0dea50214d059de0edb210a
1 #pragma once
3 #include <cstdint>
4 #include "FIFO.h"
5 #include "crsfmsp_common.h"
6 #include "crc.h"
7 #include "logging.h"
9 /* Takes a CRSF(MSP) frame and converts it to raw MSP frame
10 adding the MSP header and checksum. Handles chunked MSP messages.
13 class CROSSFIRE2MSP
15 private:
16 uint8_t outBuffer[MSP_FRAME_MAX_LEN];
17 uint32_t pktLen; // packet length of the incomming msp frame
18 uint32_t idx; // number of bytes received in the current msp frame
19 uint8_t seqNumberPrev;
20 bool frameComplete;
21 uint8_t src; // source of the msp frame (from CRSF ext header)
22 uint8_t dest; // destination of the msp frame (from CRSF ext header)
23 MSPframeType_e MSPvers; // need to store the MSP version since it can only be inferred from the first frame
25 bool isNewFrame(const uint8_t *data);
26 bool isError(const uint8_t *data);
28 uint8_t getSeqNumber(const uint8_t *data);
29 MSPframeType_e getVersion(const uint8_t *data);
30 uint8_t getHeaderDir(const uint8_t *data);
31 uint8_t getChecksum(const uint8_t *data, const uint32_t packetLen, MSPframeType_e mspVersion);
32 uint32_t getFrameLen(const uint8_t *data, MSPframeType_e mspVersion);
34 public:
35 CROSSFIRE2MSP();
36 FIFO<MSP_FRAME_MAX_LEN> FIFOout;
37 void parse(const uint8_t *data); // accept crsf frame input
38 bool isFrameReady();
39 const uint8_t *getFrame();
40 uint32_t getFrameLen();
41 void reset();
42 uint8_t getSrc();
43 uint8_t getDest();
46 extern CROSSFIRE2MSP crsf2msp;