From 53b48ad99bfea6014721d8d5487e4354cf87b0f4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 24 Jun 2023 11:46:56 +0200 Subject: [PATCH] this is tricky --- mission/tmtc/PersistentTmStore.cpp | 39 +++++++++++++++++++++++------- mission/tmtc/PersistentTmStore.h | 4 ++- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mission/tmtc/PersistentTmStore.cpp b/mission/tmtc/PersistentTmStore.cpp index f8830170..6ee2f3a6 100644 --- a/mission/tmtc/PersistentTmStore.cpp +++ b/mission/tmtc/PersistentTmStore.cpp @@ -17,7 +17,7 @@ using namespace returnvalue; -static constexpr bool DEBUG_DUMPS = false; +static constexpr bool DEBUG_DUMPS = true; PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args) : SystemObject(args.objectId), @@ -74,16 +74,21 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t continue; } - DumpIndex dumpIndex; - dumpIndex.epoch = fileEpoch; - dumpIndex.suffixIdx = extractSuffix(file.string()); if (DEBUG_DUMPS) { sif::debug << "Inserting file " << fileOrDir.path() << std::endl; - if (dumpIndex.suffixIdx.has_value()) { - sif::debug << "Suffix: " << static_cast(dumpIndex.suffixIdx.value()) << std::endl; - } } - dumpParams.orderedDumpFilestamps.emplace(dumpIndex); + DumpIndex dumpIndex; + dumpIndex.epoch = fileEpoch; + // Multiple files for the same time are supported via a special suffix. We smply count the + // number of copies and later try to dump the same number of files with the additonal + // suffixes + auto& iter = dumpParams.orderedDumpFilestamps.find(dumpIndex); + if (iter != dumpParams.orderedDumpFilestamps.end()) { + iter->additionalFiles++; + } else { + dumpIndex.additionalFiles = 0; + dumpParams.orderedDumpFilestamps.emplace(dumpIndex); + } } } return returnvalue::OK; @@ -301,7 +306,7 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() { timeval tv{}; tv.tv_sec = dumpIndex.epoch; size_t fullPathLength = 0; - createFileName(tv, dumpIndex.suffixIdx, fullPathLength); + createFileName(tv, dumpParams.currentSameFileIdx, fullPathLength); dumpParams.currentFile = path(std::string(reinterpret_cast(filePathBuf.data()), fullPathLength)); dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e); @@ -321,6 +326,22 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() { } ifile.read(reinterpret_cast(fileBuf.data()), static_cast(dumpParams.fileSize)); + if (dumpIndex.additionalFiles > 0) { + dumpParams.currentSameFileIdx++; + } + if (dumpIndex.additionalFiles > 0 and not dumpParams.currentSameFileIdx.has_value()) { + if (not dumpParams.currentSameFileIdx.has_value()) { + // Initialze the file index and stay on same file + dumpParams.currentSameFileIdx = 0; + continue; + + } else if (dumpParams.currentSameFileIdx.value() < dumpIndex.additionalFiles) { + dumpParams.currentSameFileIdx += 1; + continue; + } + } + // File will change, reset this field for correct state-keeping. + dumpParams.currentSameFileIdx = std::nullopt; // Increment iterator for next cycle. dumpParams.dumpIter++; return returnvalue::OK; diff --git a/mission/tmtc/PersistentTmStore.h b/mission/tmtc/PersistentTmStore.h index 1694a8c9..54b87a42 100644 --- a/mission/tmtc/PersistentTmStore.h +++ b/mission/tmtc/PersistentTmStore.h @@ -40,7 +40,8 @@ struct PersistentTmStoreArgs { struct DumpIndex { uint32_t epoch; - std::optional suffixIdx; + // Number of additional files with a suffix like .0, .1 etc. + uint8_t additionalFiles; // Define a custom comparison function based on the epoch variable bool operator<(const DumpIndex& other) const { return epoch < other.epoch; } }; @@ -120,6 +121,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject { std::filesystem::path currentFile; std::set orderedDumpFilestamps{}; std::set::iterator dumpIter; + std::optional currentSameFileIdx = 0; size_t fileSize = 0; size_t currentSize = 0; };