From 919141ae1033ad1be1a7f89a0e2f66800a93e01e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 12 May 2022 18:32:19 +0200 Subject: [PATCH] ccsds handler sending command to enable transmitter --- bsp_q7s/core/ObjectFactory.cpp | 2 +- bsp_te0720_1cfa/ObjectFactory.cpp | 2 +- linux/obc/PdecHandler.cpp | 17 ++- linux/obc/PdecHandler.h | 7 ++ mission/core/GenericFactory.cpp | 2 +- .../devicedefinitions/SyrlinksDefinitions.h | 1 + mission/tmtc/CCSDSHandler.cpp | 80 +++++++++++- mission/tmtc/CCSDSHandler.h | 20 ++- mission/tmtc/CMakeLists.txt | 1 + mission/utility/CMakeLists.txt | 1 - mission/utility/TmFunnel.cpp | 114 ------------------ mission/utility/TmFunnel.h | 49 -------- 12 files changed, 118 insertions(+), 178 deletions(-) delete mode 100644 mission/utility/TmFunnel.cpp delete mode 100644 mission/utility/TmFunnel.h diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index ff1e78cc..7140293f 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -91,7 +91,7 @@ #include "mission/system/AcsBoardAssembly.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" -#include "mission/utility/TmFunnel.h" +#include "mission/tmtc/TmFunnel.h" ResetArgs resetArgsGnss0; ResetArgs resetArgsGnss1; diff --git a/bsp_te0720_1cfa/ObjectFactory.cpp b/bsp_te0720_1cfa/ObjectFactory.cpp index 6be712bd..5221a1e9 100644 --- a/bsp_te0720_1cfa/ObjectFactory.cpp +++ b/bsp_te0720_1cfa/ObjectFactory.cpp @@ -27,7 +27,7 @@ #include "linux/obc/PtmeConfig.h" #include "mission/core/GenericFactory.h" #include "mission/devices/Tmp1075Handler.h" -#include "mission/utility/TmFunnel.h" +#include "mission/tmtc/TmFunnel.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" #include "objects/systemObjectList.h" diff --git a/linux/obc/PdecHandler.cpp b/linux/obc/PdecHandler.cpp index 4c8beeed..c6016919 100644 --- a/linux/obc/PdecHandler.cpp +++ b/linux/obc/PdecHandler.cpp @@ -190,15 +190,22 @@ bool PdecHandler::newTcReceived() { void PdecHandler::checkLocks() { uint32_t clcw = getClcw(); - if (!(clcw & NO_RF_MASK) && (lastClcw & NO_RF_MASK)) { - // Rf available changed from 0 to 1 + if (not (clcw & NO_RF_MASK) && not carrierLock) { triggerEvent(CARRIER_LOCK); + carrierLock = true; } - if (!(clcw & NO_BITLOCK_MASK) && (lastClcw & NO_BITLOCK_MASK)) { - // Bit lock changed from 0 to 1 + else if ((clcw & NO_RF_MASK) && carrierLock) { + carrierLock = false; + triggerEvent(LOST_CARRIER_LOCK_PDEC); + } + if (not (clcw & NO_BITLOCK_MASK) && not bitLock) { triggerEvent(BIT_LOCK_PDEC); + bitLock = true; + } + else if ((clcw & NO_BITLOCK_MASK) && bitLock) { + bitLock = false; + triggerEvent(LOST_BIT_LOCK_PDEC); } - lastClcw = clcw; } bool PdecHandler::checkFrameAna(uint32_t pdecFar) { diff --git a/linux/obc/PdecHandler.h b/linux/obc/PdecHandler.h index 14863627..aeb571fc 100644 --- a/linux/obc/PdecHandler.h +++ b/linux/obc/PdecHandler.h @@ -73,6 +73,10 @@ class PdecHandler : public SystemObject, static const Event CARRIER_LOCK = MAKE_EVENT(3, severity::INFO); //! [EXPORT] : [COMMENT] Bit lock detected (data valid) static const Event BIT_LOCK_PDEC = MAKE_EVENT(4, severity::INFO); + //! [EXPORT] : [COMMENT] Lost carrier lock + static const Event LOST_CARRIER_LOCK_PDEC = MAKE_EVENT(5, severity::INFO); + //! [EXPORT] : [COMMENT] Lost bit lock + static const Event LOST_BIT_LOCK_PDEC = MAKE_EVENT(6, severity::INFO); private: static const uint8_t INTERFACE_ID = CLASS_ID::PDEC_HANDLER; @@ -391,6 +395,9 @@ class PdecHandler : public SystemObject, // Used to check carrier and bit lock changes (default set to no rf and no bitlock) uint32_t lastClcw = 0xC000; + + bool carrierLock = false; + bool bitLock = false; }; #endif /* LINUX_OBC_PDECHANDLER_H_ */ diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index d2db67fd..5f213e97 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "OBSWConfig.h" #include "eive/definitions.h" diff --git a/mission/devices/devicedefinitions/SyrlinksDefinitions.h b/mission/devices/devicedefinitions/SyrlinksDefinitions.h index 7e3b6a20..826b2101 100644 --- a/mission/devices/devicedefinitions/SyrlinksDefinitions.h +++ b/mission/devices/devicedefinitions/SyrlinksDefinitions.h @@ -2,6 +2,7 @@ #define MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_ #include +#include "fsfw/devicehandlers/DeviceHandlerBase.h" namespace syrlinks { diff --git a/mission/tmtc/CCSDSHandler.cpp b/mission/tmtc/CCSDSHandler.cpp index 0c49f6af..6cedeb36 100644 --- a/mission/tmtc/CCSDSHandler.cpp +++ b/mission/tmtc/CCSDSHandler.cpp @@ -10,6 +10,8 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" +#include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" + CCSDSHandler::CCSDSHandler(object_id_t objectId, object_id_t ptmeId, object_id_t tcDestination, PtmeConfig* ptmeConfig, GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData, uint32_t transmitterTimeout) @@ -22,11 +24,14 @@ CCSDSHandler::CCSDSHandler(object_id_t objectId, object_id_t ptmeId, object_id_t gpioIF(gpioIF), enTxClock(enTxClock), enTxData(enTxData), - transmitterTimeout(transmitterTimeout) { + transmitterTimeout(transmitterTimeout), + commandActionHelper(this) { commandQueue = QueueFactory::instance()->createMessageQueue(QUEUE_SIZE); auto mqArgs = MqArgs(objectId, static_cast(this)); eventQueue = QueueFactory::instance()->createMessageQueue(10, EventMessage::EVENT_MESSAGE_SIZE, &mqArgs); + commandActionHelperQueue = + QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); } CCSDSHandler::~CCSDSHandler() {} @@ -120,6 +125,10 @@ ReturnValue_t CCSDSHandler::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } + if (result != HasReturnvaluesIF::RETURN_OK) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + #if OBSW_SYRLINKS_SIMULATED == 1 ptmeConfig->invertTxClock(true); #endif /* OBSW_SYRLINKS_SIMULATED == 1*/ @@ -148,8 +157,73 @@ void CCSDSHandler::readCommandQueue(void) { } } +void CCSDSHandler::readCommandActionHelperQueue() { + CommandMessage message; + for (ReturnValue_t result = commandActionHelperQueue->receiveMessage(&message); + result == RETURN_OK; result = commandActionHelperQueue->receiveMessage(&message)) { + result = commandActionHelper.handleReply(&message); + if (result == RETURN_OK) { + continue; + } + } +} + MessageQueueId_t CCSDSHandler::getCommandQueue() const { return commandQueue->getId(); } +MessageQueueIF* CCSDSHandler::getCommandQueuePtr() { return commandActionHelperQueue; } + +void CCSDSHandler::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) { return; } + +void CCSDSHandler::stepFailedReceived(ActionId_t actionId, uint8_t step, + ReturnValue_t returnCode) { + switch (actionId) { + case syrlinks::SET_TX_MODE_MODULATION: { + sif::warning << "CCSDSHandler::stepFailedReceived: Failed to set enable transmitter" + << std::endl; + break; + } + default: + sif::debug << "CCSDSHandler::stepFailedReceived: Received unexpected action reply" + << std::endl; + break; + } +} + +void CCSDSHandler::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) { + return; +} + +void CCSDSHandler::completionSuccessfulReceived(ActionId_t actionId) { + switch (actionId) { + case syrlinks::SET_TX_MODE_MODULATION: { + triggerEvent(TRANSMITTER_ENABLED); + transmitterCountdown.setTimeout(transmitterTimeout); + linkState = UP; + // Set link state of all virtual channels to link up + forwardLinkstate(); + break; + } + default: + sif::debug << "CCSDSHandler::completionSuccessfulReceived: Received unexpected action reply" + << std::endl; + break; + } +} + +void CCSDSHandler::completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) { + switch (actionId) { + case syrlinks::SET_TX_MODE_MODULATION: { + sif::warning << "CCSDSHandler::completionFailedReceived: Failed to set enable transmitter" + << std::endl; + break; + } + default: + sif::debug << "CCSDSHandler::completionFailedReceived: Received unexpected action reply" + << std::endl; + break; + } +} + void CCSDSHandler::addVirtualChannel(VcId_t vcId, VirtualChannel* virtualChannel) { if (vcId > common::NUMBER_OF_VIRTUAL_CHANNELS) { sif::warning << "CCSDSHandler::addVirtualChannel: Invalid virtual channel ID" << std::endl; @@ -312,14 +386,10 @@ void CCSDSHandler::enableTransmit() { // Transmitter already enabled return; } - transmitterCountdown.setTimeout(transmitterTimeout); #ifndef TE0720_1CFA gpioIF->pullHigh(enTxClock); gpioIF->pullHigh(enTxData); #endif /* BOARD_TE0720 == 0 */ - linkState = UP; - // Set link state of all virtual channels to link up - forwardLinkstate(); } void CCSDSHandler::checkTxTimer() { diff --git a/mission/tmtc/CCSDSHandler.h b/mission/tmtc/CCSDSHandler.h index d4cf1da4..7e95231d 100644 --- a/mission/tmtc/CCSDSHandler.h +++ b/mission/tmtc/CCSDSHandler.h @@ -17,6 +17,8 @@ #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw_hal/common/gpio/GpioIF.h" #include "fsfw_hal/common/gpio/gpioDefinitions.h" +#include "fsfw/action/CommandActionHelper.h" +#include "fsfw/action/CommandsActionsIF.h" #include "linux/obc/PtmeConfig.h" /** @@ -34,7 +36,8 @@ class CCSDSHandler : public SystemObject, public AcceptsTelecommandsIF, public HasReturnvaluesIF, public ReceivesParameterMessagesIF, - public HasActionsIF { + public HasActionsIF, + public CommandsActionsIF { public: using VcId_t = uint8_t; @@ -79,8 +82,19 @@ class CCSDSHandler : public SystemObject, virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, size_t size); + MessageQueueIF* getCommandQueuePtr() override; + void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override; + void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override; + void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override; + void completionSuccessfulReceived(ActionId_t actionId) override; + void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override; + private: static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_HANDLER; + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HANDLER; + + //! [EXPORT] : [COMMENT] Syrlinks transmitter is enabled + static const Event TRANSMITTER_ENABLED = MAKE_EVENT(1, severity::LOW); static const uint32_t QUEUE_SIZE = common::CCSDS_HANDLER_QUEUE_SIZE; @@ -120,6 +134,7 @@ class CCSDSHandler : public SystemObject, MessageQueueIF* commandQueue = nullptr; MessageQueueIF* eventQueue = nullptr; + MessageQueueIF* commandActionHelperQueue = nullptr; ParameterHelper parameterHelper; @@ -140,12 +155,15 @@ class CCSDSHandler : public SystemObject, // Countdown to disable transmitter after 15 minutes Countdown transmitterCountdown; + CommandActionHelper commandActionHelper; + // When true transmitting is started as soon as carrier lock has been detected bool enableTxWhenCarrierLock = false; bool linkState = DOWN; void readCommandQueue(void); + void readCommandActionHelperQueue(void); void handleTelemetry(); void handleTelecommands(); void checkEvents(); diff --git a/mission/tmtc/CMakeLists.txt b/mission/tmtc/CMakeLists.txt index 1d3baae7..4894ce9a 100644 --- a/mission/tmtc/CMakeLists.txt +++ b/mission/tmtc/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE CCSDSHandler.cpp VirtualChannel.cpp + TmFunnel.cpp ) diff --git a/mission/utility/CMakeLists.txt b/mission/utility/CMakeLists.txt index a6b2b7a7..a61d371d 100644 --- a/mission/utility/CMakeLists.txt +++ b/mission/utility/CMakeLists.txt @@ -1,5 +1,4 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE - TmFunnel.cpp Timestamp.cpp ProgressPrinter.cpp Filenaming.cpp diff --git a/mission/utility/TmFunnel.cpp b/mission/utility/TmFunnel.cpp deleted file mode 100644 index c47c7f9d..00000000 --- a/mission/utility/TmFunnel.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#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/utility/TmFunnel.h b/mission/utility/TmFunnel.h deleted file mode 100644 index f11dce63..00000000 --- a/mission/utility/TmFunnel.h +++ /dev/null @@ -1,49 +0,0 @@ -#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_ */