2022-01-05 11:26:01 +01:00
|
|
|
#ifndef BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
|
|
|
|
#define BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2022-01-10 16:18:18 +01:00
|
|
|
#include <string>
|
2022-01-06 18:05:21 +01:00
|
|
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
|
|
|
#include "fsfw_hal/linux/uart/UartComIF.h"
|
2022-01-10 16:18:18 +01:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2022-01-11 12:56:02 +01:00
|
|
|
#include "fsfw/tmtcservices/SourceSequenceCounter.h"
|
2022-03-17 14:28:32 +01:00
|
|
|
#include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h"
|
2022-01-06 18:05:21 +01:00
|
|
|
#include "PlocMPSoCHelper.h"
|
2022-03-22 11:35:44 +01:00
|
|
|
#include "linux/devices/devicedefinitions/MPSoCReturnValuesIF.h"
|
2021-03-29 14:37:52 +02:00
|
|
|
|
|
|
|
/**
|
2022-01-06 18:05:21 +01:00
|
|
|
* @brief This is the device handler for the MPSoC of the payload computer.
|
|
|
|
*
|
|
|
|
* @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_MPSoC
|
|
|
|
* ICD: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_TAS-ILH-IRS/ICD-PLOC/ILH&fileid=1030263
|
|
|
|
*
|
|
|
|
* @note The sequence count in the space packets must be incremented with each received and sent
|
|
|
|
* packet.
|
2021-04-22 17:32:39 +02:00
|
|
|
*
|
2021-03-29 14:37:52 +02:00
|
|
|
* @author J. Meier
|
|
|
|
*/
|
2021-07-13 08:32:14 +02:00
|
|
|
class PlocMPSoCHandler: public DeviceHandlerBase {
|
2021-03-29 14:37:52 +02:00
|
|
|
public:
|
|
|
|
|
2022-01-06 18:05:21 +01:00
|
|
|
PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF * comCookie,
|
|
|
|
PlocMPSoCHelper* plocMPSoCHelper);
|
2021-07-13 08:32:14 +02:00
|
|
|
virtual ~PlocMPSoCHandler();
|
2022-01-03 08:01:55 +01:00
|
|
|
virtual ReturnValue_t initialize() override;
|
2022-01-06 18:05:21 +01:00
|
|
|
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
|
|
|
const uint8_t* data, size_t size) override;
|
2022-01-07 09:50:04 +01:00
|
|
|
void performOperationHook() 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 SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HANDLER;
|
2021-04-12 10:16:59 +02:00
|
|
|
|
2022-01-03 08:01:55 +01:00
|
|
|
//! [EXPORT] : [COMMENT] PLOC crc failure in telemetry packet
|
|
|
|
static const Event MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW);
|
|
|
|
//! [EXPORT] : [COMMENT] PLOC receive acknowledgment failure report
|
|
|
|
static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW);
|
|
|
|
//! [EXPORT] : [COMMENT] PLOC receive execution failure report
|
|
|
|
static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW);
|
|
|
|
//! [EXPORT] : [COMMENT] PLOC reply has invalid crc
|
2022-01-11 17:58:59 +01:00
|
|
|
static const Event MPSOC_HANDLER_CRC_FAILURE = MAKE_EVENT(4, severity::LOW);
|
2022-01-03 08:01:55 +01:00
|
|
|
//! [EXPORT] : [COMMENT] Packet sequence count in received space packet does not match expected count
|
|
|
|
//! P1: Expected sequence count
|
|
|
|
//! P2: Received sequence count
|
2022-01-11 17:58:59 +01:00
|
|
|
static const Event MPSOC_HANDLER_SEQ_CNT_MISMATCH = MAKE_EVENT(5, severity::LOW);
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2022-03-21 08:53:55 +01:00
|
|
|
//! [EXPORT] : [COMMENT] Received command has file string with invalid length
|
|
|
|
static const ReturnValue_t NAME_TOO_LONG = MAKE_RETURN_CODE(0xD0);
|
|
|
|
|
2021-04-11 12:04:13 +02:00
|
|
|
static const uint16_t APID_MASK = 0x7FF;
|
2022-01-10 16:18:18 +01:00
|
|
|
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
|
2022-03-24 17:39:50 +01:00
|
|
|
static const uint8_t STATUS_OFFSET = 10;
|
2022-01-10 16:18:18 +01:00
|
|
|
|
|
|
|
MessageQueueIF* eventQueue = nullptr;
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2022-01-11 12:56:02 +01:00
|
|
|
SourceSequenceCounter sequenceCount;
|
2021-04-15 13:17:15 +02:00
|
|
|
|
2022-01-06 18:05:21 +01:00
|
|
|
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
|
2021-04-26 11:28:19 +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.
|
|
|
|
*/
|
2022-01-05 11:26:01 +01:00
|
|
|
DeviceCommandId_t nextReplyId = mpsoc::NONE;
|
2021-04-22 17:32:39 +02:00
|
|
|
|
2022-01-03 08:01:55 +01:00
|
|
|
UartComIF* uartComIf = nullptr;
|
|
|
|
|
2022-01-06 18:05:21 +01:00
|
|
|
PlocMPSoCHelper* plocMPSoCHelper = nullptr;
|
|
|
|
|
|
|
|
// Used to block incoming commands when MPSoC helper class is currently executing a command
|
|
|
|
bool plocMPSoCHelperExecuting = false;
|
|
|
|
|
2022-01-11 17:58:59 +01:00
|
|
|
class TmMemReadReport {
|
|
|
|
public:
|
|
|
|
static const uint8_t FIX_SIZE = 14;
|
|
|
|
size_t rememberRequestedSize = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
TmMemReadReport tmMemReadReport;
|
|
|
|
|
2022-01-07 09:50:04 +01:00
|
|
|
/**
|
|
|
|
* @brief Handles events received from the PLOC MPSoC helper
|
|
|
|
*/
|
|
|
|
void handleEvent(EventMessage* eventMessage);
|
|
|
|
|
2022-03-21 08:35:28 +01:00
|
|
|
ReturnValue_t prepareTcMemWrite(const uint8_t * commandData, size_t commandDataLen);
|
|
|
|
ReturnValue_t prepareTcMemRead(const uint8_t * commandData, size_t commandDataLen);
|
|
|
|
ReturnValue_t prepareTcFlashDelete(const uint8_t * commandData, size_t commandDataLen);
|
2022-03-21 11:05:41 +01:00
|
|
|
ReturnValue_t prepareTcReplayStart(const uint8_t * commandData, size_t commandDataLen);
|
2022-03-21 16:21:51 +01:00
|
|
|
ReturnValue_t prepareTcReplayStop();
|
|
|
|
ReturnValue_t prepareTcDownlinkPwrOn(const uint8_t * commandData, size_t commandDataLen);
|
|
|
|
ReturnValue_t prepareTcDownlinkPwrOff();
|
|
|
|
ReturnValue_t prepareTcReplayWriteSequence(const uint8_t * commandData, size_t commandDataLen);
|
2021-04-15 13:17:15 +02:00
|
|
|
|
|
|
|
/**
|
2022-01-05 11:26:01 +01:00
|
|
|
* @brief Copies space packet into command buffer
|
2021-04-15 13:17:15 +02:00
|
|
|
*/
|
2022-01-05 11:26:01 +01:00
|
|
|
void copyToCommandBuffer(mpsoc::TcBase* tc);
|
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-04-22 17:32:39 +02:00
|
|
|
* @brief This function handles the memory read report.
|
|
|
|
*
|
|
|
|
* @param data Pointer to the data buffer holding the memory 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-04-22 17:32:39 +02:00
|
|
|
ReturnValue_t handleMemoryReadReport(const uint8_t* data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
2022-03-24 17:39:50 +01:00
|
|
|
|
|
|
|
void printStatus(const uint8_t* data);
|
|
|
|
|
|
|
|
ReturnValue_t prepareTcModeReplay();
|
2021-03-29 14:37:52 +02:00
|
|
|
};
|
|
|
|
|
2022-01-05 11:26:01 +01:00
|
|
|
#endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */
|