From ef40db7fe401bf21d046677ee673103b8d58911a Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 17 Aug 2022 17:54:59 +0200 Subject: [PATCH] CCSDS Handler --- mission/tmtc/CCSDSActions.h | 73 ++++++++++++++++++++++ mission/tmtc/CCSDSHandler.cpp | 111 ++++++++++++++++++++-------------- mission/tmtc/CCSDSHandler.h | 26 ++++---- 3 files changed, 150 insertions(+), 60 deletions(-) create mode 100644 mission/tmtc/CCSDSActions.h diff --git a/mission/tmtc/CCSDSActions.h b/mission/tmtc/CCSDSActions.h new file mode 100644 index 00000000..bab70875 --- /dev/null +++ b/mission/tmtc/CCSDSActions.h @@ -0,0 +1,73 @@ +#pragma once + +#include +#include +#include +#include + +class CCSDSHandler; + +FSFW_ENUM( + CCSDSCommands, DeviceCommandId_t, + ((SET_LOW_RATE, 0, "Set Low rate"))((SET_HIGH_RATE, 1, "Set High Rate"))( + (EN_TRANSMITTER, 2, "Enable Transmitter"))((DISABLE_TRANSMITTER, 3, "Disable Transmitter"))( + (ARBITRARY_RATE, 4, "Set Bit Rate"))((ENABLE_TX_CLK_MANIPULATOR, 5, + "Enable Tx Clock Manipulator"))( + (DISABLE_TX_CLK_MANIPULATOR, 6, "Enable Tx Clock Manipulator"))( + (UPDATE_ON_RISING_EDGE, 7, "update data on rising edge"))((UPDATE_ON_FALLING_EDGE, 8, + "update data on falling edge"))) + +class SetLowRateAction : public TemplateAction { + public: + SetLowRateAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::SET_LOW_RATE) {} +}; +class SetHighRateAction : public TemplateAction { + public: + SetHighRateAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::SET_HIGH_RATE) {} +}; +class EnTransmitterAction + : public TemplateAction { + public: + EnTransmitterAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::EN_TRANSMITTER) {} +}; +class DisableTransmitterAction + : public TemplateAction { + public: + DisableTransmitterAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::DISABLE_TRANSMITTER) {} +}; +class ArbitraryRateAction + : public TemplateAction { + public: + ArbitraryRateAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::ARBITRARY_RATE) {} + + Parameter bitrate = Parameter::createParameter(this, "Bitrate"); +}; +class EnableTxClkManipulatorAction + : public TemplateAction { + public: + EnableTxClkManipulatorAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::ENABLE_TX_CLK_MANIPULATOR) {} +}; +class DisableTxClkManipulatorAction + : public TemplateAction { + public: + DisableTxClkManipulatorAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::DISABLE_TX_CLK_MANIPULATOR) {} +}; +class UpdateOnRisingEdgeAction + : public TemplateAction { + public: + UpdateOnRisingEdgeAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::UPDATE_ON_RISING_EDGE) {} +}; +class UpdateOnFallingEdgeAction + : public TemplateAction { + public: + UpdateOnFallingEdgeAction(CCSDSHandler* owner) + : TemplateAction(owner, CCSDSCommands::UPDATE_ON_FALLING_EDGE) {} +}; \ No newline at end of file diff --git a/mission/tmtc/CCSDSHandler.cpp b/mission/tmtc/CCSDSHandler.cpp index 0c49f6af..41181e0f 100644 --- a/mission/tmtc/CCSDSHandler.cpp +++ b/mission/tmtc/CCSDSHandler.cpp @@ -150,6 +150,8 @@ void CCSDSHandler::readCommandQueue(void) { MessageQueueId_t CCSDSHandler::getCommandQueue() const { return commandQueue->getId(); } +ActionHelper* CCSDSHandler::getActionHelper() { return &actionHelper; } + 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; @@ -201,57 +203,74 @@ MessageQueueId_t CCSDSHandler::getRequestQueue() { return tcDistributorQueueId; } -ReturnValue_t CCSDSHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) { - ReturnValue_t result = RETURN_OK; - switch (actionId) { - case SET_LOW_RATE: { - result = ptmeConfig->setRate(RATE_100KBPS); - break; - } - case SET_HIGH_RATE: { - result = ptmeConfig->setRate(RATE_500KBPS); - break; - } - case ARBITRARY_RATE: { - uint32_t bitrate = 0; - SerializeAdapter::deSerialize(&bitrate, &data, &size, SerializeIF::Endianness::BIG); - result = ptmeConfig->setRate(bitrate); - break; - } - case EN_TRANSMITTER: { - enableTransmit(); - return EXECUTION_FINISHED; - } - case DISABLE_TRANSMITTER: { - disableTransmit(); - return EXECUTION_FINISHED; - } - case ENABLE_TX_CLK_MANIPULATOR: { - result = ptmeConfig->configTxManipulator(true); - break; - } - case DISABLE_TX_CLK_MANIPULATOR: { - result = ptmeConfig->configTxManipulator(false); - break; - } - case UPDATE_ON_RISING_EDGE: { - result = ptmeConfig->invertTxClock(false); - break; - } - case UPDATE_ON_FALLING_EDGE: { - result = ptmeConfig->invertTxClock(true); - break; - } - default: - return COMMAND_NOT_IMPLEMENTED; +ReturnValue_t CCSDSHandler::executeAction(Action* action) { return action->handle(); } + +ReturnValue_t CCSDSHandler::handleAction(SetLowRateAction* action) { + ReturnValue_t result = ptmeConfig->setRate(RATE_100KBPS); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; } - if (result != RETURN_OK) { - return result; + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(SetHighRateAction* action) { + ReturnValue_t result = ptmeConfig->setRate(RATE_500KBPS); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; } + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(ArbitraryRateAction* action) { + ReturnValue_t result = ptmeConfig->setRate(action->bitrate); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; + } + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(EnTransmitterAction* action) { + enableTransmit(); return EXECUTION_FINISHED; } +ReturnValue_t CCSDSHandler::handleAction(DisableTransmitterAction* action) { + disableTransmit(); + return EXECUTION_FINISHED; +} + +ReturnValue_t CCSDSHandler::handleAction(EnableTxClkManipulatorAction* action) { + ReturnValue_t result = ptmeConfig->configTxManipulator(true); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; + } + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(DisableTxClkManipulatorAction* action) { + ReturnValue_t result = ptmeConfig->configTxManipulator(false); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; + } + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(UpdateOnRisingEdgeAction* action) { + ReturnValue_t result = ptmeConfig->invertTxClock(false); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; + } + return result; +} + +ReturnValue_t CCSDSHandler::handleAction(UpdateOnFallingEdgeAction* action) { + ReturnValue_t result = ptmeConfig->invertTxClock(true); + if (result == HasReturnvaluesIF::RETURN_OK) { + return EXECUTION_FINISHED; + } + return result; +} + void CCSDSHandler::checkEvents() { EventMessage event; for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK; diff --git a/mission/tmtc/CCSDSHandler.h b/mission/tmtc/CCSDSHandler.h index d4cf1da4..5959ff98 100644 --- a/mission/tmtc/CCSDSHandler.h +++ b/mission/tmtc/CCSDSHandler.h @@ -3,6 +3,7 @@ #include +#include "CCSDSActions.h" #include "OBSWConfig.h" #include "VirtualChannel.h" #include "fsfw/action/ActionHelper.h" @@ -76,26 +77,23 @@ class CCSDSHandler : public SystemObject, uint16_t getIdentifier() override; MessageQueueId_t getRequestQueue() override; - virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size); + virtual ActionHelper* getActionHelper() override; + virtual ReturnValue_t executeAction(Action* action); + ReturnValue_t handleAction(SetLowRateAction* action); + ReturnValue_t handleAction(SetHighRateAction* action); + ReturnValue_t handleAction(EnTransmitterAction* action); + ReturnValue_t handleAction(DisableTransmitterAction* action); + ReturnValue_t handleAction(ArbitraryRateAction* action); + ReturnValue_t handleAction(EnableTxClkManipulatorAction* action); + ReturnValue_t handleAction(DisableTxClkManipulatorAction* action); + ReturnValue_t handleAction(UpdateOnRisingEdgeAction* action); + ReturnValue_t handleAction(UpdateOnFallingEdgeAction* action); private: static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_HANDLER; static const uint32_t QUEUE_SIZE = common::CCSDS_HANDLER_QUEUE_SIZE; - static const ActionId_t SET_LOW_RATE = 0; - static const ActionId_t SET_HIGH_RATE = 1; - static const ActionId_t EN_TRANSMITTER = 2; - static const ActionId_t DISABLE_TRANSMITTER = 3; - static const ActionId_t ARBITRARY_RATE = 4; - static const ActionId_t ENABLE_TX_CLK_MANIPULATOR = 5; - static const ActionId_t DISABLE_TX_CLK_MANIPULATOR = 6; - // Will update data with respect to tx clock signal of cadu bitstream on rising edge - static const ActionId_t UPDATE_ON_RISING_EDGE = 7; - // Will update data with respect to tx clock signal of cadu bitstream on falling edge - static const ActionId_t UPDATE_ON_FALLING_EDGE = 8; - // Syrlinks supports two bitrates (200 kbps and 1000 kbps) // Due to convolutional code added by the syrlinks the input frequency must be half the // target frequency