From 8627af832c525b367f001185d95900377c66df6e Mon Sep 17 00:00:00 2001 From: anthonycake Date: Sat, 5 Dec 2020 12:17:38 +0100 Subject: [PATCH 1/3] Add debug support to GHST protocol driver Add ability for pilots to log CRC errors, unknown frames, LQ, and RSSI. Added macro to debug.h to simplify incrementing debug values without the need for local statics in client code. --- src/main/build/debug.c | 1 + src/main/build/debug.h | 2 ++ src/main/rx/ghst.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/main/build/debug.c b/src/main/build/debug.c index 417b7f2a8e..2b0428a257 100644 --- a/src/main/build/debug.c +++ b/src/main/build/debug.c @@ -98,4 +98,5 @@ const char * const debugModeNames[DEBUG_COUNT] = { "RX_TIMING", "D_LPF", "VTX_TRAMP", + "GHST" }; diff --git a/src/main/build/debug.h b/src/main/build/debug.h index b240619371..6b1eb1bc8c 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -25,6 +25,7 @@ extern int16_t debug[DEBUG16_VALUE_COUNT]; extern uint8_t debugMode; #define DEBUG_SET(mode, index, value) {if (debugMode == (mode)) {debug[(index)] = (value);}} +#define DEBUG_INCR(mode, index) {if (debugMode == (mode)) {++debug[(index)];}} #define DEBUG_SECTION_TIMES @@ -114,6 +115,7 @@ typedef enum { DEBUG_RX_TIMING, DEBUG_D_LPF, DEBUG_VTX_TRAMP, + DEBUG_GHST, DEBUG_COUNT } debugType_e; diff --git a/src/main/rx/ghst.c b/src/main/rx/ghst.c index c8108ada76..c032199ad2 100644 --- a/src/main/rx/ghst.c +++ b/src/main/rx/ghst.c @@ -74,6 +74,13 @@ STATIC_UNIT_TESTED ghstFrame_t ghstValidatedFrame; // validated frame, CRC is o STATIC_UNIT_TESTED uint32_t ghstChannelData[GHST_MAX_NUM_CHANNELS]; +enum { + DEBUG_GHST_CRC_ERRORS = 0, + DEBUG_GHST_UNKNOWN_FRAMES, + DEBUG_GHST_RX_RSSI, + DEBUG_GHST_RX_LQ +}; + static serialPort_t *serialPort; static timeUs_t ghstRxFrameStartAtUs = 0; static timeUs_t ghstRxFrameEndAtUs = 0; @@ -191,6 +198,10 @@ STATIC_UNIT_TESTED uint8_t ghstFrameStatus(rxRuntimeState_t *rxRuntimeState) return RX_FRAME_COMPLETE | RX_FRAME_PROCESSING_REQUIRED; // request callback through ghstProcessFrame to do the decoding work } + if(crc != ghstValidatedFrame.bytes[fullFrameLength - 1] ) { + DEBUG_INCR(DEBUG_GHST, DEBUG_GHST_CRC_ERRORS); + } + return RX_FRAME_DROPPED; // frame was invalid } @@ -231,6 +242,9 @@ static bool ghstProcessFrame(const rxRuntimeState_t *rxRuntimeState) case GHST_UL_RC_CHANS_HS4_RSSI: { const ghstPayloadPulsesRssi_t* const rssiFrame = (ghstPayloadPulsesRssi_t*)&ghstValidatedFrame.frame.payload; + DEBUG_SET(DEBUG_GHST, DEBUG_GHST_RX_RSSI, -rssiFrame->rssi); + DEBUG_SET(DEBUG_GHST, DEBUG_GHST_RX_LQ, rssiFrame->lq); + if (rssiSource == RSSI_SOURCE_RX_PROTOCOL) { // rssi sent sign-inverted const uint16_t rssiPercentScaled = scaleRange(-rssiFrame->rssi, GHST_RSSI_DBM_MIN, 0, GHST_RSSI_DBM_MAX, RSSI_MAX_VALUE); @@ -252,6 +266,9 @@ static bool ghstProcessFrame(const rxRuntimeState_t *rxRuntimeState) case GHST_UL_RC_CHANS_HS4_5TO8: startIdx = 4; break; case GHST_UL_RC_CHANS_HS4_9TO12: startIdx = 8; break; case GHST_UL_RC_CHANS_HS4_13TO16: startIdx = 12; break; + default: + DEBUG_INCR(DEBUG_GHST, DEBUG_GHST_UNKNOWN_FRAMES); + break; } if (startIdx > 0) From a543ed88879de8dffa4efd7da0fdbb4b0d223956 Mon Sep 17 00:00:00 2001 From: anthonycake Date: Sat, 5 Dec 2020 17:42:56 +0100 Subject: [PATCH 2/3] Switch to static storage for error counters Remove DEBUG_INCR, and switch to static counters. --- src/main/build/debug.h | 1 - src/main/rx/ghst.c | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/build/debug.h b/src/main/build/debug.h index 6b1eb1bc8c..285977efb4 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -25,7 +25,6 @@ extern int16_t debug[DEBUG16_VALUE_COUNT]; extern uint8_t debugMode; #define DEBUG_SET(mode, index, value) {if (debugMode == (mode)) {debug[(index)] = (value);}} -#define DEBUG_INCR(mode, index) {if (debugMode == (mode)) {++debug[(index)];}} #define DEBUG_SECTION_TIMES diff --git a/src/main/rx/ghst.c b/src/main/rx/ghst.c index c032199ad2..e12c623270 100644 --- a/src/main/rx/ghst.c +++ b/src/main/rx/ghst.c @@ -187,6 +187,7 @@ static bool shouldSendTelemetryFrame(void) STATIC_UNIT_TESTED uint8_t ghstFrameStatus(rxRuntimeState_t *rxRuntimeState) { UNUSED(rxRuntimeState); + static int16_t crcErrorCount = 0; if (ghstFrameAvailable) { ghstFrameAvailable = false; @@ -199,7 +200,7 @@ STATIC_UNIT_TESTED uint8_t ghstFrameStatus(rxRuntimeState_t *rxRuntimeState) } if(crc != ghstValidatedFrame.bytes[fullFrameLength - 1] ) { - DEBUG_INCR(DEBUG_GHST, DEBUG_GHST_CRC_ERRORS); + DEBUG_SET(DEBUG_GHST, DEBUG_GHST_CRC_ERRORS, ++crcErrorCount); } return RX_FRAME_DROPPED; // frame was invalid @@ -219,6 +220,8 @@ static bool ghstProcessFrame(const rxRuntimeState_t *rxRuntimeState) UNUSED(rxRuntimeState); + static int16_t unknownFrameCount = 0; + // do we have a telemetry buffer to send? if (shouldSendTelemetryFrame()) { ghstTransmittingTelemetry = true; @@ -267,7 +270,7 @@ static bool ghstProcessFrame(const rxRuntimeState_t *rxRuntimeState) case GHST_UL_RC_CHANS_HS4_9TO12: startIdx = 8; break; case GHST_UL_RC_CHANS_HS4_13TO16: startIdx = 12; break; default: - DEBUG_INCR(DEBUG_GHST, DEBUG_GHST_UNKNOWN_FRAMES); + DEBUG_SET(DEBUG_GHST, DEBUG_GHST_UNKNOWN_FRAMES, ++unknownFrameCount); break; } From 81150286c6361feb83fc518deb2255d427a11590 Mon Sep 17 00:00:00 2001 From: anthonycake Date: Tue, 15 Dec 2020 09:02:01 +0100 Subject: [PATCH 3/3] Keep reviewers happy --- src/main/build/debug.c | 2 +- src/main/rx/ghst.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/build/debug.c b/src/main/build/debug.c index 2b0428a257..1a752db76c 100644 --- a/src/main/build/debug.c +++ b/src/main/build/debug.c @@ -98,5 +98,5 @@ const char * const debugModeNames[DEBUG_COUNT] = { "RX_TIMING", "D_LPF", "VTX_TRAMP", - "GHST" + "GHST", }; diff --git a/src/main/rx/ghst.c b/src/main/rx/ghst.c index e12c623270..0ac6a968ae 100644 --- a/src/main/rx/ghst.c +++ b/src/main/rx/ghst.c @@ -78,7 +78,7 @@ enum { DEBUG_GHST_CRC_ERRORS = 0, DEBUG_GHST_UNKNOWN_FRAMES, DEBUG_GHST_RX_RSSI, - DEBUG_GHST_RX_LQ + DEBUG_GHST_RX_LQ, }; static serialPort_t *serialPort; @@ -199,7 +199,7 @@ STATIC_UNIT_TESTED uint8_t ghstFrameStatus(rxRuntimeState_t *rxRuntimeState) return RX_FRAME_COMPLETE | RX_FRAME_PROCESSING_REQUIRED; // request callback through ghstProcessFrame to do the decoding work } - if(crc != ghstValidatedFrame.bytes[fullFrameLength - 1] ) { + if (crc != ghstValidatedFrame.bytes[fullFrameLength - 1]) { DEBUG_SET(DEBUG_GHST, DEBUG_GHST_CRC_ERRORS, ++crcErrorCount); }