From a22c176d45123361523c9d0209056e78dae8ef3b Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 7 Jun 2025 15:44:36 +1200 Subject: [PATCH] add rm command to remove file --- examples/companion_radio/DataStore.cpp | 4 ++++ examples/companion_radio/DataStore.h | 1 + examples/companion_radio/MyMesh.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 795e38cc..508b270e 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -52,6 +52,10 @@ File DataStore::openRead(const char* filename) { #endif } +bool DataStore::removeFile(const char* filename) { + return _fs->remove(filename); +} + bool DataStore::formatFileSystem() { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) return _fs->format(); diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index 201dac01..32ccd196 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -38,4 +38,5 @@ public: uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]); bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len); File openRead(const char* filename); + bool removeFile(const char* filename); }; diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 79910aee..63fbf142 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1353,6 +1353,19 @@ void MyMesh::checkCLIRescueCmd() { } + } else if (memcmp(cli_command, "rm ", 3) == 0) { + + // get path from command e.g: "rm /adv_blobs" + const char *path = &cli_command[4]; + + // remove file + bool removed = _store->removeFile(path); + if(removed){ + Serial.println("File removed"); + } else { + Serial.println("Failed to remove file"); + } + } else if (strcmp(cli_command, "reboot") == 0) { board.reboot(); // doesn't return } else {