5 // TODO: MSP_PORT_INBUF_SIZE should be changed to
6 // dynamically allocate array length based on the payload size
7 // Hardcoding payload size to 8 bytes for now, since MSP is
8 // limited to a 4 byte payload on the BF side
9 #define MSP_PORT_INBUF_SIZE 8
11 #define CHECK_PACKET_PARSING() \
12 if (packet->readError) {\
22 MSP_PAYLOAD_V2_NATIVE
,
23 MSP_CHECKSUM_V2_NATIVE
,
34 typedef struct __attribute__((packed
)) {
45 uint8_t payload
[MSP_PORT_INBUF_SIZE
];
46 uint16_t payloadReadIterator
;
51 type
= MSP_PACKET_UNKNOWN
;
55 payloadReadIterator
= 0;
59 void addByte(uint8_t b
)
61 payload
[payloadSize
++] = b
;
66 type
= MSP_PACKET_RESPONSE
;
71 type
= MSP_PACKET_COMMAND
;
76 if (payloadReadIterator
>= payloadSize
) {
77 // We are trying to read beyond the length of the payload
82 return payload
[payloadReadIterator
++];
86 /////////////////////////////////////////////////
91 bool processReceivedByte(uint8_t c
);
92 mspPacket_t
* getReceivedPacket();
93 void markPacketReceived();
94 bool sendPacket(mspPacket_t
* packet
, Stream
* port
);
97 mspState_e m_inputState
;
99 uint8_t m_inputBuffer
[MSP_PORT_INBUF_SIZE
];
100 mspPacket_t m_packet
;