1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Fixed jumbo frame handling

This commit is contained in:
Martin Budden 2016-10-20 13:54:47 +01:00
parent 92c3fb7d8d
commit d8da70e3f6
2 changed files with 10 additions and 3 deletions

View file

@ -186,8 +186,6 @@ typedef enum {
#define RATEPROFILE_MASK (1 << 7) #define RATEPROFILE_MASK (1 << 7)
#define JUMBO_FRAME_SIZE_LIMIT 255
#ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE
static void msp4WayIfFn(serialPort_t *serialPort) static void msp4WayIfFn(serialPort_t *serialPort)
{ {

View file

@ -121,13 +121,22 @@ static uint8_t mspSerialChecksumBuf(uint8_t checksum, const uint8_t *data, int l
return checksum; return checksum;
} }
#define JUMBO_FRAME_SIZE_LIMIT 255
static void mspSerialEncode(mspPort_t *msp, mspPacket_t *packet) static void mspSerialEncode(mspPort_t *msp, mspPacket_t *packet)
{ {
serialBeginWrite(msp->port); serialBeginWrite(msp->port);
const int len = sbufBytesRemaining(&packet->buf); const int len = sbufBytesRemaining(&packet->buf);
const uint8_t hdr[5] = {'$', 'M', packet->result == MSP_RESULT_ERROR ? '!' : '>', len, packet->cmd}; const int mspLen = len < JUMBO_FRAME_SIZE_LIMIT ? len : JUMBO_FRAME_SIZE_LIMIT;
const uint8_t hdr[5] = {'$', 'M', packet->result == MSP_RESULT_ERROR ? '!' : '>', mspLen, packet->cmd};
serialWriteBuf(msp->port, hdr, sizeof(hdr)); serialWriteBuf(msp->port, hdr, sizeof(hdr));
uint8_t checksum = mspSerialChecksumBuf(0, hdr + 3, 2); // checksum starts from len field uint8_t checksum = mspSerialChecksumBuf(0, hdr + 3, 2); // checksum starts from len field
if (len >= JUMBO_FRAME_SIZE_LIMIT) {
serialWrite(msp->port, len & 0xff);
checksum ^= len & 0xff;
serialWrite(msp->port, (len >> 8) & 0xff);
checksum ^= (len >> 8) & 0xff;
}
if (len > 0) { if (len > 0) {
serialWriteBuf(msp->port, sbufPtr(&packet->buf), len); serialWriteBuf(msp->port, sbufPtr(&packet->buf), len);
checksum = mspSerialChecksumBuf(checksum, sbufPtr(&packet->buf), len); checksum = mspSerialChecksumBuf(checksum, sbufPtr(&packet->buf), len);