Merge branch 'mueller/master' of https://egit.irs.uni-stuttgart.de/KSat/fsfw into mueller/master
This commit is contained in:
commit
8b83541264
@ -131,9 +131,9 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATH})
|
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATHS})
|
||||||
if(IS_ABSOLUTE ${INCLUDE_PATH})
|
if(IS_ABSOLUTE ${INCLUDE_PATH})
|
||||||
set(CURR_ABS_INC_PATH "${FREERTOS_PATH}")
|
set(CURR_ABS_INC_PATH "${INCLUDE_PATH}")
|
||||||
else()
|
else()
|
||||||
get_filename_component(CURR_ABS_INC_PATH
|
get_filename_component(CURR_ABS_INC_PATH
|
||||||
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
|
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
|
||||||
|
@ -156,11 +156,11 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag
|
|||||||
sif::info << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
sif::info << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
message->getReporter() << std::setfill(' ') << std::dec;
|
message->getReporter() << std::setfill(' ') << std::dec;
|
||||||
}
|
}
|
||||||
sif::info << " report event with ID " << message->getEventId() << std::endl;
|
sif::info << " reported event with ID " << message->getEventId() << std::endl;
|
||||||
sif::info << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
|
sif::debug << translateEvents(message->getEvent()) << " | " <<std::hex << "P1 Hex: 0x" <<
|
||||||
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
|
message->getParameter1() << " | P1 Dec: " << std::dec << message->getParameter1() <<
|
||||||
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
|
std::hex << " | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " <<
|
||||||
message->getParameter2() << std::endl;
|
std::dec << message->getParameter2() << std::endl;
|
||||||
#else
|
#else
|
||||||
if (string != 0) {
|
if (string != 0) {
|
||||||
sif::printInfo("Event Manager: %s reported event with ID %d\n", string,
|
sif::printInfo("Event Manager: %s reported event with ID %d\n", string,
|
||||||
@ -186,11 +186,11 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag
|
|||||||
sif::debug << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
sif::debug << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
message->getReporter() << std::setfill(' ') << std::dec;
|
message->getReporter() << std::setfill(' ') << std::dec;
|
||||||
}
|
}
|
||||||
sif::debug << " report event with ID " << message->getEventId() << std::endl;
|
sif::debug << " reported event with ID " << message->getEventId() << std::endl;
|
||||||
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
|
sif::debug << translateEvents(message->getEvent()) << " | " <<std::hex << "P1 Hex: 0x" <<
|
||||||
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
|
message->getParameter1() << " | P1 Dec: " << std::dec << message->getParameter1() <<
|
||||||
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
|
std::hex << " | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " <<
|
||||||
message->getParameter2() << std::endl;
|
std::dec << message->getParameter2() << std::endl;
|
||||||
#else
|
#else
|
||||||
if (string != 0) {
|
if (string != 0) {
|
||||||
sif::printDebug("Event Manager: %s reported event with ID %d\n", string,
|
sif::printDebug("Event Manager: %s reported event with ID %d\n", string,
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#include "EventManagerIF.h"
|
#include "EventManagerIF.h"
|
||||||
#include "eventmatching/EventMatchTree.h"
|
#include "eventmatching/EventMatchTree.h"
|
||||||
|
#include "FSFWConfig.h"
|
||||||
#include <FSFWConfig.h>
|
|
||||||
|
|
||||||
#include "../serviceinterface/ServiceInterface.h"
|
#include "../serviceinterface/ServiceInterface.h"
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
|
@ -14,8 +14,9 @@ MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize):
|
|||||||
auto result = QueueMapManager::instance()->addMessageQueue(this, &mqId);
|
auto result = QueueMapManager::instance()->addMessageQueue(this, &mqId);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "MessageQueue::MessageQueue:"
|
sif::error << "MessageQueue::MessageQueue: Could not be created" << std::endl;
|
||||||
<< " Could not be created" << std::endl;
|
#else
|
||||||
|
sif::printError("MessageQueue::MessageQueue: Could not be created\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "BinarySemaphore.h"
|
#include "BinarySemaphore.h"
|
||||||
|
#include "unixUtility.h"
|
||||||
#include "../../serviceinterface/ServiceInterfacePrinter.h"
|
#include "../../serviceinterface/ServiceInterfacePrinter.h"
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
@ -44,10 +45,7 @@ ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
|||||||
timeOut.tv_nsec = nseconds - timeOut.tv_sec * 1000000000;
|
timeOut.tv_nsec = nseconds - timeOut.tv_sec * 1000000000;
|
||||||
result = sem_timedwait(&handle, &timeOut);
|
result = sem_timedwait(&handle, &timeOut);
|
||||||
if(result != 0 and errno == EINVAL) {
|
if(result != 0 and errno == EINVAL) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "acquire", "sem_timedwait");
|
||||||
sif::debug << "BinarySemaphore::acquire: Invalid time value possible"
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(result == 0) {
|
if(result == 0) {
|
||||||
@ -57,19 +55,21 @@ ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
|||||||
switch(errno) {
|
switch(errno) {
|
||||||
case(EAGAIN):
|
case(EAGAIN):
|
||||||
// Operation could not be performed without blocking (for sem_trywait)
|
// Operation could not be performed without blocking (for sem_trywait)
|
||||||
case(ETIMEDOUT):
|
case(ETIMEDOUT): {
|
||||||
// Semaphore is 0
|
// Semaphore is 0
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "acquire", "ETIMEDOUT");
|
||||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
case(EINVAL):
|
}
|
||||||
|
case(EINVAL): {
|
||||||
// Semaphore invalid
|
// Semaphore invalid
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "acquire", "EINVAL");
|
||||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
case(EINTR):
|
}
|
||||||
|
case(EINTR): {
|
||||||
// Call was interrupted by signal handler
|
// Call was interrupted by signal handler
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "acquire", "EINTR");
|
||||||
sif::debug << "BinarySemaphore::acquire: Signal handler interrupted."
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
"Code " << strerror(errno) << std::endl;
|
}
|
||||||
#endif
|
|
||||||
/* No break */
|
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -91,11 +91,16 @@ ReturnValue_t BinarySemaphore::release(sem_t *handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case(EINVAL):
|
case(EINVAL): {
|
||||||
// Semaphore invalid
|
// Semaphore invalid
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "release", "EINVAL");
|
||||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
case(EOVERFLOW):
|
}
|
||||||
|
case(EOVERFLOW): {
|
||||||
// SEM_MAX_VALUE overflow. This should never happen
|
// SEM_MAX_VALUE overflow. This should never happen
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "release", "EOVERFLOW");
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -128,17 +133,14 @@ void BinarySemaphore::initSemaphore(uint8_t initCount) {
|
|||||||
auto result = sem_init(&handle, true, initCount);
|
auto result = sem_init(&handle, true, initCount);
|
||||||
if(result == -1) {
|
if(result == -1) {
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case(EINVAL):
|
case(EINVAL): {
|
||||||
// Value exceeds SEM_VALUE_MAX
|
utility::printUnixErrorGeneric(CLASS_NAME, "initSemaphore", "EINVAL");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case(ENOSYS): {
|
case(ENOSYS): {
|
||||||
// System does not support process-shared semaphores
|
// System does not support process-shared semaphores
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "initSemaphore", "ENOSYS");
|
||||||
sif::error << "BinarySemaphore: Init failed with "
|
break;
|
||||||
<< strerror(errno) << std::endl;
|
|
||||||
#else
|
|
||||||
sif::printError("BinarySemaphore: Init failed with %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,8 +153,7 @@ ReturnValue_t BinarySemaphore::checkCount(sem_t* handle, uint8_t maxCount) {
|
|||||||
// Binary Semaphore special case.
|
// Binary Semaphore special case.
|
||||||
// This is a config error use lightweight printf is this is called
|
// This is a config error use lightweight printf is this is called
|
||||||
// from an interrupt
|
// from an interrupt
|
||||||
printf("BinarySemaphore::release: Value of binary semaphore greater"
|
printf("BinarySemaphore::release: Value of binary semaphore greater than 1!\n");
|
||||||
" than 1!\n");
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
static ReturnValue_t checkCount(sem_t* handle, uint8_t maxCount);
|
static ReturnValue_t checkCount(sem_t* handle, uint8_t maxCount);
|
||||||
protected:
|
protected:
|
||||||
sem_t handle;
|
sem_t handle;
|
||||||
|
static constexpr const char* CLASS_NAME = "BinarySemaphore";
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
||||||
|
@ -15,6 +15,7 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
TaskFactory.cpp
|
TaskFactory.cpp
|
||||||
Timer.cpp
|
Timer.cpp
|
||||||
tcpipHelpers.cpp
|
tcpipHelpers.cpp
|
||||||
|
unixUtility.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "../../osal/linux/CountingSemaphore.h"
|
#include "CountingSemaphore.h"
|
||||||
|
#include "unixUtility.h"
|
||||||
|
|
||||||
#include "../../serviceinterface/ServiceInterface.h"
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -7,8 +9,11 @@ CountingSemaphore::CountingSemaphore(const uint8_t maxCount, uint8_t initCount):
|
|||||||
maxCount(maxCount), initCount(initCount) {
|
maxCount(maxCount), initCount(initCount) {
|
||||||
if(initCount > maxCount) {
|
if(initCount > maxCount) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
sif::warning << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||||
"intial cout. Setting initial count to max count." << std::endl;
|
"intial cout. Setting initial count to max count" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CountingSemaphoreUsingTask: Max count bigger than "
|
||||||
|
"intial cout. Setting initial count to max count\n");
|
||||||
#endif
|
#endif
|
||||||
initCount = maxCount;
|
initCount = maxCount;
|
||||||
}
|
}
|
||||||
@ -42,11 +47,18 @@ ReturnValue_t CountingSemaphore::release(sem_t* handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case(EINVAL):
|
case(EINVAL): {
|
||||||
// Semaphore invalid
|
// Semaphore invalid
|
||||||
|
utility::printUnixErrorGeneric("CountingSemaphore", "release", "EINVAL");
|
||||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
case(EOVERFLOW):
|
}
|
||||||
|
|
||||||
|
case(EOVERFLOW): {
|
||||||
// SEM_MAX_VALUE overflow. This should never happen
|
// SEM_MAX_VALUE overflow. This should never happen
|
||||||
|
utility::printUnixErrorGeneric("CountingSemaphore", "release", "EOVERFLOW");
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "MessageQueue.h"
|
#include "MessageQueue.h"
|
||||||
|
#include "unixUtility.h"
|
||||||
|
|
||||||
#include "../../serviceinterface/ServiceInterface.h"
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
#include "../../objectmanager/ObjectManager.h"
|
#include "../../objectmanager/ObjectManager.h"
|
||||||
@ -13,9 +14,7 @@
|
|||||||
|
|
||||||
MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
||||||
id(MessageQueueIF::NO_QUEUE),lastPartner(MessageQueueIF::NO_QUEUE),
|
id(MessageQueueIF::NO_QUEUE),lastPartner(MessageQueueIF::NO_QUEUE),
|
||||||
defaultDestination(MessageQueueIF::NO_QUEUE),
|
defaultDestination(MessageQueueIF::NO_QUEUE), maxMessageSize(maxMessageSize) {
|
||||||
maxMessageSize(maxMessageSize) {
|
|
||||||
//debug << "MessageQueue::MessageQueue: Creating a queue" << std::endl;
|
|
||||||
mq_attr attributes;
|
mq_attr attributes;
|
||||||
this->id = 0;
|
this->id = 0;
|
||||||
//Set attributes
|
//Set attributes
|
||||||
@ -32,7 +31,7 @@ MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
|||||||
mode_t mode = S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH;
|
mode_t mode = S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH;
|
||||||
mqd_t tempId = mq_open(name, oflag, mode, &attributes);
|
mqd_t tempId = mq_open(name, oflag, mode, &attributes);
|
||||||
if (tempId == -1) {
|
if (tempId == -1) {
|
||||||
handleError(&attributes, messageDepth);
|
handleOpenError(&attributes, messageDepth);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Successful mq_open call
|
//Successful mq_open call
|
||||||
@ -43,102 +42,14 @@ MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
|||||||
MessageQueue::~MessageQueue() {
|
MessageQueue::~MessageQueue() {
|
||||||
int status = mq_close(this->id);
|
int status = mq_close(this->id);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "~MessageQueue", "close");
|
||||||
sif::error << "MessageQueue::Destructor: mq_close Failed with status: "
|
|
||||||
<< strerror(errno) <<std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
status = mq_unlink(name);
|
status = mq_unlink(name);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "~MessageQueue", "unlink");
|
||||||
sif::error << "MessageQueue::Destructor: mq_unlink Failed with status: "
|
|
||||||
<< strerror(errno) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueue::handleError(mq_attr* attributes,
|
|
||||||
uint32_t messageDepth) {
|
|
||||||
switch(errno) {
|
|
||||||
case(EINVAL): {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "MessageQueue::MessageQueue: Invalid name or attributes"
|
|
||||||
" for message size" << std::endl;
|
|
||||||
#endif
|
|
||||||
size_t defaultMqMaxMsg = 0;
|
|
||||||
// Not POSIX conformant, but should work for all UNIX systems.
|
|
||||||
// Just an additional helpful printout :-)
|
|
||||||
if(std::ifstream("/proc/sys/fs/mqueue/msg_max",std::ios::in) >>
|
|
||||||
defaultMqMaxMsg and defaultMqMaxMsg < messageDepth) {
|
|
||||||
/*
|
|
||||||
See: https://www.man7.org/linux/man-pages/man3/mq_open.3.html
|
|
||||||
This happens if the msg_max value is not large enough
|
|
||||||
It is ignored if the executable is run in privileged mode.
|
|
||||||
Run the unlockRealtime script or grant the mode manually by using:
|
|
||||||
sudo setcap 'CAP_SYS_RESOURCE=+ep' <pathToBinary>
|
|
||||||
|
|
||||||
Persistent solution for session:
|
|
||||||
echo <newMsgMax> | sudo tee /proc/sys/fs/mqueue/msg_max
|
|
||||||
|
|
||||||
Permanent solution:
|
|
||||||
sudo nano /etc/sysctl.conf
|
|
||||||
Append at end: fs/mqueue/msg_max = <newMsgMaxLen>
|
|
||||||
Apply changes with: sudo sysctl -p
|
|
||||||
*/
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "MessageQueue::MessageQueue: Default MQ size "
|
|
||||||
<< defaultMqMaxMsg << " is too small for requested size "
|
|
||||||
<< messageDepth << std::endl;
|
|
||||||
sif::error << "This error can be fixed by setting the maximum "
|
|
||||||
"allowed message size higher!" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case(EEXIST): {
|
|
||||||
// An error occured during open
|
|
||||||
// We need to distinguish if it is caused by an already created queue
|
|
||||||
//There's another queue with the same name
|
|
||||||
//We unlink the other queue
|
|
||||||
int status = mq_unlink(name);
|
|
||||||
if (status != 0) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "mq_unlink Failed with status: " << strerror(errno)
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Successful unlinking, try to open again
|
|
||||||
mqd_t tempId = mq_open(name,
|
|
||||||
O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
|
|
||||||
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP, attributes);
|
|
||||||
if (tempId != -1) {
|
|
||||||
//Successful mq_open
|
|
||||||
this->id = tempId;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
// Failed either the first time or the second time
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "MessageQueue::MessageQueue: Creating Queue " << name
|
|
||||||
<< " failed with status: " << strerror(errno) << std::endl;
|
|
||||||
#else
|
|
||||||
sif::printError("MessageQueue::MessageQueue: Creating Queue %s"
|
|
||||||
" failed with status: %s\n", name, strerror(errno));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
|
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
|
||||||
MessageQueueMessageIF* message, bool ignoreFault) {
|
MessageQueueMessageIF* message, bool ignoreFault) {
|
||||||
return sendMessageFrom(sendTo, message, this->getId(), false);
|
return sendMessageFrom(sendTo, message, this->getId(), false);
|
||||||
@ -205,14 +116,12 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
|||||||
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages
|
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages
|
||||||
//currently on the specified queue.
|
//currently on the specified queue.
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
case EBADF:
|
case EBADF: {
|
||||||
//mqdes doesn't represent a valid queue open for reading.
|
//mqdes doesn't represent a valid queue open for reading.
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "receiveMessage", "EBADF");
|
||||||
sif::error << "MessageQueue::receive: configuration error "
|
break;
|
||||||
<< strerror(errno) << std::endl;
|
}
|
||||||
#endif
|
case EINVAL: {
|
||||||
/*NO BREAK*/
|
|
||||||
case EINVAL:
|
|
||||||
/*
|
/*
|
||||||
* This value indicates one of the following:
|
* This value indicates one of the following:
|
||||||
* - The pointer to the buffer for storing the received message,
|
* - The pointer to the buffer for storing the received message,
|
||||||
@ -222,12 +131,10 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
|||||||
* queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't
|
* queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't
|
||||||
* been set in the queue's mq_flags.
|
* been set in the queue's mq_flags.
|
||||||
*/
|
*/
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "receiveMessage", "EINVAL");
|
||||||
sif::error << "MessageQueue::receive: configuration error "
|
break;
|
||||||
<< strerror(errno) << std::endl;
|
}
|
||||||
#endif
|
case EMSGSIZE: {
|
||||||
/*NO BREAK*/
|
|
||||||
case EMSGSIZE:
|
|
||||||
/*
|
/*
|
||||||
* This value indicates one of the following:
|
* This value indicates one of the following:
|
||||||
* - the QNX extended option MQ_READBUF_DYNAMIC hasn't been set,
|
* - the QNX extended option MQ_READBUF_DYNAMIC hasn't been set,
|
||||||
@ -237,18 +144,25 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
|||||||
* given msg_len is too short for the message that would have
|
* given msg_len is too short for the message that would have
|
||||||
* been received.
|
* been received.
|
||||||
*/
|
*/
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "receiveMessage", "EMSGSIZE");
|
||||||
sif::error << "MessageQueue::receive: configuration error "
|
break;
|
||||||
<< strerror(errno) << std::endl;
|
|
||||||
#endif
|
|
||||||
/*NO BREAK*/
|
|
||||||
case EINTR:
|
|
||||||
//The operation was interrupted by a signal.
|
|
||||||
default:
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case EINTR: {
|
||||||
|
//The operation was interrupted by a signal.
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "receiveMessage", "EINTR");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ETIMEDOUT: {
|
||||||
|
//The operation was interrupted by a signal.
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "receiveMessage", "ETIMEDOUT");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,29 +177,27 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
|
|||||||
switch(errno){
|
switch(errno){
|
||||||
case EBADF:
|
case EBADF:
|
||||||
//mqdes doesn't represent a valid message queue.
|
//mqdes doesn't represent a valid message queue.
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "flush", "EBADF");
|
||||||
sif::error << "MessageQueue::flush configuration error, "
|
break;
|
||||||
"called flush with an invalid queue ID" << std::endl;
|
|
||||||
#endif
|
|
||||||
/*NO BREAK*/
|
/*NO BREAK*/
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
//mq_attr is NULL
|
//mq_attr is NULL
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "flush", "EINVAL");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
*count = attrib.mq_curmsgs;
|
*count = attrib.mq_curmsgs;
|
||||||
attrib.mq_curmsgs = 0;
|
attrib.mq_curmsgs = 0;
|
||||||
status = mq_setattr(id,&attrib,NULL);
|
status = mq_setattr(id,&attrib,NULL);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
switch(errno){
|
switch(errno) {
|
||||||
case EBADF:
|
case EBADF:
|
||||||
//mqdes doesn't represent a valid message queue.
|
//mqdes doesn't represent a valid message queue.
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "flush", "EBADF");
|
||||||
sif::error << "MessageQueue::flush configuration error, "
|
break;
|
||||||
"called flush with an invalid queue ID" << std::endl;
|
|
||||||
#endif
|
|
||||||
/*NO BREAK*/
|
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
/*
|
/*
|
||||||
* This value indicates one of the following:
|
* This value indicates one of the following:
|
||||||
@ -294,9 +206,12 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
|
|||||||
* mq_flags includes a 0 in the MQ_MULT_NOTIFY bit. Once
|
* mq_flags includes a 0 in the MQ_MULT_NOTIFY bit. Once
|
||||||
* MQ_MULT_NOTIFY has been turned on, it may never be turned off.
|
* MQ_MULT_NOTIFY has been turned on, it may never be turned off.
|
||||||
*/
|
*/
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "flush", "EINVAL");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -337,6 +252,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
|||||||
bool ignoreFault) {
|
bool ignoreFault) {
|
||||||
if(message == nullptr) {
|
if(message == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
<<<<<<< HEAD
|
||||||
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message is "
|
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message is "
|
||||||
"nullptr!" << std::endl;
|
"nullptr!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -373,11 +289,52 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
|||||||
sif::error << strerror(errno) << " in "
|
sif::error << strerror(errno) << " in "
|
||||||
<<"mq_send to: " << sendTo << " sent from "
|
<<"mq_send to: " << sendTo << " sent from "
|
||||||
<< sentFrom << std::endl;
|
<< sentFrom << std::endl;
|
||||||
|
=======
|
||||||
|
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message is nullptr!" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("MessageQueue::sendMessageFromMessageQueue: Message is nullptr!\n");
|
||||||
|
>>>>>>> 38910143400e455f5184ad85be98e05638c2eea6
|
||||||
|
#endif
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
message->setSender(sentFrom);
|
||||||
|
int result = mq_send(sendTo,
|
||||||
|
reinterpret_cast<const char*>(message->getBuffer()),
|
||||||
|
message->getMessageSize(),0);
|
||||||
|
|
||||||
|
//TODO: Check if we're in ISR.
|
||||||
|
if (result != 0) {
|
||||||
|
if(!ignoreFault){
|
||||||
|
InternalErrorReporterIF* internalErrorReporter =
|
||||||
|
objectManager->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
|
||||||
|
if (internalErrorReporter != NULL) {
|
||||||
|
internalErrorReporter->queueMessageNotSent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(errno){
|
||||||
|
case EAGAIN:
|
||||||
|
//The O_NONBLOCK flag was set when opening the queue, or the
|
||||||
|
//MQ_NONBLOCK flag was set in its attributes, and the
|
||||||
|
//specified queue is full.
|
||||||
|
return MessageQueueIF::FULL;
|
||||||
|
case EBADF: {
|
||||||
|
//mq_des doesn't represent a valid message queue descriptor,
|
||||||
|
//or mq_des wasn't opened for writing.
|
||||||
|
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EBADF");
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "mq_send to: " << sendTo << " sent from "
|
||||||
|
<< sentFrom << "failed" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("mq_send to: %d sent from %d failed\n", sendTo, sentFrom);
|
||||||
#endif
|
#endif
|
||||||
return DESTINATION_INVALID;
|
return DESTINATION_INVALID;
|
||||||
}
|
}
|
||||||
case EINTR:
|
case EINTR:
|
||||||
//The call was interrupted by a signal.
|
//The call was interrupted by a signal.
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EINTR");
|
||||||
|
break;
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
/*
|
/*
|
||||||
* This value indicates one of the following:
|
* This value indicates one of the following:
|
||||||
@ -388,22 +345,87 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
|||||||
* - MQ_PRIO_RESTRICT is set in the mq_attr of mq_des, and
|
* - MQ_PRIO_RESTRICT is set in the mq_attr of mq_des, and
|
||||||
* msg_prio is greater than the priority of the calling process.
|
* msg_prio is greater than the priority of the calling process.
|
||||||
*/
|
*/
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EINVAL");
|
||||||
sif::error << "MessageQueue::sendMessage: Configuration error "
|
break;
|
||||||
<< strerror(errno) << " in mq_send" << std::endl;
|
|
||||||
#endif
|
|
||||||
/*NO BREAK*/
|
|
||||||
case EMSGSIZE:
|
case EMSGSIZE:
|
||||||
// The msg_len is greater than the msgsize associated with
|
// The msg_len is greater than the msgsize associated with
|
||||||
//the specified queue.
|
//the specified queue.
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EMSGSIZE");
|
||||||
sif::error << "MessageQueue::sendMessage: Size error [" <<
|
break;
|
||||||
strerror(errno) << "] in mq_send" << std::endl;
|
|
||||||
#endif
|
|
||||||
/*NO BREAK*/
|
|
||||||
default:
|
default:
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t MessageQueue::handleOpenError(mq_attr* attributes,
|
||||||
|
uint32_t messageDepth) {
|
||||||
|
switch(errno) {
|
||||||
|
case(EINVAL): {
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "MessageQueue", "EINVAL");
|
||||||
|
size_t defaultMqMaxMsg = 0;
|
||||||
|
// Not POSIX conformant, but should work for all UNIX systems.
|
||||||
|
// Just an additional helpful printout :-)
|
||||||
|
if(std::ifstream("/proc/sys/fs/mqueue/msg_max",std::ios::in) >>
|
||||||
|
defaultMqMaxMsg and defaultMqMaxMsg < messageDepth) {
|
||||||
|
/*
|
||||||
|
See: https://www.man7.org/linux/man-pages/man3/mq_open.3.html
|
||||||
|
This happens if the msg_max value is not large enough
|
||||||
|
It is ignored if the executable is run in privileged mode.
|
||||||
|
Run the unlockRealtime script or grant the mode manually by using:
|
||||||
|
sudo setcap 'CAP_SYS_RESOURCE=+ep' <pathToBinary>
|
||||||
|
|
||||||
|
Persistent solution for session:
|
||||||
|
echo <newMsgMax> | sudo tee /proc/sys/fs/mqueue/msg_max
|
||||||
|
|
||||||
|
Permanent solution:
|
||||||
|
sudo nano /etc/sysctl.conf
|
||||||
|
Append at end: fs/mqueue/msg_max = <newMsgMaxLen>
|
||||||
|
Apply changes with: sudo sysctl -p
|
||||||
|
*/
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "MessageQueue::MessageQueue: Default MQ size " << defaultMqMaxMsg <<
|
||||||
|
" is too small for requested size " << messageDepth << std::endl;
|
||||||
|
sif::error << "This error can be fixed by setting the maximum "
|
||||||
|
"allowed message size higher!" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("MessageQueue::MessageQueue: Default MQ size %d is too small for"
|
||||||
|
"requested size %d\n");
|
||||||
|
sif::printError("This error can be fixes by setting the maximum allowed"
|
||||||
|
"message size higher!\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(EEXIST): {
|
||||||
|
// An error occured during open.
|
||||||
|
// We need to distinguish if it is caused by an already created queue
|
||||||
|
// There's another queue with the same name
|
||||||
|
// We unlink the other queue
|
||||||
|
int status = mq_unlink(name);
|
||||||
|
if (status != 0) {
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "MessageQueue", "EEXIST");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Successful unlinking, try to open again
|
||||||
|
mqd_t tempId = mq_open(name,
|
||||||
|
O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
|
||||||
|
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP, attributes);
|
||||||
|
if (tempId != -1) {
|
||||||
|
//Successful mq_open
|
||||||
|
this->id = tempId;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
// Failed either the first time or the second time
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "MessageQueue", "Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
@ -181,7 +181,8 @@ private:
|
|||||||
static uint16_t queueCounter;
|
static uint16_t queueCounter;
|
||||||
const size_t maxMessageSize;
|
const size_t maxMessageSize;
|
||||||
|
|
||||||
ReturnValue_t handleError(mq_attr* attributes, uint32_t messageDepth);
|
static constexpr const char* CLASS_NAME = "MessageQueue";
|
||||||
|
ReturnValue_t handleOpenError(mq_attr* attributes, uint32_t messageDepth);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_OSAL_LINUX_MESSAGEQUEUE_H_ */
|
#endif /* FSFW_OSAL_LINUX_MESSAGEQUEUE_H_ */
|
||||||
|
@ -1,43 +1,34 @@
|
|||||||
#include "Mutex.h"
|
#include "Mutex.h"
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "unixUtility.h"
|
||||||
|
|
||||||
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
#include "../../timemanager/Clock.h"
|
#include "../../timemanager/Clock.h"
|
||||||
|
|
||||||
uint8_t Mutex::count = 0;
|
|
||||||
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
uint8_t Mutex::count = 0;
|
||||||
|
|
||||||
Mutex::Mutex() {
|
Mutex::Mutex() {
|
||||||
pthread_mutexattr_t mutexAttr;
|
pthread_mutexattr_t mutexAttr;
|
||||||
int status = pthread_mutexattr_init(&mutexAttr);
|
int status = pthread_mutexattr_init(&mutexAttr);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric("Mutex", "Mutex", "pthread_mutexattr_init");
|
||||||
sif::error << "Mutex: Attribute init failed with: " << strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
status = pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
|
status = pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric("Mutex", "Mutex", "pthread_mutexattr_setprotocol");
|
||||||
sif::error << "Mutex: Attribute set PRIO_INHERIT failed with: " << strerror(status)
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
status = pthread_mutex_init(&mutex, &mutexAttr);
|
status = pthread_mutex_init(&mutex, &mutexAttr);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric("Mutex", "Mutex", "pthread_mutex_init");
|
||||||
sif::error << "Mutex: creation with name, id " << mutex.__data.__count
|
|
||||||
<< ", " << " failed with " << strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
// After a mutex attributes object has been used to initialize one or more
|
// After a mutex attributes object has been used to initialize one or more
|
||||||
// mutexes, any function affecting the attributes object
|
// mutexes, any function affecting the attributes object
|
||||||
// (including destruction) shall not affect any previously initialized mutexes.
|
// (including destruction) shall not affect any previously initialized mutexes.
|
||||||
status = pthread_mutexattr_destroy(&mutexAttr);
|
status = pthread_mutexattr_destroy(&mutexAttr);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric("Mutex", "Mutex", "pthread_mutexattr_destroy");
|
||||||
sif::error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
||||||
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
||||||
PosixThread(name_, priority_, stackSize_), objectList(), started(false),
|
PosixThread(name_, priority_, stackSize_), objectList(), started(false),
|
||||||
@ -32,6 +31,9 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||||
<< " it implements ExecutableObjectIF!" << std::endl;
|
<< " it implements ExecutableObjectIF!" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("PeriodicTask::addComponent: Invalid object. Make sure it"
|
||||||
|
"implements ExecutableObjectIF!\n");
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -48,9 +50,6 @@ ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
|||||||
|
|
||||||
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
||||||
started = true;
|
started = true;
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
//sif::info << stackSize << std::endl;
|
|
||||||
#endif
|
|
||||||
PosixThread::createTask(&taskEntryPoint,this);
|
PosixThread::createTask(&taskEntryPoint,this);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "PosixThread.h"
|
#include "PosixThread.h"
|
||||||
|
#include "unixUtility.h"
|
||||||
|
|
||||||
#include "../../serviceinterface/ServiceInterface.h"
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
@ -49,8 +50,10 @@ void PosixThread::suspend() {
|
|||||||
sigwait(&waitSignal, &caughtSig);
|
sigwait(&waitSignal, &caughtSig);
|
||||||
if (caughtSig != SIGUSR1) {
|
if (caughtSig != SIGUSR1) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "FixedTimeslotTask: Unknown Signal received: " <<
|
sif::error << "FixedTimeslotTask::suspend: Unknown Signal received: " << caughtSig <<
|
||||||
caughtSig << std::endl;
|
std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("FixedTimeslotTask::suspend: Unknown Signal received: %d\n", caughtSig);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,18 +136,11 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
pthread_attr_t attributes;
|
pthread_attr_t attributes;
|
||||||
int status = pthread_attr_init(&attributes);
|
int status = pthread_attr_init(&attributes);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_init");
|
||||||
sif::error << "Posix Thread attribute init failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
void* stackPointer;
|
void* stackPointer;
|
||||||
status = posix_memalign(&stackPointer, sysconf(_SC_PAGESIZE), stackSize);
|
status = posix_memalign(&stackPointer, sysconf(_SC_PAGESIZE), stackSize);
|
||||||
if(status != 0){
|
if(status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "PosixThread::createTask: Stack init failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
if(errno == ENOMEM) {
|
if(errno == ENOMEM) {
|
||||||
size_t stackMb = stackSize/10e6;
|
size_t stackMb = stackSize/10e6;
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -154,35 +150,35 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
sif::printError("PosixThread::createTask: Insufficient memory for "
|
sif::printError("PosixThread::createTask: Insufficient memory for "
|
||||||
"the requested %lu MB\n", static_cast<unsigned long>(stackMb));
|
"the requested %lu MB\n", static_cast<unsigned long>(stackMb));
|
||||||
#endif
|
#endif
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "ENOMEM");
|
||||||
}
|
}
|
||||||
else if(errno == EINVAL) {
|
else if(errno == EINVAL) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PosixThread::createTask: Wrong alignment argument!"
|
sif::error << "PosixThread::createTask: Wrong alignment argument!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("PosixThread::createTask: "
|
sif::printError("PosixThread::createTask: Wrong alignment argument!\n");
|
||||||
"Wrong alignment argument!\n");
|
|
||||||
#endif
|
#endif
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "EINVAL");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_attr_setstack(&attributes, stackPointer, stackSize);
|
status = pthread_attr_setstack(&attributes, stackPointer, stackSize);
|
||||||
if(status != 0){
|
if(status != 0) {
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setstack");
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PosixThread::createTask: pthread_attr_setstack "
|
sif::warning << "Make sure the specified stack size is valid and is "
|
||||||
" failed with: " << strerror(status) << std::endl;
|
|
||||||
sif::error << "Make sure the specified stack size is valid and is "
|
|
||||||
"larger than the minimum allowed stack size." << std::endl;
|
"larger than the minimum allowed stack size." << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("Make sure the specified stack size is valid and is "
|
||||||
|
"larger than the minimum allowed stack size.\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
|
status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setinheritsched");
|
||||||
sif::error << "Posix Thread attribute setinheritsched failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#ifndef FSFW_USE_REALTIME_FOR_LINUX
|
#ifndef FSFW_USE_REALTIME_FOR_LINUX
|
||||||
#error "Please define FSFW_USE_REALTIME_FOR_LINUX with either 0 or 1"
|
#error "Please define FSFW_USE_REALTIME_FOR_LINUX with either 0 or 1"
|
||||||
@ -191,20 +187,14 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
// FIFO -> This needs root privileges for the process
|
// FIFO -> This needs root privileges for the process
|
||||||
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
|
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setschedpolicy");
|
||||||
sif::error << "Posix Thread attribute schedule policy failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sched_param scheduleParams;
|
sched_param scheduleParams;
|
||||||
scheduleParams.__sched_priority = priority;
|
scheduleParams.__sched_priority = priority;
|
||||||
status = pthread_attr_setschedparam(&attributes, &scheduleParams);
|
status = pthread_attr_setschedparam(&attributes, &scheduleParams);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setschedparam");
|
||||||
sif::error << "Posix Thread attribute schedule params failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//Set Signal Mask for suspend until startTask is called
|
//Set Signal Mask for suspend until startTask is called
|
||||||
@ -213,23 +203,17 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
sigaddset(&waitSignal, SIGUSR1);
|
sigaddset(&waitSignal, SIGUSR1);
|
||||||
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
|
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_sigmask");
|
||||||
sif::error << "Posix Thread sigmask failed failed with: " <<
|
|
||||||
strerror(status) << " errno: " << strerror(errno) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status = pthread_create(&thread,&attributes,fnc_,arg_);
|
status = pthread_create(&thread,&attributes,fnc_,arg_);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_create");
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PosixThread::createTask: Failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
sif::error << "For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call " <<
|
sif::error << "For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call " <<
|
||||||
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
|
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
|
||||||
"/etc/security/limit.conf" << std::endl;
|
"/etc/security/limit.conf" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("PosixThread::createTask: Create failed with: %s\n", strerror(status));
|
|
||||||
sif::printError("For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call "
|
sif::printError("For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call "
|
||||||
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
|
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
|
||||||
"/etc/security/limit.conf\n");
|
"/etc/security/limit.conf\n");
|
||||||
@ -238,31 +222,25 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
|
|
||||||
status = pthread_setname_np(thread,name);
|
status = pthread_setname_np(thread,name);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_setname_np");
|
||||||
sif::error << "PosixThread::createTask: setname failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
if(status == ERANGE) {
|
if(status == ERANGE) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PosixThread::createTask: Task name length longer"
|
sif::warning << "PosixThread::createTask: Task name length longer"
|
||||||
" than 16 chars. Truncating.." << std::endl;
|
" than 16 chars. Truncating.." << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("PosixThread::createTask: Task name length longer"
|
||||||
|
" than 16 chars. Truncating..\n");
|
||||||
#endif
|
#endif
|
||||||
name[15] = '\0';
|
name[15] = '\0';
|
||||||
status = pthread_setname_np(thread,name);
|
status = pthread_setname_np(thread,name);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_setname_np");
|
||||||
sif::error << "PosixThread::createTask: Setting name"
|
|
||||||
" did not work.." << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_attr_destroy(&attributes);
|
status = pthread_attr_destroy(&attributes);
|
||||||
if(status!=0){
|
if (status != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_destroy");
|
||||||
sif::error << "Posix Thread attribute destroy failed with: " <<
|
|
||||||
strerror(status) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,8 @@ private:
|
|||||||
char name[PTHREAD_MAX_NAMELEN];
|
char name[PTHREAD_MAX_NAMELEN];
|
||||||
int priority;
|
int priority;
|
||||||
size_t stackSize = 0;
|
size_t stackSize = 0;
|
||||||
|
|
||||||
|
static constexpr const char* CLASS_NAME = "PosixThread";
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_LINUX_POSIXTHREAD_H_ */
|
#endif /* FRAMEWORK_OSAL_LINUX_POSIXTHREAD_H_ */
|
||||||
|
32
osal/linux/unixUtility.cpp
Normal file
32
osal/linux/unixUtility.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "FSFWConfig.h"
|
||||||
|
#include "unixUtility.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
void utility::printUnixErrorGeneric(const char* const className,
|
||||||
|
const char* const function, const char* const failString,
|
||||||
|
sif::OutputTypes outputType) {
|
||||||
|
if(className == nullptr or failString == nullptr or function == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
if(outputType == sif::OutputTypes::OUT_ERROR) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << className << "::" << function << ":" << failString << " error: "
|
||||||
|
<< strerror(errno) << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("%s::%s: %s error: %s\n", className, function, failString, strerror(errno));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << className << "::" << function << ":" << failString << " error: "
|
||||||
|
<< strerror(errno) << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("%s::%s: %s error: %s\n", className, function, failString, strerror(errno));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
13
osal/linux/unixUtility.h
Normal file
13
osal/linux/unixUtility.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef FSFW_OSAL_LINUX_UNIXUTILITY_H_
|
||||||
|
#define FSFW_OSAL_LINUX_UNIXUTILITY_H_
|
||||||
|
|
||||||
|
#include "../../serviceinterface/serviceInterfaceDefintions.h"
|
||||||
|
|
||||||
|
namespace utility {
|
||||||
|
|
||||||
|
void printUnixErrorGeneric(const char* const className, const char* const function,
|
||||||
|
const char* const failString, sif::OutputTypes outputType = sif::OutputTypes::OUT_ERROR);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FSFW_OSAL_LINUX_UNIXUTILITY_H_ */
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||||
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||||
|
|
||||||
#include <testcfg/objects/systemObjectList.h>
|
#include "objects/systemObjectList.h"
|
||||||
|
|
||||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||||
#include <fsfw/datapoollocal/LocalDataSet.h>
|
#include <fsfw/datapoollocal/LocalDataSet.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user