From 3137ebb86eb82508c93789a21164196f6b92b431 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Feb 2023 13:02:40 +0100 Subject: [PATCH] com subsystem complete --- bsp_q7s/core/ObjectFactory.cpp | 1 - linux/ipcore/PdecHandler.cpp | 1 + mission/system/objects/ComSubsystem.cpp | 123 ++++++++++++++---------- mission/system/objects/ComSubsystem.h | 17 +++- mission/system/tree/comModeTree.h | 4 +- 5 files changed, 89 insertions(+), 57 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 347cabdd..63539cc3 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -573,7 +573,6 @@ void ObjectFactory::createSyrlinksComponents(PowerSwitchIF* pwrSwitcher) { new SyrlinksHandler(objects::SYRLINKS_HANDLER, objects::UART_COM_IF, syrlinksUartCookie, pcdu::PDU1_CH1_SYRLINKS_12V, syrlinksFdir); syrlinksHandler->setPowerSwitcher(pwrSwitcher); - syrlinksHandler->setStartUpImmediately(); syrlinksHandler->connectModeTreeParent(satsystem::com::SUBSYSTEM); #if OBSW_DEBUG_SYRLINKS == 1 syrlinksHandler->setDebugMode(true); diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 3244280e..1cf21ce0 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -165,6 +165,7 @@ ReturnValue_t PdecHandler::irqOperation() { return result; } state = State::RUNNING; + checkLocks(); break; case State::RUNNING: { nb = write(fd, &info, sizeof(info)); diff --git a/mission/system/objects/ComSubsystem.cpp b/mission/system/objects/ComSubsystem.cpp index 3ca78904..3a79ac15 100644 --- a/mission/system/objects/ComSubsystem.cpp +++ b/mission/system/objects/ComSubsystem.cpp @@ -1,5 +1,3 @@ -#include - #include "ComSubsystem.h" #include @@ -7,14 +5,11 @@ #include #include #include +#include #include -extern std::pair> COM_SEQUENCE_RX_ONLY; -//extern std::pair> COM_TABLE_RX_ONLY_TGT; -extern std::pair> COM_SEQUENCE_RX_AND_TX_DEFAULT_RATE; -extern std::pair> COM_TABLE_RX_AND_TX_DEFAULT_RATE_TGT; -extern std::pair> COM_SEQUENCE_RX_AND_TX_LOW_RATE; -extern std::pair> COM_SEQUENCE_RX_AND_TX_HIGH_RATE; +#include + ComSubsystem::ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables, uint32_t transmitterTimeout) @@ -28,8 +23,13 @@ ComSubsystem::ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequence void ComSubsystem::performChildOperation() { readEventQueue(); + // Execute default rate sequence after transition has been completed + if (rememberBitLock and not isInTransition) { + startRxAndTxLowRateSeq(); + rememberBitLock = false; + } if (countdownActive) { - checkTransmitterCountdown(); + checkTransmitterCountdown(); } Subsystem::performChildOperation(); } @@ -51,17 +51,17 @@ ReturnValue_t ComSubsystem::getParameter(uint8_t domainId, uint8_t uniqueIdentif parameterWrapper->set(datarateCfg); com::setCurrentDatarate(static_cast(newVal)); return returnvalue::OK; - } - else if ((domainId == 0) and (uniqueIdentifier == static_cast(com::ParameterId::TRANSMITTER_TIMEOUT))) { - uint8_t newVal = 0; - ReturnValue_t result = newValues->getElement(&newVal); - if (result != returnvalue::OK) { - return result; - } - parameterWrapper->set(transmitterTimeout); - transmitterTimeout = newVal; - transmitterCountdown.setTimeout(transmitterTimeout); - return returnvalue::OK; + } else if ((domainId == 0) and + (uniqueIdentifier == static_cast(com::ParameterId::TRANSMITTER_TIMEOUT))) { + uint32_t newVal = 0; + ReturnValue_t result = newValues->getElement(&newVal); + if (result != returnvalue::OK) { + return result; + } + parameterWrapper->set(transmitterTimeout); + transmitterTimeout = newVal; + transmitterCountdown.setTimeout(transmitterTimeout); + return returnvalue::OK; } return returnvalue::OK; } @@ -79,46 +79,48 @@ ReturnValue_t ComSubsystem::initialize() { if (result != returnvalue::OK) { return result; } - EventManagerIF* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); - if (manager == nullptr) { + EventManagerIF *manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); + if (manager == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "ComSubsystem::initialize: Invalid event manager" << std::endl; + sif::error << "ComSubsystem::initialize: Invalid event manager" << std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } - result = manager->registerListener(eventQueue->getId()); - if (result != returnvalue::OK) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + result = manager->registerListener(eventQueue->getId()); + if (result != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "ComSubsystem::initialize: Failed to register Com Subsystem as event " - "listener" << std::endl; + sif::warning << "ComSubsystem::initialize: Failed to register Com Subsystem as event " + "listener" + << std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } - result = manager->subscribeToEventRange(eventQueue->getId(), - event::getEventId(PdecHandler::CARRIER_LOCK), - event::getEventId(PdecHandler::BIT_LOCK_PDEC)); - if (result != returnvalue::OK) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + result = manager->subscribeToEventRange(eventQueue->getId(), + event::getEventId(PdecHandler::CARRIER_LOCK), + event::getEventId(PdecHandler::BIT_LOCK_PDEC)); + if (result != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "ComSubsystem::initialize: Failed to subscribe to events from PDEC " - "handler" - << std::endl; + sif::error << "ComSubsystem::initialize: Failed to subscribe to events from PDEC " + "handler" + << std::endl; #endif - return result; - } + return result; + } return Subsystem::initialize(); } void ComSubsystem::startTransition(Mode_t mode, Submode_t submode) { // Depending on the submode the transmitter timeout is enabled or // disabled here - if (mode == COM_SEQUENCE_RX_ONLY.first) { + if (mode == com::Submode::RX_ONLY) { transmitterCountdown.timeOut(); countdownActive = false; - } else if ((mode == COM_SEQUENCE_RX_AND_TX_DEFAULT_RATE.first) || - (mode == COM_SEQUENCE_RX_AND_TX_LOW_RATE.first) || - (mode == COM_SEQUENCE_RX_AND_TX_HIGH_RATE.first)) { - transmitterCountdown.resetTimer(); - countdownActive = true; + } else if (isTxMode(mode)) { + // Only start transmitter countdown if transmitter is not already on + if (not isTxMode(this->mode)) { + transmitterCountdown.resetTimer(); + countdownActive = true; + } } Subsystem::startTransition(mode, submode); } @@ -156,23 +158,42 @@ void ComSubsystem::handleEventMessage(EventMessage *eventMessage) { } } -void ComSubsystem::handleBitLockEvent() { startRxAndTxDefaultSeq(); } +void ComSubsystem::handleBitLockEvent() { + if (isTxMode(mode)) { + // Tx already on + return; + } + if (isInTransition) { + rememberBitLock = true; + return; + } + startRxAndTxLowRateSeq(); +} void ComSubsystem::handleCarrierLockEvent() { if (!enableTxWhenCarrierLock) { return; } - startRxAndTxDefaultSeq(); + startRxAndTxLowRateSeq(); } -void ComSubsystem::startRxAndTxDefaultSeq() { +void ComSubsystem::startRxAndTxLowRateSeq() { // Turns transmitter on - startTransition(COM_SEQUENCE_RX_AND_TX_DEFAULT_RATE.first, SUBMODE_NONE); + startTransition(com::Submode::RX_AND_TX_LOW_DATARATE, SUBMODE_NONE); } void ComSubsystem::checkTransmitterCountdown() { if (transmitterCountdown.hasTimedOut()) { - startTransition(COM_SEQUENCE_RX_ONLY.first, SUBMODE_NONE); + startTransition(com::Submode::RX_ONLY, SUBMODE_NONE); countdownActive = false; } } + +bool ComSubsystem::isTxMode(Mode_t mode) { + if ((mode == com::Submode::RX_AND_TX_DEFAULT_DATARATE) || + (mode == com::Submode::RX_AND_TX_LOW_DATARATE) || + (mode == com::Submode::RX_AND_TX_HIGH_DATARATE)) { + return true; + } + return false; +} diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index 84ac081a..6b5b41dc 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -30,6 +30,9 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { virtual void performChildOperation() override; private: + + static const Mode_t INITIAL_MODE = 0; + ReturnValue_t handleCommandMessage(CommandMessage *message) override; ReturnValue_t initialize() override; @@ -42,9 +45,14 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { void handleCarrierLockEvent(); void checkTransmitterCountdown(); /** - * @brief Enables transmitter in default (low) rate mode + * @brief Enables transmitter in low rate mode */ - void startRxAndTxDefaultSeq(); + void startRxAndTxLowRateSeq(); + + /** + * @brief Returns true if mode is a mode where the transmitter is on + */ + bool isTxMode(Mode_t mode); uint8_t datarateCfg = static_cast(com::Datarate::LOW_RATE_MODULATION_BPSK); // Maximum time after which the transmitter will be turned of. This is a @@ -62,6 +70,11 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { // Transmitter countdown only active when sysrlinks transmitter is on (modes: // rx and tx low rate, rx and tx high rate, rx and tx default rate) bool countdownActive = false; + + // True when bit lock occurred while COM subsystem is in a transition. This + // variable is used to remember the bit lock and execute the default rate + // sequence after the active transition has been completed + bool rememberBitLock = false; }; #endif /* MISSION_SYSTEM_COMSUBSYSTEM_H_ */ diff --git a/mission/system/tree/comModeTree.h b/mission/system/tree/comModeTree.h index 0f57217c..8641874e 100644 --- a/mission/system/tree/comModeTree.h +++ b/mission/system/tree/comModeTree.h @@ -12,9 +12,7 @@ extern ComSubsystem SUBSYSTEM; // The syrlinks must not transmitting longer then 15 minutes otherwise the // transceiver might be damaged due to overheating // 15 minutes in milliseconds -//static const uint32_t TRANSMITTER_TIMEOUT = 900000; - -static const uint32_t TRANSMITTER_TIMEOUT = 60000; +static const uint32_t TRANSMITTER_TIMEOUT = 900000; Subsystem& init(); } // namespace com