heater main switch commanding

This commit is contained in:
Jakob Meier 2021-02-11 08:19:48 +01:00
parent db04a06bdb
commit 1fb042875e
9 changed files with 75 additions and 24 deletions

View File

@ -164,6 +164,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
if (commandPacket == NULL) { if (commandPacket == NULL) {
sif::error << "CspComIF::cspTransfer: Failed to get memory for a csp packet from the csp " sif::error << "CspComIF::cspTransfer: Failed to get memory for a csp packet from the csp "
<< "stack" << std::endl; << "stack" << std::endl;
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -173,6 +174,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
if (!csp_send(conn, commandPacket, timeout_ms)) { if (!csp_send(conn, commandPacket, timeout_ms)) {
csp_buffer_free(commandPacket); csp_buffer_free(commandPacket);
sif::error << "CspComIF::cspTransfer: Failed to send csp packet" << std::endl; sif::error << "CspComIF::cspTransfer: Failed to send csp packet" << std::endl;
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -185,6 +187,8 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
reply = csp_read(conn, timeout_ms); reply = csp_read(conn, timeout_ms);
if (reply == NULL) { if (reply == NULL) {
sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl; sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl;
csp_buffer_free(reply);
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }
memcpy(replyBuffer, reply->data, reply->length); 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); reply = csp_read(conn, timeout_ms);
if (reply == NULL) { if (reply == NULL) {
sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl; sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl;
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }
if ((reply->length + bytesRead) > iter->second.size()) { if ((reply->length + bytesRead) > iter->second.size()) {
sif::error << "CspComIF::cspTransfer: Reply buffer to short" << std::endl; sif::error << "CspComIF::cspTransfer: Reply buffer to short" << std::endl;
csp_buffer_free(reply);
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }
memcpy(replyBuffer + bytesRead, reply->data, reply->length); memcpy(replyBuffer + bytesRead, reply->data, reply->length);
@ -209,6 +216,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
if(expectedSize != 0){ if(expectedSize != 0){
sif::error << "CspComIF::cspTransfer: Received more bytes than requested" << std::endl; sif::error << "CspComIF::cspTransfer: Received more bytes than requested" << std::endl;
csp_close(conn);
return RETURN_FAILED; return RETURN_FAILED;
} }

View File

@ -14,7 +14,7 @@
#define TE0720 0 #define TE0720 0
#define PDU2_DEBUG 0 #define PDU2_DEBUG 1
#define PDU1_DEBUG 0 #define PDU1_DEBUG 0
#include "OBSWVersion.h" #include "OBSWVersion.h"

View File

@ -73,7 +73,7 @@ void ObjectFactory::produceGenericObjects() {
new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING,
apid::EIVE_OBSW, pus::PUS_SERVICE_5, 50); apid::EIVE_OBSW, pus::PUS_SERVICE_5, 50);
new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, 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, new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT,
apid::EIVE_OBSW, pus::PUS_SERVICE_9); apid::EIVE_OBSW, pus::PUS_SERVICE_9);
new Service17Test(objects::PUS_SERVICE_17_TEST, apid::EIVE_OBSW, new Service17Test(objects::PUS_SERVICE_17_TEST, apid::EIVE_OBSW,

View File

@ -112,6 +112,9 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId,
switchNr_t switchNr = *data; switchNr_t switchNr = *data;
HeaterMapIter heaterMapIter = heaterMap.find(switchNr); HeaterMapIter heaterMapIter = heaterMap.find(switchNr);
if (heaterMapIter != heaterMap.end()) { if (heaterMapIter != heaterMap.end()) {
if (heaterMapIter->second.active) {
return COMMAND_ALREADY_WAITING;
}
heaterMapIter->second.action = *(data + 1); heaterMapIter->second.action = *(data + 1);
heaterMapIter->second.active = true; heaterMapIter->second.active = true;
heaterMapIter->second.replyQueue = commandedBy; heaterMapIter->second.replyQueue = commandedBy;
@ -184,7 +187,7 @@ void HeaterHandler::handleActiveCommands(){
void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) {
ReturnValue_t result; ReturnValue_t result = RETURN_OK;
switchNr_t switchNr; switchNr_t switchNr;
/* Check if command waits for main switch being set on and whether the timeout has expired */ /* 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()) { && heaterMapIter->second.mainSwitchCountdown.hasTimedOut()) {
//TODO - This requires the initiation of an FDIR procedure //TODO - This requires the initiation of an FDIR procedure
triggerEvent(MAIN_SWITCH_TIMEOUT); triggerEvent(MAIN_SWITCH_TIMEOUT);
sif::error << "HeaterHandler::handleSwitchOnCommand: Main switch setting on timeout"
<< std::endl;
heaterMapIter->second.active = false; 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; return;
} }
@ -202,7 +212,8 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) {
if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { if (mainSwitchState == PowerSwitchIF::SWITCH_ON) {
if (!checkSwitchState(switchNr)) { if (!checkSwitchState(switchNr)) {
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
result = gpioInterface->pullHigh(gpioId); // result = gpioInterface->pullHigh(gpioId);
result = RETURN_OK;
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id"
<< gpioId << "high" << std::endl; << gpioId << "high" << std::endl;
@ -222,11 +233,18 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) {
heaterMapIter->second.action, result); heaterMapIter->second.action, result);
} }
heaterMapIter->second.active = false; 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) { else if (mainSwitchState == PowerSwitchIF::SWITCH_OFF) {
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, mainLineSwitcher->sendSwitchCommand(mainLineSwitch,
PowerSwitchIF::SWITCH_ON); PowerSwitchIF::SWITCH_ON);
heaterMapIter->second.mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs()); heaterMapIter->second.mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs());
heaterMapIter->second.waitMainSwitchOn = true;
} }
else { else {
sif::debug << "HeaterHandler::handleActiveCommands: Failed to get state of" sif::debug << "HeaterHandler::handleActiveCommands: Failed to get state of"
@ -240,11 +258,13 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) {
} }
void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) {
ReturnValue_t result; ReturnValue_t result = RETURN_OK;
switchNr_t switchNr = heaterMapIter->first; switchNr_t switchNr = heaterMapIter->first;
/* Check whether switch is already off */
if (checkSwitchState(switchNr)) { if (checkSwitchState(switchNr)) {
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
result = gpioInterface->pullLow(gpioId); // result = gpioInterface->pullLow(gpioId);
result = RETURN_OK;
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id"
<< gpioId << " low" << std::endl; << gpioId << " low" << std::endl;
@ -252,9 +272,14 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) {
} }
else { else {
switchStates[switchNr] = OFF; 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 { else {
sif::info << "HeaterHandler::handleSwitchOffCommand: Switch already off" << std::endl;
triggerEvent(SWITCH_ALREADY_OFF, switchNr); triggerEvent(SWITCH_ALREADY_OFF, switchNr);
} }
if (heaterMapIter->second.replyQueue != NO_COMMANDER) { if (heaterMapIter->second.replyQueue != NO_COMMANDER) {
@ -268,6 +293,15 @@ bool HeaterHandler::checkSwitchState(int switchNr) {
return switchStates[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 HeaterHandler::getGpioIdFromSwitchNr(int switchNr) {
gpioId_t gpioId = 0xFFFF; gpioId_t gpioId = 0xFFFF;
switch(switchNr) { switch(switchNr) {

View File

@ -57,6 +57,8 @@ private:
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); 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 INIT_FAILED = MAKE_RETURN_CODE(0xA2);
static const ReturnValue_t INVALID_SWITCH_NR = MAKE_RETURN_CODE(0xA3); 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 uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_HANDLER;
static const Event GPIO_PULL_HIGH_FAILED = MAKE_EVENT(0, severity::LOW); static const Event GPIO_PULL_HIGH_FAILED = MAKE_EVENT(0, severity::LOW);
@ -168,6 +170,12 @@ private:
void handleSwitchOffCommand(HeaterMapIter heaterMapIter); 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_ */ #endif /* MISSION_DEVICES_HEATERHANDLER_H_ */

View File

@ -223,8 +223,7 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const
return; return;
} }
const uint8_t* parameterValuePtr = &parameterValue; GomspaceSetParamMessage setParamMessage(memoryAddress, &parameterValue, parameterValueSize);
GomspaceSetParamMessage setParamMessage(memoryAddress, &parameterValuePtr, parameterValueSize);
size_t serializedLength = 0; size_t serializedLength = 0;
uint8_t command[4]; uint8_t command[4];
@ -268,7 +267,7 @@ ReturnValue_t PCDUHandler::getFuseState( uint8_t fuseNr ) const {
} }
uint32_t PCDUHandler::getSwitchDelayMs(void) const { uint32_t PCDUHandler::getSwitchDelayMs(void) const {
return 5000; return 15000;
} }
object_id_t PCDUHandler::getObjectId() const { object_id_t PCDUHandler::getObjectId() const {

View File

@ -394,7 +394,7 @@ class GomspaceSetParamMessage : public SerialLinkedListAdapter<SerializeIF> {
public: public:
/* The size of the largest parameter */ /* The size of the largest parameter */
static const uint32_t MAX_SIZE = 4; static const uint8_t MAX_SIZE = 4;
/** /**
* @brief Constructor * @brief Constructor
@ -404,11 +404,9 @@ public:
* @param parameterSize The size of the parameter. * @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) : uint8_t parameterSize) :
memoryAddress(memoryAddress) { memoryAddress(memoryAddress), parameterValueBuffer(parameterValue, parameterSize, true) {
size_t size = parameterSize;
parameterValueInfo.deSerialize(parameterValue, &size, SerializeIF::Endianness::BIG);
setLinks(); setLinks();
} }
@ -416,10 +414,14 @@ private:
GomspaceSetParamMessage(const GomspaceSetParamMessage &reply); GomspaceSetParamMessage(const GomspaceSetParamMessage &reply);
void setLinks() { void setLinks() {
setStart(&memoryAddress); setStart(&memoryAddress);
memoryAddress.setNext(&parameterValueInfo); memoryAddress.setNext(&parameterValueBuffer);
} }
SerializeElement<uint16_t> memoryAddress; SerializeElement<uint16_t> memoryAddress;
SerializeElement<SerialFixedArrayListAdapter<uint8_t, MAX_SIZE, uint8_t>> parameterValueInfo; /**
* Parameter can be uint8_t, uint16_t or uint32_t. Thus max size of parameterValueBuffer is
* four bytes.
*/
SerializeElement<SerialBufferAdapter<uint8_t>> parameterValueBuffer;
}; };

View File

@ -829,13 +829,13 @@ namespace PDU2 {
*/ */
static const uint16_t CONFIG_ADDRESS_OUT_EN_Q7S = 0x48; 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_PAYLOAD_PCDU_CH1 = 0x49;
static const uint16_t CONFIG_ADDRESS_OUT_EN_RW = 0x50; static const uint16_t CONFIG_ADDRESS_OUT_EN_RW = 0x4A;
static const uint16_t CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN = 0x51; static const uint16_t CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN = 0x4B;
static const uint16_t CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT = 0x52; static const uint16_t CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT = 0x4C;
static const uint16_t CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM = 0x53; static const uint16_t CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM = 0x4D;
static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6PLOC = 0x54; static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6PLOC = 0x4E;
static const uint16_t CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B = 0x55; static const uint16_t CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B = 0x4F;
static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA = 0x56; static const uint16_t CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA = 0x50;
/** /**
* @brief This class defines a dataset for the hk table of the PDU2. * @brief This class defines a dataset for the hk table of the PDU2.

2
tmtc

@ -1 +1 @@
Subproject commit b4868b78e1eca3680e3d21924da80418737d11e9 Subproject commit 4433fb68ac268ab72f763c2ef80b13d84600ad47