eive-obsw/mission/utility/TmFunnel.cpp

123 lines
3.8 KiB
C++
Raw Normal View History

2021-09-19 12:27:48 +02:00
#include "OBSWConfig.h"
2020-09-16 16:22:36 +02:00
#include <fsfw/ipc/QueueFactory.h>
2021-06-21 16:54:33 +02:00
#include <fsfw/tmtcpacket/pus/tm.h>
2021-06-08 16:45:25 +02:00
#include <fsfw/objectmanager/ObjectManager.h>
2020-09-16 16:22:36 +02:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
2020-09-30 17:17:01 +02:00
#include <mission/utility/TmFunnel.h>
2020-09-16 16:22:36 +02:00
object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT;
object_id_t TmFunnel::storageDestination = objects::NO_OBJECT;
2020-09-30 17:17:01 +02:00
TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth):
SystemObject(objectId), messageDepth(messageDepth) {
2020-09-16 16:22:36 +02:00
tmQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
MessageQueueMessage::MAX_MESSAGE_SIZE);
storageQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
MessageQueueMessage::MAX_MESSAGE_SIZE);
}
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);
while(status == HasReturnvaluesIF::RETURN_OK)
{
status = handlePacket(&currentMessage);
if(status != HasReturnvaluesIF::RETURN_OK){
break;
}
status = tmQueue->receiveMessage(&currentMessage);
}
if (status == MessageQueueIF::EMPTY) {
return HasReturnvaluesIF::RETURN_OK;
}
else {
return status;
}
}
ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
uint8_t* packetData = nullptr;
size_t size = 0;
2021-09-22 16:54:55 +02:00
ReturnValue_t result = tmStore->modifyData(message->getStorageId(),
2020-09-16 16:22:36 +02:00
&packetData, &size);
if(result != HasReturnvaluesIF::RETURN_OK){
return result;
}
TmPacketPusC packet(packetData);
2020-09-16 16:22:36 +02:00
packet.setPacketSequenceCount(this->sourceSequenceCount);
sourceSequenceCount++;
sourceSequenceCount = sourceSequenceCount %
SpacePacketBase::LIMIT_SEQUENCE_COUNT;
packet.setErrorControl();
result = tmQueue->sendToDefault(message);
if(result != HasReturnvaluesIF::RETURN_OK){
2021-09-22 16:54:55 +02:00
tmStore->deleteData(message->getStorageId());
2020-09-16 16:22:36 +02:00
sif::error << "TmFunnel::handlePacket: Error sending to downlink "
"handler" << std::endl;
return result;
}
2020-09-30 17:17:01 +02:00
if(storageDestination != objects::NO_OBJECT) {
2020-09-16 16:22:36 +02:00
result = storageQueue->sendToDefault(message);
if(result != HasReturnvaluesIF::RETURN_OK){
2021-09-22 16:54:55 +02:00
tmStore->deleteData(message->getStorageId());
2020-09-16 16:22:36 +02:00
sif::error << "TmFunnel::handlePacket: Error sending to storage "
"handler" << std::endl;
return result;
}
}
return result;
}
ReturnValue_t TmFunnel::initialize() {
2021-09-22 16:54:55 +02:00
tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if(tmStore == nullptr) {
2020-09-16 16:22:36 +02:00
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 =
2021-06-08 16:45:25 +02:00
ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination);
2020-09-16 16:22:36 +02:00
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;
}
2021-09-19 12:27:48 +02:00
2021-09-26 08:29:30 +02:00
#if OBSW_TM_TO_PTME == 1
2021-09-19 12:27:48 +02:00
// Live TM will be sent via the virtual channel 0
2021-09-30 09:34:01 +02:00
tmQueue->setDefaultDestination(tmTarget->getReportReceptionQueue(config::LIVE_TM));
2021-09-19 12:27:48 +02:00
#else
2020-09-16 16:22:36 +02:00
tmQueue->setDefaultDestination(tmTarget->getReportReceptionQueue());
2021-09-26 08:29:30 +02:00
#endif /* OBSW_TM_TO_PTME == 1 */
2020-09-16 16:22:36 +02:00
2020-09-30 17:17:01 +02:00
// Storage destination is optional.
if(storageDestination == objects::NO_OBJECT) {
return SystemObject::initialize();
}
2020-09-16 16:22:36 +02:00
AcceptsTelemetryIF* storageTarget =
2021-06-08 16:45:25 +02:00
ObjectManager::instance()->get<AcceptsTelemetryIF>(storageDestination);
2020-09-16 16:22:36 +02:00
if(storageTarget != nullptr) {
storageQueue->setDefaultDestination(
storageTarget->getReportReceptionQueue());
}
return SystemObject::initialize();
}