eive-obsw/mission/devices/SolarArrayDeploymentHandler.cpp

178 lines
7.2 KiB
C++
Raw Normal View History

#include "SolarArrayDeploymentHandler.h"
#include <devices/gpioIds.h>
#include <fsfw/ipc/QueueFactory.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw_hal/common/gpio/GpioCookie.h>
2022-10-12 13:56:25 +02:00
SolarArrayDeploymentHandler::SolarArrayDeploymentHandler(object_id_t setObjectId_,
GpioIF& gpioInterface,
PowerSwitchIF& mainLineSwitcher_,
pcdu::Switches mainLineSwitch_,
2022-10-12 14:09:07 +02:00
gpioId_t deplSA1, gpioId_t deplSA2,
SdCardMountedIF& sdcMountedIF)
: SystemObject(setObjectId_),
2022-10-12 13:56:25 +02:00
gpioInterface(gpioInterface),
deplSA1(deplSA1),
deplSA2(deplSA2),
2022-10-12 13:21:58 +02:00
mainLineSwitcher(mainLineSwitcher_),
mainLineSwitch(mainLineSwitch_),
actionHelper(this, nullptr) {
auto mqArgs = MqArgs(setObjectId_, static_cast<void*>(this));
commandQueue = QueueFactory::instance()->createMessageQueue(
cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
SolarArrayDeploymentHandler::~SolarArrayDeploymentHandler() {}
ReturnValue_t SolarArrayDeploymentHandler::performOperation(uint8_t operationCode) {
2022-10-12 14:09:07 +02:00
handleStateMachine();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t SolarArrayDeploymentHandler::initialize() {
2022-10-12 14:09:07 +02:00
ReturnValue_t result = actionHelper.initialize(commandQueue);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2022-10-12 14:09:07 +02:00
return SystemObject::initialize();
}
void SolarArrayDeploymentHandler::handleStateMachine() {
2022-10-12 13:56:25 +02:00
// switch (stateMachine) {
// case WAIT_ON_DELOYMENT_COMMAND:
// readCommandQueue();
// break;
// case SWITCH_8V_ON:
// mainLineSwitcher.sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON);
// mainSwitchCountdown.setTimeout(mainLineSwitcher.getSwitchDelayMs());
// stateMachine = WAIT_ON_8V_SWITCH;
// break;
// case WAIT_ON_8V_SWITCH:
// performWaitOn8VActions();
// break;
// case SWITCH_DEPL_GPIOS:
// deploymentTransistorsOn();
// break;
2022-10-12 13:58:48 +02:00
// case WAIT_ON_DEPLOYMENT_FINISH:
// handleDeploymentFinish();
// break;
2022-10-12 13:56:25 +02:00
// case WAIT_FOR_MAIN_SWITCH_OFF:
// if (mainLineSwitcher.getSwitchState(mainLineSwitch) == PowerSwitchIF::SWITCH_OFF) {
// stateMachine = WAIT_ON_DELOYMENT_COMMAND;
// } else if (mainSwitchCountdown.hasTimedOut()) {
// triggerEvent(MAIN_SWITCH_OFF_TIMEOUT);
// sif::error << "SolarArrayDeploymentHandler::handleStateMachine: Failed to switch main"
// << " switch off" << std::endl;
// stateMachine = WAIT_ON_DELOYMENT_COMMAND;
// }
// break;
// default:
// sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Invalid state" <<
// std::endl; break;
// }
}
void SolarArrayDeploymentHandler::performWaitOn8VActions() {
2022-10-12 13:56:25 +02:00
// if (mainLineSwitcher.getSwitchState(mainLineSwitch) == PowerSwitchIF::SWITCH_ON) {
// stateMachine = SWITCH_DEPL_GPIOS;
// } else {
// if (mainSwitchCountdown.hasTimedOut()) {
// triggerEvent(MAIN_SWITCH_ON_TIMEOUT);
// actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS,
// MAIN_SWITCH_TIMEOUT_FAILURE);
// stateMachine = WAIT_ON_DELOYMENT_COMMAND;
// }
// }
}
2022-10-12 13:21:58 +02:00
void SolarArrayDeploymentHandler::deploymentTransistorsOn() {
2022-10-12 13:56:25 +02:00
// ReturnValue_t result = returnvalue::OK;
// result = gpioInterface->pullHigh(deplSA1);
// if (result != returnvalue::OK) {
// sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
// " array deployment switch 1 high "
// << std::endl;
// /* If gpio switch high failed, state machine is reset to wait for a command reinitiating
// * the deployment sequence. */
// stateMachine = WAIT_ON_DELOYMENT_COMMAND;
// triggerEvent(DEPL_SA1_GPIO_SWTICH_ON_FAILED);
// actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS,
// SWITCHING_DEPL_SA2_FAILED); mainLineSwitcher.sendSwitchCommand(mainLineSwitch,
// PowerSwitchIF::SWITCH_OFF);
// }
// result = gpioInterface->pullHigh(deplSA2);
// if (result != returnvalue::OK) {
// sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
// " array deployment switch 2 high "
// << std::endl;
// stateMachine = WAIT_ON_DELOYMENT_COMMAND;
// triggerEvent(DEPL_SA2_GPIO_SWTICH_ON_FAILED);
// actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS,
// SWITCHING_DEPL_SA2_FAILED); mainLineSwitcher.sendSwitchCommand(mainLineSwitch,
// PowerSwitchIF::SWITCH_OFF);
// }
// deploymentCountdown.setTimeout(burnTimeMs);
// stateMachine = WAIT_ON_DEPLOYMENT_FINISH;
}
2022-10-12 13:56:25 +02:00
// void SolarArrayDeploymentHandler::handleDeploymentFinish() {
// ReturnValue_t result = returnvalue::OK;
2022-10-12 13:58:48 +02:00
// if (deploymentCountdown.hasTimedOut()) {
// actionHelper.finish(true, rememberCommanderId, DEPLOY_SOLAR_ARRAYS, returnvalue::OK);
// result = gpioInterface->pullLow(deplSA1);
// if (result != returnvalue::OK) {
// sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
// " array deployment switch 1 low "
// << std::endl;
// }
// result = gpioInterface->pullLow(deplSA2);
// if (result != returnvalue::OK) {
// sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
// " array deployment switch 2 low "
// << std::endl;
// }
2022-10-12 13:21:58 +02:00
// mainLineSwitcher.sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
// mainSwitchCountdown.setTimeout(mainLineSwitcher.getSwitchDelayMs());
// stateMachine = WAIT_FOR_MAIN_SWITCH_OFF;
// }
//}
void SolarArrayDeploymentHandler::readCommandQueue() {
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return;
}
result = actionHelper.handleActionMessage(&command);
2022-08-24 17:27:47 +02:00
if (result == returnvalue::OK) {
return;
}
}
ReturnValue_t SolarArrayDeploymentHandler::executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
ReturnValue_t result;
2022-10-12 13:56:25 +02:00
// if (stateMachine != WAIT_ON_DELOYMENT_COMMAND) {
// sif::error << "SolarArrayDeploymentHandler::executeAction: Received command while not in"
// << "waiting-on-command-state" << std::endl;
// return DEPLOYMENT_ALREADY_EXECUTING;
// }
// if (actionId != DEPLOY_SOLAR_ARRAYS) {
// sif::error << "SolarArrayDeploymentHandler::executeAction: Received invalid command"
// << std::endl;
// result = COMMAND_NOT_SUPPORTED;
// } else {
// stateMachine = SWITCH_8V_ON;
// rememberCommanderId = commandedBy;
// result = returnvalue::OK;
// }
return result;
}
MessageQueueId_t SolarArrayDeploymentHandler::getCommandQueue() const {
return commandQueue->getId();
}