2021-07-13 08:32:14 +02:00
# ifndef MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
# define MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
2021-03-29 14:37:52 +02:00
2022-03-23 11:13:59 +01:00
# include "OBSWConfig.h"
2022-03-17 14:28:32 +01:00
# include <linux/devices/devicedefinitions/PlocSupervisorDefinitions.h>
2021-08-09 17:19:10 +02:00
# include <bsp_q7s/memory/SdCardManager.h>
2021-03-29 14:37:52 +02:00
# include <fsfw/devicehandlers/DeviceHandlerBase.h>
2021-08-03 15:58:01 +02:00
# include <fsfw_hal/linux/uart/UartComIF.h>
2021-03-29 14:37:52 +02:00
/**
2021-07-13 08:32:14 +02:00
* @ brief This is the device handler for the supervisor of the PLOC which is programmed by
* Thales .
2021-04-22 17:32:39 +02:00
*
2021-07-13 08:32:14 +02:00
* @ details The PLOC uses the space packet protocol for communication . To 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 % 20 Components / PLOC & fileid = 940960
2021-03-29 14:37:52 +02:00
* @ author J . Meier
*/
2021-07-13 08:32:14 +02:00
class PlocSupervisorHandler : public DeviceHandlerBase {
2021-03-29 14:37:52 +02:00
public :
2021-07-23 13:27:58 +02:00
PlocSupervisorHandler ( object_id_t objectId , object_id_t uartComIFid , CookieIF * comCookie ) ;
2021-07-13 08:32:14 +02:00
virtual ~ PlocSupervisorHandler ( ) ;
2021-03-29 14:37:52 +02:00
2021-07-23 13:27:58 +02:00
virtual ReturnValue_t initialize ( ) override ;
2021-03-29 14:37:52 +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 ;
void setNormalDatapoolEntriesInvalid ( ) override ;
uint32_t getTransitionDelayMs ( Mode_t modeFrom , Mode_t modeTo ) override ;
ReturnValue_t initializeLocalDataPool ( localpool : : DataPool & localDataPoolMap ,
LocalDataPoolManager & poolManager ) override ;
2021-04-22 17:32:39 +02:00
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 ;
2021-03-29 14:37:52 +02:00
private :
2021-07-13 08:32:14 +02:00
static const uint8_t INTERFACE_ID = CLASS_ID : : PLOC_SUPERVISOR_HANDLER ;
//! [EXPORT] : [COMMENT] Space Packet received from PLOC supervisor has invalid CRC
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE ( 0xA0 ) ;
//! [EXPORT] : [COMMENT] Received ACK failure reply from PLOC supervisor
static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE ( 0xA1 ) ;
//! [EXPORT] : [COMMENT] Received execution failure reply from PLOC supervisor
static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE ( 0xA2 ) ;
//! [EXPORT] : [COMMENT] Received space packet with invalid APID from PLOC supervisor
static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE ( 0xA3 ) ;
//! [EXPORT] : [COMMENT] Failed to read current system time
static const ReturnValue_t GET_TIME_FAILURE = MAKE_RETURN_CODE ( 0xA4 ) ;
2021-07-26 19:56:00 +02:00
//! [EXPORT] : [COMMENT] Received command with invalid watchdog parameter. Valid watchdogs are 0 for PS, 1 for PL and 2 for INT
2022-01-03 08:01:55 +01:00
static const ReturnValue_t INVALID_WATCHDOG = MAKE_RETURN_CODE ( 0xA5 ) ;
2021-07-26 19:56:00 +02:00
//! [EXPORT] : [COMMENT] Received watchdog timeout config command with invalid timeout. Valid timeouts must be in the range between 1000 and 360000 ms.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t INVALID_WATCHDOG_TIMEOUT = MAKE_RETURN_CODE ( 0xA6 ) ;
2021-07-27 12:02:30 +02:00
//! [EXPORT] : [COMMENT] Received latchup config command with invalid latchup ID
2022-01-03 08:01:55 +01:00
static const ReturnValue_t INVALID_LATCHUP_ID = MAKE_RETURN_CODE ( 0xA7 ) ;
2021-07-28 08:38:36 +02:00
//! [EXPORT] : [COMMENT] Received set adc sweep period command with invalid sweep period. Must be larger than 21.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t SWEEP_PERIOD_TOO_SMALL = MAKE_RETURN_CODE ( 0xA8 ) ;
2021-07-28 19:34:10 +02:00
//! [EXPORT] : [COMMENT] Receive auto EM test command with invalid test param. Valid params are 1 and 2.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t INVALID_TEST_PARAM = MAKE_RETURN_CODE ( 0xA9 ) ;
2021-07-31 08:32:57 +02:00
//! [EXPORT] : [COMMENT] Returned when scanning for MRAM dump packets failed.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t MRAM_PACKET_PARSING_FAILURE = MAKE_RETURN_CODE ( 0xAA ) ;
2021-08-01 17:11:32 +02:00
//! [EXPORT] : [COMMENT] Returned when the start and stop addresses of the MRAM dump or MRAM wipe commands are invalid (e.g. start address bigger than stop address)
2022-01-03 08:01:55 +01:00
static const ReturnValue_t INVALID_MRAM_ADDRESSES = MAKE_RETURN_CODE ( 0xAB ) ;
2021-08-01 17:11:32 +02:00
//! [EXPORT] : [COMMENT] Expect reception of an MRAM dump packet but received space packet with other apid.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t NO_MRAM_PACKET = MAKE_RETURN_CODE ( 0xAC ) ;
2021-08-08 15:02:59 +02:00
//! [EXPORT] : [COMMENT] Path to PLOC directory on SD card does not exist
2022-01-03 08:01:55 +01:00
static const ReturnValue_t PATH_DOES_NOT_EXIST = MAKE_RETURN_CODE ( 0xAD ) ;
2021-08-08 15:02:59 +02:00
//! [EXPORT] : [COMMENT] MRAM dump file does not exists. The file should actually already have been created with the reception of the first dump packet.
2022-01-03 08:01:55 +01:00
static const ReturnValue_t MRAM_FILE_NOT_EXISTS = MAKE_RETURN_CODE ( 0xAE ) ;
2021-07-13 08:32:14 +02:00
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID : : PLOC_SUPERVISOR_HANDLER ;
2021-08-05 16:37:39 +02:00
//! [EXPORT] : [COMMENT] PLOC supervisor crc failure in telemetry packet
2021-07-13 08:32:14 +02:00
static const Event SUPV_MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT ( 1 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] PLOC supervisor received acknowledgment failure report
static const Event SUPV_ACK_FAILURE = MAKE_EVENT ( 2 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] PLOC received execution failure report
static const Event SUPV_EXE_FAILURE = MAKE_EVENT ( 3 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] PLOC supervisor reply has invalid crc
static const Event SUPV_CRC_FAILURE_EVENT = MAKE_EVENT ( 4 , severity : : LOW ) ;
2021-03-29 14:37:52 +02:00
2021-04-11 12:04:13 +02:00
static const uint16_t APID_MASK = 0x7FF ;
2021-04-27 17:34:50 +02:00
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF ;
2021-03-29 14:37:52 +02:00
2021-07-13 08:32:14 +02:00
uint8_t commandBuffer [ PLOC_SPV : : MAX_COMMAND_SIZE ] ;
2021-04-15 13:17:15 +02:00
2021-04-22 17:32:39 +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 .
*/
2021-07-13 08:32:14 +02:00
DeviceCommandId_t nextReplyId = PLOC_SPV : : NONE ;
2021-04-22 17:32:39 +02:00
2021-07-28 08:38:36 +02:00
UartComIF * uartComIf = nullptr ;
2021-07-13 08:32:14 +02:00
PLOC_SPV : : HkSet hkset ;
2021-07-24 13:57:05 +02:00
PLOC_SPV : : BootStatusReport bootStatusReport ;
2021-07-28 08:38:36 +02:00
PLOC_SPV : : LatchupStatusReport latchupStatusReport ;
2021-03-29 14:37:52 +02:00
2021-07-31 08:32:57 +02:00
/** Number of expected replies following the MRAM dump command */
uint32_t expectedMramDumpPackets = 0 ;
2021-08-01 17:11:32 +02:00
uint32_t receivedMramDumpPackets = 0 ;
2021-07-31 08:32:57 +02:00
/** Set to true as soon as a complete space packet is present in the spacePacketBuffer */
bool packetInBuffer = false ;
/** Points to the next free position in the space packet buffer */
uint16_t bufferTop = 0 ;
/** This buffer is used to concatenate space packets received in two different read steps */
uint8_t spacePacketBuffer [ PLOC_SPV : : MAX_PACKET_SIZE ] ;
2021-07-23 13:27:58 +02:00
2022-03-27 10:56:40 +02:00
# ifdef TE0720_1CFA
2021-08-08 15:02:59 +02:00
SdCardManager * sdcMan = nullptr ;
2021-08-17 16:14:23 +02:00
# endif /* BOARD_TE0720 == 0 */
2021-08-08 15:02:59 +02:00
/** Path to PLOC specific files on SD card */
std : : string plocFilePath = " ploc " ;
std : : string activeMramFile ;
/** Setting this variable to true will enable direct downlink of MRAM packets */
bool downlinkMramDump = false ;
2021-03-29 14:37:52 +02:00
/**
2021-04-11 12:04:13 +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 .
2021-03-29 14:37:52 +02:00
*
2021-04-11 12:04:13 +02:00
* @ return RETURN_OK if CRC is ok , otherwise CRC_FAILURE .
*/
2021-04-15 13:17:15 +02:00
ReturnValue_t verifyPacket ( const uint8_t * start , size_t foundLen ) ;
2021-04-11 12:04:13 +02:00
/**
2021-04-22 17:32:39 +02:00
* @ brief This function handles the acknowledgment report .
*
* @ param data Pointer to the data holding the acknowledgment report .
*
* @ return RETURN_OK if successful , otherwise an error code .
2021-04-11 12:04:13 +02:00
*/
2021-04-22 17:32:39 +02:00
ReturnValue_t handleAckReport ( const uint8_t * data ) ;
2021-04-11 12:04:13 +02:00
/**
* @ brief This function handles the data of a execution report .
2021-03-29 14:37:52 +02:00
*
2021-04-22 17:32:39 +02:00
* @ param data Pointer to the received data packet .
2021-04-15 13:17:15 +02:00
*
* @ return RETURN_OK if successful , otherwise an error code .
2021-03-29 14:37:52 +02:00
*/
2021-04-22 17:32:39 +02:00
ReturnValue_t handleExecutionReport ( const uint8_t * data ) ;
2021-03-29 14:37:52 +02:00
/**
2021-07-13 08:32:14 +02:00
* @ brief This function handles the housekeeping report . This means verifying the CRC of the
* reply and filling the appropriate dataset .
2021-04-22 17:32:39 +02:00
*
2021-07-13 08:32:14 +02:00
* @ param data Pointer to the data buffer holding the housekeeping read report .
2021-04-11 12:04:13 +02:00
*
2021-04-22 17:32:39 +02:00
* @ return RETURN_OK if successful , otherwise an error code .
2021-04-11 12:04:13 +02:00
*/
2021-07-13 08:32:14 +02:00
ReturnValue_t handleHkReport ( const uint8_t * data ) ;
2021-04-22 17:32:39 +02:00
2021-07-24 13:57:05 +02:00
/**
* @ 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 ) ;
2021-07-28 08:38:36 +02:00
ReturnValue_t handleLatchupStatusReport ( const uint8_t * data ) ;
2021-04-22 17:32:39 +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 ( ) ;
2021-03-29 14:37:52 +02:00
2021-04-11 12:04:13 +02:00
/**
* @ brief This function handles action message replies in case the telemetry has been
* requested by another object .
2021-03-29 14:37:52 +02:00
*
2021-04-22 17:32:39 +02:00
* @ param data Pointer to the telemetry data .
2021-04-11 12:04:13 +02:00
* @ param dataSize Size of telemetry in bytes .
* @ param replyId Id of the reply . This will be added to the ActionMessage .
2021-03-29 14:37:52 +02:00
*/
2021-04-11 12:04:13 +02:00
void handleDeviceTM ( const uint8_t * data , size_t dataSize , DeviceCommandId_t replyId ) ;
2021-04-22 17:32:39 +02:00
2021-07-13 08:32:14 +02:00
/**
* @ brief This function prepares a space packet which does not transport any data in the
* packet data field apart from the crc .
*/
void prepareEmptyCmd ( uint16_t apid ) ;
/**
* @ brief This function initializes the space packet to select the boot image of the MPSoC .
*/
void prepareSelBootImageCmd ( const uint8_t * commandData ) ;
2021-07-22 08:06:04 +02:00
void prepareDisableHk ( ) ;
2021-07-13 08:32:14 +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 .
*/
void prepareSetBootTimeoutCmd ( const uint8_t * commandData ) ;
2021-07-22 08:06:04 +02:00
void prepareRestartTriesCmd ( const uint8_t * commandData ) ;
2021-07-26 16:30:20 +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 ) ;
2021-07-26 19:56:00 +02:00
/**
* @ 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 ) ;
2021-07-27 12:02:30 +02:00
ReturnValue_t prepareLatchupConfigCmd ( const uint8_t * commandData ,
DeviceCommandId_t deviceCommand ) ;
ReturnValue_t prepareAutoCalibrateAlertCmd ( const uint8_t * commandData ) ;
2021-07-28 08:38:36 +02:00
ReturnValue_t prepareSetAlertLimitCmd ( const uint8_t * commandData ) ;
ReturnValue_t prepareSetAlertIrqFilterCmd ( const uint8_t * commandData ) ;
ReturnValue_t prepareSetAdcSweetPeriodCmd ( const uint8_t * commandData ) ;
void prepareSetAdcEnabledChannelsCmd ( const uint8_t * commandData ) ;
void prepareSetAdcWindowAndStrideCmd ( const uint8_t * commandData ) ;
void prepareSetAdcThresholdCmd ( const uint8_t * commandData ) ;
2021-07-28 11:55:16 +02:00
void prepareEnableNvmsCmd ( const uint8_t * commandData ) ;
void prepareSelectNvmCmd ( const uint8_t * commandData ) ;
2021-07-28 19:34:10 +02:00
ReturnValue_t prepareRunAutoEmTest ( const uint8_t * commandData ) ;
2021-08-01 17:11:32 +02:00
ReturnValue_t prepareWipeMramCmd ( const uint8_t * commandData ) ;
ReturnValue_t prepareDumpMramCmd ( const uint8_t * commandData ) ;
2021-08-02 15:28:57 +02:00
void preparePrintCpuStatsCmd ( const uint8_t * commandData ) ;
void prepareSetDbgVerbosityCmd ( const uint8_t * commandData ) ;
void prepareSetGpioCmd ( const uint8_t * commandData ) ;
void prepareReadGpioCmd ( const uint8_t * commandData ) ;
2021-07-27 12:02:30 +02:00
/**
* @ brief Copies the content of a space packet to the command buffer .
*/
void packetToOutBuffer ( uint8_t * packetData , size_t fullSize ) ;
2021-04-22 17:32:39 +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 ( ) ;
/**
* @ 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 ( ) ;
2021-07-31 08:32:57 +02:00
/**
* @ brief Function is called in scanForReply and fills the spacePacketBuffer with the read
* data until a full packet has been received .
*/
ReturnValue_t parseMramPackets ( const uint8_t * packet , size_t remainingSize , size_t * foundlen ) ;
2021-08-01 17:11:32 +02:00
/**
* @ brief This function generates the Service 8 packets for the MRAM dump data .
*/
2021-08-31 11:20:21 +02:00
ReturnValue_t handleMramDumpPacket ( DeviceCommandId_t id ) ;
2021-08-01 17:11:32 +02:00
/**
* @ 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 .
*/
2021-08-31 11:20:21 +02:00
void increaseExpectedMramReplies ( DeviceCommandId_t id ) ;
2021-08-01 17:11:32 +02:00
/**
* @ brief Function checks if the packet written to the space packet buffer is really a
* MRAM dump packet .
*/
ReturnValue_t checkMramPacketApid ( ) ;
2021-08-08 15:02:59 +02:00
/**
* @ brief Writes the data of the MRAM dump to a file . The file will be created when receiving
* the first packet .
*/
2021-08-31 11:20:21 +02:00
ReturnValue_t handleMramDumpFile ( DeviceCommandId_t id ) ;
2021-08-08 15:02:59 +02:00
/**
* @ 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 ) ;
2021-03-29 14:37:52 +02:00
} ;
2021-07-13 08:32:14 +02:00
# endif /* MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_ */