eive-obsw/linux/payload/FreshSupvHandler.h

189 lines
7.6 KiB
C
Raw Permalink Normal View History

2023-11-09 11:11:47 +01:00
#ifndef LINUX_PAYLOAD_FRESHSUPVHANDLER_H_
#define LINUX_PAYLOAD_FRESHSUPVHANDLER_H_
2023-11-09 11:57:49 +01:00
#include <fsfw/power/PowerSwitchIF.h>
2023-11-09 17:19:28 +01:00
#include <mission/controller/controllerdefinitions/PowerCtrlDefinitions.h>
#include <map>
2023-11-09 11:57:49 +01:00
#include "PlocSupvUartMan.h"
2023-11-09 11:11:47 +01:00
#include "fsfw/devicehandlers/FreshDeviceHandlerBase.h"
2023-11-09 11:57:49 +01:00
#include "fsfw/power/definitions.h"
#include "fsfw_hal/linux/gpio/Gpio.h"
2023-11-09 11:44:00 +01:00
#include "plocSupvDefs.h"
2023-11-09 11:35:28 +01:00
2023-11-09 17:19:28 +01:00
using supv::TcBase;
2023-11-09 11:35:28 +01:00
class FreshSupvHandler : public FreshDeviceHandlerBase {
public:
2023-11-14 13:25:53 +01:00
enum OpCode { DEFAULT_OPERATION = 0, PARSE_TM = 1 };
2023-11-09 11:35:28 +01:00
2023-11-09 11:57:49 +01:00
FreshSupvHandler(DhbConfig cfg, CookieIF* comCookie, Gpio uartIsolatorSwitch,
2023-11-15 11:31:57 +01:00
PowerSwitchIF& switchIF, power::Switch_t powerSwitch);
2023-11-09 11:35:28 +01:00
/**
* Periodic helper executed function, implemented by child class.
*/
void performDeviceOperation(uint8_t opCode) override;
2023-11-09 11:11:47 +01:00
2023-11-09 11:35:28 +01:00
/**
* Implemented by child class. Handle all command messages which are
* not health, mode, action or housekeeping messages.
* @param message
* @return
*/
ReturnValue_t handleCommandMessage(CommandMessage* message) override;
2023-11-09 11:11:47 +01:00
2023-11-09 17:19:28 +01:00
ReturnValue_t initialize() override;
2023-11-09 11:57:49 +01:00
2023-11-09 17:19:28 +01:00
private:
2023-11-09 11:35:28 +01:00
// HK manager abstract functions.
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
// Mode abstract functions
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) override;
// Action override. Forward to user.
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
2023-11-09 17:19:28 +01:00
/**
* @overload
* @param submode
*/
void startTransition(Mode_t newMode, Submode_t submode) override;
2023-11-21 17:37:26 +01:00
ReturnValue_t performDeviceOperationPreQueueHandling(uint8_t opCode) override;
2023-11-09 17:19:28 +01:00
void handleTransitionToOn();
void handleTransitionToOff();
2023-11-09 11:35:28 +01:00
private:
2023-11-09 17:19:28 +01:00
static constexpr bool SET_TIME_DURING_BOOT = true;
2023-11-13 15:33:11 +01:00
static const uint8_t SIZE_NULL_TERMINATOR = 1;
2023-11-09 17:19:28 +01:00
enum class StartupState : uint8_t {
IDLE,
POWER_SWITCHING,
BOOTING,
SET_TIME,
WAIT_FOR_TIME_REPLY,
TIME_WAS_SET,
ON
};
StartupState startupState = StartupState::IDLE;
2023-11-13 15:33:11 +01:00
MessageQueueIF* eventQueue = nullptr;
supv::TmBase tmReader;
2023-11-09 17:19:28 +01:00
enum class ShutdownState : uint8_t { IDLE, POWER_SWITCHING };
ShutdownState shutdownState = ShutdownState::IDLE;
2023-11-15 11:31:57 +01:00
PlocSupvUartManager* uartManager;
2023-11-09 17:19:28 +01:00
CookieIF* comCookie;
PowerSwitchIF& switchIF;
power::Switch_t switchId;
Gpio uartIsolatorSwitch;
2023-11-09 11:57:49 +01:00
2023-11-09 11:44:00 +01:00
supv::HkSet hkSet;
supv::BootStatusReport bootStatusReport;
supv::LatchupStatusReport latchupStatusReport;
supv::CountersReport countersReport;
supv::AdcReport adcReport;
2023-11-09 11:35:28 +01:00
bool transitionActive = false;
2023-11-09 11:44:00 +01:00
2023-11-09 17:19:28 +01:00
Mode_t targetMode = HasModesIF::MODE_INVALID;
Submode_t targetSubmode = 0;
2023-11-14 11:49:13 +01:00
Countdown switchTimeout = Countdown(2000);
2023-11-09 17:19:28 +01:00
// Vorago nees some time to boot properly
Countdown bootTimeout = Countdown(supv::BOOT_TIMEOUT_MS);
2023-11-21 17:20:41 +01:00
// Countdown interCmdCd = Countdown(supv::INTER_COMMAND_DELAY);
2023-11-09 17:19:28 +01:00
2023-11-09 11:44:00 +01:00
PoolEntry<uint16_t> adcRawEntry = PoolEntry<uint16_t>(16);
PoolEntry<uint16_t> adcEngEntry = PoolEntry<uint16_t>(16);
PoolEntry<uint32_t> latchupCounters = PoolEntry<uint32_t>(7);
PoolEntry<uint8_t> fmcStateEntry = PoolEntry<uint8_t>(1);
PoolEntry<uint8_t> bootStateEntry = PoolEntry<uint8_t>(1);
PoolEntry<uint8_t> bootCyclesEntry = PoolEntry<uint8_t>(1);
PoolEntry<uint32_t> tempSupEntry = PoolEntry<uint32_t>(1);
2023-11-09 17:19:28 +01:00
pwrctrl::EnablePl enablePl = pwrctrl::EnablePl(objects::POWER_CONTROLLER);
struct ActiveCmdInfo {
2023-11-15 11:31:57 +01:00
ActiveCmdInfo(DeviceCommandId_t commandId, uint32_t cmdCountdownMs)
: commandId(commandId), cmdCountdown(cmdCountdownMs) {}
2023-11-09 17:19:28 +01:00
2023-11-15 08:48:31 +01:00
DeviceCommandId_t commandId = DeviceHandlerIF::NO_COMMAND_ID;
2023-11-09 17:19:28 +01:00
bool isPending = false;
bool ackRecv = false;
bool ackExeRecv = false;
2023-11-14 11:49:13 +01:00
bool replyPacketExpected = false;
bool replyPacketReceived = false;
2023-11-09 17:19:28 +01:00
MessageQueueId_t commandedBy = MessageQueueIF::NO_QUEUE;
bool requiresActionReply = false;
Countdown cmdCountdown;
};
2023-11-13 16:32:40 +01:00
uint32_t buildActiveCmdKey(uint16_t moduleApid, uint8_t serviceId);
2023-11-09 17:19:28 +01:00
// Map for Action commands. For normal commands, a separate static structure will be used.
2023-11-13 16:32:40 +01:00
std::map<uint32_t, ActiveCmdInfo> activeActionCmds;
2023-11-09 17:19:28 +01:00
2023-11-15 11:31:57 +01:00
std::array<uint8_t, supv::MAX_COMMAND_SIZE> commandBuffer{};
2023-11-09 17:19:28 +01:00
SpacePacketCreator creator;
supv::TcParams spParams = supv::TcParams(creator);
2023-11-21 17:20:41 +01:00
DeviceCommandId_t commandedByCached = MessageQueueIF::NO_QUEUE;
2023-11-09 17:19:28 +01:00
ReturnValue_t parseTmPackets();
2023-11-15 11:31:57 +01:00
ReturnValue_t sendCommand(DeviceCommandId_t commandId, TcBase& tc, bool replyPacketExpected,
uint32_t cmdCountdownMs = 1000);
ReturnValue_t sendEmptyCmd(DeviceCommandId_t commandId, uint16_t apid, uint8_t serviceId,
bool replyPacketExpected);
2023-11-09 17:19:28 +01:00
ReturnValue_t prepareSelBootImageCmd(const uint8_t* commandData);
ReturnValue_t prepareSetTimeRefCmd();
ReturnValue_t prepareSetBootTimeoutCmd(const uint8_t* commandData, size_t cmdDataLen);
ReturnValue_t prepareRestartTriesCmd(const uint8_t* commandData, size_t cmdDataLen);
ReturnValue_t prepareDisableHk();
ReturnValue_t prepareLatchupConfigCmd(const uint8_t* commandData, DeviceCommandId_t deviceCommand,
size_t cmdDataLen);
ReturnValue_t prepareSetAlertLimitCmd(const uint8_t* commandData, size_t cmdDataLen);
ReturnValue_t prepareFactoryResetCmd(const uint8_t* commandData, size_t len);
ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData, size_t cmdDataLen);
ReturnValue_t prepareSetGpioCmd(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareReadGpioCmd(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData);
ReturnValue_t prepareSetAdcWindowAndStrideCmd(const uint8_t* commandData);
ReturnValue_t prepareSetAdcThresholdCmd(const uint8_t* commandData);
ReturnValue_t prepareWipeMramCmd(const uint8_t* commandData, size_t cmdDataLen);
2023-11-13 15:33:11 +01:00
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size,
supv::UpdateParams& params);
ReturnValue_t extractBaseParams(const uint8_t** commandData, size_t& remSize,
supv::UpdateParams& params);
void handleEvent(EventMessage* eventMessage);
void handleBadApidServiceCombination(Event event, unsigned int apid, unsigned int serviceId);
2023-11-13 15:33:11 +01:00
ReturnValue_t eventSubscription();
void handlePacketPrint();
2023-11-09 17:19:28 +01:00
bool isCommandAlreadyActive(ActionId_t actionId) const;
2023-11-13 16:32:40 +01:00
ReturnValue_t handleAckReport(const uint8_t* data);
void printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId);
ReturnValue_t handleExecutionReport(const uint8_t* data);
ReturnValue_t handleExecutionSuccessReport(ActiveCmdInfo& info, supv::ExecutionReport& report);
void handleExecutionFailureReport(ActiveCmdInfo& info, supv::ExecutionReport& report);
2023-11-14 11:49:13 +01:00
ReturnValue_t handleHkReport(const uint8_t* data);
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
void confirmReplyPacketReceived(supv::Apid apid, uint8_t serviceId);
2023-11-14 15:28:27 +01:00
void performCommandCompletionHandling(supv::Apid apid, uint8_t serviceId, ActiveCmdInfo& info);
2023-11-14 11:49:13 +01:00
ReturnValue_t handleBootStatusReport(const uint8_t* data);
ReturnValue_t genericHandleTm(const char* contextString, const uint8_t* data,
LocalPoolDataSetBase& set, supv::Apid apid, uint8_t serviceId);
ReturnValue_t handleLatchupStatusReport(const uint8_t* data);
2023-11-15 14:17:43 +01:00
bool isCommandPending() const;
2023-11-09 11:35:28 +01:00
};
2023-11-09 11:11:47 +01:00
#endif /* LINUX_PAYLOAD_FRESHSUPVHANDLER_H_ */