Refactor TM handling #450

Merged
muellerr merged 47 commits from refactor_tm_handling into develop 2023-03-11 15:05:22 +01:00
5 changed files with 72 additions and 40 deletions
Showing only changes of commit 49e3002abc - Show all commits

View File

@ -1,6 +1,7 @@
#ifndef LINUX_OBC_VCINTERFACEIF_H_
#define LINUX_OBC_VCINTERFACEIF_H_
#include <mission/tmtc/DirectTmSinkIF.h>
#include <stddef.h>
#include "fsfw/returnvalues/returnvalue.h"
@ -8,22 +9,14 @@
/**
* @brief Interface class for managing different virtual channels of the PTME IP core implemented
* in the programmable logic.
*
* @details
* Also implements @DirectTmSinkIF to allow wiriting to the VC directly.
* @author J. Meier
*/
class VcInterfaceIF {
class VcInterfaceIF : public DirectTmSinkIF {
public:
virtual ~VcInterfaceIF(){};
/**
* @brief Implememts the functionality to write data in the virtual channel of the PTME IP
* Core.
*
* @param data Pointer to buffer holding the data to write
* @param size Number of bytes to write
*/
virtual ReturnValue_t write(const uint8_t* data, size_t size) = 0;
virtual ReturnValue_t initialize() = 0;
};

View File

@ -0,0 +1,21 @@
#ifndef MISSION_TMTC_DIRECTTMSINKIF_H_
#define MISSION_TMTC_DIRECTTMSINKIF_H_
#include <cstddef>
#include "fsfw/retval.h"
class DirectTmSinkIF {
public:
virtual ~DirectTmSinkIF() = default;
/**
* @brief Implememts the functionality to write to a TM sink directly
*
* @param data Pointer to buffer holding the data to write
* @param size Number of bytes to write
*/
virtual ReturnValue_t write(const uint8_t* data, size_t size) = 0;
};
#endif /* MISSION_TMTC_DIRECTTMSINKIF_H_ */

View File

@ -69,14 +69,14 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&dumpUntilUnixSeconds, accessor.second.data() + 4, &size,
SerializeIF::Endianness::NETWORK);
dumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds);
startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds);
}
}
return returnvalue::OK;
}
void PersistentTmStore::dumpFrom(uint32_t fromUnixSeconds) {
return dumpFromUpTo(fromUnixSeconds, currentTv.tv_sec);
ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) {
return startDumpFromUpTo(fromUnixSeconds, currentTv.tv_sec);
}
ReturnValue_t PersistentTmStore::storePacket(PusTmReader& reader) {
@ -155,7 +155,7 @@ void PersistentTmStore::deleteUpTo(uint32_t unixSeconds) {
}
// Convert file time to the UNIX epoch
struct tm fileTime {};
if (pathToTm(file.path(), fileTime) != returnvalue::OK) {
if (pathToTime(file.path(), fileTime) != returnvalue::OK) {
sif::error << "Time extraction for " << file << "failed" << std::endl;
continue;
}
@ -166,32 +166,30 @@ void PersistentTmStore::deleteUpTo(uint32_t unixSeconds) {
}
}
void PersistentTmStore::dumpFromUpTo(uint32_t fromUnixSeconds, uint32_t upToUnixSeconds) {
ReturnValue_t PersistentTmStore::startDumpFromUpTo(uint32_t fromUnixSeconds,
uint32_t upToUnixSeconds) {
using namespace std::filesystem;
for (auto const& file : directory_iterator(basePath)) {
if (file.is_directory()) {
continue;
}
struct tm fileTime {};
if (pathToTm(file.path(), fileTime) != returnvalue::OK) {
sif::error << "Time extraction for file " << file << "failed" << std::endl;
continue;
}
auto fileEpoch = static_cast<uint32_t>(timegm(&fileTime));
if ((fileEpoch > fromUnixSeconds) and (fileEpoch + rolloverDiffSeconds <= upToUnixSeconds)) {
fileToPackets(file, fileEpoch);
}
}
}
ReturnValue_t PersistentTmStore::pathToTm(const std::filesystem::path& path, struct tm& time) {
auto pathStr = path.string();
size_t splitChar = pathStr.find('_');
auto timeOnlyStr = pathStr.substr(splitChar + 1);
if (nullptr == strptime(timeOnlyStr.c_str(), FILE_DATE_FORMAT, &time)) {
if (state == State::DUMPING) {
return returnvalue::FAILED;
}
activeDumpDirIter = directory_iterator(basePath);
state = State::DUMPING;
return returnvalue::OK;
// for (auto const& file : directory_iterator(basePath)) {
// if (file.is_directory()) {
// continue;
// }
// struct tm fileTime {};
// if (pathToTm(file.path(), fileTime) != returnvalue::OK) {
// sif::error << "Time extraction for file " << file << "failed" << std::endl;
// continue;
// }
// auto fileEpoch = static_cast<uint32_t>(timegm(&fileTime));
// if ((fileEpoch > fromUnixSeconds) and (fileEpoch + rolloverDiffSeconds <= upToUnixSeconds))
// {
// fileToPackets(file, fileEpoch);
// }
// }
}
void PersistentTmStore::fileToPackets(const std::filesystem::path& path, uint32_t unixStamp) {
@ -227,6 +225,18 @@ void PersistentTmStore::fileToPackets(const std::filesystem::path& path, uint32_
}
}
ReturnValue_t PersistentTmStore::dumpNextPacket(size_t& dumpedLen) {}
ReturnValue_t PersistentTmStore::pathToTime(const std::filesystem::path& path, struct tm& time) {
auto pathStr = path.string();
size_t splitChar = pathStr.find('_');
auto timeOnlyStr = pathStr.substr(splitChar + 1);
if (nullptr == strptime(timeOnlyStr.c_str(), FILE_DATE_FORMAT, &time)) {
return returnvalue::FAILED;
}
return returnvalue::OK;
}
ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional<uint8_t> suffix) {
using namespace std::filesystem;
unsigned currentIdx = 0;

View File

@ -17,6 +17,7 @@ enum class RolloverInterval { MINUTELY, HOURLY, DAILY };
class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
public:
enum class State { IDLE, DUMPING };
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PERSISTENT_TM_STORE;
//! [EXPORT] : [COMMENT]
@ -32,8 +33,9 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore, TmFunnelBase& tmFunnel);
void deleteUpTo(uint32_t unixSeconds);
void dumpFrom(uint32_t fromUnixSeconds);
void dumpFromUpTo(uint32_t fromUnixSeconds, uint32_t upToUnixSeconds);
ReturnValue_t startDumpFrom(uint32_t fromUnixSeconds);
ReturnValue_t startDumpFromUpTo(uint32_t fromUnixSeconds, uint32_t upToUnixSeconds);
ReturnValue_t dumpNextPacket(size_t& dumpedLen);
// ReturnValue_t passPacket(PusTmReader& reader);
ReturnValue_t storePacket(PusTmReader& reader);
@ -45,6 +47,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
static constexpr char FILE_DATE_FORMAT[] = "%FT%H%M%SZ";
MessageQueueIF* tcQueue;
State state = State::IDLE;
// PacketFilter filter;
CdsShortTimeStamper timeReader;
bool baseDirUninitialized = true;
@ -56,6 +59,10 @@ 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;
std::optional<std::filesystem::path> activeFile;
SdCardMountedIF& sdcMan;
StorageManagerIF& tmStore;
@ -68,7 +75,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
ReturnValue_t createMostRecentFile(std::optional<uint8_t> suffix);
static ReturnValue_t pathToTm(const std::filesystem::path& path, struct tm& time);
static ReturnValue_t pathToTime(const std::filesystem::path& path, struct tm& time);
void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp);
bool updateBaseDir();
ReturnValue_t assignAndOrCreateMostRecentFile();

View File

@ -4,6 +4,7 @@
#include <fsfw/ipc/messageQueueDefinitions.h>
#include <fsfw/storagemanager/StorageManagerIF.h>
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
#include <fsfw/tmtcservices/TmTcMessage.h>
#include <vector>