1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 21:35:44 +03:00

Fix dataflash read by only using serialWriteBuf in mspSerialEncode

This commit is contained in:
Martin Budden 2016-11-23 18:02:32 +00:00
parent 4040a1dd7a
commit 83472a6989

View file

@ -125,20 +125,21 @@ static int 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 int mspLen = len < JUMBO_FRAME_SIZE_LIMIT ? len : JUMBO_FRAME_SIZE_LIMIT; 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}; uint8_t hdr[8] = {'$', 'M', packet->result == MSP_RESULT_ERROR ? '!' : '>', mspLen, packet->cmd};
serialWriteBuf(msp->port, hdr, sizeof(hdr)); int hdrLen = 5;
uint8_t checksum = mspSerialChecksumBuf(0, hdr + 3, 2); // checksum starts from len field #define CHECKSUM_STARTPOS 3 // checksum starts from mspLen field
if (len >= JUMBO_FRAME_SIZE_LIMIT) { if (len >= JUMBO_FRAME_SIZE_LIMIT) {
serialWrite(msp->port, len & 0xff); hdrLen += 2;
checksum ^= len & 0xff; hdr[5] = len & 0xff;
serialWrite(msp->port, (len >> 8) & 0xff); hdr[6] = (len >> 8) & 0xff;
checksum ^= (len >> 8) & 0xff;
} }
serialWriteBuf(msp->port, hdr, hdrLen);
uint8_t checksum = mspSerialChecksumBuf(0, hdr + CHECKSUM_STARTPOS, hdrLen - CHECKSUM_STARTPOS);
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);
} }
serialWrite(msp->port, checksum); serialWriteBuf(msp->port, &checksum, 1);
serialEndWrite(msp->port); serialEndWrite(msp->port);
return sizeof(hdr) + len + 1; // header, data, and checksum return sizeof(hdr) + len + 1; // header, data, and checksum
} }