eive-obsw/mission/devices/HeaterHandler.h

154 lines
4.3 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>
2021-01-28 14:55:21 +01:00
#include <fsfwconfig/devices/heaterSwitcherList.h>
2021-01-23 17:22:40 +01:00
/**
* @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:
/** Device command IDs */
static const DeviceCommandId_t SWITCH_HEATER;
2021-01-28 14:55:21 +01:00
HeaterHandler(object_id_t setObjectId, object_id_t gpioDriverId, CookieIF * gpioCookie,
object_id_t mainLineSwitcherObjectId, uint8_t mainLineSwitch);
virtual ~HeaterHandler();
2021-01-23 17:22:40 +01:00
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:
2021-01-28 14:55:21 +01:00
static const uint8_t INTERFACE_ID = CLASS_ID::PCDU_HANDLER;
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 INVALID_SWITCH_NR = MAKE_RETURN_CODE(0xA3);
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_LOW_FAILED = MAKE_EVENT(1, severity::LOW);
static const Event SWITCH_ALREADY_ON = MAKE_EVENT(2, severity::LOW);
static const Event SWITCH_ALREADY_OFF = MAKE_EVENT(3, severity::LOW);
2021-01-23 17:22:40 +01:00
ReturnValue_t buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen);
2021-01-28 14:55:21 +01:00
/**
* @brief Returns the state of a switch (ON - true, or OFF - false).
* @param switchNr The number of the switch to check.
*/
bool checkSwitchState(int switchNr);
/**
* @brief Returns the ID of the GPIO related to a heater identified by the switch number
* which is defined in the heaterSwitches list.
*/
gpioId_t getGpioIdFromSwitchNr(switchNr);
2021-01-23 17:22:40 +01:00
/**
* @brief This function runs commands waiting for execution.
*/
2021-01-28 14:55:21 +01:00
void handleActiveCommands();
ReturnValue_t initializeHeaterMap();
/**
* @brief Sets all switches to OFF.
*/
void setInitialSwitchStates();
enum SwitchState : bool {
ON = true,
OFF = false
};
2021-01-23 17:22:40 +01:00
/**
* @brief Struct holding information about a heater command to execute.
*
* @param action The action to perform.
* @param replyQueue The queue of the commander to which status replies
* will be sent.
2021-01-28 14:55:21 +01:00
* @param active True if command is waiting for execution, otherwise false.
2021-01-23 17:22:40 +01:00
*/
2021-01-28 14:55:21 +01:00
typedef struct HeaterCommandInfo {
2021-01-23 17:22:40 +01:00
uint8_t action;
MessageQueueId_t replyQueue;
2021-01-28 14:55:21 +01:00
bool active = false;
} HeaterCommandInfo_t;
2021-01-23 17:22:40 +01:00
enum SwitchAction {
SET_SWITCH_ON,
SET_SWITCH_OFF
};
2021-01-28 14:55:21 +01:00
using switchNr_t = int;
using HeaterMap = std::unordered_map<switchNr_t, HeaterCommandInfo_t>;
using HeaterMapIter = HeaterMap::iterator;
2021-01-23 17:22:40 +01:00
2021-01-28 14:55:21 +01:00
HeateerMap heaterMap;
HeaterMapIter heaterMapIter;
bool switchStates[heaterSwitches::NUMBER_OF_SWITCHES];
2021-01-23 17:22:40 +01:00
/** Size of command queue */
size_t cmdQueueSize = 20;
/**
* 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;
2021-01-28 14:55:21 +01:00
object_id_t mainLineSwitcherObjectId;
/** Switch number of the heater power supply switch */
uint8_t mainLineSwitch;
2021-01-23 17:22:40 +01:00
/**
* Power switcher object which controls the 8V main line of the heater
* logic on the TCS board.
*/
2021-01-28 14:55:21 +01:00
PowerSwitchIF *mainLineSwitcher = nullptr;
ActionHelper actionHelper;
2021-01-23 17:22:40 +01:00
2021-01-28 14:55:21 +01:00
StorageManagerIF *IPCStore = nullptr;
2021-01-23 17:22:40 +01:00
};
#endif /* MISSION_DEVICES_HEATERHANDLER_H_ */