eive-obsw/mission/tmtc/PersistentTmStore.h

86 lines
3.0 KiB
C
Raw Normal View History

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>
2023-02-07 12:19:13 +01:00
#include <fsfw/timemanager/CdsShortTimeStamper.h>
2023-02-21 20:43:16 +01:00
#include <fsfw/tmstorage/TmStoreFrontendSimpleIF.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-12-19 14:40:27 +01:00
#include "TmFunnelBase.h"
2023-02-07 12:19:13 +01:00
#include "eive/eventSubsystemIds.h"
2022-12-19 14:40:27 +01:00
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-13 15:34:13 +01:00
enum class RolloverInterval { MINUTELY, HOURLY, DAILY };
2022-12-12 10:06:30 +01:00
2023-02-21 21:37:30 +01:00
class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
2022-10-24 10:57:30 +02:00
public:
2023-02-07 12:19:13 +01:00
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PERSISTENT_TM_STORE;
//! [EXPORT] : [COMMENT]
//! P1: Result code of TM packet parser.
//! P2: Timestamp of possibly corrupt file as a unix timestamp.
static constexpr Event POSSIBLE_FILE_CORRUPTION =
event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
2023-02-21 21:37:30 +01:00
PersistentTmStore(object_id_t objectId, const char* baseDir, std::string baseName,
RolloverInterval intervalUnit, uint32_t intervalCount, timeval& currentTv,
StorageManagerIF& tmStore, SdCardMountedIF& sdcMan);
2022-12-13 14:19:43 +01:00
2023-02-22 13:27:16 +01:00
ReturnValue_t initializeTmStore();
2023-02-21 20:43:16 +01:00
ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore, TmFunnelBase& tmFunnel);
2022-12-13 14:19:43 +01:00
void addApid(uint16_t apid);
void addService(uint8_t service);
2022-12-13 15:56:40 +01:00
void addServiceSubservice(uint8_t service, uint8_t subservice);
2022-10-25 18:20:21 +02:00
2022-12-19 13:25:45 +01:00
void deleteUpTo(uint32_t unixSeconds);
2023-02-07 15:22:01 +01:00
void dumpFrom(uint32_t fromUnixSeconds, TmFunnelBase& tmFunnel);
2022-12-19 14:40:27 +01:00
void dumpFromUpTo(uint32_t fromUnixSeconds, uint32_t upToUnixSeconds, TmFunnelBase& tmFunnel);
2022-12-19 13:25:45 +01:00
2022-10-25 18:20:21 +02:00
ReturnValue_t passPacket(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;
2023-02-22 13:27:16 +01:00
// ISO8601 timestamp.
static constexpr char FILE_DATE_FORMAT[] = "%FT%H%M%SZ";
2022-12-12 10:06:30 +01:00
2023-02-21 20:43:16 +01:00
MessageQueueIF* tcQueue;
2022-11-11 15:39:27 +01:00
PacketFilter filter;
2023-02-07 12:19:13 +01:00
CdsShortTimeStamper timeReader;
2022-12-12 18:27:01 +01:00
bool baseDirUninitialized = true;
2022-12-14 10:35:30 +01:00
const char* baseDir;
2022-12-12 10:06:30 +01:00
std::string baseName;
2022-12-14 10:34:23 +01:00
std::filesystem::path basePath;
2022-12-12 18:27:01 +01:00
uint32_t rolloverDiffSeconds = 0;
2022-12-13 15:34:13 +01:00
std::array<uint8_t, MAX_FILESIZE> fileBuf{};
timeval& currentTv;
2023-02-22 13:27:16 +01:00
timeval activeFileTv{};
std::optional<std::filesystem::path> activeFile;
2022-10-25 18:20:21 +02:00
SdCardMountedIF& sdcMan;
2023-02-07 12:19:13 +01:00
StorageManagerIF& tmStore;
2022-12-12 18:27:01 +01:00
2023-02-21 20:43:16 +01:00
/**
* To get the queue where commands shall be sent.
* @return Id of command queue.
*/
[[nodiscard]] MessageQueueId_t getCommandQueue() const override;
2022-12-12 18:27:01 +01:00
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
2023-02-22 13:27:16 +01:00
ReturnValue_t createMostRecentFile();
static ReturnValue_t pathToTm(const std::filesystem::path& path, struct tm& time);
2023-02-07 12:19:13 +01:00
void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp, TmFunnelBase& funnel);
2023-02-22 18:06:34 +01:00
bool updateBaseDir();
2023-02-22 13:27:16 +01:00
ReturnValue_t assignAndOrCreateMostRecentFile();
2022-12-13 14:30:16 +01:00
ReturnValue_t storePacket(PusTmReader& reader);
2022-10-24 10:57:30 +02:00
};
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */