From ae6f6538d2ace17b0364f8db5356b90081d2bda4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 Jan 2023 19:40:27 +0100 Subject: [PATCH] add syrlinks submode handling --- bsp_q7s/core/ObjectFactory.cpp | 4 +- mission/devices/SyrlinksHandler.cpp | 111 +++++++++++++++--- mission/devices/SyrlinksHandler.h | 15 ++- .../devicedefinitions/SyrlinksDefinitions.h | 8 ++ 4 files changed, 117 insertions(+), 21 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 6754a49b..503ac067 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -56,6 +56,7 @@ #endif #include #include +#include #include @@ -88,7 +89,6 @@ #include "mission/devices/RadiationSensorHandler.h" #include "mission/devices/RwHandler.h" #include "mission/devices/SolarArrayDeploymentHandler.h" -#include #include "mission/devices/Tmp1075Handler.h" #include "mission/devices/devicedefinitions/GomspaceDefinitions.h" #include "mission/devices/devicedefinitions/Max31865Definitions.h" @@ -587,7 +587,7 @@ void ObjectFactory::createSyrlinksComponents(PowerSwitchIF* pwrSwitcher) { auto syrlinksFdir = new SyrlinksFdir(objects::SYRLINKS_HK_HANDLER); auto syrlinksHandler = new SyrlinksHandler(objects::SYRLINKS_HK_HANDLER, objects::UART_COM_IF, syrlinksUartCookie, - pcdu::PDU1_CH1_SYRLINKS_12V, syrlinksFdir); + pcdu::PDU1_CH1_SYRLINKS_12V, syrlinksFdir); syrlinksHandler->setPowerSwitcher(pwrSwitcher); #if OBSW_DEBUG_SYRLINKS == 1 syrlinksHandler->setDebugMode(true); diff --git a/mission/devices/SyrlinksHandler.cpp b/mission/devices/SyrlinksHandler.cpp index 9462da73..4205f67f 100644 --- a/mission/devices/SyrlinksHandler.cpp +++ b/mission/devices/SyrlinksHandler.cpp @@ -1,10 +1,11 @@ #include #include #include + #include "OBSWConfig.h" SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, - power::Switch_t powerSwitch, FailureIsolationBase* customFdir) + power::Switch_t powerSwitch, FailureIsolationBase* customFdir) : DeviceHandlerBase(objectId, comIF, comCookie, customFdir), rxDataset(this), txDataset(this), @@ -15,16 +16,17 @@ SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, Cookie } } -SyrlinksHandler::~SyrlinksHandler() {} +SyrlinksHandler::~SyrlinksHandler() = default; void SyrlinksHandler::doStartUp() { - switch (startupState) { - case StartupState::OFF: { - startupState = StartupState::ENABLE_TEMPERATURE_PROTECTION; + switch (internalState) { + case InternalState::OFF: { + internalState = InternalState::ENABLE_TEMPERATURE_PROTECTION; break; } - case StartupState::DONE: { + case InternalState::IDLE: { setMode(_MODE_TO_ON); + commandExecuted = false; break; } default: @@ -34,6 +36,8 @@ void SyrlinksHandler::doStartUp() { void SyrlinksHandler::doShutDown() { setMode(_MODE_POWER_DOWN); + commandExecuted = false; + internalState = InternalState::OFF; temperatureSet.setValidity(false, true); } @@ -84,11 +88,23 @@ ReturnValue_t SyrlinksHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { } ReturnValue_t SyrlinksHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { - switch (startupState) { - case StartupState::ENABLE_TEMPERATURE_PROTECTION: { + switch (internalState) { + case InternalState::ENABLE_TEMPERATURE_PROTECTION: { *id = syrlinks::WRITE_LCL_CONFIG; return buildCommandFromCommand(*id, nullptr, 0); } + case InternalState::SET_TX_MODULATION: { + *id = syrlinks::SET_TX_MODE_MODULATION; + return buildCommandFromCommand(*id, nullptr, 0); + } + case InternalState::SET_TX_CW: { + *id = syrlinks::SET_TX_MODE_CW; + return buildCommandFromCommand(*id, nullptr, 0); + } + case InternalState::SET_TX_STANDBY: { + *id = syrlinks::SET_TX_MODE_STANDBY; + return buildCommandFromCommand(*id, nullptr, 0); + } default: break; } @@ -96,8 +112,8 @@ ReturnValue_t SyrlinksHandler::buildTransitionDeviceCommand(DeviceCommandId_t* i } ReturnValue_t SyrlinksHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, - const uint8_t* commandData, - size_t commandDataLen) { + const uint8_t* commandData, + size_t commandDataLen) { switch (deviceCommand) { case (syrlinks::RESET_UNIT): { prepareCommand(resetCommand, deviceCommand); @@ -223,7 +239,7 @@ void SyrlinksHandler::fillCommandAndReplyMap() { } ReturnValue_t SyrlinksHandler::scanForReply(const uint8_t* start, size_t remainingSize, - DeviceCommandId_t* foundId, size_t* foundLen) { + DeviceCommandId_t* foundId, size_t* foundLen) { ReturnValue_t result = returnvalue::OK; if (*start != '<') { @@ -592,7 +608,7 @@ void SyrlinksHandler::setNormalDatapoolEntriesInvalid() {} uint32_t SyrlinksHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; } ReturnValue_t SyrlinksHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) { + LocalDataPoolManager& poolManager) { localDataPoolMap.emplace(syrlinks::RX_STATUS, new PoolEntry({0})); localDataPoolMap.emplace(syrlinks::RX_SENSITIVITY, new PoolEntry({0})); localDataPoolMap.emplace(syrlinks::RX_FREQUENCY_SHIFT, new PoolEntry({0})); @@ -624,10 +640,36 @@ float SyrlinksHandler::calcTempVal(uint16_t raw) { return 0.126984 * raw - 67.87 ReturnValue_t SyrlinksHandler::handleAckReply(const uint8_t* packet) { ReturnValue_t result = parseReplyStatus(reinterpret_cast(packet + syrlinks::MESSAGE_HEADER_SIZE)); - if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result != returnvalue::OK) { - startupState = StartupState::OFF; - } else if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result == returnvalue::OK) { - startupState = StartupState::DONE; + switch (rememberCommandId) { + case (syrlinks::WRITE_LCL_CONFIG): { + if (result != returnvalue::OK) { + internalState = InternalState::OFF; + } else if (result == returnvalue::OK) { + internalState = InternalState::IDLE; + } + break; + } + case (syrlinks::SET_TX_MODE_STANDBY): { + if (result == returnvalue::OK) { + internalState = InternalState::IDLE; + commandExecuted = true; + } + break; + } + case (syrlinks::SET_TX_MODE_MODULATION): { + if (result == returnvalue::OK) { + internalState = InternalState::IDLE; + commandExecuted = true; + } + break; + } + case (syrlinks::SET_TX_MODE_CW): { + if (result == returnvalue::OK) { + internalState = InternalState::IDLE; + commandExecuted = true; + } + break; + } } return result; } @@ -640,3 +682,40 @@ void SyrlinksHandler::prepareCommand(std::string command, DeviceCommandId_t comm } void SyrlinksHandler::setDebugMode(bool enable) { this->debugMode = enable; } + +void SyrlinksHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { + Mode_t tgtMode = getBaseMode(getMode()); + if (tgtMode == HasModesIF::MODE_ON or tgtMode == DeviceHandlerIF::MODE_NORMAL) { + switch (getSubmode()) { + case (syrlinks::Submode::TX_MODULATION): { + if (commandExecuted) { + setMode(tgtMode); + return; + } + internalState = InternalState::SET_TX_MODULATION; + break; + } + case (syrlinks::Submode::TX_STANDBY): { + if (commandExecuted) { + setMode(tgtMode); + return; + } + internalState = InternalState::SET_TX_STANDBY; + break; + } + case (syrlinks::Submode::TX_CW): { + if (commandExecuted) { + setMode(tgtMode); + return; + } + internalState = InternalState::SET_TX_CW; + break; + } + default: { + setMode(tgtMode); + } + } + } else { + setMode(tgtMode); + } +} diff --git a/mission/devices/SyrlinksHandler.h b/mission/devices/SyrlinksHandler.h index 2eb849be..8940da29 100644 --- a/mission/devices/SyrlinksHandler.h +++ b/mission/devices/SyrlinksHandler.h @@ -21,7 +21,7 @@ class SyrlinksHandler : public DeviceHandlerBase { public: SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, - power::Switch_t powerSwitch, FailureIsolationBase* customFdir); + power::Switch_t powerSwitch, FailureIsolationBase* customFdir); virtual ~SyrlinksHandler(); /** @@ -34,6 +34,7 @@ class SyrlinksHandler : public DeviceHandlerBase { protected: void doStartUp() override; void doShutDown() override; + void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override; ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, @@ -104,12 +105,20 @@ class SyrlinksHandler : public DeviceHandlerBase { uint16_t rawTempBasebandBoard = 0; float tempPowerAmplifier = 0; float tempBasebandBoard = 0; + bool commandExecuted = false; uint8_t commandBuffer[syrlinks::MAX_COMMAND_SIZE]; - enum class StartupState { OFF, ENABLE_TEMPERATURE_PROTECTION, DONE }; + enum class InternalState { + OFF, + ENABLE_TEMPERATURE_PROTECTION, + SET_TX_MODULATION, + SET_TX_CW, + SET_TX_STANDBY, + IDLE + }; - StartupState startupState = StartupState::OFF; + InternalState internalState = InternalState::OFF; /** * This object is used to store the id of the next command to execute. This controls the diff --git a/mission/devices/devicedefinitions/SyrlinksDefinitions.h b/mission/devices/devicedefinitions/SyrlinksDefinitions.h index 14d5b621..05ac7f0f 100644 --- a/mission/devices/devicedefinitions/SyrlinksDefinitions.h +++ b/mission/devices/devicedefinitions/SyrlinksDefinitions.h @@ -6,6 +6,14 @@ namespace syrlinks { +enum Submode { + DEFAULT, + TX_STANDBY, + TX_MODULATION, + // TODO: Is this needed? + TX_CW +}; + static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYRLINKS; static constexpr Event FDIR_REACTION_IGNORED = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM);