2022-10-24 10:57:30 +02:00
|
|
|
#ifndef MISSION_TMTC_TMSTOREBACKEND_H_
|
|
|
|
#define MISSION_TMTC_TMSTOREBACKEND_H_
|
|
|
|
|
2022-10-25 18:20:21 +02:00
|
|
|
#include <fsfw/objectmanager/SystemObject.h>
|
2022-10-24 10:57:30 +02:00
|
|
|
#include <fsfw/tmstorage/TmStoreFrontendIF.h>
|
2022-10-25 18:20:21 +02:00
|
|
|
#include <fsfw/tmtcpacket/pus/tm/PusTmReader.h>
|
2022-10-24 10:57:30 +02:00
|
|
|
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
|
2022-11-11 15:39:27 +01:00
|
|
|
#include <mission/memory/SdCardMountedIF.h>
|
2022-10-24 10:57:30 +02:00
|
|
|
|
2022-12-12 18:17:59 +01:00
|
|
|
#include <filesystem>
|
|
|
|
|
2022-10-25 18:20:21 +02:00
|
|
|
struct PacketFilter {
|
2022-11-11 15:39:27 +01:00
|
|
|
std::optional<std::vector<uint16_t>> apid;
|
|
|
|
std::optional<std::vector<uint8_t>> services;
|
|
|
|
std::optional<std::vector<std::pair<uint8_t, uint8_t>>> serviceSubservices;
|
2022-10-25 18:20:21 +02:00
|
|
|
};
|
|
|
|
|
2022-12-12 10:06:30 +01:00
|
|
|
enum class RolloverInterval { HOURLY, DAILY };
|
|
|
|
|
2022-10-25 18:20:21 +02:00
|
|
|
class TmStore : public SystemObject {
|
2022-10-24 10:57:30 +02:00
|
|
|
public:
|
2022-12-12 18:27:01 +01:00
|
|
|
TmStore(object_id_t objectId, std::string baseName, RolloverInterval intervalUnit,
|
|
|
|
uint32_t intervalCount, PacketFilter filter, SdCardMountedIF& sdcMan);
|
2022-10-25 18:20:21 +02:00
|
|
|
|
|
|
|
ReturnValue_t passPacket(PusTmReader& reader);
|
2022-11-11 15:39:27 +01:00
|
|
|
ReturnValue_t storePacket(PusTmReader& reader);
|
2022-10-24 10:57:30 +02:00
|
|
|
|
|
|
|
private:
|
2022-12-12 10:06:30 +01:00
|
|
|
static constexpr size_t MAX_FILESIZE = 8192;
|
|
|
|
|
2022-10-24 10:57:30 +02:00
|
|
|
/**
|
|
|
|
* To get the queue where commands shall be sent.
|
|
|
|
* @return Id of command queue.
|
|
|
|
*/
|
2022-10-25 18:20:21 +02:00
|
|
|
MessageQueueId_t getCommandQueue();
|
2022-11-11 15:39:27 +01:00
|
|
|
PacketFilter filter;
|
2022-12-12 18:27:01 +01:00
|
|
|
bool baseDirUninitialized = true;
|
2022-12-12 10:06:30 +01:00
|
|
|
std::string baseName;
|
2022-12-12 18:27:01 +01:00
|
|
|
std::filesystem::path baseDir;
|
|
|
|
uint32_t rolloverDiffSeconds = 0;
|
2022-12-12 10:06:30 +01:00
|
|
|
char NAME_BUF[524] = {};
|
|
|
|
std::array<uint8_t, 8192> fileBuf{};
|
2022-12-12 18:17:59 +01:00
|
|
|
std::optional<timeval> mostRecentTv;
|
|
|
|
std::optional<std::filesystem::path> mostRecentFile;
|
2022-10-25 18:20:21 +02:00
|
|
|
SdCardMountedIF& sdcMan;
|
2022-12-12 18:27:01 +01:00
|
|
|
|
|
|
|
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
|
|
|
|
void updateBaseDir();
|
|
|
|
void assignMostRecentFile();
|
2022-10-24 10:57:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */
|