heater handler wip
This commit is contained in:
@ -1,121 +1,101 @@
|
||||
#include <mission/devices/HeaterHandler.h>
|
||||
#include <fsfwconfig/devices/powerSwitcherList.h>
|
||||
|
||||
HeaterHandler::HeaterHandler(object_id_t setObjectId,
|
||||
object_id_t gpioDriverId, CookieIF * gpioCookie, object_id_t mainLineSwitcherObjectId, uint8_t mainLineSwitch) :
|
||||
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
|
||||
gpioDriverId(gpioDriver), gpioCookie(gpioCookie), mainLineSwitcherObjectId(mainLineSwitcherObjectId), mainLineSwitch(mainLineSwitch),
|
||||
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
||||
actionHelper(this, nullptr), hkManager(this, nullptr),
|
||||
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
|
||||
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
|
||||
switchOffWasReported(false), childTransitionDelay(5000),
|
||||
transitionSourceMode(_MODE_POWER_DOWN),
|
||||
transitionSourceSubMode(SUBMODE_NONE) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
powerSwitcher = objectManager->get<PowerSwitcherIF>(
|
||||
mainLineSwitcherObjectId);
|
||||
HeaterHandler::HeaterHandler(object_id_t setObjectId, object_id_t gpioDriverId,
|
||||
CookieIF * gpioCookie, object_id_t mainLineSwitcherObjectId, uint8_t mainLineSwitch) :
|
||||
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), gpioDriverId(gpioDriver),
|
||||
gpioCookie(gpioCookie), mainLineSwitcherObjectId(mainLineSwitcherObjectId), mainLineSwitch(
|
||||
mainLineSwitch), actionHelper(this, nullptr) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
HeaterHandler::~HeaterHandler() {
|
||||
}
|
||||
|
||||
ReturnValue_t performOperation(uint8_t operationCode) {
|
||||
ReturnValue_t HeaterHandler::performOperation(uint8_t operationCode) {
|
||||
|
||||
if (operationCode == DeviceHandlerIF::PERFORM_OPERATION) {
|
||||
readCommandQueue();
|
||||
handlePendingCommand();
|
||||
doStateMachine();
|
||||
|
||||
checkSwitchState();
|
||||
decrementDeviceReplyMap();
|
||||
fdirInstance->checkForFailures();
|
||||
hkSwitcher.performOperation();
|
||||
performOperationHook();
|
||||
handleActiveCommands();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
ReturnValue_t HeaterHandler::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
result = initializeHeaterMap();
|
||||
if (result != RETURN_OK) {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
gpioInterface = objectManager->get<GpioIF>(gpioDriverId);
|
||||
if (gpioInterface == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "HeaterHandler::initialize: Invalid Gpio interface."
|
||||
<< std::endl;
|
||||
#endif
|
||||
sif::error << "HeaterHandler::initialize: Invalid Gpio interface." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
result = gpioInterface->initializeInterface(gpioCookie);
|
||||
if (result != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "HeaterHandler::initialize: Failed to initialize Gpio "
|
||||
<< "interface"<< std::endl;
|
||||
#endif
|
||||
return result;
|
||||
sif::error << "HeaterHandler::initialize: Failed to initialize Gpio interface" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (IPCStore == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "HeaterHandler::initialize: IPC store not set up in "
|
||||
"factory." << std::endl;
|
||||
#endif
|
||||
sif::error << "HeaterHandler::initialize: IPC store not set up in factory." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
if(powerSwitcherId != objects::NO_OBJECT) {
|
||||
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
|
||||
if (powerSwitcher == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "HeaterHandler::initialize: Power switcher "
|
||||
<< "object ID set but no valid object found." << std::endl;
|
||||
#endif
|
||||
if(mainLineSwitcherObjectId != objects::NO_OBJECT) {
|
||||
mainLineSwitcher = objectManager->get<PowerSwitchIF>(mainLineSwitcherObjectId);
|
||||
if (mainLineSwitcher == nullptr) {
|
||||
sif::error << "HeaterHandler::initialize: Main line switcher failed to fetch object"
|
||||
<< "from object ID." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
result = healthHelper.initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = modeHelper.initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = actionHelper.initialize(commandQueue);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
fillCommandAndReplyMap();
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::readCommandQueue() {
|
||||
|
||||
if (dontCheckQueue()) {
|
||||
return;
|
||||
ReturnValue_t HeaterHandler::initializeHeaterMap(){
|
||||
heaterMapIter = heaterMap.begin();
|
||||
HeaterCommandInfo_t heaterCommandInfo;
|
||||
for(int switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) {
|
||||
std::pair status = heaterMap.emplace(switchNr, heaterCommandInfo);
|
||||
if (status.second == false) {
|
||||
sif::error << "HeaterHandler::initializeHeaterMap: Failed to initialize heater map"
|
||||
<< std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void HeaterHandler::setInitialSwitchStates() {
|
||||
for (int switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) {
|
||||
switchStates[switchNr] = OFF;
|
||||
}
|
||||
}
|
||||
|
||||
void HeaterHandler::readCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result != RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = actionHelper.handleActionMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
@ -124,56 +104,51 @@ void DeviceHandlerBase::readCommandQueue() {
|
||||
|
||||
ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) {
|
||||
ReturnValue_t result = acceptExternalDeviceCommands();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
heaterCommandMap::iterator iter = HeaterCommandMap.find(actionId);
|
||||
if (iter == heaterCommandMap.end()) {
|
||||
if (actionId != SWITCH_ON && actionId != SWITCH_OFF) {
|
||||
result = COMMAND_NOT_SUPPORTED;
|
||||
} else {
|
||||
if (commandedBy == commandQueue){
|
||||
heaterCommand(*(data), *(data + 1), NO_COMMANDER);
|
||||
commandPending = true;
|
||||
heaterMapIter = heaterMap.find(*data);
|
||||
if (heaterMapIter != heaterMap.end()) {
|
||||
heaterMapIter.second.action = *(data + 1);
|
||||
heaterMapIter.second.active = true;
|
||||
}
|
||||
else {
|
||||
heaterCommand(*(data), *(data + 1), commandedBy);
|
||||
commandPending = true;
|
||||
sif::error << "HeaterHandler::executeAction: Invalid switchNr" << std::endl;
|
||||
return INVALID_SWITCH_NR;
|
||||
}
|
||||
result = RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::acceptExternalDeviceCommands() {
|
||||
if (mode != MODE_ON) {
|
||||
return WRONG_MODE_FOR_COMMAND;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void HeaterHandler::sendSwitchCommand(uint8_t switchNr,
|
||||
ReturnValue_t onOff) const {
|
||||
|
||||
ReturnValue_t result;
|
||||
store_address_t address;
|
||||
HeaterCommand_t command;
|
||||
store_address_t storeAddress;
|
||||
uint8_t commandData[2];
|
||||
|
||||
switch(onOff) {
|
||||
case PowerSwitchIF::SWITCH_ON:
|
||||
command(SWITCH_ON, switchNr);
|
||||
commandData[0] = switchNr;
|
||||
commandData[1] = SET_SWITCH_ON;
|
||||
case PowerSwitchIF::SWITCH_OFF:
|
||||
command(SWITCH_OFF, switchNr);
|
||||
commandData[0] = switchNr;
|
||||
commandData[1] = SET_SWITCH_OFF;
|
||||
default:
|
||||
sif::error << "HeaterHandler::sendSwitchCommand: Invalid switch request"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
result = IPCStore->addData(&address, &command, sizeof(command));
|
||||
result = IPCStore->addData(&storeAddress, commandData, sizeof(commandData));
|
||||
if (result == RETURN_OK) {
|
||||
CommandMessage message;
|
||||
ActionMessage::setCommand(&message,
|
||||
HeaterHandler::SWITCH_HEATER, address);
|
||||
HeaterHandler::SWITCH_HEATER, storeAddress);
|
||||
/* Send heater command to own command queue */
|
||||
result = commandQueue->sendMessage(commandQueue, &message, 0);
|
||||
if (result != RETURN_OK) {
|
||||
@ -183,32 +158,79 @@ void HeaterHandler::sendSwitchCommand(uint8_t switchNr,
|
||||
}
|
||||
}
|
||||
|
||||
void HeaterHandler::handlePendingCommand(){
|
||||
void HeaterHandler::handleActiveCommands(){
|
||||
ReturnValue_t result;
|
||||
|
||||
if (!commandPending) {
|
||||
return;
|
||||
}
|
||||
switch(heaterCommand.action) {
|
||||
case SET_SWITCH_ON:
|
||||
result = gpioInterface->pullHigh(heaterCommand.heaterSwitchNr);
|
||||
if (result != RETURN_OK) {
|
||||
triggerEvent()
|
||||
heaterMapIter = heaterMap.begin();
|
||||
for (; heaterMapIter != mapToAdd.end(); heaterMapIter++) {
|
||||
if (heaterMapIter.second.active) {
|
||||
switch(heaterMapIter.second.action) {
|
||||
case SET_SWITCH_ON:
|
||||
int switchNr = heaterMapIter.first();
|
||||
/* Check state of main line switch */
|
||||
if (mainLineSwitcher->getSwitchState(pcduSwitches::TCS_BOARD_8V_HEATER_IN)
|
||||
== SWITCH_ON) {
|
||||
if (!checkSwitchState(switchNr)) {
|
||||
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
|
||||
result = gpioInterface->pullHigh(gpioId);
|
||||
if (result != RETURN_OK) {
|
||||
triggerEvent(GPIO_PULL_HIGH_FAILED, result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
triggerEvent(SWITCH_ALREADY_ON, switchNr);
|
||||
}
|
||||
/* There is no need to send action finish replies if the sender was the
|
||||
* HeaterHandler itself. */
|
||||
if (heaterMapIter.second.replyQueue != commandQueue) {
|
||||
actionHelper.finish(heaterMapIter.second.replyQueue,
|
||||
heaterMapIter.second.action, result);
|
||||
}
|
||||
heaterMapIter.second.active = false;
|
||||
}
|
||||
else {
|
||||
mainLineSwitcher->sendSwitchCommand(pcduSwitches::TCS_BOARD_8V_HEATER_IN);
|
||||
}
|
||||
break;
|
||||
case SET_SWITCH_OFF:
|
||||
int switchNr = heaterMapIter.first();
|
||||
if (checkSwitchState(switchNr)) {
|
||||
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
|
||||
result = gpioInterface->pullLow(gpioId);
|
||||
triggerEvent(GPIO_PULL_LOW_FAILED, result);
|
||||
}
|
||||
else {
|
||||
triggerEvent(SWITCH_ALREADY_OFF, switchNr);
|
||||
}
|
||||
if (heaterCommand.replyQueue != NO_COMMANDER) {
|
||||
actionHelper.finish(heaterMapIter.second.replyQueue,
|
||||
heaterMapIter.second.action, result);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sif::error << "HeaterHandler::handleActiveCommands: Invalid action commanded"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (heaterCommand.replyQueue != NO_COMMANDER) {
|
||||
actionHelper.finish(heaterCommand.replyQueue, heaterCommand.action,
|
||||
result);
|
||||
}
|
||||
commandPending = false;
|
||||
break;
|
||||
case SET_SWITCH_OFF:
|
||||
result = gpioInterface->pullLow(heaterCommand.heaterSwitchNr);
|
||||
if (heaterCommand.replyQueue != NO_COMMANDER) {
|
||||
actionHelper.finish(heaterCommand.replyQueue, heaterCommand.action,
|
||||
result);
|
||||
}
|
||||
commandPending = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool HeaterHandler::checkSwitchState(int switchNr) {
|
||||
return switchStates[switchNr];
|
||||
}
|
||||
|
||||
gpioId_t HeaterHandler::getGpioIdFromSwitchNr(switchNr) {
|
||||
gpioId_t gpioId = 0xFFFF;
|
||||
switch(switchNr) {
|
||||
case heaterSwitches::PAYLOAD_CAMERA:
|
||||
gpioId = gpioIds::HEATER_0;
|
||||
break;
|
||||
default:
|
||||
sif::error << "HeaterHandler::getGpioIdFromSwitchNr: Unknown heater switch number"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
return gpioId;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user