From 5ccb3d1488a0605e27d694310ace80cd9cb2c26c Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 11 Feb 2021 08:19:48 +0100 Subject: [PATCH] heater main switch commanding --- bsp_q7s/comIF/CspComIF.cpp | 8 ++++ fsfwconfig/OBSWConfig.h | 2 +- mission/core/GenericFactory.cpp | 2 +- mission/devices/HeaterHandler.cpp | 42 +++++++++++++++++-- mission/devices/HeaterHandler.h | 8 ++++ mission/devices/PCDUHandler.cpp | 5 +-- .../devicedefinitions/GomSpacePackets.h | 16 +++---- .../devicedefinitions/GomspaceDefinitions.h | 14 +++---- tmtc | 2 +- 9 files changed, 75 insertions(+), 24 deletions(-) diff --git a/bsp_q7s/comIF/CspComIF.cpp b/bsp_q7s/comIF/CspComIF.cpp index 4a95487b..52a92cc9 100644 --- a/bsp_q7s/comIF/CspComIF.cpp +++ b/bsp_q7s/comIF/CspComIF.cpp @@ -164,6 +164,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, if (commandPacket == NULL) { sif::error << "CspComIF::cspTransfer: Failed to get memory for a csp packet from the csp " << "stack" << std::endl; + csp_close(conn); return RETURN_FAILED; } @@ -173,6 +174,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, if (!csp_send(conn, commandPacket, timeout_ms)) { csp_buffer_free(commandPacket); sif::error << "CspComIF::cspTransfer: Failed to send csp packet" << std::endl; + csp_close(conn); return RETURN_FAILED; } @@ -185,6 +187,8 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, reply = csp_read(conn, timeout_ms); if (reply == NULL) { sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl; + csp_buffer_free(reply); + csp_close(conn); return RETURN_FAILED; } memcpy(replyBuffer, reply->data, reply->length); @@ -195,10 +199,13 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, reply = csp_read(conn, timeout_ms); if (reply == NULL) { sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl; + csp_close(conn); return RETURN_FAILED; } if ((reply->length + bytesRead) > iter->second.size()) { sif::error << "CspComIF::cspTransfer: Reply buffer to short" << std::endl; + csp_buffer_free(reply); + csp_close(conn); return RETURN_FAILED; } memcpy(replyBuffer + bytesRead, reply->data, reply->length); @@ -209,6 +216,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, if(expectedSize != 0){ sif::error << "CspComIF::cspTransfer: Received more bytes than requested" << std::endl; + csp_close(conn); return RETURN_FAILED; } diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 954931d8..ed3ee6f5 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -14,7 +14,7 @@ #define TE0720 0 -#define PDU2_DEBUG 0 +#define PDU2_DEBUG 1 #define PDU1_DEBUG 0 #include "OBSWVersion.h" diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index 0b50a45d..2a254cf0 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -73,7 +73,7 @@ void ObjectFactory::produceGenericObjects() { new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::EIVE_OBSW, pus::PUS_SERVICE_5, 50); new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, - apid::EIVE_OBSW, pus::PUS_SERVICE_8, 3, 10); + apid::EIVE_OBSW, pus::PUS_SERVICE_8, 3, 60); new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::EIVE_OBSW, pus::PUS_SERVICE_9); new Service17Test(objects::PUS_SERVICE_17_TEST, apid::EIVE_OBSW, diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 99e43b95..6f383ca1 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -112,6 +112,9 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, switchNr_t switchNr = *data; HeaterMapIter heaterMapIter = heaterMap.find(switchNr); if (heaterMapIter != heaterMap.end()) { + if (heaterMapIter->second.active) { + return COMMAND_ALREADY_WAITING; + } heaterMapIter->second.action = *(data + 1); heaterMapIter->second.active = true; heaterMapIter->second.replyQueue = commandedBy; @@ -184,7 +187,7 @@ void HeaterHandler::handleActiveCommands(){ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { - ReturnValue_t result; + ReturnValue_t result = RETURN_OK; switchNr_t switchNr; /* Check if command waits for main switch being set on and whether the timeout has expired */ @@ -192,7 +195,14 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { && heaterMapIter->second.mainSwitchCountdown.hasTimedOut()) { //TODO - This requires the initiation of an FDIR procedure triggerEvent(MAIN_SWITCH_TIMEOUT); + sif::error << "HeaterHandler::handleSwitchOnCommand: Main switch setting on timeout" + << std::endl; heaterMapIter->second.active = false; + heaterMapIter->second.waitMainSwitchOn = false; + if (heaterMapIter->second.replyQueue != commandQueue->getId()) { + actionHelper.finish(heaterMapIter->second.replyQueue, heaterMapIter->second.action, + MAIN_SWITCH_SET_TIMEOUT ); + } return; } @@ -202,7 +212,8 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { if (!checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); - result = gpioInterface->pullHigh(gpioId); +// result = gpioInterface->pullHigh(gpioId); + result = RETURN_OK; if (result != RETURN_OK) { sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" << gpioId << "high" << std::endl; @@ -222,11 +233,18 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { heaterMapIter->second.action, result); } heaterMapIter->second.active = false; + heaterMapIter->second.waitMainSwitchOn = false; + } + else if (mainSwitchState == PowerSwitchIF::SWITCH_OFF + && heaterMapIter->second.waitMainSwitchOn) { + /* Just waiting for the main switch being set on */ + return; } else if (mainSwitchState == PowerSwitchIF::SWITCH_OFF) { mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON); heaterMapIter->second.mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs()); + heaterMapIter->second.waitMainSwitchOn = true; } else { sif::debug << "HeaterHandler::handleActiveCommands: Failed to get state of" @@ -240,11 +258,13 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { } void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { - ReturnValue_t result; + ReturnValue_t result = RETURN_OK; switchNr_t switchNr = heaterMapIter->first; + /* Check whether switch is already off */ if (checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); - result = gpioInterface->pullLow(gpioId); +// result = gpioInterface->pullLow(gpioId); + result = RETURN_OK; if (result != RETURN_OK) { sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" << gpioId << " low" << std::endl; @@ -252,9 +272,14 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { } else { switchStates[switchNr] = OFF; + /* When all switches are off, also main line switch will be turned off */ + if (allSwitchesOff()) { + mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); + } } } else { + sif::info << "HeaterHandler::handleSwitchOffCommand: Switch already off" << std::endl; triggerEvent(SWITCH_ALREADY_OFF, switchNr); } if (heaterMapIter->second.replyQueue != NO_COMMANDER) { @@ -268,6 +293,15 @@ bool HeaterHandler::checkSwitchState(int switchNr) { return switchStates[switchNr]; } +bool HeaterHandler::allSwitchesOff() { + bool allSwitchesOrd = false; + /* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ + for (switchNr_t switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) { + allSwitchesOrd = allSwitchesOrd || switchStates[switchNr]; + } + return !allSwitchesOrd; +} + gpioId_t HeaterHandler::getGpioIdFromSwitchNr(int switchNr) { gpioId_t gpioId = 0xFFFF; switch(switchNr) { diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index d05b7609..22b33165 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -57,6 +57,8 @@ private: static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); static const ReturnValue_t INIT_FAILED = MAKE_RETURN_CODE(0xA2); static const ReturnValue_t INVALID_SWITCH_NR = MAKE_RETURN_CODE(0xA3); + static const ReturnValue_t MAIN_SWITCH_SET_TIMEOUT = MAKE_RETURN_CODE(0xA4); + static const ReturnValue_t COMMAND_ALREADY_WAITING = MAKE_RETURN_CODE(0xA5); static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_HANDLER; static const Event GPIO_PULL_HIGH_FAILED = MAKE_EVENT(0, severity::LOW); @@ -168,6 +170,12 @@ private: void handleSwitchOffCommand(HeaterMapIter heaterMapIter); + /** + * @brief Checks if all switches are off. + * @return True if all switches are off, otherwise false. + */ + bool allSwitchesOff(); + }; #endif /* MISSION_DEVICES_HEATERHANDLER_H_ */ diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index f441cf3d..6e9227d3 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -223,8 +223,7 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const return; } - const uint8_t* parameterValuePtr = ¶meterValue; - GomspaceSetParamMessage setParamMessage(memoryAddress, ¶meterValuePtr, parameterValueSize); + GomspaceSetParamMessage setParamMessage(memoryAddress, ¶meterValue, parameterValueSize); size_t serializedLength = 0; uint8_t command[4]; @@ -268,7 +267,7 @@ ReturnValue_t PCDUHandler::getFuseState( uint8_t fuseNr ) const { } uint32_t PCDUHandler::getSwitchDelayMs(void) const { - return 5000; + return 15000; } object_id_t PCDUHandler::getObjectId() const { diff --git a/mission/devices/devicedefinitions/GomSpacePackets.h b/mission/devices/devicedefinitions/GomSpacePackets.h index cd2b1f28..d410a3af 100644 --- a/mission/devices/devicedefinitions/GomSpacePackets.h +++ b/mission/devices/devicedefinitions/GomSpacePackets.h @@ -394,7 +394,7 @@ class GomspaceSetParamMessage : public SerialLinkedListAdapter { public: /* The size of the largest parameter */ - static const uint32_t MAX_SIZE = 4; + static const uint8_t MAX_SIZE = 4; /** * @brief Constructor @@ -404,11 +404,9 @@ public: * @param parameterSize The size of the parameter. * */ - GomspaceSetParamMessage(uint16_t memoryAddress, const uint8_t** parameterValue, + GomspaceSetParamMessage(uint16_t memoryAddress, const uint8_t* parameterValue, uint8_t parameterSize) : - memoryAddress(memoryAddress) { - size_t size = parameterSize; - parameterValueInfo.deSerialize(parameterValue, &size, SerializeIF::Endianness::BIG); + memoryAddress(memoryAddress), parameterValueBuffer(parameterValue, parameterSize, true) { setLinks(); } @@ -416,10 +414,14 @@ private: GomspaceSetParamMessage(const GomspaceSetParamMessage &reply); void setLinks() { setStart(&memoryAddress); - memoryAddress.setNext(¶meterValueInfo); + memoryAddress.setNext(¶meterValueBuffer); } SerializeElement memoryAddress; - SerializeElement> parameterValueInfo; + /** + * Parameter can be uint8_t, uint16_t or uint32_t. Thus max size of parameterValueBuffer is + * four bytes. + */ + SerializeElement> parameterValueBuffer; }; diff --git a/mission/devices/devicedefinitions/GomspaceDefinitions.h b/mission/devices/devicedefinitions/GomspaceDefinitions.h index 970af25f..43bf60b1 100644 --- a/mission/devices/devicedefinitions/GomspaceDefinitions.h +++ b/mission/devices/devicedefinitions/GomspaceDefinitions.h @@ -829,13 +829,13 @@ namespace PDU2 { */ static const uint16_t CONFIG_ADDRESS_OUT_EN_Q7S = 0x48; static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH1 = 0x49; - static const uint16_t CONFIG_ADDRESS_OUT_EN_RW = 0x50; - static const uint16_t CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN = 0x51; - static const uint16_t CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT = 0x52; - static const uint16_t CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM = 0x53; - static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6PLOC = 0x54; - static const uint16_t CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B = 0x55; - static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA = 0x56; + static const uint16_t CONFIG_ADDRESS_OUT_EN_RW = 0x4A; + static const uint16_t CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN = 0x4B; + static const uint16_t CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT = 0x4C; + static const uint16_t CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM = 0x4D; + static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6PLOC = 0x4E; + static const uint16_t CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B = 0x4F; + static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA = 0x50; /** * @brief This class defines a dataset for the hk table of the PDU2. diff --git a/tmtc b/tmtc index b4868b78..4433fb68 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit b4868b78e1eca3680e3d21924da80418737d11e9 +Subproject commit 4433fb68ac268ab72f763c2ef80b13d84600ad47