diff --git a/osal/host/Clock.cpp b/osal/host/Clock.cpp index 17d98ba8..41321eeb 100644 --- a/osal/host/Clock.cpp +++ b/osal/host/Clock.cpp @@ -106,11 +106,6 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { return HasReturnvaluesIF::RETURN_OK; } -uint32_t Clock::getUptimeSeconds() { - timeval uptime = getUptime(); - return uptime.tv_sec; -} - ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { // do some magic with chrono (C++20!) diff --git a/osal/host/FixedTimeslotTask.cpp b/osal/host/FixedTimeslotTask.cpp index 3c31eb76..9e892bb5 100644 --- a/osal/host/FixedTimeslotTask.cpp +++ b/osal/host/FixedTimeslotTask.cpp @@ -1,7 +1,9 @@ -#include "FixedTimeslotTask.h" -#include "Mutex.h" +#include "../../osal/host/FixedTimeslotTask.h" #include "../../ipc/MutexFactory.h" +#include "../../osal/host/Mutex.h" +#include "../../osal/host/FixedTimeslotTask.h" + #include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../tasks/ExecutableObjectIF.h" @@ -33,18 +35,18 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority, reinterpret_cast(mainThread.native_handle()), ABOVE_NORMAL_PRIORITY_CLASS); if(result != 0) { - sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with " - << "code " << GetLastError() << std::endl; + sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code " + << GetLastError() << std::endl; } result = SetThreadPriority( reinterpret_cast(mainThread.native_handle()), THREAD_PRIORITY_NORMAL); if(result != 0) { - sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with " - "code " << GetLastError() << std::endl; + sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code " + << 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 } @@ -58,8 +60,7 @@ FixedTimeslotTask::~FixedTimeslotTask(void) { } void FixedTimeslotTask::taskEntryPoint(void* argument) { - FixedTimeslotTask *originalTask( - reinterpret_cast(argument)); + FixedTimeslotTask *originalTask(reinterpret_cast(argument)); if (not originalTask->started) { // we have to suspend/block here until the task is started. @@ -114,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 } diff --git a/osal/host/FixedTimeslotTask.h b/osal/host/FixedTimeslotTask.h index 9985e2ee..f3fffd0f 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/MessageQueue.cpp b/osal/host/MessageQueue.cpp index bced3713..d662d782 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; } diff --git a/osal/host/Mutex.cpp b/osal/host/Mutex.cpp index 8471cab8..ad8873df 100644 --- a/osal/host/Mutex.cpp +++ b/osal/host/Mutex.cpp @@ -4,21 +4,18 @@ 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; } } 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 af56b8f7..c0fa19b7 100644 --- a/osal/host/Mutex.h +++ b/osal/host/Mutex.h @@ -1,5 +1,5 @@ -#ifndef FSFW_OSAL_HOST_MUTEX_H_ -#define FSFW_OSAL_HOST_MUTEX_H_ +#ifndef FSFW_OSAL_HOSTED_MUTEX_H_ +#define FSFW_OSAL_HOSTED_MUTEX_H_ #include "../../ipc/MutexIF.h" @@ -22,8 +22,8 @@ public: std::timed_mutex* getMutexHandle(); private: - bool locked = false; + //bool locked = false; std::timed_mutex mutex; }; -#endif /* FSFW_OSAL_HOST_MUTEX_H_ */ +#endif /* FSFW_OSAL_HOSTED_MUTEX_H_ */ diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index f7807a17..5662c7cc 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -89,16 +89,16 @@ 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( std::chrono::system_clock::now().time_since_epoch()) }; - auto nextStartTime{ currentStartTime }; - - for (const auto& object: objectList) { - object->initializeAfterTaskCreation(); - } + auto nextStartTime { currentStartTime }; /* Enter the loop that defines the task behavior. */ for (;;) { @@ -109,10 +109,6 @@ void PeriodicTask::taskFunctionality() { object->performOperation(); } if(not delayForInterval(¤tStartTime, periodChrono)) { -#ifdef DEBUG - sif::warning << "PeriodicTask: " << taskName << - " missed deadline!\n" << std::flush; -#endif if(deadlineMissedFunc != nullptr) { this->deadlineMissedFunc(); } @@ -126,7 +122,6 @@ 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; } diff --git a/osal/host/PeriodicTask.h b/osal/host/PeriodicTask.h index 7689788a..00cb6a24 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. diff --git a/osal/host/QueueFactory.cpp b/osal/host/QueueFactory.cpp index 7feb1ad6..1a679c96 100644 --- a/osal/host/QueueFactory.cpp +++ b/osal/host/QueueFactory.cpp @@ -1,7 +1,11 @@ + #include "MessageQueue.h" -#include "../../ipc/QueueFactory.h" + #include "../../ipc/MessageQueueSenderIF.h" +#include "../../ipc/MessageQueueMessageIF.h" +#include "../../ipc/QueueFactory.h" #include "../../serviceinterface/ServiceInterfaceStream.h" + #include QueueFactory* QueueFactory::factoryInstance = nullptr; diff --git a/osal/host/QueueMapManager.cpp b/osal/host/QueueMapManager.cpp index c3d94584..621f46bc 100644 --- a/osal/host/QueueMapManager.cpp +++ b/osal/host/QueueMapManager.cpp @@ -44,17 +44,9 @@ MessageQueueIF* QueueMapManager::getMessageQueue( return queueIter->second; } else { - if(messageQueueId == MessageQueueIF::NO_QUEUE) { - sif::error << "QueueMapManager::getQueueHandle: Configuration" - << " error, NO_QUEUE was passed to this function!" - << std::endl; - } - else { - sif::warning << "QueueMapManager::getQueueHandle: The ID " - << messageQueueId << " does not exists in the map." - << std::endl; - } - return nullptr; + sif::warning << "QueueMapManager::getQueueHandle: The ID " << + messageQueueId << " does not exists in the map" << std::endl; + return nullptr; } }