eive-obsw/mission/tmtc/PusTmFunnel.cpp

171 lines
6.2 KiB
C++
Raw Normal View History

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"
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"
PusTmFunnel::PusTmFunnel(object_id_t objectId, TimeReaderIF &timeReader, StorageManagerIF &tmStore,
2022-12-19 13:57:05 +01:00
SdCardMountedIF &sdcMan, uint32_t tmMsgDepth, uint32_t tcMsgDepth,
StorageManagerIF &ipcStore)
: TmFunnelBase(objectId, tmStore, tmMsgDepth, tcMsgDepth, ipcStore),
2022-12-13 14:19:43 +01:00
timeReader(timeReader),
2022-12-14 10:54:18 +01:00
miscStore(objects::MISC_TM_STORE, "tm", "misc", RolloverInterval::HOURLY, 2, currentTv,
sdcMan),
okStore(objects::OK_TM_STORE, "tm", "ok", RolloverInterval::MINUTELY, 30, currentTv, sdcMan),
notOkStore(objects::NOT_OK_TM_STORE, "tm", "nok", RolloverInterval::MINUTELY, 30, currentTv,
2022-12-14 10:42:16 +01:00
sdcMan),
2022-12-14 10:54:18 +01:00
hkStore(objects::HK_TM_STORE, "tm", "hk", RolloverInterval::MINUTELY, 15, currentTv, sdcMan),
2022-12-13 14:38:30 +01:00
sdcMan(sdcMan) {
Clock::getClock_timeval(&currentTv);
2022-12-13 15:43:41 +01:00
Clock::getUptime(&lastTvUpdate);
hkStore.addApid(config::EIVE_PUS_APID);
hkStore.addService(3);
2022-12-13 14:30:16 +01:00
miscStore.addApid(config::EIVE_PUS_APID);
miscStore.addService(17);
2022-12-14 15:09:57 +01:00
miscStore.addService(2);
2022-12-14 10:54:18 +01:00
miscStore.addService(200);
2022-12-13 15:56:40 +01:00
okStore.addApid(config::EIVE_PUS_APID);
okStore.addServiceSubservice(5, 1);
2022-12-14 10:34:23 +01:00
okStore.addApid(config::EIVE_PUS_APID);
2022-12-14 10:54:18 +01:00
okStore.addService(8);
2022-12-14 10:34:23 +01:00
okStore.addServiceSubservice(1, 1);
okStore.addServiceSubservice(1, 3);
okStore.addServiceSubservice(1, 5);
okStore.addServiceSubservice(1, 7);
2022-12-14 10:54:18 +01:00
notOkStore.addApid(config::EIVE_PUS_APID);
notOkStore.addServiceSubservice(5, 2);
notOkStore.addServiceSubservice(5, 3);
notOkStore.addServiceSubservice(5, 4);
notOkStore.addServiceSubservice(1, 2);
notOkStore.addServiceSubservice(1, 4);
notOkStore.addServiceSubservice(1, 6);
notOkStore.addServiceSubservice(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;
ReturnValue_t status = tcQueue->receiveMessage(&cmdMessage);
while (status == returnvalue::OK) {
2022-12-19 13:57:05 +01:00
if (cmdMessage.getMessageType() == messagetypes::TM_STORE) {
Command_t cmd = cmdMessage.getCommand();
2022-12-19 13:25:45 +01:00
object_id_t objectId = TmStoreMessage::getObjectId(&cmdMessage);
2022-12-19 13:57:05 +01:00
TmStore *tmStore = nullptr;
2022-12-19 13:25:45 +01:00
switch (objectId) {
case (objects::HK_TM_STORE): {
2022-12-19 13:57:05 +01:00
tmStore = &hkStore;
2022-12-19 13:25:45 +01:00
break;
}
case (objects::OK_TM_STORE): {
2022-12-19 13:57:05 +01:00
tmStore = &okStore;
2022-12-19 13:25:45 +01:00
break;
}
case (objects::NOT_OK_TM_STORE): {
2022-12-19 13:57:05 +01:00
tmStore = &notOkStore;
2022-12-19 13:25:45 +01:00
break;
}
case (objects::MISC_TM_STORE): {
2022-12-19 13:57:05 +01:00
tmStore = &miscStore;
2022-12-19 13:25:45 +01:00
break;
}
default: {
}
}
2022-12-19 13:57:05 +01:00
if (tmStore == nullptr) {
continue;
}
if (cmd == TmStoreMessage::DELETE_STORE_CONTENT_TIME) {
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
uint32_t deleteUpToUnixSeconds = 0;
size_t size = accessor.second.size();
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK);
tmStore->deleteUpTo(deleteUpToUnixSeconds);
} else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
2022-12-19 14:01:15 +01:00
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
uint32_t dumpFromUnixSeconds;
uint32_t dumpUntilUnixSeconds;
size_t size = accessor.second.size();
SerializeAdapter::deSerialize(&dumpFromUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&dumpUntilUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK);
// TODO: TM store missing, and maybe there is a better way to do this?
2022-12-19 14:40:27 +01:00
tmStore->dumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds, *this);
2022-12-19 13:57:05 +01:00
}
2022-12-19 13:25:45 +01:00
}
}
2022-10-21 11:51:44 +02:00
TmTcMessage currentMessage;
2022-12-19 13:25:45 +01:00
status = tmQueue->receiveMessage(&currentMessage);
2022-10-21 11:51:44 +02:00
while (status == returnvalue::OK) {
status = handlePacket(currentMessage);
if (status != returnvalue::OK) {
sif::warning << "TmFunnel packet handling failed" << std::endl;
break;
}
status = tmQueue->receiveMessage(&currentMessage);
}
return status;
}
ReturnValue_t PusTmFunnel::handlePacket(TmTcMessage &message) {
uint8_t *packetData = nullptr;
size_t size = 0;
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();
2022-12-13 15:43:41 +01:00
timeval currentUptime;
Clock::getUptime(&currentUptime);
if (currentUptime.tv_sec - lastTvUpdate.tv_sec >
static_cast<signed int>(TV_UPDATE_INTERVAL_SECS)) {
Clock::getClock_timeval(&currentTv);
lastTvUpdate = currentUptime;
}
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);
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
void PusTmFunnel::initStoresIfPossible(bool sdCardUsable) {
if (not storesInitialized and sdCardUsable) {
2022-12-13 14:38:30 +01:00
miscStore.updateBaseDir();
2022-12-13 15:56:40 +01:00
okStore.updateBaseDir();
hkStore.updateBaseDir();
notOkStore.updateBaseDir();
2022-12-13 14:38:30 +01:00
storesInitialized = true;
}
}
ReturnValue_t PusTmFunnel::initialize() {
initStoresIfPossible(sdcMan.isSdCardUsable(std::nullopt));
2022-12-13 14:30:16 +01:00
return returnvalue::OK;
}