From 90b31f5ee72c28be2763b35e6fc73809c0f85947 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" <–meierj@irs.uni-stuttgart.de> Date: Fri, 23 Jul 2021 13:27:58 +0200 Subject: [PATCH] added uart flush in ploc supervisor handler --- mission/devices/PlocSupervisorHandler.cpp | 70 +++++++++++++++++------ mission/devices/PlocSupervisorHandler.h | 9 ++- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/mission/devices/PlocSupervisorHandler.cpp b/mission/devices/PlocSupervisorHandler.cpp index a075a66c..21310248 100644 --- a/mission/devices/PlocSupervisorHandler.cpp +++ b/mission/devices/PlocSupervisorHandler.cpp @@ -5,8 +5,8 @@ #include #include -PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), hkset(this) { +PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF * comCookie) : + DeviceHandlerBase(objectId, uartComIFid, comCookie), hkset(this) { if (comCookie == NULL) { sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl; } @@ -15,6 +15,20 @@ PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t c PlocSupervisorHandler::~PlocSupervisorHandler() { } +ReturnValue_t PlocSupervisorHandler::initialize() { + ReturnValue_t result = RETURN_OK; + result = DeviceHandlerBase::initialize(); + if (result != RETURN_OK) { + return result; + } + uartComIf = dynamic_cast(communicationInterface); + if (uartComIf == nullptr) { + sif::warning << "PlocSupervisorHandler::initialize: Invalid uart com if" << std::endl; + return INVALID_UART_COM_IF; + } + return result; +} + void PlocSupervisorHandler::doStartUp(){ #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 @@ -41,52 +55,72 @@ ReturnValue_t PlocSupervisorHandler::buildTransitionDeviceCommand( ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t * commandData, size_t commandDataLen) { + ReturnValue_t result = RETURN_FAILED; switch(deviceCommand) { case(PLOC_SPV::GET_HK_REPORT): { prepareEmptyCmd(PLOC_SPV::APID_GET_HK_REPORT); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::RESTART_MPSOC): { prepareEmptyCmd(PLOC_SPV::APID_RESTART_MPSOC); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::START_MPSOC): { prepareEmptyCmd(PLOC_SPV::APID_START_MPSOC); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::SHUTDOWN_MPSOC): { prepareEmptyCmd(PLOC_SPV::APID_SHUTWOWN_MPSOC); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::SEL_MPSOC_BOOT_IMAGE): { prepareSelBootImageCmd(commandData); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::RESET_MPSOC): { prepareEmptyCmd(PLOC_SPV::APID_RESET_MPSOC); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::SET_TIME_REF): { - return prepareSetTimeRefCmd(); + result = prepareSetTimeRefCmd(); + break; } case(PLOC_SPV::SET_BOOT_TIMEOUT): { prepareSetBootTimeoutCmd(commandData); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::SET_MAX_RESTART_TRIES): { prepareRestartTriesCmd(commandData); - return RETURN_OK; + result = RETURN_OK; + break; } case(PLOC_SPV::DISABLE_PERIOIC_HK_TRANSMISSION): { prepareDisableHk(); - return RETURN_OK; + result = RETURN_OK; + break; } default: sif::debug << "PlocSupervisorHandler::buildCommandFromCommand: Command not implemented" << std::endl; - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + break; } - return HasReturnvaluesIF::RETURN_FAILED; + + if (result == RETURN_OK) { + /** + * Flushing the receive buffer to make sure there are no data left from a faulty reply. + */ + uartComIf->flushUartRxBuffer(comCookie); + } + + return result; } void PlocSupervisorHandler::fillCommandAndReplyMap() { @@ -222,7 +256,7 @@ ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) { triggerEvent(SUPV_CRC_FAILURE_EVENT); sendFailureReport(PLOC_SPV::ACK_REPORT, CRC_FAILURE); disableAllReplies(); - return IGNORE_REPLY_DATA; + return RETURN_OK; } uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK; @@ -564,8 +598,8 @@ void PlocSupervisorHandler::disableAllReplies() { /* If the command expects a telemetry packet the appropriate tm reply will be disabled here */ switch (commandId) { - case PLOC_SPV::HK_REPORT: { - iter = deviceReplyMap.find(PLOC_SPV::HK_REPORT); + case PLOC_SPV::GET_HK_REPORT: { + iter = deviceReplyMap.find(PLOC_SPV::GET_HK_REPORT); info = &(iter->second); info->delayCycles = 0; info->command = deviceCommandMap.end(); @@ -608,5 +642,5 @@ void PlocSupervisorHandler::disableExeReportReply() { info->delayCycles = 0; info->command = deviceCommandMap.end(); /* Expected replies is set to one here. The value will set to 0 in replyToReply() */ - info->command->second.expectedReplies = 0; + info->command->second.expectedReplies = 1; } diff --git a/mission/devices/PlocSupervisorHandler.h b/mission/devices/PlocSupervisorHandler.h index 400b1873..f56dab99 100644 --- a/mission/devices/PlocSupervisorHandler.h +++ b/mission/devices/PlocSupervisorHandler.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * @brief This is the device handler for the supervisor of the PLOC which is programmed by @@ -20,9 +21,11 @@ class PlocSupervisorHandler: public DeviceHandlerBase { public: - PlocSupervisorHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie); + PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF * comCookie); virtual ~PlocSupervisorHandler(); + virtual ReturnValue_t initialize() override; + protected: void doStartUp() override; void doShutDown() override; @@ -58,6 +61,8 @@ private: 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); + //! [EXPORT] : [COMMENT] Invalid communication interface specified + static const ReturnValue_t INVALID_UART_COM_IF = MAKE_RETURN_CODE(0xA5); static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_SUPERVISOR_HANDLER; @@ -96,6 +101,8 @@ private: PLOC_SPV::HkSet hkset; + UartComIF* uartComIf = nullptr; + /** * @brief This function checks the crc of the received PLOC reply. *