From 887283041034d63af09ff9bdbe55d0f691a48e49 Mon Sep 17 00:00:00 2001 From: tbs-fpv Date: Mon, 12 Apr 2021 11:23:26 +0800 Subject: [PATCH] fix the invalid payload size for link stats TX frame --- src/main/rx/crsf.c | 26 +++++++++++++------------- src/main/rx/crsf_protocol.h | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/rx/crsf.c b/src/main/rx/crsf.c index af40563020..ea9a3ffff8 100644 --- a/src/main/rx/crsf.c +++ b/src/main/rx/crsf.c @@ -387,13 +387,13 @@ STATIC_UNIT_TESTED void crsfDataReceive(uint16_t c, void *data) #if defined(USE_CRSF_LINK_STATISTICS) case CRSF_FRAMETYPE_LINK_STATISTICS: { - // if to FC and 10 bytes + CRSF_FRAME_ORIGIN_DEST_SIZE - if ((rssiSource == RSSI_SOURCE_RX_PROTOCOL_CRSF) && - (crsfFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) && - (crsfFrame.frame.frameLength == CRSF_FRAME_ORIGIN_DEST_SIZE + CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE)) { - const crsfLinkStatistics_t* statsFrame = (const crsfLinkStatistics_t*)&crsfFrame.frame.payload; - handleCrsfLinkStatisticsFrame(statsFrame, currentTimeUs); - } + // if to FC and 10 bytes + CRSF_FRAME_ORIGIN_DEST_SIZE + if ((rssiSource == RSSI_SOURCE_RX_PROTOCOL_CRSF) && + (crsfFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) && + (crsfFrame.frame.frameLength == CRSF_FRAME_ORIGIN_DEST_SIZE + CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE)) { + const crsfLinkStatistics_t* statsFrame = (const crsfLinkStatistics_t*)&crsfFrame.frame.payload; + handleCrsfLinkStatisticsFrame(statsFrame, currentTimeUs); + } break; } #if defined(USE_CRSF_V3) @@ -401,12 +401,12 @@ STATIC_UNIT_TESTED void crsfDataReceive(uint16_t c, void *data) break; } case CRSF_FRAMETYPE_LINK_STATISTICS_TX: { - if ((rssiSource == RSSI_SOURCE_RX_PROTOCOL_CRSF) && - (crsfFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) && - (crsfFrame.frame.frameLength == CRSF_FRAME_ORIGIN_DEST_SIZE + CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE)) { - const crsfLinkStatisticsTx_t* statsFrame = (const crsfLinkStatisticsTx_t*)&crsfFrame.frame.payload; - handleCrsfLinkStatisticsTxFrame(statsFrame, currentTimeUs); - } + if ((rssiSource == RSSI_SOURCE_RX_PROTOCOL_CRSF) && + (crsfFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) && + (crsfFrame.frame.frameLength == CRSF_FRAME_ORIGIN_DEST_SIZE + CRSF_FRAME_LINK_STATISTICS_TX_PAYLOAD_SIZE)) { + const crsfLinkStatisticsTx_t* statsFrame = (const crsfLinkStatisticsTx_t*)&crsfFrame.frame.payload; + handleCrsfLinkStatisticsTxFrame(statsFrame, currentTimeUs); + } break; } #endif diff --git a/src/main/rx/crsf_protocol.h b/src/main/rx/crsf_protocol.h index 9b2a23a1f0..395c3a378e 100644 --- a/src/main/rx/crsf_protocol.h +++ b/src/main/rx/crsf_protocol.h @@ -84,6 +84,7 @@ enum { CRSF_FRAME_GPS_PAYLOAD_SIZE = 15, CRSF_FRAME_BATTERY_SENSOR_PAYLOAD_SIZE = 8, CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE = 10, + CRSF_FRAME_LINK_STATISTICS_TX_PAYLOAD_SIZE = 6, CRSF_FRAME_RC_CHANNELS_PAYLOAD_SIZE = 22, // 11 bits per channel * 16 channels = 22 bytes. CRSF_FRAME_ATTITUDE_PAYLOAD_SIZE = 6, };