implemented core write
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
This commit is contained in:
parent
ed603f4e48
commit
1f381d9477
@ -5,6 +5,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace returnvalue;
|
using namespace returnvalue;
|
||||||
|
|
||||||
@ -58,10 +59,18 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
|
|||||||
if (not mostRecentFile) {
|
if (not mostRecentFile) {
|
||||||
assignMostRecentFile();
|
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
|
if (currentTv.tv_sec < mostRecentTv.value().tv_sec or
|
||||||
// since last timestamp exceeds rollover interval?
|
currentTv.tv_sec - mostRecentTv.value().tv_sec > static_cast<int>(rolloverDiffSeconds)) {
|
||||||
// TODO: If file does not exist or rollover criteria met: Create new file with current timestamp.
|
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;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +94,8 @@ void TmStore::updateBaseDir() {
|
|||||||
baseDirUninitialized = false;
|
baseDirUninitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t TmStore::updateCurrentTimestamp() { return Clock::getClock_timeval(¤tTv); }
|
||||||
|
|
||||||
void TmStore::assignMostRecentFile() {
|
void TmStore::assignMostRecentFile() {
|
||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
for (auto const& file : directory_iterator(baseDir)) {
|
for (auto const& file : directory_iterator(baseDir)) {
|
||||||
@ -113,3 +124,5 @@ void TmStore::assignMostRecentFile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t TmStore::storePacketInternal(PusTmReader& reader) { return returnvalue::OK; }
|
||||||
|
@ -22,6 +22,8 @@ class TmStore : public SystemObject {
|
|||||||
TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
|
TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
|
||||||
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan);
|
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan);
|
||||||
|
|
||||||
|
void updateBaseDir();
|
||||||
|
ReturnValue_t updateCurrentTimestamp();
|
||||||
ReturnValue_t passPacket(PusTmReader& reader);
|
ReturnValue_t passPacket(PusTmReader& reader);
|
||||||
ReturnValue_t storePacket(PusTmReader& reader);
|
ReturnValue_t storePacket(PusTmReader& reader);
|
||||||
|
|
||||||
@ -38,15 +40,15 @@ class TmStore : public SystemObject {
|
|||||||
std::string baseName;
|
std::string baseName;
|
||||||
std::filesystem::path baseDir;
|
std::filesystem::path baseDir;
|
||||||
uint32_t rolloverDiffSeconds = 0;
|
uint32_t rolloverDiffSeconds = 0;
|
||||||
char NAME_BUF[524] = {};
|
|
||||||
std::array<uint8_t, 8192> fileBuf{};
|
std::array<uint8_t, 8192> fileBuf{};
|
||||||
|
timeval currentTv{};
|
||||||
std::optional<timeval> mostRecentTv;
|
std::optional<timeval> mostRecentTv;
|
||||||
std::optional<std::filesystem::path> mostRecentFile;
|
std::optional<std::filesystem::path> mostRecentFile;
|
||||||
SdCardMountedIF& sdcMan;
|
SdCardMountedIF& sdcMan;
|
||||||
|
|
||||||
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
|
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
|
||||||
void updateBaseDir();
|
|
||||||
void assignMostRecentFile();
|
void assignMostRecentFile();
|
||||||
|
ReturnValue_t storePacketInternal(PusTmReader& reader);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */
|
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user