From 004e98457f22054c8cbd56253004ef2f8cd28be0 Mon Sep 17 00:00:00 2001 From: jirif Date: Mon, 11 Sep 2017 21:19:26 +0200 Subject: [PATCH 1/2] "diff|dump all" export can be used as direct copy/paste import "defaults" command causing reboot of the FC and ignoring remaining part of the pasted commands from "diff|dump all" exports. This change adding "nosave" parameter/functionality for the "defaults" command and "diff|dump all" exports. This parameter will not save eeprom and do not reboot the FC. --- src/main/fc/cli.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index bb6236d9db..9213a4e396 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2762,11 +2762,11 @@ static void cliSave(char *cmdline) static void cliDefaults(char *cmdline) { - UNUSED(cmdline); - cliPrintHashLine("resetting to defaults"); - resetEEPROM(); - cliReboot(); + resetConfigs(); + if (isEmpty(cmdline)) { + cliSave(NULL); + } } STATIC_UNIT_TESTED void cliGet(char *cmdline) @@ -3435,7 +3435,7 @@ static void printConfig(char *cmdline, bool doDiff) if ((dumpMask & (DUMP_ALL | DO_DIFF)) == (DUMP_ALL | DO_DIFF)) { cliPrintHashLine("reset configuration to default settings"); - cliPrint("defaults"); + cliPrint("defaults nosave"); cliPrintLinefeed(); } @@ -3600,7 +3600,7 @@ const clicmd_t cmdTable[] = { #ifdef LED_STRIP CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor), #endif - CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", NULL, cliDefaults), + CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "[nosave]", cliDefaults), CLI_COMMAND_DEF("diff", "list configuration changes from default", "[master|profile|rates|all] {defaults}", cliDiff), #ifdef USE_DSHOT From 96c7ef22c860776a2af06a3f8d71daaf8a90c976 Mon Sep 17 00:00:00 2001 From: jirif Date: Tue, 12 Sep 2017 10:05:45 +0200 Subject: [PATCH 2/2] add strict argument checking for the "defaults" cli command --- src/main/fc/cli.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 9213a4e396..ccb95f36a1 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2762,9 +2762,19 @@ static void cliSave(char *cmdline) static void cliDefaults(char *cmdline) { + bool saveConfigs; + + if (isEmpty(cmdline)) { + saveConfigs = true; + } else if (strncasecmp(cmdline, "nosave", 6) == 0) { + saveConfigs = false; + } else { + return; + } + cliPrintHashLine("resetting to defaults"); resetConfigs(); - if (isEmpty(cmdline)) { + if (saveConfigs) { cliSave(NULL); } }