From 37196c8e3b5e2795dc75243aa38412464e79de9e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 1 Dec 2020 23:47:11 +0100 Subject: [PATCH 01/11] atomic fix --- osal/host/FixedTimeslotTask.h | 2 +- osal/host/PeriodicTask.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osal/host/FixedTimeslotTask.h b/osal/host/FixedTimeslotTask.h index 9985e2ee6..f3fffd0f0 100644 --- a/osal/host/FixedTimeslotTask.h +++ b/osal/host/FixedTimeslotTask.h @@ -74,7 +74,7 @@ protected: //!< Typedef for the List of objects. typedef std::vector ObjectList; std::thread mainThread; - std::atomic terminateThread = false; + std::atomic terminateThread { false }; //! Polling sequence table which contains the object to execute //! and information like the timeslots and the passed execution step. diff --git a/osal/host/PeriodicTask.h b/osal/host/PeriodicTask.h index 7689788ac..00cb6a24e 100644 --- a/osal/host/PeriodicTask.h +++ b/osal/host/PeriodicTask.h @@ -69,7 +69,7 @@ protected: //!< Typedef for the List of objects. typedef std::vector ObjectList; std::thread mainThread; - std::atomic terminateThread = false; + std::atomic terminateThread { false }; /** * @brief This attribute holds a list of objects to be executed. -- 2.34.1 From a92f6c5d8e06c3cee2328671d1e3138211ba49e4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 00:05:54 +0100 Subject: [PATCH 02/11] mutex bugfix for host --- osal/host/Mutex.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osal/host/Mutex.cpp b/osal/host/Mutex.cpp index 8471cab80..fa3aa24c9 100644 --- a/osal/host/Mutex.cpp +++ b/osal/host/Mutex.cpp @@ -4,12 +4,12 @@ Mutex::Mutex() {} ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) { - if(timeoutMs == MutexIF::BLOCKING) { + if(timeoutType == MutexIF::BLOCKING) { mutex.lock(); locked = true; return HasReturnvaluesIF::RETURN_OK; } - else if(timeoutMs == MutexIF::POLLING) { + else if(timeoutType == MutexIF::POLLING) { if(mutex.try_lock()) { locked = true; return HasReturnvaluesIF::RETURN_OK; -- 2.34.1 From 206d4b58b287a6a4a56df478d010225bfefe583d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 00:17:12 +0100 Subject: [PATCH 03/11] removed boolean var --- osal/host/Mutex.cpp | 7 ------- osal/host/Mutex.h | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/osal/host/Mutex.cpp b/osal/host/Mutex.cpp index fa3aa24c9..ad8873dfc 100644 --- a/osal/host/Mutex.cpp +++ b/osal/host/Mutex.cpp @@ -6,19 +6,16 @@ Mutex::Mutex() {} ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) { if(timeoutType == MutexIF::BLOCKING) { mutex.lock(); - locked = true; return HasReturnvaluesIF::RETURN_OK; } else if(timeoutType == MutexIF::POLLING) { if(mutex.try_lock()) { - locked = true; return HasReturnvaluesIF::RETURN_OK; } } else if(timeoutMs > MutexIF::POLLING){ auto chronoMs = std::chrono::milliseconds(timeoutMs); if(mutex.try_lock_for(chronoMs)) { - locked = true; return HasReturnvaluesIF::RETURN_OK; } } @@ -26,11 +23,7 @@ ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) { } ReturnValue_t Mutex::unlockMutex() { - if(not locked) { - return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX; - } mutex.unlock(); - locked = false; return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/host/Mutex.h b/osal/host/Mutex.h index 24dafbbda..c0fa19b78 100644 --- a/osal/host/Mutex.h +++ b/osal/host/Mutex.h @@ -22,7 +22,7 @@ public: std::timed_mutex* getMutexHandle(); private: - bool locked = false; + //bool locked = false; std::timed_mutex mutex; }; -- 2.34.1 From f5c384de14da3275fbd00487a2bc481de9cd99ea Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 00:27:53 +0100 Subject: [PATCH 04/11] some bugfixes --- osal/windows/TmTcWinUdpBridge.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index 7e283c2a7..1f66290fb 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -6,6 +6,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, uint16_t serverPort, uint16_t clientPort): TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { mutex = MutexFactory::instance()->createMutex(); + communicationLinkUp = false; // Initiates Winsock DLL. WSAData wsaData; @@ -90,7 +91,6 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { // sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" // " sent." << std::endl; return HasReturnvaluesIF::RETURN_OK; - return HasReturnvaluesIF::RETURN_OK; } void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { @@ -101,6 +101,7 @@ void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { // &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; // sif::debug << "IP Address Old: " << inet_ntop(AF_INET, // &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; + registerCommConnect(); // Set new IP address if it has changed. if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) { @@ -114,7 +115,7 @@ void TmTcWinUdpBridge::handleSocketError() { switch(errCode) { case(WSANOTINITIALISED): { sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: " - << "WSAStartup(...) call " << "necessary" << std::endl; + << "WSAStartup(...) call necessary" << std::endl; break; } default: { @@ -154,11 +155,11 @@ void TmTcWinUdpBridge::handleSendError() { switch(errCode) { case(WSANOTINITIALISED): { sif::info << "TmTcWinUdpBridge::handleSendError: WSANOTINITIALISED: " - << "WSAStartup(...) call " << "necessary" << std::endl; + << "WSAStartup(...) call necessary" << std::endl; break; } case(WSAEADDRNOTAVAIL): { - sif::info << "TmTcWinUdpBridge::handleReadError: WSAEADDRNOTAVAIL: " + sif::info << "TmTcWinUdpBridge::handleSendError: WSAEADDRNOTAVAIL: " << "Check target address. " << std::endl; break; } -- 2.34.1 From 73d3defe9f1edc043911e17884ca09d8dcdda48a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 00:32:07 +0100 Subject: [PATCH 05/11] error output improved --- osal/host/QueueMapManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osal/host/QueueMapManager.cpp b/osal/host/QueueMapManager.cpp index 1b2094e91..621f46bce 100644 --- a/osal/host/QueueMapManager.cpp +++ b/osal/host/QueueMapManager.cpp @@ -44,7 +44,7 @@ MessageQueueIF* QueueMapManager::getMessageQueue( return queueIter->second; } else { - sif::warning << "QueueMapManager::getQueueHandle: The ID" << + sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId << " does not exists in the map" << std::endl; return nullptr; } -- 2.34.1 From 8ad30d489a35cdd6ee27c2e14cfd907d85b62ee0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 00:58:13 +0100 Subject: [PATCH 06/11] important bugfix for host osal --- osal/host/PeriodicTask.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index f4ee079b1..fb2369637 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -89,6 +89,10 @@ ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) { } void PeriodicTask::taskFunctionality() { + for (const auto& object: objectList) { + object->initializeAfterTaskCreation(); + } + std::chrono::milliseconds periodChrono(static_cast(period*1000)); auto currentStartTime { std::chrono::duration_cast( @@ -101,9 +105,8 @@ void PeriodicTask::taskFunctionality() { if(terminateThread.load()) { break; } - for (ObjectList::iterator it = objectList.begin(); - it != objectList.end(); ++it) { - (*it)->performOperation(); + for (const auto& object: objectList) { + object->performOperation(); } if(not delayForInterval(¤tStartTime, periodChrono)) { sif::warning << "PeriodicTask: " << taskName << -- 2.34.1 From 7b742a2e6775d8f2b5e8b0121d39a84d293cdd94 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 01:00:07 +0100 Subject: [PATCH 07/11] warning removed from osal --- osal/host/PeriodicTask.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index fb2369637..5662c7cca 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -98,7 +98,7 @@ void PeriodicTask::taskFunctionality() { std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()) }; - auto nextStartTime{ currentStartTime }; + auto nextStartTime { currentStartTime }; /* Enter the loop that defines the task behavior. */ for (;;) { @@ -109,8 +109,6 @@ void PeriodicTask::taskFunctionality() { object->performOperation(); } if(not delayForInterval(¤tStartTime, periodChrono)) { - sif::warning << "PeriodicTask: " << taskName << - " missed deadline!\n" << std::flush; if(deadlineMissedFunc != nullptr) { this->deadlineMissedFunc(); } -- 2.34.1 From 558220643e05a6eaaad0fce5107c3a1c12eea9ae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 01:01:31 +0100 Subject: [PATCH 08/11] small form improvements --- osal/host/FixedTimeslotTask.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osal/host/FixedTimeslotTask.cpp b/osal/host/FixedTimeslotTask.cpp index e78c974a4..7000024ee 100644 --- a/osal/host/FixedTimeslotTask.cpp +++ b/osal/host/FixedTimeslotTask.cpp @@ -115,8 +115,9 @@ void FixedTimeslotTask::taskFunctionality() { this->pollingSeqTable.executeAndAdvance(); if (not pollingSeqTable.slotFollowsImmediately()) { // we need to wait before executing the current slot - //this gives us the time to wait: - interval = chron_ms(this->pollingSeqTable.getIntervalToPreviousSlotMs()); + // this gives us the time to wait: + interval = chron_ms( + this->pollingSeqTable.getIntervalToPreviousSlotMs()); delayForInterval(¤tStartTime, interval); //TODO deadline missed check } -- 2.34.1 From 2deb7037b0e58156a8fc04095b57c9eee0003395 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Dec 2020 01:07:40 +0100 Subject: [PATCH 09/11] todo added --- osal/host/FixedTimeslotTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osal/host/FixedTimeslotTask.cpp b/osal/host/FixedTimeslotTask.cpp index 7000024ee..9e892bb58 100644 --- a/osal/host/FixedTimeslotTask.cpp +++ b/osal/host/FixedTimeslotTask.cpp @@ -46,7 +46,7 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority, << GetLastError() << std::endl; } #elif defined(LINUX) - // we can just copy and paste the code from linux here. + // TODO: we can just copy and paste the code from the linux OSAL here. #endif } -- 2.34.1 From 983556b3b3c70b9d4c337ebfc44cbe0290da96ec Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 5 Dec 2020 01:21:04 +0100 Subject: [PATCH 10/11] evil bug fixed --- osal/host/MessageQueue.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/osal/host/MessageQueue.cpp b/osal/host/MessageQueue.cpp index bced37139..f1f5867b5 100644 --- a/osal/host/MessageQueue.cpp +++ b/osal/host/MessageQueue.cpp @@ -34,7 +34,7 @@ ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message, } ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) { - if (this->lastPartner != 0) { + if (this->lastPartner != MessageQueueIF::NO_QUEUE) { return sendMessageFrom(this->lastPartner, message, this->getId()); } else { return MessageQueueIF::NO_REPLY_PARTNER; @@ -106,6 +106,7 @@ bool MessageQueue::isDefaultDestinationSet() const { ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault) { + message->setSender(sentFrom); if(message->getMessageSize() > message->getMaximumMessageSize()) { // Actually, this should never happen or an error will be emitted // in MessageQueueMessage. @@ -126,7 +127,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, // TODO: Better returnvalue return HasReturnvaluesIF::RETURN_FAILED; } - if(targetQueue->messageQueue.size() < targetQueue->messageDepth) { MutexHelper mutexLock(targetQueue->queueLock, MutexIF::TimeoutType::WAITING, 20); @@ -145,7 +145,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, else { return MessageQueueIF::FULL; } - message->setSender(sentFrom); return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1 From bb11bc5685e54366c819803c8ec5655ba4acdc4d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 5 Dec 2020 17:11:34 +0100 Subject: [PATCH 11/11] task if is set now --- osal/host/PeriodicTask.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index 5662c7cca..bfa6c3fd6 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -122,6 +122,7 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) { if (newObject == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } + newObject->setTaskIF(this); objectList.push_back(newObject); return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1