From 13f3963f6989c022a96d80752520960693cae9ea Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 27 Jan 2023 18:38:36 +0100 Subject: [PATCH] Update - COM Subsystem now handles datarate config - torquer config and comCfg moved to mission/config folder - CCSDS Handler: Added default rate submode --- CHANGELOG.md | 6 ++++ .../fsfwconfig/pollingsequence/DummyPst.cpp | 3 +- bsp_q7s/em/emObjectFactory.cpp | 2 +- mission/CMakeLists.txt | 1 + mission/comDefs.h | 8 ++++- mission/config/CMakeLists.txt | 1 + mission/config/comCfg.cpp | 26 ++++++++++++++ mission/config/comCfg.h | 15 ++++++++ mission/{devices => config}/torquer.cpp | 0 mission/{devices => config}/torquer.h | 0 mission/controller/AcsController.cpp | 2 +- mission/devices/CMakeLists.txt | 3 +- mission/devices/ImtqHandler.cpp | 2 +- mission/devices/SyrlinksHandler.cpp | 21 +++--------- mission/devices/SyrlinksHandler.h | 3 -- mission/system/objects/ComSubsystem.cpp | 29 +++++++++++++++- mission/system/objects/ComSubsystem.h | 13 ++++++- mission/system/tree/comModeTree.cpp | 29 +++++++++------- mission/tmtc/CcsdsIpCoreHandler.cpp | 34 +++++++++++++------ 19 files changed, 145 insertions(+), 53 deletions(-) create mode 100644 mission/config/CMakeLists.txt create mode 100644 mission/config/comCfg.cpp create mode 100644 mission/config/comCfg.h rename mission/{devices => config}/torquer.cpp (100%) rename mission/{devices => config}/torquer.h (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6261d7c0..ac0c853b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ change warranting a new major release: # [unreleased] +## Added + +- First COM subsystem implementation. It mirrors the Syrlinks mode/submodes but also takes + care of commanding the CCSDS handler. It expects the Syrlinks submodes as mode commands. + PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/358 + # [v1.21.0] 2023-01-26 TMTC version: v2.5.0 diff --git a/bsp_hosted/fsfwconfig/pollingsequence/DummyPst.cpp b/bsp_hosted/fsfwconfig/pollingsequence/DummyPst.cpp index 69415ff6..de1efa0e 100644 --- a/bsp_hosted/fsfwconfig/pollingsequence/DummyPst.cpp +++ b/bsp_hosted/fsfwconfig/pollingsequence/DummyPst.cpp @@ -44,8 +44,7 @@ ReturnValue_t dummy_pst::pst(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::STAR_TRACKER, length * 0, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::STAR_TRACKER, length * 0, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SYRLINKS_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SYRLINKS_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SYRLINKS_HANDLER, length * 0, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SYRLINKS_HANDLER, length * 0, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SYRLINKS_HANDLER, length * 0, DeviceHandlerIF::SEND_READ); diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index a32ab288..375ddb0f 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -4,7 +4,6 @@ #include #include "OBSWConfig.h" -#include "mission/system/tree/comModeTree.h" #include "bsp_q7s/core/CoreController.h" #include "bsp_q7s/core/ObjectFactory.h" #include "busConf.h" @@ -15,6 +14,7 @@ #include "linux/ObjectFactory.h" #include "linux/callbacks/gpioCallbacks.h" #include "mission/core/GenericFactory.h" +#include "mission/system/tree/comModeTree.h" void ObjectFactory::produce(void* args) { ObjectFactory::setStatics(); diff --git a/mission/CMakeLists.txt b/mission/CMakeLists.txt index 6b4248bf..d3782d4b 100644 --- a/mission/CMakeLists.txt +++ b/mission/CMakeLists.txt @@ -7,3 +7,4 @@ add_subdirectory(tmtc) add_subdirectory(system) add_subdirectory(csp) add_subdirectory(cfdp) +add_subdirectory(config) diff --git a/mission/comDefs.h b/mission/comDefs.h index a271ba31..5538b166 100644 --- a/mission/comDefs.h +++ b/mission/comDefs.h @@ -18,7 +18,13 @@ enum Submode : uint8_t { NUM_SUBMODES }; -enum class CcsdsSubmode : uint8_t { UNSET = 0, DATARATE_LOW = 1, DATARATE_HIGH = 2 }; +enum class CcsdsSubmode : uint8_t { + UNSET = 0, + DATARATE_LOW = 1, + DATARATE_HIGH = 2, + DATARATE_DEFAULT = 3 +}; +enum class ParameterId : uint8_t { DATARATE = 0 }; } // namespace com diff --git a/mission/config/CMakeLists.txt b/mission/config/CMakeLists.txt new file mode 100644 index 00000000..5cacbf02 --- /dev/null +++ b/mission/config/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${LIB_EIVE_MISSION} PRIVATE comCfg.cpp torquer.cpp) diff --git a/mission/config/comCfg.cpp b/mission/config/comCfg.cpp new file mode 100644 index 00000000..9e350a9d --- /dev/null +++ b/mission/config/comCfg.cpp @@ -0,0 +1,26 @@ +#include "comCfg.h" + +#include +#include + +com::Datarate DATARATE_CFG_RAW = com::Datarate::LOW_RATE_MODULATION_BPSK; +MutexIF* DATARATE_LOCK = nullptr; + +MutexIF* lazyLock(); + +com::Datarate com::getCurrentDatarate() { + MutexGuard mg(lazyLock()); + return DATARATE_CFG_RAW; +} + +void com::setCurrentDatarate(com::Datarate newRate) { + MutexGuard mg(lazyLock()); + DATARATE_CFG_RAW = newRate; +} + +MutexIF* lazyLock() { + if (DATARATE_LOCK == nullptr) { + return MutexFactory::instance()->createMutex(); + } + return DATARATE_LOCK; +} diff --git a/mission/config/comCfg.h b/mission/config/comCfg.h new file mode 100644 index 00000000..54a49ade --- /dev/null +++ b/mission/config/comCfg.h @@ -0,0 +1,15 @@ +#ifndef MISSION_COMCFG_H_ +#define MISSION_COMCFG_H_ + +#include + +#include "mission/comDefs.h" + +namespace com { + +com::Datarate getCurrentDatarate(); +void setCurrentDatarate(com::Datarate newRate); + +} // namespace com + +#endif /* MISSION_COMCFG_H_ */ diff --git a/mission/devices/torquer.cpp b/mission/config/torquer.cpp similarity index 100% rename from mission/devices/torquer.cpp rename to mission/config/torquer.cpp diff --git a/mission/devices/torquer.h b/mission/config/torquer.h similarity index 100% rename from mission/devices/torquer.h rename to mission/config/torquer.h diff --git a/mission/controller/AcsController.cpp b/mission/controller/AcsController.cpp index 2702cfe6..e684e4d4 100644 --- a/mission/controller/AcsController.cpp +++ b/mission/controller/AcsController.cpp @@ -2,7 +2,7 @@ #include -#include "mission/devices/torquer.h" +#include "mission/config/torquer.h" AcsController::AcsController(object_id_t objectId) : ExtendedControllerBase(objectId), diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 9af182b8..ce02c688 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -20,7 +20,6 @@ target_sources( SusHandler.cpp PayloadPcduHandler.cpp SolarArrayDeploymentHandler.cpp - ScexDeviceHandler.cpp - torquer.cpp) + ScexDeviceHandler.cpp) add_subdirectory(devicedefinitions) diff --git a/mission/devices/ImtqHandler.cpp b/mission/devices/ImtqHandler.cpp index a0e717f8..8cdb8de6 100644 --- a/mission/devices/ImtqHandler.cpp +++ b/mission/devices/ImtqHandler.cpp @@ -25,7 +25,7 @@ #include #include -#include "mission/devices/torquer.h" +#include "mission/config/torquer.h" static constexpr bool ACTUATION_WIRETAPPING = false; diff --git a/mission/devices/SyrlinksHandler.cpp b/mission/devices/SyrlinksHandler.cpp index 14583bf9..a636a314 100644 --- a/mission/devices/SyrlinksHandler.cpp +++ b/mission/devices/SyrlinksHandler.cpp @@ -3,6 +3,7 @@ #include #include "OBSWConfig.h" +#include "mission/config/comCfg.h" SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, power::Switch_t powerSwitch, FailureIsolationBase* customFdir) @@ -685,7 +686,7 @@ ReturnValue_t SyrlinksHandler::handleAckReply(const uint8_t* packet) { } case (syrlinks::SET_TX_MODE_MODULATION): case (syrlinks::SET_TX_MODE_CW): { - triggerEvent(syrlinks::TX_ON, getSubmode(), datarateCfgRaw); + triggerEvent(syrlinks::TX_ON, getSubmode(), static_cast(com::getCurrentDatarate())); break; } } @@ -706,18 +707,6 @@ ReturnValue_t SyrlinksHandler::getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - if ((domainId == 0) and (uniqueId == static_cast(syrlinks::ParameterId::DATARATE))) { - uint8_t newVal = 0; - ReturnValue_t result = newValues->getElement(&newVal); - if (result != returnvalue::OK) { - return result; - } - if (newVal >= static_cast(com::Datarate::NUM_DATARATES)) { - return HasParametersIF::INVALID_VALUE; - } - parameterWrapper->set(datarateCfgRaw); - return returnvalue::OK; - } return DeviceHandlerBase::getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); } @@ -773,12 +762,12 @@ void SyrlinksHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (tgtMode == HasModesIF::MODE_ON or tgtMode == DeviceHandlerIF::MODE_NORMAL) { switch (getSubmode()) { case (com::Submode::RX_AND_TX_DEFAULT_DATARATE): { - if (datarateCfgRaw == static_cast(com::Datarate::LOW_RATE_MODULATION_BPSK)) { + auto currentDatarate = com::getCurrentDatarate(); + if (currentDatarate == com::Datarate::LOW_RATE_MODULATION_BPSK) { if (txOnHandler(InternalState::SELECT_MODULATION_BPSK)) { return; } - } else if (datarateCfgRaw == - static_cast(com::Datarate::HIGH_RATE_MODULATION_0QPSK)) { + } else if (currentDatarate == com::Datarate::HIGH_RATE_MODULATION_0QPSK) { if (txOnHandler(InternalState::SELECT_MODULATION_0QPSK)) { return; } diff --git a/mission/devices/SyrlinksHandler.h b/mission/devices/SyrlinksHandler.h index fc1419d2..ea5c0336 100644 --- a/mission/devices/SyrlinksHandler.h +++ b/mission/devices/SyrlinksHandler.h @@ -104,9 +104,6 @@ class SyrlinksHandler : public DeviceHandlerBase { syrlinks::TemperatureSet temperatureSet; const power::Switch_t powerSwitch = power::NO_SWITCH; - // Use uint8_t for compatibility with parameter interface - uint8_t datarateCfgRaw = static_cast(com::Datarate::LOW_RATE_MODULATION_BPSK); - // com::Datarate datarateCfg = com::Datarate::LOW_RATE_MODULATION_BPSK; bool debugMode = false; uint8_t agcValueHighByte = 0; diff --git a/mission/system/objects/ComSubsystem.cpp b/mission/system/objects/ComSubsystem.cpp index 794eede6..9fd183b6 100644 --- a/mission/system/objects/ComSubsystem.cpp +++ b/mission/system/objects/ComSubsystem.cpp @@ -1,5 +1,32 @@ #include "ComSubsystem.h" +#include + +#include "mission/config/comCfg.h" + ComSubsystem::ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables) - : Subsystem(setObjectId, maxNumberOfSequences, maxNumberOfTables) {} + : Subsystem(setObjectId, maxNumberOfSequences, maxNumberOfTables), paramHelper(this) { + com::setCurrentDatarate(com::Datarate::LOW_RATE_MODULATION_BPSK); +} + +MessageQueueId_t ComSubsystem::getCommandQueue() const { return Subsystem::getCommandQueue(); } + +ReturnValue_t ComSubsystem::getParameter(uint8_t domainId, uint8_t uniqueIdentifier, + ParameterWrapper *parameterWrapper, + const ParameterWrapper *newValues, uint16_t startAtIndex) { + if ((domainId == 0) and (uniqueIdentifier == static_cast(com::ParameterId::DATARATE))) { + uint8_t newVal = 0; + ReturnValue_t result = newValues->getElement(&newVal); + if (result != returnvalue::OK) { + return result; + } + if (newVal >= static_cast(com::Datarate::NUM_DATARATES)) { + return HasParametersIF::INVALID_VALUE; + } + parameterWrapper->set(datarateCfg); + com::setCurrentDatarate(static_cast(newVal)); + return returnvalue::OK; + } + return returnvalue::OK; +} diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index 0bdaeb15..9e3bfda7 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -1,13 +1,24 @@ #ifndef MISSION_SYSTEM_COMSUBSYSTEM_H_ #define MISSION_SYSTEM_COMSUBSYSTEM_H_ +#include +#include #include -class ComSubsystem : public Subsystem { +#include "mission/comDefs.h" + +class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { public: ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables); + MessageQueueId_t getCommandQueue() const override; + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueIdentifier, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex) override; + private: + uint8_t datarateCfg = static_cast(com::Datarate::LOW_RATE_MODULATION_BPSK); + ParameterHelper paramHelper; }; #endif /* MISSION_SYSTEM_COMSUBSYSTEM_H_ */ diff --git a/mission/system/tree/comModeTree.cpp b/mission/system/tree/comModeTree.cpp index 92ab66f2..6d40c3d4 100644 --- a/mission/system/tree/comModeTree.cpp +++ b/mission/system/tree/comModeTree.cpp @@ -19,7 +19,8 @@ static const auto NML = DeviceHandlerIF::MODE_NORMAL; auto COM_SEQUENCE_RX_ONLY = std::make_pair(::com::Submode::RX_ONLY, FixedArrayList()); -auto COM_TABLE_RX_ONLY_TGT = std::make_pair((::com::Submode::RX_ONLY << 24) | 1, FixedArrayList()); +auto COM_TABLE_RX_ONLY_TGT = + std::make_pair((::com::Submode::RX_ONLY << 24) | 1, FixedArrayList()); auto COM_TABLE_RX_ONLY_TRANS_0 = std::make_pair((::com::Submode::RX_ONLY << 24) | 2, FixedArrayList()); auto COM_TABLE_RX_ONLY_TRANS_1 = @@ -27,26 +28,28 @@ auto COM_TABLE_RX_ONLY_TRANS_1 = auto COM_SEQUENCE_RX_AND_TX_LOW_RATE = std::make_pair(::com::Submode::RX_AND_TX_LOW_DATARATE, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_LOW_RATE_TGT = - std::make_pair((::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 1, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_LOW_RATE_TRANS_0 = - std::make_pair((::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 2, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_LOW_RATE_TRANS_1 = - std::make_pair((::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 3, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_LOW_RATE_TGT = std::make_pair( + (::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 1, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_LOW_RATE_TRANS_0 = std::make_pair( + (::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 2, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_LOW_RATE_TRANS_1 = std::make_pair( + (::com::Submode::RX_AND_TX_LOW_DATARATE << 24) | 3, FixedArrayList()); auto COM_SEQUENCE_RX_AND_TX_HIGH_RATE = std::make_pair(::com::Submode::RX_AND_TX_HIGH_DATARATE, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_HIGH_RATE_TGT = - std::make_pair((::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 1, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_HIGH_RATE_TRANS_0 = - std::make_pair((::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 2, FixedArrayList()); -auto COM_TABLE_RX_AND_TX_HIGH_RATE_TRANS_1 = - std::make_pair((::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 3, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_HIGH_RATE_TGT = std::make_pair( + (::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 1, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_HIGH_RATE_TRANS_0 = std::make_pair( + (::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 2, FixedArrayList()); +auto COM_TABLE_RX_AND_TX_HIGH_RATE_TRANS_1 = std::make_pair( + (::com::Submode::RX_AND_TX_HIGH_DATARATE << 24) | 3, FixedArrayList()); namespace { + void buildRxOnlySequence(Subsystem& ss, ModeListEntry& eh); void buildTxAndRxLowRateSequence(Subsystem& ss, ModeListEntry& eh); void buildTxAndRxHighRateSequence(Subsystem& ss, ModeListEntry& eh); + } // namespace void satsystem::com::init() { diff --git a/mission/tmtc/CcsdsIpCoreHandler.cpp b/mission/tmtc/CcsdsIpCoreHandler.cpp index f215c8cf..14d7f14b 100644 --- a/mission/tmtc/CcsdsIpCoreHandler.cpp +++ b/mission/tmtc/CcsdsIpCoreHandler.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "eive/definitions.h" #include "fsfw/events/EventManagerIF.h" @@ -378,18 +379,31 @@ ReturnValue_t CcsdsIpCoreHandler::checkModeCommand(Mode_t mode, Submode_t submod } void CcsdsIpCoreHandler::startTransition(Mode_t mode, Submode_t submode) { + auto rateHigh = [&]() { + ReturnValue_t result = ptmeConfig->setRate(RATE_500KBPS); + if (result == returnvalue::OK) { + mode = HasModesIF::MODE_ON; + } + }; + auto rateLow = [&]() { + ReturnValue_t result = ptmeConfig->setRate(RATE_100KBPS); + if (result == returnvalue::OK) { + mode = HasModesIF::MODE_ON; + } + }; if (mode == HasModesIF::MODE_ON) { enableTransmit(); - if (submode == static_cast(com::CcsdsSubmode::DATARATE_HIGH)) { - ReturnValue_t result = ptmeConfig->setRate(RATE_500KBPS); - if (result == returnvalue::OK) { - mode = HasModesIF::MODE_ON; + if (submode == static_cast(com::CcsdsSubmode::DATARATE_DEFAULT)) { + com::Datarate currentDatarate = com::getCurrentDatarate(); + if (currentDatarate == com::Datarate::LOW_RATE_MODULATION_BPSK) { + rateLow(); + } else if (currentDatarate == com::Datarate::HIGH_RATE_MODULATION_0QPSK) { + rateHigh(); } + } else if (submode == static_cast(com::CcsdsSubmode::DATARATE_HIGH)) { + rateHigh(); } else if (submode == static_cast(com::CcsdsSubmode::DATARATE_LOW)) { - ReturnValue_t result = ptmeConfig->setRate(RATE_100KBPS); - if (result == returnvalue::OK) { - mode = HasModesIF::MODE_ON; - } + rateLow(); } } else if (mode == HasModesIF::MODE_OFF) { disableTransmit(); @@ -399,9 +413,7 @@ void CcsdsIpCoreHandler::startTransition(Mode_t mode, Submode_t submode) { announceMode(false); } -void CcsdsIpCoreHandler::announceMode(bool recursive) { - triggerEvent(MODE_INFO, mode, submode); -} +void CcsdsIpCoreHandler::announceMode(bool recursive) { triggerEvent(MODE_INFO, mode, submode); } void CcsdsIpCoreHandler::disableTransmit() { #ifndef TE0720_1CFA