heater wip

This commit is contained in:
2021-01-23 17:22:40 +01:00
parent b7d3818202
commit 61ed56ace9
24 changed files with 810 additions and 77 deletions

View File

@@ -37,7 +37,8 @@ public:
protected:
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override;
virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id)
override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override;
void fillCommandAndReplyMap() override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,

View File

@@ -0,0 +1,214 @@
#include <mission/devices/HeaterHandler.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() {
}
ReturnValue_t performOperation(uint8_t operationCode) {
if (operationCode == DeviceHandlerIF::PERFORM_OPERATION) {
readCommandQueue();
handlePendingCommand();
doStateMachine();
checkSwitchState();
decrementDeviceReplyMap();
fdirInstance->checkForFailures();
hkSwitcher.performOperation();
performOperationHook();
return RETURN_OK;
}
}
ReturnValue_t DeviceHandlerBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
gpioInterface = objectManager->get<GpioIF>(gpioDriverId);
if (gpioInterface == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "HeaterHandler::initialize: Invalid Gpio interface."
<< std::endl;
#endif
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;
}
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
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
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;
}
fillCommandAndReplyMap();
return RETURN_OK;
}
void DeviceHandlerBase::readCommandQueue() {
if (dontCheckQueue()) {
return;
}
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;
}
}
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()) {
result = COMMAND_NOT_SUPPORTED;
} else {
if (commandedBy == commandQueue){
heaterCommand(*(data), *(data + 1), NO_COMMANDER);
commandPending = true;
}
else {
heaterCommand(*(data), *(data + 1), commandedBy);
commandPending = true;
}
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;
switch(onOff) {
case PowerSwitchIF::SWITCH_ON:
command(SWITCH_ON, switchNr);
case PowerSwitchIF::SWITCH_OFF:
command(SWITCH_OFF, switchNr);
default:
sif::error << "HeaterHandler::sendSwitchCommand: Invalid switch request"
<< std::endl;
}
result = IPCStore->addData(&address, &command, sizeof(command));
if (result == RETURN_OK) {
CommandMessage message;
ActionMessage::setCommand(&message,
HeaterHandler::SWITCH_HEATER, address);
/* Send heater command to own command queue */
result = commandQueue->sendMessage(commandQueue, &message, 0);
if (result != RETURN_OK) {
debug << "HeaterHandler::sendSwitchCommand: Failed to send switch"
<< "message" << std::endl;
}
}
}
void HeaterHandler::handlePendingCommand(){
ReturnValue_t result;
if (!commandPending) {
return;
}
switch(heaterCommand.action) {
case SET_SWITCH_ON:
result = gpioInterface->pullHigh(heaterCommand.heaterSwitchNr);
if (result != RETURN_OK) {
triggerEvent()
}
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;
}
}

View File

@@ -0,0 +1,132 @@
#ifndef MISSION_DEVICES_HEATERHANDLER_H_
#define MISSION_DEVICES_HEATERHANDLER_H_
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/action/HasActionsIF.h>
#include <fsfw/modes/HasModesIF.h>
#include <fsfw/power/PowerSwitchIF.h>
/**
* @brief This class intends the control of heaters.
*
* @author J. Meier
*/
class HeaterHandler: public ExecutableObjectIF,
public PowerSwitchIF,
public SystemObject,
public HasActionsIF,
public HasModesIF,
public HasReturnvaluesIF {
public:
/** Command not in heaterCommandMap */
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1);
/** Heater mode is MODE_OFF */
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
/** Device command IDs */
static const DeviceCommandId_t SWITCH_HEATER;
virtual ReturnValue_t performOperation(uint8_t operationCode = 0);
void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override;
virtual void sendFuseOnCommand(uint8_t fuseNr) override;
/**
* @brief This function will be called from the Heater object to check
* the current switch state.
*/
virtual ReturnValue_t getSwitchState( uint8_t switchNr ) override;
virtual ReturnValue_t getFuseState( uint8_t fuseNr ) override;
virtual uint32_t getSwitchDelayMs(void) override;
ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data, size_t size)
override;
private:
static const MessageQueueId_t NO_COMMANDER = 0;
ReturnValue_t buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen);
ReturnValue_t acceptExternalDeviceCommands();
/**
* @brief This function runs commands waiting for execution.
*/
void handlePendingCommand();
/**
* @brief Struct holding information about a heater command to execute.
*
* @param action The action to perform.
* @param heaterSwitchNr The number of a switch which correlates with the
* GPIO to drive.
* @param replyQueue The queue of the commander to which status replies
* will be sent.
*/
typedef struct HeaterCommand {
HeaterCommand(uint8_t action_, uint8_t heaterSwitchNr,
MessageQueueId_t replyQueue_) {
action = action_;
heaterSwitchNr = heaterSwitchNr_;
replyQueue = replyQueue_;
}
uint8_t action;
uint8_t heaterSwitchNr;
MessageQueueId_t replyQueue;
} HeaterCommand_t;
enum SwitchAction {
SET_SWITCH_ON,
SET_SWITCH_OFF
};
/** This HeaterCommand instance holds the next heater command to execute */
HeaterCommand_t heaterCommand;
/**
* This variable is set when the command stored in heaterCommand shall be
* executed.
*/
bool commandPending;
/** Size of command queue */
size_t cmdQueueSize = 20;
/**
* Current mode of the HeaterHandler. Should only be changed with setMode().
*/
Mode_t mode;
/**
* Current submode of the HeaterHandler. Should only be change with
* setMode().
*/
Submode_t submode;
/**
* The object ID of the GPIO driver which enables and disables the
* heaters.
*/
object_id_t gpioDriverId;
GpioIF* gpioInterface;
/** Queue to receive messages from other objects. */
MessageQueueIF* commandQueue = nullptr;
/**
* Power switcher object which controls the 8V main line of the heater
* logic on the TCS board.
*/
PowerSwitchIF *powerSwitcher;
HeaterHandler();
virtual ~HeaterHandler();
};
#endif /* MISSION_DEVICES_HEATERHANDLER_H_ */

View File

@@ -0,0 +1,18 @@
/*
* PCDUHandler.cpp
*
* Created on: 21.01.2021
* Author: jakob
*/
#include "PCDUHandler.h"
PCDUHandler::PCDUHandler() {
// TODO Auto-generated constructor stub
}
PCDUHandler::~PCDUHandler() {
// TODO Auto-generated destructor stub
}

View File

@@ -0,0 +1,20 @@
/*
* PCDUHandler.h
*
* Created on: 21.01.2021
* Author: jakob
*/
#ifndef MISSION_DEVICES_PCDUHANDLER_H_
#define MISSION_DEVICES_PCDUHANDLER_H_
/**
* @brief
*/
class PCDUHandler: public PowerSwitchIF {
public:
PCDUHandler();
virtual ~PCDUHandler();
};
#endif /* MISSION_DEVICES_PCDUHANDLER_H_ */

View File

@@ -0,0 +1,18 @@
/*
* PDU2Handler.cpp
*
* Created on: 23.01.2021
* Author: jakob
*/
#include "PDU2Handler.h"
PDU2Handler::PDU2Handler() {
// TODO Auto-generated constructor stub
}
PDU2Handler::~PDU2Handler() {
// TODO Auto-generated destructor stub
}

View File

@@ -0,0 +1,26 @@
#ifndef MISSION_DEVICES_PDU2HANDLER_H_
#define MISSION_DEVICES_PDU2HANDLER_H_
#include "GomspaceDeviceHandler.h"
/**
* @brief This is the device handler for the PDU2.
*
* @details The PDU2 controls the
* power supply of the following devices:
* Xiphos Q7S, 8V, channel 0
* Reaction wheels 5V, channel 2
* TCS Board heater input, 8V, channel 3
* SUS, 3,3V, channel 4
* Deployment mechanism, 8V, channel 5
* P/L PCDU, 15,9V, channel 1 and channel 6
* ACS Board (Gyro, MGMs, GPS), 3,3V channel 7
* Payload Camera, 8V, channel 8
*/
class PDU2Handler: public GomspaceDeviceHandler {
public:
PDU2Handler();
virtual ~PDU2Handler();
};
#endif /* MISSION_DEVICES_PDU2HANDLER_H_ */

View File

@@ -178,7 +178,8 @@ private:
* device*/
SerializeElement<uint8_t> action = 0x00; // get param
SerializeElement<uint8_t> tableId;
SerializeElement<uint16_t> addresslength; // size of address
/* Size of address. Set to 0 to get full table */
SerializeElement<uint16_t> addresslength;
SerializeElement<uint16_t> checksum;
SerializeElement<uint16_t> seq;
SerializeElement<uint16_t> total;