this logic should work
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-12-12 18:17:59 +01:00
parent a9699ad969
commit 293082a7e8
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 19 additions and 10 deletions

View File

@ -61,8 +61,6 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
create_directory(baseDir); create_directory(baseDir);
} }
if (not mostRecentFile) { if (not mostRecentFile) {
// TODO: Find most recent file by iterating through all files and remembering the file
// with the most recent timestamp.
for (auto const& file : directory_iterator(baseDir)) { for (auto const& file : directory_iterator(baseDir)) {
if (file.is_directory()) { if (file.is_directory()) {
continue; continue;
@ -72,13 +70,21 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
if (pathStr.find(baseName) == std::string::npos) { if (pathStr.find(baseName) == std::string::npos) {
continue; continue;
} }
float seconds = 0.0; unsigned int underscorePos = pathStr.find_last_of('_');
char* prefix = nullptr; std::string stampStr = pathStr.substr(underscorePos + 1);
int count = sscanf(pathStr.c_str(), int count =
"%s_%4" SCNu32 "-%2" SCNu32 "-%2" SCNu32 "T%2" SCNu32 ":%2" SCNu32 ":%fZ", sscanf(stampStr.c_str(),
prefix, &tod.year, &tod.month, &tod.day, &tod.hour, &tod.minute, &seconds); "%4" SCNu32 "-%2" SCNu32 "-%2" SCNu32 "T%2" SCNu32 ":%2" SCNu32 ":%2" SCNu32 "Z",
tod.second = std::floor(seconds); &tod.year, &tod.month, &tod.day, &tod.hour, &tod.minute, &tod.second);
static_cast<void>(count); if (count != 6) {
continue;
}
timeval tv{};
Clock::convertTimeOfDayToTimeval(&tod, &tv);
if (not mostRecentTv || tv > mostRecentTv.value()) {
mostRecentTv = tv;
mostRecentFile = file.path();
}
} }
} }
// TODO: Need to find the file of the most recent file. // TODO: Need to find the file of the most recent file.

View File

@ -7,6 +7,8 @@
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h> #include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
#include <mission/memory/SdCardMountedIF.h> #include <mission/memory/SdCardMountedIF.h>
#include <filesystem>
struct PacketFilter { struct PacketFilter {
std::optional<std::vector<uint16_t>> apid; std::optional<std::vector<uint16_t>> apid;
std::optional<std::vector<uint8_t>> services; std::optional<std::vector<uint8_t>> services;
@ -37,7 +39,8 @@ class TmStore : public SystemObject {
uint8_t intervalFactor; uint8_t intervalFactor;
char NAME_BUF[524] = {}; char NAME_BUF[524] = {};
std::array<uint8_t, 8192> fileBuf{}; std::array<uint8_t, 8192> fileBuf{};
std::optional<std::string> mostRecentFile; std::optional<timeval> mostRecentTv;
std::optional<std::filesystem::path> mostRecentFile;
SdCardMountedIF& sdcMan; SdCardMountedIF& sdcMan;
}; };