implemented core write
EIVE/eive-obsw/pipeline/pr-develop This commit looks good Details

This commit is contained in:
Robin Müller 2022-12-12 18:42:51 +01:00
parent ed603f4e48
commit 1f381d9477
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 21 additions and 6 deletions

View File

@ -5,6 +5,7 @@
#include <algorithm>
#include <cinttypes>
#include <filesystem>
#include <fstream>
using namespace returnvalue;
@ -58,10 +59,18 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
if (not mostRecentFile) {
assignMostRecentFile();
}
// TODO: Need to find the file of the most recent file.
// TODO: If file exists: Determine whether file rolls over: Maximum file size reached? Interval
// since last timestamp exceeds rollover interval?
// TODO: If file does not exist or rollover criteria met: Create new file with current timestamp.
if (currentTv.tv_sec < mostRecentTv.value().tv_sec or
currentTv.tv_sec - mostRecentTv.value().tv_sec > static_cast<int>(rolloverDiffSeconds)) {
if (file_size(mostRecentFile.value()) + reader.getFullPacketLen() > fileBuf.size()) {
// TODO: Rename old file to XYZ.1..z , create new file with the same name as old one,
// update most recent file with that name
}
}
// Rollover conditions were handled, write to file now
std::ofstream of(mostRecentFile.value(), std::ios::app | std::ios::binary);
of.write(reinterpret_cast<const char*>(reader.getFullData()), reader.getFullPacketLen());
return returnvalue::OK;
}
@ -85,6 +94,8 @@ void TmStore::updateBaseDir() {
baseDirUninitialized = false;
}
ReturnValue_t TmStore::updateCurrentTimestamp() { return Clock::getClock_timeval(&currentTv); }
void TmStore::assignMostRecentFile() {
using namespace std::filesystem;
for (auto const& file : directory_iterator(baseDir)) {
@ -113,3 +124,5 @@ void TmStore::assignMostRecentFile() {
}
}
}
ReturnValue_t TmStore::storePacketInternal(PusTmReader& reader) { return returnvalue::OK; }

View File

@ -22,6 +22,8 @@ class TmStore : public SystemObject {
TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan);
void updateBaseDir();
ReturnValue_t updateCurrentTimestamp();
ReturnValue_t passPacket(PusTmReader& reader);
ReturnValue_t storePacket(PusTmReader& reader);
@ -38,15 +40,15 @@ class TmStore : public SystemObject {
std::string baseName;
std::filesystem::path baseDir;
uint32_t rolloverDiffSeconds = 0;
char NAME_BUF[524] = {};
std::array<uint8_t, 8192> fileBuf{};
timeval currentTv{};
std::optional<timeval> mostRecentTv;
std::optional<std::filesystem::path> mostRecentFile;
SdCardMountedIF& sdcMan;
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
void updateBaseDir();
void assignMostRecentFile();
ReturnValue_t storePacketInternal(PusTmReader& reader);
};
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */