eive-obsw/mission/tmtc/TmFunnel.cpp

124 lines
4.1 KiB
C++
Raw Normal View History

2022-06-23 12:05:56 +02:00
#include <fsfw/ipc/QueueFactory.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
2022-08-15 11:57:57 +02:00
#include <fsfw/timemanager/CdsShortTimeStamper.h>
2022-06-23 12:05:56 +02:00
#include <fsfw/tmtcpacket/pus/tm.h>
#include <mission/tmtc/TmFunnel.h>
#include "OBSWConfig.h"
object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT;
object_id_t TmFunnel::storageDestination = objects::NO_OBJECT;
2022-08-15 11:57:57 +02:00
TmFunnel::TmFunnel(object_id_t objectId, CdsShortTimeStamper& timeReader, uint32_t messageDepth,
uint8_t reportReceptionVc)
: SystemObject(objectId),
timeReader(timeReader),
messageDepth(messageDepth),
reportReceptionVc(reportReceptionVc) {
2022-06-23 12:05:56 +02:00
auto mqArgs = MqArgs(objectId, static_cast<void*>(this));
tmQueue = QueueFactory::instance()->createMessageQueue(
messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
storageQueue = QueueFactory::instance()->createMessageQueue(
messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
TmFunnel::~TmFunnel() {}
MessageQueueId_t TmFunnel::getReportReceptionQueue(uint8_t virtualChannel) {
return tmQueue->getId();
}
ReturnValue_t TmFunnel::performOperation(uint8_t operationCode) {
TmTcMessage currentMessage;
ReturnValue_t status = tmQueue->receiveMessage(&currentMessage);
2022-08-24 17:27:47 +02:00
while (status == returnvalue::OK) {
2022-06-23 12:05:56 +02:00
status = handlePacket(&currentMessage);
2022-08-24 17:27:47 +02:00
if (status != returnvalue::OK) {
2022-06-23 12:05:56 +02:00
break;
}
status = tmQueue->receiveMessage(&currentMessage);
}
if (status == MessageQueueIF::EMPTY) {
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-06-23 12:05:56 +02:00
} else {
return status;
}
}
ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
uint8_t* packetData = nullptr;
size_t size = 0;
ReturnValue_t result = tmStore->modifyData(message->getStorageId(), &packetData, &size);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-06-23 12:05:56 +02:00
return result;
}
2022-08-15 11:57:57 +02:00
PusTmZeroCopyWriter packet(timeReader, packetData, size);
result = packet.parseDataWithoutCrcCheck();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-15 11:57:57 +02:00
return result;
}
packet.setSequenceCount(sourceSequenceCount++);
sourceSequenceCount = sourceSequenceCount % ccsds::LIMIT_SEQUENCE_COUNT;
packet.updateErrorControl();
2022-06-23 12:05:56 +02:00
result = tmQueue->sendToDefault(message);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-06-23 12:05:56 +02:00
tmStore->deleteData(message->getStorageId());
sif::error << "TmFunnel::handlePacket: Error sending to downlink "
"handler"
<< std::endl;
return result;
}
if (storageDestination != objects::NO_OBJECT) {
result = storageQueue->sendToDefault(message);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-06-23 12:05:56 +02:00
tmStore->deleteData(message->getStorageId());
sif::error << "TmFunnel::handlePacket: Error sending to storage "
"handler"
<< std::endl;
return result;
}
}
return result;
}
ReturnValue_t TmFunnel::initialize() {
tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (tmStore == nullptr) {
sif::error << "TmFunnel::initialize: TM store not set." << std::endl;
sif::error << "Make sure the tm store is set up properly"
" and implements StorageManagerIF"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
AcceptsTelemetryIF* tmTarget =
ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination);
if (tmTarget == nullptr) {
sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl;
sif::error << "Make sure the downlink destination object is set up "
"properly and implements AcceptsTelemetryIF"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmQueue->setDefaultDestination(tmTarget->getReportReceptionQueue(reportReceptionVc));
// Storage destination is optional.
if (storageDestination == objects::NO_OBJECT) {
return SystemObject::initialize();
}
AcceptsTelemetryIF* storageTarget =
ObjectManager::instance()->get<AcceptsTelemetryIF>(storageDestination);
if (storageTarget != nullptr) {
2022-08-15 11:57:57 +02:00
storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue(0));
2022-06-23 12:05:56 +02:00
}
return SystemObject::initialize();
}