2022-10-21 11:51:44 +02:00
|
|
|
#include "PusTmFunnel.h"
|
|
|
|
|
2022-12-13 14:26:20 +01:00
|
|
|
#include "eive/definitions.h"
|
2022-12-13 14:19:43 +01:00
|
|
|
#include "eive/objects.h"
|
2022-12-19 13:25:45 +01:00
|
|
|
#include "fsfw/ipc/CommandMessage.h"
|
2022-10-21 11:51:44 +02:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
|
|
#include "fsfw/objectmanager.h"
|
2023-02-22 14:27:50 +01:00
|
|
|
#include "fsfw/pus/Service5EventReporting.h"
|
2022-12-19 13:25:45 +01:00
|
|
|
#include "fsfw/tmstorage/TmStoreMessage.h"
|
2022-10-21 11:51:44 +02:00
|
|
|
#include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h"
|
2023-02-22 14:27:50 +01:00
|
|
|
#include "tmtc/pusIds.h"
|
2022-10-21 11:51:44 +02:00
|
|
|
|
2023-02-08 17:43:43 +01:00
|
|
|
PusTmFunnel::PusTmFunnel(TmFunnelBase::FunnelCfg cfg, TimeReaderIF &timeReader,
|
|
|
|
SdCardMountedIF &sdcMan)
|
|
|
|
: TmFunnelBase(cfg),
|
2022-12-13 14:19:43 +01:00
|
|
|
timeReader(timeReader),
|
2023-02-24 18:10:43 +01:00
|
|
|
miscStore(objects::MISC_TM_STORE, "tm", "misc", RolloverInterval::HOURLY, 2, tmStore, sdcMan),
|
|
|
|
okStore(objects::OK_TM_STORE, "tm", "ok", RolloverInterval::MINUTELY, 30, tmStore, sdcMan),
|
|
|
|
notOkStore(objects::NOT_OK_TM_STORE, "tm", "nok", RolloverInterval::MINUTELY, 30, tmStore,
|
|
|
|
sdcMan),
|
|
|
|
hkStore(objects::HK_TM_STORE, "tm", "hk", RolloverInterval::MINUTELY, 15, tmStore, sdcMan),
|
2022-12-13 14:38:30 +01:00
|
|
|
sdcMan(sdcMan) {
|
2022-12-13 15:24:51 +01:00
|
|
|
Clock::getClock_timeval(¤tTv);
|
2022-12-13 15:43:41 +01:00
|
|
|
Clock::getUptime(&lastTvUpdate);
|
2022-12-14 11:00:07 +01:00
|
|
|
hkStore.addApid(config::EIVE_PUS_APID);
|
2023-02-22 14:21:24 +01:00
|
|
|
hkStore.addService(pus::PUS_SERVICE_3);
|
2022-12-13 14:30:16 +01:00
|
|
|
miscStore.addApid(config::EIVE_PUS_APID);
|
2023-02-22 14:21:24 +01:00
|
|
|
miscStore.addService(pus::PUS_SERVICE_17);
|
|
|
|
miscStore.addService(pus::PUS_SERVICE_2);
|
|
|
|
miscStore.addService(pus::PUS_SERVICE_200);
|
|
|
|
miscStore.addService(pus::PUS_SERVICE_201);
|
|
|
|
miscStore.addService(pus::PUS_SERVICE_9);
|
|
|
|
miscStore.addService(pus::PUS_SERVICE_20);
|
2022-12-13 15:56:40 +01:00
|
|
|
okStore.addApid(config::EIVE_PUS_APID);
|
2023-02-22 14:27:50 +01:00
|
|
|
okStore.addServiceSubservice(pus::PUS_SERVICE_5,
|
|
|
|
Service5EventReporting::Subservice::NORMAL_REPORT);
|
2023-02-22 14:21:24 +01:00
|
|
|
okStore.addService(pus::PUS_SERVICE_8);
|
|
|
|
okStore.addServiceSubservice(pus::PUS_SERVICE_1, 1);
|
|
|
|
okStore.addServiceSubservice(pus::PUS_SERVICE_1, 3);
|
|
|
|
okStore.addServiceSubservice(pus::PUS_SERVICE_1, 5);
|
|
|
|
okStore.addServiceSubservice(pus::PUS_SERVICE_1, 7);
|
2022-12-14 10:54:18 +01:00
|
|
|
notOkStore.addApid(config::EIVE_PUS_APID);
|
2023-02-22 14:21:24 +01:00
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_5, 2);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_5, 3);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_5, 4);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_1, 2);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_1, 4);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_1, 6);
|
|
|
|
notOkStore.addServiceSubservice(pus::PUS_SERVICE_1, 8);
|
2022-12-13 14:26:20 +01:00
|
|
|
}
|
2022-10-21 11:51:44 +02:00
|
|
|
|
|
|
|
PusTmFunnel::~PusTmFunnel() = default;
|
|
|
|
|
|
|
|
ReturnValue_t PusTmFunnel::performOperation(uint8_t) {
|
2022-12-19 13:25:45 +01:00
|
|
|
CommandMessage cmdMessage;
|
2023-02-22 13:27:16 +01:00
|
|
|
ReturnValue_t result;
|
|
|
|
try {
|
|
|
|
result = okStore.handleCommandQueue(ipcStore, *this);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
sif::error << "PusTmFunnel::performOperation: Issue handling OK store command" << std::endl;
|
|
|
|
}
|
|
|
|
result = notOkStore.handleCommandQueue(ipcStore, *this);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
sif::error << "PusTmFunnel::performOperation: Issue handling NOT OK store command"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
result = hkStore.handleCommandQueue(ipcStore, *this);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
sif::error << "PusTmFunnel::performOperation: Issue handling HK store command" << std::endl;
|
|
|
|
}
|
|
|
|
result = miscStore.handleCommandQueue(ipcStore, *this);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
sif::error << "PusTmFunnel::performOperation: Issue handling MISC store command" << std::endl;
|
|
|
|
}
|
|
|
|
} catch (const std::bad_optional_access &e) {
|
|
|
|
sif::error << e.what() << "when handling TM store command" << std::endl;
|
2022-12-19 13:25:45 +01:00
|
|
|
}
|
2023-02-21 20:22:24 +01:00
|
|
|
|
2022-10-21 11:51:44 +02:00
|
|
|
TmTcMessage currentMessage;
|
2023-02-19 17:06:08 +01:00
|
|
|
unsigned int count = 0;
|
2023-02-21 20:43:16 +01:00
|
|
|
result = tmQueue->receiveMessage(¤tMessage);
|
|
|
|
while (result == returnvalue::OK) {
|
|
|
|
result = handleTmPacket(currentMessage);
|
|
|
|
if (result != returnvalue::OK) {
|
2022-10-21 11:51:44 +02:00
|
|
|
sif::warning << "TmFunnel packet handling failed" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2023-02-19 17:06:08 +01:00
|
|
|
count++;
|
2023-02-21 20:43:16 +01:00
|
|
|
if (count == 500) {
|
2023-02-19 17:06:08 +01:00
|
|
|
sif::error << "PusTmFunnel: Possible message storm detected" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2023-02-21 20:43:16 +01:00
|
|
|
result = tmQueue->receiveMessage(¤tMessage);
|
2022-10-21 11:51:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 20:43:16 +01:00
|
|
|
if (result == MessageQueueIF::EMPTY) {
|
2022-10-21 11:51:44 +02:00
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
2023-02-21 20:43:16 +01:00
|
|
|
return result;
|
2022-10-21 11:51:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-08 17:43:43 +01:00
|
|
|
ReturnValue_t PusTmFunnel::handleTmPacket(TmTcMessage &message) {
|
2022-10-21 11:51:44 +02:00
|
|
|
uint8_t *packetData = nullptr;
|
|
|
|
size_t size = 0;
|
2022-11-02 10:26:45 +01:00
|
|
|
store_address_t origStoreId = message.getStorageId();
|
|
|
|
ReturnValue_t result = tmStore.modifyData(origStoreId, &packetData, &size);
|
2022-10-21 11:51:44 +02:00
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
PusTmZeroCopyWriter packet(timeReader, packetData, size);
|
|
|
|
result = packet.parseDataWithoutCrcCheck();
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "PusTmFunnel::handlePacket: Error parsing received PUS packet" << std::endl;
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
packet.setSequenceCount(sourceSequenceCount++);
|
|
|
|
sourceSequenceCount = sourceSequenceCount % ccsds::LIMIT_SEQUENCE_COUNT;
|
|
|
|
packet.updateErrorControl();
|
|
|
|
|
2023-02-20 15:17:31 +01:00
|
|
|
timeval currentUptime{};
|
2022-12-13 15:43:41 +01:00
|
|
|
Clock::getUptime(¤tUptime);
|
|
|
|
if (currentUptime.tv_sec - lastTvUpdate.tv_sec >
|
|
|
|
static_cast<signed int>(TV_UPDATE_INTERVAL_SECS)) {
|
|
|
|
Clock::getClock_timeval(¤tTv);
|
|
|
|
lastTvUpdate = currentUptime;
|
|
|
|
}
|
|
|
|
|
2022-12-14 11:00:07 +01:00
|
|
|
bool sdcUsable = sdcMan.isSdCardUsable(std::nullopt);
|
|
|
|
initStoresIfPossible(sdcUsable);
|
|
|
|
if (sdcUsable) {
|
2022-12-13 14:38:30 +01:00
|
|
|
miscStore.passPacket(packet);
|
2022-12-13 15:56:40 +01:00
|
|
|
okStore.passPacket(packet);
|
2023-02-20 15:42:04 +01:00
|
|
|
notOkStore.passPacket(packet);
|
|
|
|
hkStore.passPacket(packet);
|
2022-12-13 14:33:16 +01:00
|
|
|
}
|
2022-12-19 14:40:27 +01:00
|
|
|
return sendPacketToDestinations(origStoreId, message, packetData, size);
|
2022-10-21 11:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *PusTmFunnel::getName() const { return "PUS TM Funnel"; }
|
2022-12-13 14:30:16 +01:00
|
|
|
|
2022-12-14 11:00:07 +01:00
|
|
|
void PusTmFunnel::initStoresIfPossible(bool sdCardUsable) {
|
2023-02-22 18:06:34 +01:00
|
|
|
if (not storesInitialized and sdCardUsable and sdcMan.getCurrentMountPrefix() != nullptr) {
|
2023-02-22 13:27:16 +01:00
|
|
|
miscStore.initializeTmStore();
|
|
|
|
okStore.initializeTmStore();
|
|
|
|
hkStore.initializeTmStore();
|
|
|
|
notOkStore.initializeTmStore();
|
2022-12-13 14:38:30 +01:00
|
|
|
storesInitialized = true;
|
|
|
|
}
|
2022-12-14 11:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PusTmFunnel::initialize() {
|
|
|
|
initStoresIfPossible(sdcMan.isSdCardUsable(std::nullopt));
|
2022-12-13 14:30:16 +01:00
|
|
|
return returnvalue::OK;
|
|
|
|
}
|