Skip to content

Commit

Permalink
[GS] Get log file names
Browse files Browse the repository at this point in the history
  • Loading branch information
l-jost committed Sep 22, 2024
1 parent a135223 commit 957ce57
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ground_station/src/logging/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions ground_station/src/logging/recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 957ce57

Please sign in to comment.