diff --git a/ground_station/src/logging/recorder.cpp b/ground_station/src/logging/recorder.cpp index 9a0e2297..6c6d8d92 100644 --- a/ground_station/src/logging/recorder.cpp +++ b/ground_station/src/logging/recorder.cpp @@ -67,3 +67,49 @@ void Recorder::recordTask(void *pvParameter) { } vTaskDelete(nullptr); } + +uint8_t Recorder::getFileCount() { + if (!fatfs.chdir(directory)) { + console.warning.print("[REC] Open directory failed"); + console.warning.println(directory); + return 0; + } + + File file = fatfs.open("/logs/"); + + uint8_t count = 0; + File entry = file.openNextFile(); + while (entry) { + count++; + entry.close(); + entry = file.openNextFile(); + } + file.close(); + return count; +} + +bool Recorder::getFileNameByIndex(uint8_t index, char *name) { + if (!fatfs.chdir(directory)) { + console.warning.print("[REC] Open directory failed"); + console.warning.println(directory); + return false; + } + + File file = fatfs.open("/logs/"); + + uint8_t count = 0; + File entry = file.openNextFile(); + while (entry) { + if (count == index) { + entry.getName(name, 30); + entry.close(); + file.close(); + return true; + } + count++; + entry.close(); + entry = file.openNextFile(); + } + file.close(); + return false; +} diff --git a/ground_station/src/logging/recorder.hpp b/ground_station/src/logging/recorder.hpp index 306afe77..510211e9 100644 --- a/ground_station/src/logging/recorder.hpp +++ b/ground_station/src/logging/recorder.hpp @@ -28,6 +28,12 @@ class Recorder { } } + uint8_t getFileCount(); + + bool getFileNameByIndex(uint8_t index, char* name); + + const char* getDirectory() { return directory; } + private: bool initialized = false; bool enabled = false;