mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 11:59:58 +03:00
Add cliDebugPrint functions to facilitate easy debug printing t… (#8905)
Add cliDebugPrint functions to facilitate easy debug printing to CLI
This commit is contained in:
commit
5efceb11a1
5 changed files with 86 additions and 13 deletions
|
@ -24,3 +24,15 @@
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#include "build_config.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
|
||||||
|
|
|
@ -26,11 +26,3 @@ const char * const targetName = __TARGET__;
|
||||||
const char * const shortGitRevision = __REVISION__;
|
const char * const shortGitRevision = __REVISION__;
|
||||||
const char * const buildDate = __DATE__;
|
const char * const buildDate = __DATE__;
|
||||||
const char * const buildTime = __TIME__;
|
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
|
|
||||||
|
|
|
@ -310,8 +310,12 @@ static void cliWriterFlush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cliPrint(const char *str)
|
void cliPrint(const char *str)
|
||||||
{
|
{
|
||||||
|
if (!cliMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cliWriter) {
|
if (cliWriter) {
|
||||||
while (*str) {
|
while (*str) {
|
||||||
bufWriterAppend(cliWriter, *str++);
|
bufWriterAppend(cliWriter, *str++);
|
||||||
|
@ -320,12 +324,12 @@ static void cliPrint(const char *str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliPrintLinefeed(void)
|
void cliPrintLinefeed(void)
|
||||||
{
|
{
|
||||||
cliPrint("\r\n");
|
cliPrint("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliPrintLine(const char *str)
|
void cliPrintLine(const char *str)
|
||||||
{
|
{
|
||||||
cliPrint(str);
|
cliPrint(str);
|
||||||
cliPrintLinefeed();
|
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_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
cliPrintfva(format, va);
|
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_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
cliPrintfva(format, va);
|
cliPrintfva(format, va);
|
||||||
|
|
|
@ -29,3 +29,11 @@ bool hasCustomDefaults(void);
|
||||||
struct serialPort_s;
|
struct serialPort_s;
|
||||||
void cliEnter(struct serialPort_s *serialPort);
|
void cliEnter(struct serialPort_s *serialPort);
|
||||||
bool resetConfigToCustomDefaults(void);
|
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
|
||||||
|
|
49
src/main/cli/cli_debug_print.h
Normal file
49
src/main/cli/cli_debug_print.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue