some fixes for thread shutdown code
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-11-08 14:52:07 +01:00
parent 763bf2d85b
commit f564fb5c1a
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 102 additions and 76 deletions

View File

@ -64,7 +64,7 @@ ReturnValue_t PlocSupervisorHandler::initialize() {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
supvHelper->setComCookie(comCookie); // supvHelper->setComCookie(comCookie);
result = eventSubscription(); result = eventSubscription();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -97,7 +97,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
switch (actionId) { switch (actionId) {
case TERMINATE_SUPV_HELPER: { case TERMINATE_SUPV_HELPER: {
supvHelper->stopProcess(); supvHelper->stop();
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
default: default:
@ -148,18 +148,18 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
plocSupvHelperExecuting = true; plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case LOGGING_REQUEST_EVENT_BUFFERS: { // case LOGGING_REQUEST_EVENT_BUFFERS: {
if (size > config::MAX_PATH_SIZE) { // if (size > config::MAX_PATH_SIZE) {
return result::FILENAME_TOO_LONG; // return result::FILENAME_TOO_LONG;
} // }
result = supvHelper->startEventBufferRequest( // result = supvHelper->startEventBufferRequest(
std::string(reinterpret_cast<const char*>(data), size)); // std::string(reinterpret_cast<const char*>(data), size));
if (result != returnvalue::OK) { // if (result != returnvalue::OK) {
return result; // return result;
} // }
plocSupvHelperExecuting = true; // plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; // return EXECUTION_FINISHED;
} // }
default: default:
break; break;
} }

View File

@ -167,7 +167,7 @@ ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) {
return returnvalue::OK; 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, ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
uint32_t startAddress) { 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) { 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; ReturnValue_t result = returnvalue::OK;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
result = FilesystemHelper::checkPath(params.file); result = FilesystemHelper::checkPath(params.file);
@ -204,70 +210,93 @@ ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
#endif #endif
update.file = params.file; {
update.fullFileSize = getFileSize(update.file); MutexGuard mg(lock);
if (params.bytesWritten > update.fullFileSize) {
sif::warning << "Invalid start bytes counter " << params.bytesWritten update.file = params.file;
<< ", smaller than full file length" << update.fullFileSize << std::endl; update.fullFileSize = getFileSize(update.file);
return returnvalue::FAILED; 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; return result;
} }
ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId, ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId,
uint32_t startAddress) { uint32_t startAddress) {
update.file = file; lock->lockMutex();
update.fullFileSize = getFileSize(file); InternalState current = state;
return performMemCheck(memoryId, startAddress, getFileSize(update.file), true); 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, ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId,
size_t sizeToCheck, bool checkCrc) { uint32_t startAddress, size_t sizeToCheck,
update.memoryId = memoryId; bool checkCrc) {
update.startAddress = startAddress; {
update.length = sizeToCheck; MutexGuard mg(lock);
update.crcShouldBeChecked = checkCrc; update.file = file;
request = Request::CHECK_MEMORY; update.fullFileSize = getFileSize(file);
uartComIF->flushUartTxAndRxBuf(comCookie); state = InternalState::LONGER_REQUEST;
semaphore->release(); request = Request::CHECK_MEMORY;
update.memoryId = memoryId;
update.startAddress = startAddress;
update.length = sizeToCheck;
update.crcShouldBeChecked = checkCrc;
}
return returnvalue::OK; 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; 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; 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() { void PlocSupvHelper::executeFullCheckMemoryCommand() {
ReturnValue_t result; ReturnValue_t result;
@ -356,11 +385,6 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
uint16_t dataLength = 0; uint16_t dataLength = 0;
ccsds::SequenceFlags seqFlags; ccsds::SequenceFlags seqFlags;
while (update.bytesWritten < update.fullFileSize) { while (update.bytesWritten < update.fullFileSize) {
if (terminate) {
terminate = false;
triggerEvent(TERMINATED_UPDATE_PROCEDURE);
return PROCESS_TERMINATED;
}
size_t remainingSize = update.fullFileSize - update.bytesWritten; size_t remainingSize = update.fullFileSize - update.bytesWritten;
bool lastSegment = false; bool lastSegment = false;
if (remainingSize > supv::WriteMemory::CHUNK_MAX) { if (remainingSize > supv::WriteMemory::CHUNK_MAX) {
@ -1031,5 +1055,8 @@ ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc(size_t& readSize) {
void PlocSupvHelper::performUartShutdown() { void PlocSupvHelper::performUartShutdown() {
tcflush(serialPort, TCIOFLUSH); tcflush(serialPort, TCIOFLUSH);
// Clear ring buffers
recRingBuf.clear();
ipcRingBuf.clear();
state = InternalState::GO_TO_SLEEP; state = InternalState::GO_TO_SLEEP;
} }

View File

@ -122,7 +122,7 @@ class PlocSupvHelper : public DeviceCommunicationIF,
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;
ReturnValue_t setComIF(UartComIF* uartComfIF_); ReturnValue_t setComIF(UartComIF* uartComfIF_);
void setComCookie(CookieIF* comCookie_); // void setComCookie(CookieIF* comCookie_);
/** /**
* @brief Starts update procedure * @brief Starts update procedure
@ -136,24 +136,24 @@ class PlocSupvHelper : public DeviceCommunicationIF,
ReturnValue_t performUpdate(const supv::UpdateParams& params); ReturnValue_t performUpdate(const supv::UpdateParams& params);
ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress); ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress);
ReturnValue_t performMemCheck(uint8_t memoryId, uint32_t startAddress, size_t sizeToCheck, ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress,
bool checkCrc); size_t sizeToCheck, bool checkCrc);
ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress); ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress);
/** /**
* @brief This initiate the continuation of a failed update. * @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 * @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. * @brief Can be used to interrupt a running data transfer.
*/ */
void stopProcess(); void stop();
static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount);
@ -242,7 +242,6 @@ class PlocSupvHelper : public DeviceCommunicationIF,
std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{}; std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{};
bool terminate = false;
bool debugMode = false; bool debugMode = false;
/** /**
* Communication interface responsible for data transactions between OBC and Supervisor. * Communication interface responsible for data transactions between OBC and Supervisor.