diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index df0796cc..f71cafe3 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -64,7 +64,7 @@ ReturnValue_t PlocSupervisorHandler::initialize() { if (result != returnvalue::OK) { return ObjectManagerIF::CHILD_INIT_FAILED; } - supvHelper->setComCookie(comCookie); + // supvHelper->setComCookie(comCookie); result = eventSubscription(); if (result != returnvalue::OK) { @@ -97,7 +97,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, switch (actionId) { case TERMINATE_SUPV_HELPER: { - supvHelper->stopProcess(); + supvHelper->stop(); return EXECUTION_FINISHED; } default: @@ -148,18 +148,18 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } - case LOGGING_REQUEST_EVENT_BUFFERS: { - if (size > config::MAX_PATH_SIZE) { - return result::FILENAME_TOO_LONG; - } - result = supvHelper->startEventBufferRequest( - std::string(reinterpret_cast(data), size)); - if (result != returnvalue::OK) { - return result; - } - plocSupvHelperExecuting = true; - return EXECUTION_FINISHED; - } + // case LOGGING_REQUEST_EVENT_BUFFERS: { + // if (size > config::MAX_PATH_SIZE) { + // return result::FILENAME_TOO_LONG; + // } + // result = supvHelper->startEventBufferRequest( + // std::string(reinterpret_cast(data), size)); + // if (result != returnvalue::OK) { + // return result; + // } + // plocSupvHelperExecuting = true; + // return EXECUTION_FINISHED; + // } default: break; } diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 997c6a7a..c9e9ad72 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -167,7 +167,7 @@ ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) { return returnvalue::OK; } -void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; } +// void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; } ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress) { @@ -182,6 +182,12 @@ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, } ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) { + lock->lockMutex(); + InternalState current = state; + lock->unlockMutex(); + if (current != InternalState::DEFAULT) { + return HasActionsIF::IS_BUSY; + } ReturnValue_t result = returnvalue::OK; #ifdef XIPHOS_Q7S result = FilesystemHelper::checkPath(params.file); @@ -204,70 +210,93 @@ ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) { return returnvalue::FAILED; } #endif - update.file = params.file; - update.fullFileSize = getFileSize(update.file); - if (params.bytesWritten > update.fullFileSize) { - sif::warning << "Invalid start bytes counter " << params.bytesWritten - << ", smaller than full file length" << update.fullFileSize << std::endl; - return returnvalue::FAILED; + { + MutexGuard mg(lock); + + update.file = params.file; + update.fullFileSize = getFileSize(update.file); + if (params.bytesWritten > update.fullFileSize) { + sif::warning << "Invalid start bytes counter " << params.bytesWritten + << ", smaller than full file length" << update.fullFileSize << std::endl; + return returnvalue::FAILED; + } + update.length = update.fullFileSize - params.bytesWritten; + update.memoryId = params.memId; + update.startAddress = params.startAddr; + update.progressPercent = 0; + update.bytesWritten = params.bytesWritten; + update.crcShouldBeChecked = true; + update.packetNum = 1; + update.deleteMemory = params.deleteMemory; + update.sequenceCount = params.seqCount; + state = InternalState::LONGER_REQUEST; + request = Request::UPDATE; } - update.length = update.fullFileSize - params.bytesWritten; - update.memoryId = params.memId; - update.startAddress = params.startAddr; - update.progressPercent = 0; - update.bytesWritten = params.bytesWritten; - update.crcShouldBeChecked = true; - update.packetNum = 1; - update.deleteMemory = params.deleteMemory; - update.sequenceCount = params.seqCount; - request = Request::UPDATE; - uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore->release(); return result; } ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress) { - update.file = file; - update.fullFileSize = getFileSize(file); - return performMemCheck(memoryId, startAddress, getFileSize(update.file), true); + lock->lockMutex(); + InternalState current = state; + lock->unlockMutex(); + if (current != InternalState::DEFAULT) { + return HasActionsIF::IS_BUSY; + } + return performMemCheck(file, memoryId, startAddress, getFileSize(update.file), true); } -ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAddress, - size_t sizeToCheck, bool checkCrc) { - update.memoryId = memoryId; - update.startAddress = startAddress; - update.length = sizeToCheck; - update.crcShouldBeChecked = checkCrc; - request = Request::CHECK_MEMORY; - uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore->release(); +ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId, + uint32_t startAddress, size_t sizeToCheck, + bool checkCrc) { + { + MutexGuard mg(lock); + update.file = file; + update.fullFileSize = getFileSize(file); + state = InternalState::LONGER_REQUEST; + request = Request::CHECK_MEMORY; + update.memoryId = memoryId; + update.startAddress = startAddress; + update.length = sizeToCheck; + update.crcShouldBeChecked = checkCrc; + } return returnvalue::OK; } -void PlocSupvHelper::initiateUpdateContinuation() { +ReturnValue_t PlocSupvHelper::initiateUpdateContinuation() { + lock->lockMutex(); + InternalState current = state; + lock->unlockMutex(); + if (current != InternalState::DEFAULT) { + return HasActionsIF::IS_BUSY; + } + MutexGuard mg(lock); + state = InternalState::LONGER_REQUEST; request = Request::CONTINUE_UPDATE; - semaphore->release(); -} - -ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) { -#ifdef XIPHOS_Q7S - ReturnValue_t result = FilesystemHelper::checkPath(path); - if (result != returnvalue::OK) { - return result; - } -#endif - if (not std::filesystem::exists(path)) { - return PATH_NOT_EXISTS; - } - eventBufferReq.path = path; - request = Request::REQUEST_EVENT_BUFFER; - uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore->release(); return returnvalue::OK; } -void PlocSupvHelper::stopProcess() { terminate = true; } +// ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) { +//#ifdef XIPHOS_Q7S +// ReturnValue_t result = FilesystemHelper::checkPath(path); +// if (result != returnvalue::OK) { +// return result; +// } +//#endif +// if (not std::filesystem::exists(path)) { +// return PATH_NOT_EXISTS; +// } +// eventBufferReq.path = path; +// request = Request::REQUEST_EVENT_BUFFER; +// //uartComIF->flushUartTxAndRxBuf(comCookie); +// semaphore->release(); +// return returnvalue::OK; +// } + +void PlocSupvHelper::stop() { + MutexGuard mg(lock); + state = InternalState::GO_TO_SLEEP; +} void PlocSupvHelper::executeFullCheckMemoryCommand() { ReturnValue_t result; @@ -356,11 +385,6 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() { uint16_t dataLength = 0; ccsds::SequenceFlags seqFlags; while (update.bytesWritten < update.fullFileSize) { - if (terminate) { - terminate = false; - triggerEvent(TERMINATED_UPDATE_PROCEDURE); - return PROCESS_TERMINATED; - } size_t remainingSize = update.fullFileSize - update.bytesWritten; bool lastSegment = false; if (remainingSize > supv::WriteMemory::CHUNK_MAX) { @@ -1031,5 +1055,8 @@ ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc(size_t& readSize) { void PlocSupvHelper::performUartShutdown() { tcflush(serialPort, TCIOFLUSH); + // Clear ring buffers + recRingBuf.clear(); + ipcRingBuf.clear(); state = InternalState::GO_TO_SLEEP; } diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index d36234e2..9426b2e4 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -122,7 +122,7 @@ class PlocSupvHelper : public DeviceCommunicationIF, ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t setComIF(UartComIF* uartComfIF_); - void setComCookie(CookieIF* comCookie_); + // void setComCookie(CookieIF* comCookie_); /** * @brief Starts update procedure @@ -136,24 +136,24 @@ class PlocSupvHelper : public DeviceCommunicationIF, ReturnValue_t performUpdate(const supv::UpdateParams& params); ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress); - ReturnValue_t performMemCheck(uint8_t memoryId, uint32_t startAddress, size_t sizeToCheck, - bool checkCrc); + ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress, + size_t sizeToCheck, bool checkCrc); ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress); /** * @brief This initiate the continuation of a failed update. */ - void initiateUpdateContinuation(); + ReturnValue_t initiateUpdateContinuation(); /** * @brief Calling this function will initiate the procedure to request the event buffer */ - ReturnValue_t startEventBufferRequest(std::string path); + // ReturnValue_t startEventBufferRequest(std::string path); /** * @brief Can be used to interrupt a running data transfer. */ - void stopProcess(); + void stop(); static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); @@ -242,7 +242,6 @@ class PlocSupvHelper : public DeviceCommunicationIF, std::array tmBuf{}; - bool terminate = false; bool debugMode = false; /** * Communication interface responsible for data transactions between OBC and Supervisor.