Persistent Tm Store now has dump state
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
2023-03-09 13:15:42 +01:00
parent 49e3002abc
commit eb61996f91
3 changed files with 133 additions and 50 deletions

View File

@ -7,17 +7,22 @@
#include <fsfw/tmtcpacket/pus/tm/PusTmReader.h>
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
#include <mission/memory/SdCardMountedIF.h>
#include <mission/tmtc/DirectTmSinkIF.h>
#include <filesystem>
#include "TmFunnelBase.h"
#include "eive/eventSubsystemIds.h"
#include "eive/resultClassIds.h"
enum class RolloverInterval { MINUTELY, HOURLY, DAILY };
class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
public:
enum class State { IDLE, DUMPING };
static constexpr uint8_t INTERFACE_ID = CLASS_ID::PERSISTENT_TM_STORE;
static constexpr ReturnValue_t DUMP_DONE = returnvalue::makeCode(INTERFACE_ID, 0);
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PERSISTENT_TM_STORE;
//! [EXPORT] : [COMMENT]
@ -25,6 +30,9 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
//! P2: Timestamp of possibly corrupt file as a unix timestamp.
static constexpr Event POSSIBLE_FILE_CORRUPTION =
event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
//! [EXPORT] : [COMMENT] File in store too large. P1: Detected file size
//! P2: Allowed file size
static constexpr Event FILE_TOO_LARGE = event::makeEvent(SUBSYSTEM_ID, 1, severity::LOW);
PersistentTmStore(object_id_t objectId, const char* baseDir, std::string baseName,
RolloverInterval intervalUnit, uint32_t intervalCount,
StorageManagerIF& tmStore, SdCardMountedIF& sdcMan);
@ -35,7 +43,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
void deleteUpTo(uint32_t unixSeconds);
ReturnValue_t startDumpFrom(uint32_t fromUnixSeconds);
ReturnValue_t startDumpFromUpTo(uint32_t fromUnixSeconds, uint32_t upToUnixSeconds);
ReturnValue_t dumpNextPacket(size_t& dumpedLen);
ReturnValue_t dumpNextPacket(DirectTmSinkIF& tmSink, size_t& dumpedLen);
// ReturnValue_t passPacket(PusTmReader& reader);
ReturnValue_t storePacket(PusTmReader& reader);
@ -46,6 +54,9 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
// ISO8601 timestamp.
static constexpr char FILE_DATE_FORMAT[] = "%FT%H%M%SZ";
//! [EXPORT] : [SKIP]
static constexpr ReturnValue_t INVALID_FILE_DETECTED_AND_DELETED = returnvalue::makeCode(2, 1);
MessageQueueIF* tcQueue;
State state = State::IDLE;
// PacketFilter filter;
@ -59,10 +70,17 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
std::array<uint8_t, MAX_FILESIZE> fileBuf{};
timeval currentTv;
timeval activeFileTv{};
std::filesystem::directory_iterator activeDumpDirIter;
std::filesystem::path activeDumpFile;
size_t activeDumpFileSize = 0;
size_t activeDumpCurrentSize = 0;
struct ActiveDumpParams {
uint32_t fromUnixTime = 0;
uint32_t untilUnixTime = 0;
uint32_t currentFileUnixStamp = 0;
std::filesystem::directory_iterator dirIter;
std::filesystem::directory_entry dirEntry;
size_t fileSize = 0;
size_t currentSize = 0;
};
ActiveDumpParams dumpParams;
std::optional<std::filesystem::path> activeFile;
SdCardMountedIF& sdcMan;
StorageManagerIF& tmStore;
@ -77,6 +95,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
ReturnValue_t createMostRecentFile(std::optional<uint8_t> suffix);
static ReturnValue_t pathToTime(const std::filesystem::path& path, struct tm& time);
void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp);
ReturnValue_t loadNextDumpFile();
bool updateBaseDir();
ReturnValue_t assignAndOrCreateMostRecentFile();
};