eive-obsw/archive/PlocSupervisorHandler.h

390 lines
15 KiB
C
Raw Permalink Normal View History

#ifndef MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
#define MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
2021-03-29 14:37:52 +02:00
2023-03-26 16:42:00 +02:00
#include <linux/payload/PlocSupvUartMan.h>
#include <linux/payload/plocSupvDefs.h>
2023-09-29 15:37:47 +02:00
#include <mission/controller/controllerdefinitions/PowerCtrlDefinitions.h>
2022-03-28 13:54:46 +02:00
#include "OBSWConfig.h"
#include "devices/powerSwitcherList.h"
2022-03-27 14:42:20 +02:00
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
2022-04-30 16:21:59 +02:00
#include "fsfw/timemanager/Countdown.h"
2022-03-28 09:08:11 +02:00
#include "fsfw_hal/linux/gpio/Gpio.h"
2022-03-28 13:54:46 +02:00
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
2022-11-10 18:07:59 +01:00
#include "fsfw_hal/linux/serial/SerialComIF.h"
2021-03-29 14:37:52 +02:00
#ifdef XIPHOS_Q7S
#include "bsp_q7s/fs/SdCardManager.h"
#endif
2022-11-08 19:53:26 +01:00
using supv::ExecutionReport;
using supv::TcBase;
2023-11-08 18:19:24 +01:00
static constexpr bool DEBUG_PLOC_SUPV = true;
static constexpr bool REDUCE_NORMAL_MODE_PRINTOUT = true;
2022-11-08 19:53:26 +01:00
2021-03-29 14:37:52 +02:00
/**
* @brief This is the device handler for the supervisor of the PLOC which is programmed by
* Thales.
*
2022-04-10 18:46:39 +02:00
* @details The PLOC uses the space packet protocol for communication. On each command the PLOC
* answers with at least one acknowledgment and one execution report.
* Flight manual:
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/PLOC_Commands
* ILH ICD: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/
* Arbeitsdaten/08_Used%20Components/PLOC&fileid=940960
2021-03-29 14:37:52 +02:00
* @author J. Meier
*/
2022-03-27 13:07:18 +02:00
class PlocSupervisorHandler : public DeviceHandlerBase {
public:
2022-11-16 15:03:10 +01:00
PlocSupervisorHandler(object_id_t objectId, CookieIF* comCookie, Gpio uartIsolatorSwitch,
power::Switch_t powerSwitch, PlocSupvUartManager& supvHelper);
2022-03-27 13:07:18 +02:00
virtual ~PlocSupervisorHandler();
virtual ReturnValue_t initialize() override;
2022-04-10 18:46:39 +02:00
void performOperationHook() override;
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
2022-03-27 13:07:18 +02:00
protected:
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
void fillCommandAndReplyMap() override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId,
size_t* foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) override;
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies = 1, bool useAlternateId = false,
DeviceCommandId_t alternateReplyID = 0) override;
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
2022-11-21 18:32:23 +01:00
// ReturnValue_t doSendReadHook() override;
void doOffActivity() override;
2022-03-27 13:07:18 +02:00
private:
static const uint16_t APID_MASK = 0x7FF;
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
2022-04-06 17:27:44 +02:00
static const uint8_t EXE_STATUS_OFFSET = 10;
2022-04-10 18:46:39 +02:00
static const uint8_t SIZE_NULL_TERMINATOR = 1;
2022-04-27 16:08:17 +02:00
// 5 s
static const uint32_t EXECUTION_DEFAULT_TIMEOUT = 5000;
2022-05-23 12:05:42 +02:00
// 70 S
2023-11-08 18:19:24 +01:00
static const uint32_t ACKNOWLEDGE_DEFAULT_TIMEOUT = 5000;
2022-05-06 19:34:12 +02:00
// 60 s
static const uint32_t MRAM_DUMP_EXECUTION_TIMEOUT = 60000;
// 70 s
static const uint32_t COPY_ADC_TO_MRAM_TIMEOUT = 70000;
// 60 s
static const uint32_t MRAM_DUMP_TIMEOUT = 60000;
2023-11-09 17:19:28 +01:00
2023-05-12 09:32:24 +02:00
enum class StartupState : uint8_t {
OFF,
BOOTING,
SET_TIME,
WAIT_FOR_TIME_REPLY,
TIME_WAS_SET,
ON
};
2022-05-03 14:59:23 +02:00
2022-12-23 11:46:01 +01:00
static constexpr bool SET_TIME_DURING_BOOT = true;
2022-06-03 18:03:25 +02:00
2022-05-03 14:59:23 +02:00
StartupState startupState = StartupState::OFF;
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
uint8_t commandBuffer[supv::MAX_COMMAND_SIZE];
SpacePacketCreator creator;
2022-11-07 11:19:10 +01:00
supv::TcParams spParams = supv::TcParams(creator);
2022-03-27 13:07:18 +02:00
/**
* This variable is used to store the id of the next reply to receive. This is necessary
* because the PLOC sends as reply to each command at least one acknowledgment and execution
* report.
*/
2022-03-30 09:19:30 +02:00
DeviceCommandId_t nextReplyId = supv::NONE;
2022-03-27 13:07:18 +02:00
SerialComIF* uartComIf = nullptr;
2022-03-27 14:42:20 +02:00
LinuxLibgpioIF* gpioComIF = nullptr;
2022-03-28 09:08:11 +02:00
Gpio uartIsolatorSwitch;
2022-11-21 18:32:23 +01:00
bool shutdownCmdSent = false;
2023-11-08 18:19:24 +01:00
// Yeah, I am using an extra variable because I once again don't know
// what the hell the base class is doing and I don't care anymore.
bool normalCommandIsPending = false;
// True men implement their reply timeout handling themselves!
Countdown normalCmdCd = Countdown(2000);
bool commandIsPending = false;
Countdown cmdCd = Countdown(2000);
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
supv::HkSet hkset;
supv::BootStatusReport bootStatusReport;
supv::LatchupStatusReport latchupStatusReport;
2023-11-08 10:46:59 +01:00
supv::CountersReport countersReport;
2022-04-21 16:30:23 +02:00
supv::AdcReport adcReport;
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
const power::Switch_t powerSwitch = power::NO_SWITCH;
2022-11-08 14:26:52 +01:00
supv::TmBase tmReader;
2022-11-15 17:41:15 +01:00
PlocSupvUartManager& uartManager;
2022-04-10 18:46:39 +02:00
MessageQueueIF* eventQueue = nullptr;
2022-03-27 13:07:18 +02:00
/** Number of expected replies following the MRAM dump command */
uint32_t expectedMramDumpPackets = 0;
uint32_t receivedMramDumpPackets = 0;
/** Set to true as soon as a complete space packet is present in the spacePacketBuffer */
bool packetInBuffer = false;
/** This buffer is used to concatenate space packets received in two different read steps */
2022-03-30 09:19:30 +02:00
uint8_t spacePacketBuffer[supv::MAX_PACKET_SIZE];
#ifdef XIPHOS_Q7S
2022-03-27 13:07:18 +02:00
SdCardManager* sdcMan = nullptr;
#endif
2021-08-08 15:02:59 +02:00
2022-05-05 08:55:45 +02:00
// Path to supervisor specific files on SD card
std::string supervisorFilePath = "ploc/supervisor";
2022-03-27 13:07:18 +02:00
std::string activeMramFile;
2022-05-23 12:05:42 +02:00
Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false);
Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false);
2022-05-03 14:59:23 +02:00
// Vorago nees some time to boot properly
2023-11-09 17:19:28 +01:00
Countdown bootTimeout = Countdown(supv::BOOT_TIMEOUT_MS);
Countdown mramDumpTimeout = Countdown(MRAM_DUMP_TIMEOUT);
2022-04-27 16:08:17 +02:00
2023-11-08 10:46:59 +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);
2023-02-12 20:01:20 +01:00
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);
2022-04-27 16:08:17 +02:00
/**
* @brief Adjusts the timeout of the execution report dependent on command
*/
void setExecutionTimeout(DeviceCommandId_t command);
void handlePacketPrint();
2022-04-10 18:46:39 +02:00
/**
* @brief Handles event messages received from the supervisor helper
*/
void handleEvent(EventMessage* eventMessage);
2022-03-28 13:54:46 +02:00
ReturnValue_t getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches);
2022-03-27 13:07:18 +02:00
/**
* @brief This function checks the crc of the received PLOC reply.
*
* @param start Pointer to the first byte of the reply.
* @param foundLen Pointer to the length of the whole packet.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if CRC is ok, otherwise CRC_FAILURE.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
/**
* @brief This function handles the acknowledgment report.
*
* @param data Pointer to the data holding the acknowledgment report.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleAckReport(const uint8_t* data);
/**
* @brief This function handles the data of a execution report.
*
* @param data Pointer to the received data packet.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleExecutionReport(const uint8_t* data);
/**
* @brief This function handles the housekeeping report. This means verifying the CRC of the
* reply and filling the appropriate dataset.
*
* @param data Pointer to the data buffer holding the housekeeping read report.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleHkReport(const uint8_t* data);
/**
* @brief This function calls the function to check the CRC of the received boot status report
* and fills the associated dataset with the boot status information.
*/
ReturnValue_t handleBootStatusReport(const uint8_t* data);
ReturnValue_t handleLatchupStatusReport(const uint8_t* data);
2023-11-08 10:46:59 +01:00
ReturnValue_t handleCounterReport(const uint8_t* data);
2022-11-08 14:26:52 +01:00
void handleBadApidServiceCombination(Event result, unsigned int apid, unsigned int serviceId);
2022-04-21 16:30:23 +02:00
ReturnValue_t handleAdcReport(const uint8_t* data);
2023-11-08 10:46:59 +01:00
ReturnValue_t genericHandleTm(const char* contextString, const uint8_t* data,
LocalPoolDataSetBase& set);
2022-03-27 13:07:18 +02:00
2023-11-08 18:19:24 +01:00
void disableCommand(DeviceCommandId_t cmd);
2022-03-27 13:07:18 +02:00
/**
* @brief Depending on the current active command, this function sets the reply id of the
* next reply after a successful acknowledgment report has been received. This is
* required by the function getNextReplyLength() to identify the length of the next
* reply to read.
*/
void setNextReplyId();
/**
* @brief This function handles action message replies in case the telemetry has been
* requested by another object.
*
* @param data Pointer to the telemetry data.
* @param dataSize Size of telemetry in bytes.
* @param replyId Id of the reply. This will be added to the ActionMessage.
*/
2022-11-17 15:48:44 +01:00
void handleDeviceTm(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId);
2022-03-27 13:07:18 +02:00
/**
* @brief This function prepares a space packet which does not transport any data in the
* packet data field apart from the crc.
*/
2022-11-07 11:19:10 +01:00
ReturnValue_t prepareEmptyCmd(uint16_t apid, uint8_t serviceId);
2022-03-27 13:07:18 +02:00
/**
* @brief This function initializes the space packet to select the boot image of the MPSoC.
*/
ReturnValue_t prepareSelBootImageCmd(const uint8_t* commandData);
2022-03-27 13:07:18 +02:00
ReturnValue_t prepareDisableHk();
2022-03-27 13:07:18 +02:00
/**
* @brief This function fills the commandBuffer with the data to update the time of the
* PLOC supervisor.
*/
ReturnValue_t prepareSetTimeRefCmd();
/**
* @brief This function fills the commandBuffer with the data to change the boot timeout
* value in the PLOC supervisor.
*/
ReturnValue_t prepareSetBootTimeoutCmd(const uint8_t* commandData);
2022-03-27 13:07:18 +02:00
ReturnValue_t prepareRestartTriesCmd(const uint8_t* commandData);
2022-03-27 13:07:18 +02:00
2022-11-08 20:37:57 +01:00
ReturnValue_t prepareFactoryResetCmd(const uint8_t* commandData, size_t len);
2022-03-27 13:07:18 +02:00
/**
* @brief This function fills the command buffer with the packet to enable or disable the
* watchdogs on the PLOC.
*/
void prepareWatchdogsEnableCmd(const uint8_t* commandData);
/**
* @brief This function fills the command buffer with the packet to set the watchdog timer
* of one of the three watchdogs (PS, PL, INT).
*/
ReturnValue_t prepareWatchdogsConfigTimeoutCmd(const uint8_t* commandData);
ReturnValue_t prepareLatchupConfigCmd(const uint8_t* commandData,
DeviceCommandId_t deviceCommand);
ReturnValue_t prepareSetAlertLimitCmd(const uint8_t* commandData);
2022-11-09 19:24:48 +01:00
ReturnValue_t prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData);
ReturnValue_t prepareSetAdcWindowAndStrideCmd(const uint8_t* commandData);
ReturnValue_t prepareSetAdcThresholdCmd(const uint8_t* commandData);
2022-03-27 13:07:18 +02:00
ReturnValue_t prepareRunAutoEmTest(const uint8_t* commandData);
2022-11-10 13:50:18 +01:00
ReturnValue_t prepareWipeMramCmd(const uint8_t* commandData);
2023-11-08 10:46:59 +01:00
ReturnValue_t prepareSetGpioCmd(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareReadGpioCmd(const uint8_t* commandData, size_t commandDataLen);
2022-03-27 13:07:18 +02:00
/**
* @brief Copies the content of a space packet to the command buffer.
*/
void finishTcPrep(TcBase& tc);
2022-03-27 13:07:18 +02:00
/**
* @brief In case an acknowledgment failure reply has been received this function disables
* all previously enabled commands and resets the exepected replies variable of an
* active command.
*/
void disableAllReplies();
void disableReply(DeviceCommandId_t replyId);
2022-03-27 13:07:18 +02:00
/**
* @brief This function sends a failure report if the active action was commanded by an other
* object.
*
* @param replyId The id of the reply which signals a failure.
* @param status A status byte which gives information about the failure type.
*/
void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status);
/**
* @brief This function disables the execution report reply. Within this function also the
* the variable expectedReplies of an active command will be set to 0.
*/
void disableExeReportReply();
/**
* @brief This function generates the Service 8 packets for the MRAM dump data.
*/
ReturnValue_t handleMramDumpPacket(DeviceCommandId_t id);
/**
* @brief With this function the number of expected replies following an MRAM dump command
* will be increased. This is necessary to release the command in case not all replies
* have been received.
*/
void increaseExpectedMramReplies(DeviceCommandId_t id);
/**
* @brief Writes the data of the MRAM dump to a file. The file will be created when receiving
* the first packet.
*/
ReturnValue_t handleMramDumpFile(DeviceCommandId_t id);
/**
* @brief Extracts the length field of a spacePacket referenced by the spacePacket pointer.
*
* @param spacePacket Pointer to the buffer holding the space packet.
*
* @return The value stored in the length field of the data field.
*/
uint16_t readSpacePacketLength(uint8_t* spacePacket);
/**
* @brief Extracts the sequence flags from a space packet referenced by the spacePacket
* pointer.
*
* @param spacePacket Pointer to the buffer holding the space packet.
*
* @return uint8_t where the two least significant bits hold the sequence flags.
*/
uint8_t readSequenceFlags(uint8_t* spacePacket);
ReturnValue_t createMramDumpFile();
ReturnValue_t getTimeStampString(std::string& timeStamp);
2022-04-06 07:10:20 +02:00
ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData);
2022-04-10 18:46:39 +02:00
2022-08-24 12:02:16 +02:00
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size,
supv::UpdateParams& params);
2022-08-22 13:50:24 +02:00
ReturnValue_t extractBaseParams(const uint8_t** commandData, size_t& remSize,
2022-08-24 12:02:16 +02:00
supv::UpdateParams& params);
2022-04-10 18:46:39 +02:00
ReturnValue_t eventSubscription();
2022-04-29 08:34:23 +02:00
2022-11-08 19:53:26 +01:00
ReturnValue_t handleExecutionSuccessReport(ExecutionReport& report);
void handleExecutionFailureReport(ExecutionReport& report);
void printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId);
2023-09-29 15:37:47 +02:00
pwrctrl::EnablePl enablePl = pwrctrl::EnablePl(objects::POWER_CONTROLLER);
ReturnValue_t checkModeCommand(Mode_t commandedMode, Submode_t commandedSubmode,
uint32_t* msToReachTheMode) override;
2021-03-29 14:37:52 +02:00
};
#endif /* MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_ */