Merge branch 'development' into mueller/action-unittest-fix

This commit is contained in:
Steffen Gaisser 2020-12-08 14:12:49 +01:00
commit db5c54fcfe
10 changed files with 28 additions and 29 deletions

View File

@ -1,5 +1,8 @@
## Changes from ASTP 0.0.1 to 1.0.0 ## Changes from ASTP 0.0.1 to 1.0.0
### Host OSAL
- Bugfix in MessageQueue, which caused the sender not to be set properly
### FreeRTOS OSAL ### FreeRTOS OSAL

View File

@ -46,7 +46,7 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
<< GetLastError() << std::endl; << GetLastError() << std::endl;
} }
#elif defined(LINUX) #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 #endif
} }
@ -115,8 +115,9 @@ void FixedTimeslotTask::taskFunctionality() {
this->pollingSeqTable.executeAndAdvance(); this->pollingSeqTable.executeAndAdvance();
if (not pollingSeqTable.slotFollowsImmediately()) { if (not pollingSeqTable.slotFollowsImmediately()) {
// we need to wait before executing the current slot // we need to wait before executing the current slot
//this gives us the time to wait: // this gives us the time to wait:
interval = chron_ms(this->pollingSeqTable.getIntervalToPreviousSlotMs()); interval = chron_ms(
this->pollingSeqTable.getIntervalToPreviousSlotMs());
delayForInterval(&currentStartTime, interval); delayForInterval(&currentStartTime, interval);
//TODO deadline missed check //TODO deadline missed check
} }

View File

@ -74,7 +74,7 @@ protected:
//!< Typedef for the List of objects. //!< Typedef for the List of objects.
typedef std::vector<ExecutableObjectIF*> ObjectList; typedef std::vector<ExecutableObjectIF*> ObjectList;
std::thread mainThread; std::thread mainThread;
std::atomic<bool> terminateThread = false; std::atomic<bool> terminateThread { false };
//! Polling sequence table which contains the object to execute //! Polling sequence table which contains the object to execute
//! and information like the timeslots and the passed execution step. //! and information like the timeslots and the passed execution step.

View File

@ -34,7 +34,7 @@ ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
} }
ReturnValue_t MessageQueue::reply(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()); return sendMessageFrom(this->lastPartner, message, this->getId());
} else { } else {
return MessageQueueIF::NO_REPLY_PARTNER; return MessageQueueIF::NO_REPLY_PARTNER;
@ -106,6 +106,7 @@ bool MessageQueue::isDefaultDestinationSet() const {
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
message->setSender(sentFrom);
if(message->getMessageSize() > message->getMaximumMessageSize()) { if(message->getMessageSize() > message->getMaximumMessageSize()) {
// Actually, this should never happen or an error will be emitted // Actually, this should never happen or an error will be emitted
// in MessageQueueMessage. // in MessageQueueMessage.
@ -126,7 +127,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
// TODO: Better returnvalue // TODO: Better returnvalue
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
if(targetQueue->messageQueue.size() < targetQueue->messageDepth) { if(targetQueue->messageQueue.size() < targetQueue->messageDepth) {
MutexHelper mutexLock(targetQueue->queueLock, MutexHelper mutexLock(targetQueue->queueLock,
MutexIF::TimeoutType::WAITING, 20); MutexIF::TimeoutType::WAITING, 20);
@ -145,7 +145,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
else { else {
return MessageQueueIF::FULL; return MessageQueueIF::FULL;
} }
message->setSender(sentFrom);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -4,21 +4,18 @@
Mutex::Mutex() {} Mutex::Mutex() {}
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) { ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
if(timeoutMs == MutexIF::BLOCKING) { if(timeoutType == MutexIF::BLOCKING) {
mutex.lock(); mutex.lock();
locked = true;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
else if(timeoutMs == MutexIF::POLLING) { else if(timeoutType == MutexIF::POLLING) {
if(mutex.try_lock()) { if(mutex.try_lock()) {
locked = true;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
} }
else if(timeoutMs > MutexIF::POLLING){ else if(timeoutMs > MutexIF::POLLING){
auto chronoMs = std::chrono::milliseconds(timeoutMs); auto chronoMs = std::chrono::milliseconds(timeoutMs);
if(mutex.try_lock_for(chronoMs)) { if(mutex.try_lock_for(chronoMs)) {
locked = true;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
} }
@ -26,11 +23,7 @@ ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
} }
ReturnValue_t Mutex::unlockMutex() { ReturnValue_t Mutex::unlockMutex() {
if(not locked) {
return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX;
}
mutex.unlock(); mutex.unlock();
locked = false;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -22,7 +22,7 @@ public:
std::timed_mutex* getMutexHandle(); std::timed_mutex* getMutexHandle();
private: private:
bool locked = false; //bool locked = false;
std::timed_mutex mutex; std::timed_mutex mutex;
}; };

View File

@ -89,25 +89,26 @@ ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
} }
void PeriodicTask::taskFunctionality() { void PeriodicTask::taskFunctionality() {
for (const auto& object: objectList) {
object->initializeAfterTaskCreation();
}
std::chrono::milliseconds periodChrono(static_cast<uint32_t>(period*1000)); std::chrono::milliseconds periodChrono(static_cast<uint32_t>(period*1000));
auto currentStartTime { auto currentStartTime {
std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()) std::chrono::system_clock::now().time_since_epoch())
}; };
auto nextStartTime{ currentStartTime }; auto nextStartTime { currentStartTime };
/* Enter the loop that defines the task behavior. */ /* Enter the loop that defines the task behavior. */
for (;;) { for (;;) {
if(terminateThread.load()) { if(terminateThread.load()) {
break; break;
} }
for (ObjectList::iterator it = objectList.begin(); for (const auto& object: objectList) {
it != objectList.end(); ++it) { object->performOperation();
(*it)->performOperation();
} }
if(not delayForInterval(&currentStartTime, periodChrono)) { if(not delayForInterval(&currentStartTime, periodChrono)) {
sif::warning << "PeriodicTask: " << taskName <<
" missed deadline!\n" << std::flush;
if(deadlineMissedFunc != nullptr) { if(deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc(); this->deadlineMissedFunc();
} }
@ -121,6 +122,7 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
if (newObject == nullptr) { if (newObject == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
newObject->setTaskIF(this);
objectList.push_back(newObject); objectList.push_back(newObject);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -69,7 +69,7 @@ protected:
//!< Typedef for the List of objects. //!< Typedef for the List of objects.
typedef std::vector<ExecutableObjectIF*> ObjectList; typedef std::vector<ExecutableObjectIF*> ObjectList;
std::thread mainThread; std::thread mainThread;
std::atomic<bool> terminateThread = false; std::atomic<bool> terminateThread { false };
/** /**
* @brief This attribute holds a list of objects to be executed. * @brief This attribute holds a list of objects to be executed.

View File

@ -44,7 +44,7 @@ MessageQueueIF* QueueMapManager::getMessageQueue(
return queueIter->second; return queueIter->second;
} }
else { else {
sif::warning << "QueueMapManager::getQueueHandle: The ID" << sif::warning << "QueueMapManager::getQueueHandle: The ID " <<
messageQueueId << " does not exists in the map" << std::endl; messageQueueId << " does not exists in the map" << std::endl;
return nullptr; return nullptr;
} }

View File

@ -6,6 +6,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
uint16_t serverPort, uint16_t clientPort): uint16_t serverPort, uint16_t clientPort):
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
communicationLinkUp = false;
// Initiates Winsock DLL. // Initiates Winsock DLL.
WSAData wsaData; WSAData wsaData;
@ -90,7 +91,6 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" // sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
// " sent." << std::endl; // " sent." << std::endl;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
return HasReturnvaluesIF::RETURN_OK;
} }
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { 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; // &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
// sif::debug << "IP Address Old: " << inet_ntop(AF_INET, // sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; // &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
registerCommConnect();
// Set new IP address if it has changed. // Set new IP address if it has changed.
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) { if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
@ -114,7 +115,7 @@ void TmTcWinUdpBridge::handleSocketError() {
switch(errCode) { switch(errCode) {
case(WSANOTINITIALISED): { case(WSANOTINITIALISED): {
sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: " sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: "
<< "WSAStartup(...) call " << "necessary" << std::endl; << "WSAStartup(...) call necessary" << std::endl;
break; break;
} }
default: { default: {
@ -154,11 +155,11 @@ void TmTcWinUdpBridge::handleSendError() {
switch(errCode) { switch(errCode) {
case(WSANOTINITIALISED): { case(WSANOTINITIALISED): {
sif::info << "TmTcWinUdpBridge::handleSendError: WSANOTINITIALISED: " sif::info << "TmTcWinUdpBridge::handleSendError: WSANOTINITIALISED: "
<< "WSAStartup(...) call " << "necessary" << std::endl; << "WSAStartup(...) call necessary" << std::endl;
break; break;
} }
case(WSAEADDRNOTAVAIL): { case(WSAEADDRNOTAVAIL): {
sif::info << "TmTcWinUdpBridge::handleReadError: WSAEADDRNOTAVAIL: " sif::info << "TmTcWinUdpBridge::handleSendError: WSAEADDRNOTAVAIL: "
<< "Check target address. " << std::endl; << "Check target address. " << std::endl;
break; break;
} }