Add debug code for blackbox output bandwidth measurement (#9060)

Add debug code for blackbox output bandwidth measurement
This commit is contained in:
Michael Keller 2019-10-22 11:28:46 +13:00 committed by GitHub
commit bb92da061e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 1 deletions

View File

@ -28,6 +28,20 @@
#ifdef USE_BLACKBOX
#include "build/debug.h"
// Debugging code that become useful when output bandwidth saturation is suspected.
// Set debug_mode = BLACKBOX_OUTPUT to see following debug values.
//
// 0: Average output bandwidth in last 100ms
// 1: Maximum hold of above.
// 2: Bytes dropped due to output buffer full.
//
// Note that bandwidth usage slightly increases when DEBUG_BB_OUTPUT is enabled,
// as output will include debug variables themselves.
#define DEBUG_BB_OUTPUT
#include "blackbox.h"
#include "blackbox_io.h"
@ -87,8 +101,19 @@ void blackboxOpen(void)
}
}
#ifdef DEBUG_BB_OUTPUT
static uint32_t bbBits;
static timeMs_t bbLastclearMs;
static uint16_t bbRateMax;
static uint32_t bbDrops;
#endif
void blackboxWrite(uint8_t value)
{
#ifdef DEBUG_BB_OUTPUT
bbBits += 8;
#endif
switch (blackboxConfig()->device) {
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
@ -102,9 +127,32 @@ void blackboxWrite(uint8_t value)
#endif
case BLACKBOX_DEVICE_SERIAL:
default:
#ifdef DEBUG_BB_OUTPUT
bbBits += 2;
if (serialTxBytesFree(blackboxPort) == 0) {
++bbDrops;
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 2, bbDrops);
return;
}
#endif
serialWrite(blackboxPort, value);
break;
}
#ifdef DEBUG_BB_OUTPUT
timeMs_t now = millis();
if (now > bbLastclearMs + 100) { // Debug log every 100[msec]
uint16_t bbRate = ((bbBits * 10 + 5) / (now - bbLastclearMs)) / 10; // In unit of [Kbps]
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 0, bbRate);
if (bbRate > bbRateMax) {
bbRateMax = bbRate;
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 1, bbRateMax);
}
bbLastclearMs = now;
bbBits = 0;
}
#endif
}
// Print the null-terminated string 's' to the blackbox device and return the number of bytes written

View File

@ -93,4 +93,5 @@ const char * const debugModeNames[DEBUG_COUNT] = {
"DYN_IDLE",
"FF_LIMIT",
"FF_INTERPOLATED",
"BLACKBOX_OUTPUT",
};

View File

@ -109,6 +109,7 @@ typedef enum {
DEBUG_DYN_IDLE,
DEBUG_FF_LIMIT,
DEBUG_FF_INTERPOLATED,
DEBUG_BLACKBOX_OUTPUT,
DEBUG_COUNT
} debugType_e;

View File

@ -20,6 +20,8 @@
extern "C" {
#include "platform.h"
#include "build/debug.h"
#include "blackbox/blackbox.h"
#include "common/utils.h"
@ -362,7 +364,8 @@ uint8_t armingFlags;
uint8_t stateFlags;
const uint32_t baudRates[] = {0, 9600, 19200, 38400, 57600, 115200, 230400, 250000,
400000, 460800, 500000, 921600, 1000000, 1500000, 2000000, 2470000}; // see baudRate_e
uint8_t debugMode;
uint8_t debugMode = 0;
int16_t debug[DEBUG16_VALUE_COUNT];
int32_t blackboxHeaderBudget;
gpsSolutionData_t gpsSol;
int32_t GPS_home[2];