diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 672551528..a0c5cf82e 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -3861,10 +3861,6 @@ bool MyMesh::handleTxRoutingCommand(const char* command, char* reply, size_t rep return true; } -#if defined(RAK_4631) && defined(COMPANION_RADIO_FULL) -// Keep occasional management work out of the space-optimized hot call graph. -__attribute__((cold)) -#endif bool MyMesh::handleLocalControlCommand(const char* command, char* reply, size_t reply_size) { if (!command || !reply || reply_size == 0) return false; @@ -9959,9 +9955,6 @@ bool MyMesh::streamTerminalBusy() const { } #endif -#if defined(RAK_4631) && defined(COMPANION_RADIO_FULL) -__attribute__((cold)) -#endif void MyMesh::handleTerminalCommand(char* command, bool reader_prompt, mesh::ReaderTryWrite reader_try_write) { while (*command == ' ' || *command == '\t') command++; diff --git a/src/helpers/SdCardCLI.cpp b/src/helpers/SdCardCLI.cpp index 346f4fc52..249de85b4 100644 --- a/src/helpers/SdCardCLI.cpp +++ b/src/helpers/SdCardCLI.cpp @@ -80,21 +80,22 @@ bool handleSdCardSet(SdCardCLIState& state, MainBoard& board, const char* action_args = skipSpacesConst(config + 6); bool is_format; - bool force = false; - if (strcmp(action_args, "format") == 0) { + const char* suffix; + if (strncmp(action_args, "format", 6) == 0) { is_format = true; - } else if (strcmp(action_args, "format --force") == 0) { - is_format = true; - force = true; - } else if (strcmp(action_args, "erase") == 0) { + suffix = action_args + 6; + } else if (strncmp(action_args, "erase", 5) == 0) { is_format = false; - } else if (strcmp(action_args, "erase --force") == 0) { - is_format = false; - force = true; + suffix = action_args + 5; } else { mesh::cli::formatError(reply, capacity, "use set sdcard format|erase [--force]"); return true; } + const bool force = strcmp(suffix, " --force") == 0; + if (*suffix && !force) { + mesh::cli::formatError(reply, capacity, "use set sdcard format|erase [--force]"); + return true; + } const bool recorded = is_format ? state.format_recorded : state.erase_recorded; const uint32_t ran_at = is_format ? state.format_at : state.erase_at; @@ -198,16 +199,13 @@ bool handleSdCardGet(SdCardCLIState& state, MainBoard& board, formatSdCardElapsed(erase_age, sizeof(erase_age), state.erase_recorded, state.erase_at, now); snprintf(reply, capacity, "> format: %s, erase: %s", format_age, erase_age); - } else if (strcmp(query, "format") == 0) { + } else if (strcmp(query, "format") == 0 || strcmp(query, "erase") == 0) { + const bool format = *query == 'f'; char age[32]; - formatSdCardElapsed(age, sizeof(age), state.format_recorded, - state.format_at, now); - snprintf(reply, capacity, "> format: %s", age); - } else if (strcmp(query, "erase") == 0) { - char age[32]; - formatSdCardElapsed(age, sizeof(age), state.erase_recorded, - state.erase_at, now); - snprintf(reply, capacity, "> erase: %s", age); + formatSdCardElapsed(age, sizeof(age), + format ? state.format_recorded : state.erase_recorded, + format ? state.format_at : state.erase_at, now); + snprintf(reply, capacity, "> %s: %s", query, age); } else if (strcmp(query, "free") == 0) { if (!sdCardBusAvailable(reply, capacity)) return true; if (!mesh::ota::ota_acquire_context(reply, capacity)) return true; diff --git a/test/test_sdcard_cli_parity.py b/test/test_sdcard_cli_parity.py index 64ed249f9..1901f15cd 100644 --- a/test/test_sdcard_cli_parity.py +++ b/test/test_sdcard_cli_parity.py @@ -133,6 +133,13 @@ int main() { assert(strstr(reply.text, "apply is pending") && !context.prepares && !context.card.formats); context.apply_pending = false; context.card.format_ok = false; + for (const char* value : {"set sdcard formats", "set sdcard eraseX", + "set sdcard format--force", "set sdcard erase --force", + "set sdcard format\t--force", "set sdcard erase --force "}) { + assert(command(value)); + assert(strcmp(reply.text, "Error: use set sdcard format|erase [--force]") == 0); + assert(context.card.formats == 0 && context.card.erases == 0 && context.prepares == 0); + } assert(command("set sdcard format")); assert(strstr(reply.text, "format failed") && context.prepares == 1 && context.finishes == 1); assert(strcmp(reply.text, "Error: SD card format failed: card unavailable") == 0);