#include "fsfw/action/ActionMessage.h" #include "fsfw/action/CommandsActionsIF.h" #include "fsfw/devicehandlers/DeviceHandlerIF.h" #include "fsfw/devicehandlers/FreshDeviceHandlerBase.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/messageQueueDefinitions.h" #include "fsfw/modes/ModeMessage.h" #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/power/PowerSwitchIF.h" #include "fsfw/power/definitions.h" #include "fsfw/returnvalues/returnvalue.h" #include "fsfw_hal/linux/gpio/Gpio.h" #include "linux/payload/MpsocCommunication.h" #include "linux/payload/PlocMpsocSpecialComHelper.h" #include "linux/payload/plocMpsocHelpers.h" class FreshMpsocHandler : public FreshDeviceHandlerBase, public CommandsActionsIF { public: enum OpCode { DEFAULT_OPERATION = 0, PARSE_TM = 1 }; static constexpr uint32_t MPSOC_MODE_CMD_TIMEOUT_MS = 120000; FreshMpsocHandler(DhbConfig cfg, MpsocCommunication& comInterface, PlocMpsocSpecialComHelper& specialComHelper, Gpio uartIsolatorSwitch, object_id_t supervisorHandler, PowerSwitchIF& powerSwitcher, power::Switch_t camSwitchId); /** * Periodic helper executed function, implemented by child class. */ void performDeviceOperation(uint8_t opCode) override; void performDefaultDeviceOperation(); /** * 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; ReturnValue_t initialize() override; private: enum class StartupState { IDLE, HW_INIT, DONE } startupState = StartupState::IDLE; enum class PowerState { IDLE, PENDING_STARTUP, PENDING_SHUTDOWN, SUPV_FAILED, DONE }; enum TransitionState { NONE, TO_ON, TO_OFF, SUBMODE } transitionState = TransitionState::NONE; MpsocCommunication& comInterface; PlocMpsocSpecialComHelper& specialComHelper; MessageQueueIF* eventQueue = nullptr; SourceSequenceCounter commandSequenceCount = SourceSequenceCounter(0); MessageQueueIF* commandActionHelperQueue = nullptr; CommandActionHelper commandActionHelper; Gpio uartIsolatorSwitch; mpsoc::HkReport hkReport; object_id_t supervisorHandler; Countdown mpsocBootTransitionCd = Countdown(6500); Countdown supvTransitionCd = Countdown(3000); PoolEntry peStatus = PoolEntry(); PoolEntry peMode = PoolEntry(); PoolEntry peDownlinkPwrOn = PoolEntry(); PoolEntry peDownlinkReplyActive = PoolEntry(); PoolEntry peDownlinkJesdSyncStatus = PoolEntry(); PoolEntry peDownlinkDacStatus = PoolEntry(); PoolEntry peCameraStatus = PoolEntry(); PoolEntry peCameraSdiStatus = PoolEntry(); PoolEntry peCameraFpgaTemp = PoolEntry(); PoolEntry peCameraSocTemp = PoolEntry(); PoolEntry peSysmonTemp = PoolEntry(); PoolEntry peSysmonVccInt = PoolEntry(); PoolEntry peSysmonVccAux = PoolEntry(); PoolEntry peSysmonVccBram = PoolEntry(); PoolEntry peSysmonVccPaux = PoolEntry(); PoolEntry peSysmonVccPint = PoolEntry(); PoolEntry peSysmonVccPdro = PoolEntry(); PoolEntry peSysmonMb12V = PoolEntry(); PoolEntry peSysmonMb3V3 = PoolEntry(); PoolEntry peSysmonMb1V8 = PoolEntry(); PoolEntry peSysmonVcc12V = PoolEntry(); PoolEntry peSysmonVcc5V = PoolEntry(); PoolEntry peSysmonVcc3V3 = PoolEntry(); PoolEntry peSysmonVcc3V3VA = PoolEntry(); PoolEntry peSysmonVcc2V5DDR = PoolEntry(); PoolEntry peSysmonVcc1V2DDR = PoolEntry(); PoolEntry peSysmonVcc0V9 = PoolEntry(); PoolEntry peSysmonVcc0V6VTT = PoolEntry(); PoolEntry peSysmonSafeCotsCur = PoolEntry(); PoolEntry peSysmonNvm4XoCur = PoolEntry(); PoolEntry peSemUncorrectableErrs = PoolEntry(); PoolEntry peSemCorrectableErrs = PoolEntry(); PoolEntry peSemStatus = PoolEntry(); PoolEntry peRebootMpsocRequired = PoolEntry(); PowerState powerState; bool specialComHelperExecuting = false; struct ActionCommandInfo { Countdown cmdCountdown = Countdown(mpsoc::DEFAULT_CMD_TIMEOUT_MS); bool pending = false; MessageQueueId_t commandedBy = MessageQueueIF::NO_QUEUE; DeviceCommandId_t pendingCmd = DeviceHandlerIF::NO_COMMAND_ID; uint16_t pendingCmdMpsocApid = 0; void reset() { pending = false; commandedBy = MessageQueueIF::NO_QUEUE; pendingCmd = DeviceHandlerIF::NO_COMMAND_ID; } void start(DeviceCommandId_t commandId, MessageQueueId_t commandedBy) { pending = true; cmdCountdown.resetTimer(); pendingCmd = commandId; this->commandedBy = commandedBy; } } activeCmdInfo; uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; SpacePacketCreator creator; ploc::SpTcParams spParams = ploc::SpTcParams(creator); Mode_t targetMode = HasModesIF::MODE_UNDEFINED; Submode_t targetSubmode = 0; struct TmMemReadReport { static const uint8_t FIX_SIZE = 14; size_t rememberRequestedSize = 0; }; TmMemReadReport tmMemReadReport; uint32_t lastReplySequenceCount = 0; uint8_t skipSupvCommandingToOn = false; PowerSwitchIF& powerSwitcher; power::Switch_t camSwitchId; // 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; /** * @overload * @param submode */ void startTransition(Mode_t newMode, Submode_t submode) override; ReturnValue_t performDeviceOperationPreQueueHandling(uint8_t opCode) override; // CommandsActionsIF overrides. MessageQueueIF* getCommandQueuePtr() override; void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override; void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override; void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override; void completionSuccessfulReceived(ActionId_t actionId) override; void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override; ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) override; void handleActionCommandFailure(ActionId_t actionId, ReturnValue_t returnCode); ReturnValue_t executeRegularCmd(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, size_t dataLen); void handleTransitionToOn(); void handleTransitionToOff(); ReturnValue_t commandTcModeReplay(); ReturnValue_t commandTcMemWrite(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcMemRead(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcFlashDelete(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcReplayStart(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcReplayStop(); ReturnValue_t commandTcDownlinkPwrOn(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcDownlinkPwrOff(); ReturnValue_t commandTcGetHkReport(); ReturnValue_t commandTcGetDirContent(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcReplayWriteSequence(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcCamCmdSend(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcModeIdle(); ReturnValue_t commandTcCamTakePic(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcSimplexStreamFile(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcSimplexStoreFile(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcDownlinkDataModulate(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcModeSnapshot(); ReturnValue_t finishAndSendTc(DeviceCommandId_t cmdId, mpsoc::TcBase& tcBase, uint32_t cmdCountdown = mpsoc::DEFAULT_CMD_TIMEOUT_MS); void handleEvent(EventMessage* eventMessage); void cmdDoneHandler(bool success, ReturnValue_t result); ReturnValue_t handleDeviceReply(); ReturnValue_t handleAckReport(); ReturnValue_t handleExecutionReport(); void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status); ReturnValue_t reportReplyData(DeviceCommandId_t tmId); ReturnValue_t handleGetHkReport(); bool handleHwStartup(); bool handleHwShutdown(); void stopSpecialComHelper(); void commandSubmodeTransition(); void commonSpecialComInit(); void commonSpecialComStop(); void commandInitHandling(ActionId_t actionId, MessageQueueId_t commandedBy); };