2022-11-02 10:26:45 +01:00
|
|
|
#include "TmFunnelBase.h"
|
|
|
|
|
2022-12-19 14:40:27 +01:00
|
|
|
#include <fsfw/tmtcservices/TmTcMessage.h>
|
|
|
|
|
2023-06-25 12:41:20 +02:00
|
|
|
#include <atomic>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
|
2022-11-02 10:26:45 +01:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
|
|
|
2023-02-08 17:43:43 +01:00
|
|
|
TmFunnelBase::TmFunnelBase(FunnelCfg cfg)
|
2023-03-09 11:46:13 +01:00
|
|
|
: SystemObject(cfg.objectId),
|
|
|
|
name(cfg.name),
|
|
|
|
tmStore(cfg.tmStore),
|
|
|
|
ipcStore(cfg.ipcStore),
|
|
|
|
tmQueue(QueueFactory::instance()->createMessageQueue(cfg.tmMsgDepth)),
|
2023-06-25 12:41:20 +02:00
|
|
|
liveDemux(*tmQueue),
|
|
|
|
sdcMan(cfg.sdcMan),
|
|
|
|
sequenceCounterFilename(cfg.sequenceCounterFilename),
|
|
|
|
saveSequenceCount(cfg.saveSequenceCount) {}
|
2023-03-09 11:46:13 +01:00
|
|
|
|
|
|
|
ReturnValue_t TmFunnelBase::demultiplexLivePackets(store_address_t origStoreId,
|
|
|
|
const uint8_t *tmData, size_t tmSize) {
|
|
|
|
return liveDemux.demultiplexPackets(tmStore, origStoreId, tmData, tmSize);
|
2022-11-02 10:26:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TmFunnelBase::~TmFunnelBase() { QueueFactory::instance()->deleteMessageQueue(tmQueue); }
|
|
|
|
|
|
|
|
MessageQueueId_t TmFunnelBase::getReportReceptionQueue(uint8_t virtualChannel) const {
|
|
|
|
return tmQueue->getId();
|
|
|
|
}
|
|
|
|
|
2023-09-11 19:23:48 +02:00
|
|
|
uint32_t TmFunnelBase::addLiveDestination(const char *name,
|
|
|
|
const AcceptsTelemetryIF &downlinkDestination,
|
|
|
|
uint8_t vcid) {
|
|
|
|
return liveDemux.addDestination(name, downlinkDestination, vcid);
|
2022-12-19 14:40:27 +01:00
|
|
|
}
|
2023-06-25 12:41:20 +02:00
|
|
|
|
|
|
|
ReturnValue_t TmFunnelBase::initialize() {
|
|
|
|
using namespace std::filesystem;
|
|
|
|
// The filesystem should always be available at the start.. Let's assume it always is, otherwise
|
|
|
|
// we just live with a regular 0 initialization. It simplifies a lot.
|
|
|
|
std::error_code e;
|
2023-06-26 11:14:11 +02:00
|
|
|
path filePath =
|
|
|
|
path(path(sdcMan.getCurrentMountPrefix()) / path("conf") / path(sequenceCounterFilename));
|
2023-06-25 12:41:20 +02:00
|
|
|
if (exists(filePath, e)) {
|
|
|
|
std::ifstream ifile(filePath);
|
|
|
|
if (ifile.bad()) {
|
|
|
|
sif::error << "TmFunnelBase::initialize: Faulty file open for sequence counter initialization"
|
|
|
|
<< std::endl;
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
|
|
|
if (not(ifile >> sourceSequenceCount)) {
|
|
|
|
// Initialize to 0 in any case if reading a number failed.
|
|
|
|
sourceSequenceCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmFunnelBase::saveSequenceCountToFile() {
|
|
|
|
using namespace std::filesystem;
|
|
|
|
std::error_code e;
|
2023-06-26 11:14:11 +02:00
|
|
|
path filePath =
|
|
|
|
path(path(sdcMan.getCurrentMountPrefix()) / path("conf") / path(sequenceCounterFilename));
|
2023-06-25 12:41:20 +02:00
|
|
|
std::ofstream ofile(filePath);
|
|
|
|
if (ofile.bad()) {
|
|
|
|
return returnvalue::FAILED;
|
|
|
|
}
|
|
|
|
ofile << sourceSequenceCount << "\n";
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
2023-09-11 20:16:54 +02:00
|
|
|
|
|
|
|
uint32_t TmFunnelBase::addLiveDestinationByRawId(const char *name,
|
|
|
|
MessageQueueId_t downlinkDestination,
|
|
|
|
uint8_t vcid) {
|
|
|
|
return liveDemux.addDestinationByRawId(name, downlinkDestination, vcid);
|
|
|
|
}
|