From af039c540a4fea796534b57aa69e704fe69d0ac3 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Jun 2022 12:05:56 +0200 Subject: [PATCH] moved TmFunnel --- bsp_te0720_1cfa/ObjectFactory.cpp | 4 ++ fsfw | 2 +- mission/tmtc/CCSDSHandler.cpp | 3 +- mission/tmtc/TmFunnel.cpp | 114 ++++++++++++++++++++++++++++++ mission/tmtc/TmFunnel.h | 49 +++++++++++++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 mission/tmtc/TmFunnel.cpp create mode 100644 mission/tmtc/TmFunnel.h diff --git a/bsp_te0720_1cfa/ObjectFactory.cpp b/bsp_te0720_1cfa/ObjectFactory.cpp index c9ca8a43..8c88a37a 100644 --- a/bsp_te0720_1cfa/ObjectFactory.cpp +++ b/bsp_te0720_1cfa/ObjectFactory.cpp @@ -43,7 +43,11 @@ void Factory::setStaticFrameworkObjectIds() { CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR; CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; +#if OBSW_TM_TO_PTME == 1 + TmFunnel::downlinkDestination = objects::CCSDS_HANDLER; +#else TmFunnel::downlinkDestination = objects::TMTC_BRIDGE; +#endif TmFunnel::storageDestination = objects::NO_OBJECT; VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; diff --git a/fsfw b/fsfw index cda81fc8..36669fd4 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit cda81fc8415c3873c035aa7ebbfa3fe93d519f08 +Subproject commit 36669fd4d914a2397a0c64e3292dde7145b1f077 diff --git a/mission/tmtc/CCSDSHandler.cpp b/mission/tmtc/CCSDSHandler.cpp index 6cedeb36..65c8182c 100644 --- a/mission/tmtc/CCSDSHandler.cpp +++ b/mission/tmtc/CCSDSHandler.cpp @@ -130,7 +130,8 @@ ReturnValue_t CCSDSHandler::initialize() { } #if OBSW_SYRLINKS_SIMULATED == 1 - ptmeConfig->invertTxClock(true); + // Update data on rising edge + ptmeConfig->invertTxClock(false); #endif /* OBSW_SYRLINKS_SIMULATED == 1*/ return result; diff --git a/mission/tmtc/TmFunnel.cpp b/mission/tmtc/TmFunnel.cpp new file mode 100644 index 00000000..2eada527 --- /dev/null +++ b/mission/tmtc/TmFunnel.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include + +#include "OBSWConfig.h" + +object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT; +object_id_t TmFunnel::storageDestination = objects::NO_OBJECT; + +TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth, uint8_t reportReceptionVc) + : SystemObject(objectId), messageDepth(messageDepth), reportReceptionVc(reportReceptionVc) { + auto mqArgs = MqArgs(objectId, static_cast(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(¤tMessage); + while (status == HasReturnvaluesIF::RETURN_OK) { + status = handlePacket(¤tMessage); + if (status != HasReturnvaluesIF::RETURN_OK) { + break; + } + status = tmQueue->receiveMessage(¤tMessage); + } + + 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; + ReturnValue_t result = tmStore->modifyData(message->getStorageId(), &packetData, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + TmPacketPusC packet(packetData); + packet.setPacketSequenceCount(this->sourceSequenceCount); + sourceSequenceCount++; + sourceSequenceCount = sourceSequenceCount % SpacePacketBase::LIMIT_SEQUENCE_COUNT; + packet.setErrorControl(); + + result = tmQueue->sendToDefault(message); + if (result != HasReturnvaluesIF::RETURN_OK) { + 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); + if (result != HasReturnvaluesIF::RETURN_OK) { + 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(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(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(storageDestination); + if (storageTarget != nullptr) { + storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue()); + } + + return SystemObject::initialize(); +} diff --git a/mission/tmtc/TmFunnel.h b/mission/tmtc/TmFunnel.h new file mode 100644 index 00000000..f11dce63 --- /dev/null +++ b/mission/tmtc/TmFunnel.h @@ -0,0 +1,49 @@ +#ifndef MISSION_UTILITY_TMFUNNEL_H_ +#define MISSION_UTILITY_TMFUNNEL_H_ + +#include +#include +#include +#include +#include + +namespace Factory { +void setStaticFrameworkObjectIds(); +} + +/** + * @brief TM Recipient. + * @details + * Main telemetry receiver. All generated telemetry is funneled into + * this object. + * @ingroup utility + * @author J. Meier + */ +class TmFunnel : public AcceptsTelemetryIF, public ExecutableObjectIF, public SystemObject { + friend void(Factory::setStaticFrameworkObjectIds)(); + + public: + TmFunnel(object_id_t objectId, uint32_t messageDepth = 20, uint8_t reportReceptionVc = 0); + virtual ~TmFunnel(); + + virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + virtual ReturnValue_t initialize() override; + + protected: + static object_id_t downlinkDestination; + static object_id_t storageDestination; + + private: + uint32_t messageDepth = 0; + uint8_t reportReceptionVc = 0; + uint16_t sourceSequenceCount = 0; + MessageQueueIF* tmQueue = nullptr; + MessageQueueIF* storageQueue = nullptr; + + StorageManagerIF* tmStore = nullptr; + + ReturnValue_t handlePacket(TmTcMessage* message); +}; + +#endif /* MISSION_UTILITY_TMFUNNEL_H_ */