tc mem write and tc mem read implemented

This commit is contained in:
2021-04-22 17:32:39 +02:00
parent 7c28b2a0bc
commit a0a5c4c8aa
4 changed files with 401 additions and 194 deletions

View File

@ -6,7 +6,10 @@
#include <string.h>
/**
* @brief This is the device handler for the ISIS Magnetorquer iMTQ.
* @brief This is the device handler for the PLOC.
*
* @details The PLOC uses the space packet protocol for communication. On each command the PLOC
* answers at least with one acknowledgment and one execution report.
*
* @author J. Meier
*/
@ -37,30 +40,38 @@ protected:
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;
private:
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_HANDLER;
static const ReturnValue_t TC_ACK_FAILURE = MAKE_RETURN_CODE(0xA0);
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA1);
static const ReturnValue_t EXE_REPLY_CRC_FAILURE = MAKE_RETURN_CODE(0xA1);
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0); //!> Space Packet received from PLOC has invalid CRC
static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1); //!> Received ACK failure reply from PLOC
static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2); //!> Received execution failure reply from PLOC
static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3); //!> Received space packet with invalid APID from PLOC
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER;
static const Event REQUESTING_TM_READ_REPORT_FAILED = MAKE_EVENT(0, severity::LOW);
static const Event TM_READ_RPT_INVALID_CRC = MAKE_EVENT(1, severity::LOW);
static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW);
static const Event CRC_FAILURE_IN_ACK_REPLY = MAKE_EVENT(2, severity::LOW);
static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW);
static const Event EXE_RPT_INVALID_CRC = MAKE_EVENT(4, severity::LOW);
static const Event MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW); //!> PLOC crc failure in telemetry packet
static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); //!> PLOC receive acknowledgment failure report
static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW); //!> PLOC receive execution failure report
static const Event CRC_FAILURE_EVENT = MAKE_EVENT(4, severity::LOW); //!> PLOC reply has invalid crc
static const uint16_t APID_MASK = 0x7FF;
DeviceCommandId_t rememberCommandId = PLOC::NONE;
uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE];
/**
* 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.
*/
DeviceCommandId_t nextReplyId = PLOC::NONE;
/**
* @brief This function fills the commandBuffer to initiate the write memory command.
*
@ -92,39 +103,71 @@ private:
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
/**
* @brief This function reads and handles the execution reply.
* @param RETURN_OK if reading and handling of reply successful, otherwise failure value.
* @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.
*/
ReturnValue_t receiveExecutionReport();
ReturnValue_t handleAckReport(const uint8_t* data);
/**
* @brief This function handles the data of a execution report.
*
* @param receivedData Pointer to the received data
* @param receivedDataLen Size in bytes of the received data
* @param data Pointer to the received data packet.
*
* @return RETURN_OK if successful, otherwise an error code.
*/
void handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen);
ReturnValue_t handleExecutionReport(const uint8_t* data);
/**
* @brief This function reads and handles the memory read report telemetry packet received
* after requesting the packet with the TC_MEM_READ command.
* @brief This function handles the memory read report.
*
* @details In case of a valid packet the received memory content will be forwarded to the
* commanding object via an action message.
* @param data Pointer to the data buffer holding the memory read report.
*
* @return RETURN_OK if successful, otherwise an error code.
*/
ReturnValue_t receiveTmMemoryReadReport();
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();
/**
* @brief This function handles action message replies in case the telemetry has been
* requested by another object.
*
* @param data Pointer to the telemtry data.
* @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.
*/
void handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId);
/**
* @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();
};
#endif /* MISSION_DEVICES_PLOCHANDLER_H_ */