#ifndef MISSION_DEVICES_PLOCHANDLER_H_ #define MISSION_DEVICES_PLOCHANDLER_H_ #include #include #include /** * @brief This is the device handler for the ISIS Magnetorquer iMTQ. * * @author J. Meier */ class PlocHandler: public DeviceHandlerBase { public: PlocHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie); virtual ~PlocHandler(); /** * @brief Sets mode to MODE_NORMAL. Can be used for debugging. */ void setModeNormal(); 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; 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 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 uint16_t APID_MASK = 0x7FF; DeviceCommandId_t rememberCommandId = PLOC::NONE; uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; /** * @brief This function fills the commandBuffer to initiate the write memory command. * * @param commandData Pointer to action command data. * @param commanDataLen Size of command data in bytes. * * @return RETURN_OK if successful, else RETURN_FAILURE. */ ReturnValue_t prepareTcMemWriteCommand(const uint8_t * commandData, size_t commandDataLen); /** * @brief This function fills the commandBuffer to initiate the write reads command. * * @param commandData Pointer to action command data. * @param commanDataLen Size of command data in bytes. * * @return RETURN_OK if successful, else RETURN_FAILURE. */ ReturnValue_t prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen); /** * @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. * * @return RETURN_OK if CRC is ok, otherwise CRC_FAILURE. */ 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. */ ReturnValue_t receiveExecutionReport(); /** * @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 * * @return RETURN_OK if successful, otherwise an error code. */ void handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen); /** * @brief This function reads and handles the memory read report telemetry packet received * after requesting the packet with the TC_MEM_READ command. * * @details In case of a valid packet the received memory content will be forwarded to the * commanding object via an action message. */ ReturnValue_t receiveTmMemoryReadReport(); /** * @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 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); }; #endif /* MISSION_DEVICES_PLOCHANDLER_H_ */