continued TM store impl
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:27:01 +01:00
parent 293082a7e8
commit ed603f4e48
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 65 additions and 42 deletions

View File

@ -8,14 +8,11 @@
using namespace returnvalue;
TmStore::TmStore(object_id_t objectId, std::string baseName, RolloverInterval interval,
uint8_t intervalFactor, PacketFilter filter, SdCardMountedIF& sdcMan)
: SystemObject(objectId),
filter(filter),
baseName(std::move(baseName)),
interval(interval),
intervalFactor(intervalFactor),
sdcMan(sdcMan) {}
TmStore::TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan)
: SystemObject(objectId), filter(filter), baseName(std::move(baseName)), sdcMan(sdcMan) {
calcDiffSeconds(intervalUnit, intervalCount);
}
ReturnValue_t TmStore::passPacket(PusTmReader& reader) {
bool inApidList = false;
@ -54,13 +51,42 @@ ReturnValue_t TmStore::passPacket(PusTmReader& reader) {
ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
using namespace std::filesystem;
std::string currentPrefix = sdcMan.getCurrentMountPrefix();
path baseDir = path(currentPrefix) / baseName;
if (baseDirUninitialized) {
updateBaseDir();
}
// It is assumed here that the filesystem is usable.
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.
return returnvalue::OK;
}
MessageQueueId_t TmStore::getCommandQueue() { return MessageQueueIF::NO_QUEUE; }
void TmStore::calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount) {
if (intervalUnit == RolloverInterval::HOURLY) {
rolloverDiffSeconds = 60 * intervalCount;
} else if (intervalUnit == RolloverInterval::DAILY) {
rolloverDiffSeconds = 60 * 24 * intervalCount;
}
}
void TmStore::updateBaseDir() {
using namespace std::filesystem;
std::string currentPrefix = sdcMan.getCurrentMountPrefix();
baseDir = path(currentPrefix) / baseName;
if (not exists(baseDir)) {
create_directory(baseDir);
}
if (not mostRecentFile) {
baseDirUninitialized = false;
}
void TmStore::assignMostRecentFile() {
using namespace std::filesystem;
for (auto const& file : directory_iterator(baseDir)) {
if (file.is_directory()) {
continue;
@ -86,12 +112,4 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
mostRecentFile = file.path();
}
}
}
// 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.
return returnvalue::OK;
}
MessageQueueId_t TmStore::getCommandQueue() { return MessageQueueIF::NO_QUEUE; }

View File

@ -19,8 +19,8 @@ enum class RolloverInterval { HOURLY, DAILY };
class TmStore : public SystemObject {
public:
TmStore(object_id_t objectId, std::string baseName, RolloverInterval interval,
uint8_t intervalFactor, PacketFilter filter, SdCardMountedIF& sdcMan);
TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan);
ReturnValue_t passPacket(PusTmReader& reader);
ReturnValue_t storePacket(PusTmReader& reader);
@ -34,14 +34,19 @@ class TmStore : public SystemObject {
*/
MessageQueueId_t getCommandQueue();
PacketFilter filter;
bool baseDirUninitialized = true;
std::string baseName;
RolloverInterval interval;
uint8_t intervalFactor;
std::filesystem::path baseDir;
uint32_t rolloverDiffSeconds = 0;
char NAME_BUF[524] = {};
std::array<uint8_t, 8192> fileBuf{};
std::optional<timeval> mostRecentTv;
std::optional<std::filesystem::path> mostRecentFile;
SdCardMountedIF& sdcMan;
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
void updateBaseDir();
void assignMostRecentFile();
};
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */