eive-obsw/mission/devices/HeaterHandler.h

133 lines
3.5 KiB
C
Raw Normal View History

2021-01-23 17:22:40 +01:00
#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_ */