Add cliDebugPrint functions to facilitate easy debug printing to CLI

To use, include `cli/cli_debug_print.h` in your code and be sure `USE_CLI_DEBUG_PRINT` is defined. Then you'll have access to the following functions to print debugging messages in the CLI:
```
cliDebugPrintLineFeed
cliDebugPrint
cliDebugPrintLine
cliDebugPrintf
cliDebugPrintLinef
```
Output is suppressed when the CLI is not open.

May interfere with the autocomplete initialization when first entering the CLI if your code is outputting data when the CLI first opens. But as this is only meant for debugging it shouldn't be much of a concern.

You may also need to rate limit your messages if printing data in a loop.

All of the debugging code must be removed from any completed code before submission.
This commit is contained in:
Bruce Luckcuck 2019-09-17 19:14:27 -04:00
parent 08e8afa090
commit 9cb48c97fd
5 changed files with 86 additions and 13 deletions

View File

@ -24,3 +24,15 @@
#include "platform.h"
#include "build_config.h"
#ifdef STM32F1
#warning STM32F1 based targets are unsupported as of Betaflight 3.3.
#endif
#ifdef STM32F3
#warning STM32F3 based targets are unsupported as of Betaflight 4.1.
#endif
#ifdef USE_CLI_DEBUG_PRINT
#warning Do not use USE_CLI_DEBUG_PRINT for production builds.
#endif

View File

@ -26,11 +26,3 @@ const char * const targetName = __TARGET__;
const char * const shortGitRevision = __REVISION__;
const char * const buildDate = __DATE__;
const char * const buildTime = __TIME__;
#ifdef STM32F1
#warning STM32F1 based targets are unsupported as of Betaflight 3.3.
#endif
#ifdef STM32F3
#warning STM32F3 based targets are unsupported as of Betaflight 4.1.
#endif

View File

@ -310,8 +310,12 @@ static void cliWriterFlush()
}
static void cliPrint(const char *str)
void cliPrint(const char *str)
{
if (!cliMode) {
return;
}
if (cliWriter) {
while (*str) {
bufWriterAppend(cliWriter, *str++);
@ -320,12 +324,12 @@ static void cliPrint(const char *str)
}
}
static void cliPrintLinefeed(void)
void cliPrintLinefeed(void)
{
cliPrint("\r\n");
}
static void cliPrintLine(const char *str)
void cliPrintLine(const char *str)
{
cliPrint(str);
cliPrintLinefeed();
@ -391,8 +395,12 @@ static bool cliDefaultPrintLinef(dumpFlags_t dumpMask, bool equalsDefault, const
}
}
static void cliPrintf(const char *format, ...)
void cliPrintf(const char *format, ...)
{
if (!cliMode) {
return;
}
va_list va;
va_start(va, format);
cliPrintfva(format, va);
@ -400,8 +408,12 @@ static void cliPrintf(const char *format, ...)
}
static void cliPrintLinef(const char *format, ...)
void cliPrintLinef(const char *format, ...)
{
if (!cliMode) {
return;
}
va_list va;
va_start(va, format);
cliPrintfva(format, va);

View File

@ -29,3 +29,11 @@ bool hasCustomDefaults(void);
struct serialPort_s;
void cliEnter(struct serialPort_s *serialPort);
bool resetConfigToCustomDefaults(void);
#ifdef USE_CLI_DEBUG_PRINT
void cliPrint(const char *str);
void cliPrintLinefeed(void);
void cliPrintLine(const char *str);
void cliPrintf(const char *format, ...);
void cliPrintLinef(const char *format, ...);
#endif

View File

@ -0,0 +1,49 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
// Provides: cliPrintDebug... functions for displaying debugging information in the CLI
//
// Usage: Make sure USE_CLI_DEBUG_PRINT is defined
// Include this header in your code
// Add cliDebugPrint... statements as needed in your code
// Use the CLI to see the output of the debugging statements
//
// Cautions: Be sure to include rate limiting logic to your debug printing
// if needed otherwise you can flood the output.
//
// Be sure to reverse the Usage steps above to remove the debugging
// elements before submitting final code.
#include "platform.h"
#ifdef USE_CLI_DEBUG_PRINT
#include "cli/cli.h"
// Commands to print debugging information to the CLI
#define cliDebugPrintLinefeed cliPrintLinefeed
#define cliDebugPrintLinef cliPrintLinef
#define cliDebugPrintLine cliPrintLine
#define cliDebugPrintf cliPrintf
#define cliDebugPrint cliPrint
#else
#error "Do not #include cli_debug_print.h unless you intend to do debugging and also define USE_CLI_DEBUG_PRINT"
#endif