mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Add CLI batch support for presenting warnings when pasting configs
Adds a new `batch` command used to delineate a group of commands as a related batch. The primary purpose is to group commands sent from the Configurator resulting from a copy/pasted config. Currently the output of the `diff all` command appends a `save` at the end of its output. So when a user pastes in their config to restore they may not see any errors because the `save` command causes the flight controller to reboot before they can review. When commands are wrapped inside of a batch, any errors will set a flag that will issue a warning when the `save` command is executed. This allows the user ro review and correct there configuration.
This commit is contained in:
parent
499ddc003b
commit
8c1e6fa017
2 changed files with 81 additions and 0 deletions
|
@ -191,6 +191,11 @@ static int8_t rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
static bool featureMaskIsCopied = false;
|
static bool featureMaskIsCopied = false;
|
||||||
static uint32_t featureMaskCopy;
|
static uint32_t featureMaskCopy;
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
static bool commandBatchActive = false;
|
||||||
|
static bool commandBatchError = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USE_BOARD_INFO)
|
#if defined(USE_BOARD_INFO)
|
||||||
static bool boardInformationUpdated = false;
|
static bool boardInformationUpdated = false;
|
||||||
#if defined(USE_SIGNATURE)
|
#if defined(USE_SIGNATURE)
|
||||||
|
@ -399,6 +404,12 @@ static void cliPrintErrorVa(const char *format, va_list va)
|
||||||
cliPrintfva(format, va);
|
cliPrintfva(format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
cliPrint("###");
|
cliPrint("###");
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
if (commandBatchActive) {
|
||||||
|
commandBatchError = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliPrintError(const char *format, ...)
|
static void cliPrintError(const char *format, ...)
|
||||||
|
@ -3764,10 +3775,54 @@ static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask)
|
||||||
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
static void cliPrintCommandBatchWarning(const char *warning)
|
||||||
|
{
|
||||||
|
cliPrintErrorLinef("ERRORS WERE DETECTED - PLEASE REVIEW BEFORE CONTINUING");
|
||||||
|
if (warning) {
|
||||||
|
cliPrintErrorLinef(warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resetCommandBatch(void)
|
||||||
|
{
|
||||||
|
commandBatchActive = false;
|
||||||
|
commandBatchError = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cliBatch(char *cmdline)
|
||||||
|
{
|
||||||
|
if (strncasecmp(cmdline, "start", 5) == 0) {
|
||||||
|
if (!commandBatchActive) {
|
||||||
|
commandBatchActive = true;
|
||||||
|
commandBatchError = false;
|
||||||
|
}
|
||||||
|
cliPrintLine("Command batch started");
|
||||||
|
} else if (strncasecmp(cmdline, "end", 3) == 0) {
|
||||||
|
if (commandBatchActive && commandBatchError) {
|
||||||
|
cliPrintCommandBatchWarning(NULL);
|
||||||
|
} else {
|
||||||
|
cliPrintLine("Command batch ended");
|
||||||
|
}
|
||||||
|
resetCommandBatch();
|
||||||
|
} else {
|
||||||
|
cliPrintErrorLinef("Invalid option");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void cliSave(char *cmdline)
|
static void cliSave(char *cmdline)
|
||||||
{
|
{
|
||||||
UNUSED(cmdline);
|
UNUSED(cmdline);
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
if (commandBatchActive && commandBatchError) {
|
||||||
|
cliPrintCommandBatchWarning("PLEASE FIX ERRORS THEN 'SAVE'");
|
||||||
|
resetCommandBatch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
cliPrintHashLine("saving");
|
cliPrintHashLine("saving");
|
||||||
|
|
||||||
#if defined(USE_BOARD_INFO)
|
#if defined(USE_BOARD_INFO)
|
||||||
|
@ -3806,6 +3861,14 @@ static void cliDefaults(char *cmdline)
|
||||||
|
|
||||||
resetConfigs();
|
resetConfigs();
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
// Reset only the error state and allow the batch active state to remain.
|
||||||
|
// This way if a "defaults nosave" was issued after the "batch on" we'll
|
||||||
|
// only reset the current error state but the batch will still be active
|
||||||
|
// for subsequent commands.
|
||||||
|
commandBatchError = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (saveConfigs) {
|
if (saveConfigs) {
|
||||||
cliSave(NULL);
|
cliSave(NULL);
|
||||||
}
|
}
|
||||||
|
@ -5238,6 +5301,11 @@ static void printConfig(char *cmdline, bool doDiff)
|
||||||
cliPrintLinefeed();
|
cliPrintLinefeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
cliPrintHashLine("start the command batch");
|
||||||
|
cliPrintLine("batch start");
|
||||||
|
#endif
|
||||||
|
|
||||||
cliPrintHashLine("name");
|
cliPrintHashLine("name");
|
||||||
printName(dumpMask, &pilotConfig_Copy);
|
printName(dumpMask, &pilotConfig_Copy);
|
||||||
}
|
}
|
||||||
|
@ -5382,6 +5450,11 @@ static void printConfig(char *cmdline, bool doDiff)
|
||||||
|
|
||||||
if (dumpMask & DUMP_RATES) {
|
if (dumpMask & DUMP_RATES) {
|
||||||
cliDumpRateProfile(systemConfig_Copy.activeRateProfile, dumpMask);
|
cliDumpRateProfile(systemConfig_Copy.activeRateProfile, dumpMask);
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
cliPrintHashLine("end the command batch");
|
||||||
|
cliPrintLine("batch end");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5461,6 +5534,9 @@ static void cliHelp(char *cmdline);
|
||||||
const clicmd_t cmdTable[] = {
|
const clicmd_t cmdTable[] = {
|
||||||
CLI_COMMAND_DEF("adjrange", "configure adjustment ranges", NULL, cliAdjustmentRange),
|
CLI_COMMAND_DEF("adjrange", "configure adjustment ranges", NULL, cliAdjustmentRange),
|
||||||
CLI_COMMAND_DEF("aux", "configure modes", "<index> <mode> <aux> <start> <end> <logic>", cliAux),
|
CLI_COMMAND_DEF("aux", "configure modes", "<index> <mode> <aux> <start> <end> <logic>", cliAux),
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
CLI_COMMAND_DEF("batch", "start or end a batch of commands", "start | end", cliBatch),
|
||||||
|
#endif
|
||||||
#if defined(USE_BEEPER)
|
#if defined(USE_BEEPER)
|
||||||
#if defined(USE_DSHOT)
|
#if defined(USE_DSHOT)
|
||||||
CLI_COMMAND_DEF("beacon", "enable/disable Dshot beacon for a condition", "list\r\n"
|
CLI_COMMAND_DEF("beacon", "enable/disable Dshot beacon for a condition", "list\r\n"
|
||||||
|
@ -5743,6 +5819,10 @@ void cliEnter(serialPort_t *serialPort)
|
||||||
setArmingDisabled(ARMING_DISABLED_CLI);
|
setArmingDisabled(ARMING_DISABLED_CLI);
|
||||||
|
|
||||||
cliPrompt();
|
cliPrompt();
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
resetCommandBatch();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void cliInit(const serialConfig_t *serialConfig)
|
void cliInit(const serialConfig_t *serialConfig)
|
||||||
|
|
|
@ -162,6 +162,7 @@
|
||||||
#if (FLASH_SIZE > 64)
|
#if (FLASH_SIZE > 64)
|
||||||
#define USE_ACRO_TRAINER
|
#define USE_ACRO_TRAINER
|
||||||
#define USE_BLACKBOX
|
#define USE_BLACKBOX
|
||||||
|
#define USE_CLI_BATCH
|
||||||
#define USE_RESOURCE_MGMT
|
#define USE_RESOURCE_MGMT
|
||||||
#define USE_RUNAWAY_TAKEOFF // Runaway Takeoff Prevention (anti-taz)
|
#define USE_RUNAWAY_TAKEOFF // Runaway Takeoff Prevention (anti-taz)
|
||||||
#define USE_SERVOS
|
#define USE_SERVOS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue