Merge pull request 'Update Package' (#420) from KSat/fsfw:mueller/update-package into development

Reviewed-on: #420
This commit is contained in:
Steffen Gaisser 2021-05-25 14:10:33 +02:00
commit 2737bc390c
17 changed files with 165 additions and 123 deletions

View File

@ -1,15 +1,23 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
ipc/missionMessageTypes.cpp
objects/FsfwFactory.cpp
pollingsequence/PollingSequenceFactory.cpp
)
# Should be added to include path
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
if(NOT FSFW_CONFIG_PATH)
set(FSFW_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(${TARGET_NAME} PRIVATE
ipc/missionMessageTypes.cpp
pollingsequence/PollingSequenceFactory.cpp
objects/FsfwFactory.cpp
)
# If a special translation file for object IDs exists, compile it.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${TARGET_NAME} PRIVATE
objects/translateObjects.cpp
)
endif()
# If a special translation file for events exists, compile it.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${TARGET_NAME} PRIVATE
events/translateEvents.cpp
)
endif()

View File

@ -1,8 +1,6 @@
#include "EventManager.h"
#include "EventMessage.h"
#include <FSFWConfig.h>
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../ipc/QueueFactory.h"
#include "../ipc/MutexFactory.h"
@ -115,53 +113,6 @@ ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
return result;
}
#if FSFW_OBJ_EVENT_TRANSLATION == 1
void EventManager::printEvent(EventMessage* message) {
const char *string = 0;
switch (message->getSeverity()) {
case severity::INFO:
#if DEBUG_INFO_EVENT == 1
string = translateObject(message->getReporter());
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "EVENT: ";
if (string != 0) {
sif::info << string;
} else {
sif::info << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::info << " reported " << translateEvents(message->getEvent()) << " ("
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
<< message->getParameter1() << " P2: 0x"
<< message->getParameter2() << std::dec << std::endl;
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* DEBUG_INFO_EVENT == 1 */
break;
default:
string = translateObject(message->getReporter());
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "EventManager: ";
if (string != 0) {
sif::debug << string;
}
else {
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::debug << " reported " << translateEvents(message->getEvent())
<< " (" << std::dec << message->getEventId() << ") "
<< std::endl;
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
<< ", P1 Dec: " << std::dec << message->getParameter1()
<< std::endl;
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
<< ", P2 Dec: " << std::dec << message->getParameter2()
<< std::endl;
#endif
break;
}
}
#endif
void EventManager::lockMutex() {
mutex->lockMutex(timeoutType, timeoutMs);
}
@ -175,3 +126,85 @@ void EventManager::setMutexTimeout(MutexIF::TimeoutType timeoutType,
this->timeoutType = timeoutType;
this->timeoutMs = timeoutMs;
}
#if FSFW_OBJ_EVENT_TRANSLATION == 1
void EventManager::printEvent(EventMessage* message) {
switch (message->getSeverity()) {
case severity::INFO: {
#if FSFW_DEBUG_INFO == 1
printUtility(sif::OutputTypes::OUT_INFO, message);
#endif /* DEBUG_INFO_EVENT == 1 */
break;
}
default:
printUtility(sif::OutputTypes::OUT_DEBUG, message);
break;
}
}
void EventManager::printUtility(sif::OutputTypes printType, EventMessage *message) {
const char *string = 0;
if(printType == sif::OutputTypes::OUT_INFO) {
string = translateObject(message->getReporter());
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "EventManager: ";
if (string != 0) {
sif::info << string;
}
else {
sif::info << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
message->getReporter() << std::setfill(' ') << std::dec;
}
sif::info << " report event with ID " << message->getEventId() << std::endl;
sif::info << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
message->getParameter2() << std::endl;
#else
if (string != 0) {
sif::printInfo("Event Manager: %s reported event with ID %d\n", string,
message->getEventId());
}
else {
sif::printInfo("Event Manager: Reporter ID 0x%08x reported event with ID %d\n",
message->getReporter(), message->getEventId());
}
sif::printInfo("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
message->getParameter1(), message->getParameter1(),
message->getParameter2(), message->getParameter2());
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
}
else {
string = translateObject(message->getReporter());
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "EventManager: ";
if (string != 0) {
sif::debug << string;
}
else {
sif::debug << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
message->getReporter() << std::setfill(' ') << std::dec;
}
sif::debug << " report event with ID " << message->getEventId() << std::endl;
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
message->getParameter2() << std::endl;
#else
if (string != 0) {
sif::printDebug("Event Manager: %s reported event with ID %d\n", string,
message->getEventId());
}
else {
sif::printDebug("Event Manager: Reporter ID 0x%08x reported event with ID %d\n",
message->getReporter(), message->getEventId());
}
sif::printDebug("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
message->getParameter1(), message->getParameter1(),
message->getParameter2(), message->getParameter2());
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
}
}
#endif /* FSFW_OBJ_EVENT_TRANSLATION == 1 */

View File

@ -6,6 +6,7 @@
#include <FSFWConfig.h>
#include "../serviceinterface/ServiceInterface.h"
#include "../objectmanager/SystemObject.h"
#include "../storagemanager/LocalPool.h"
#include "../tasks/ExecutableObjectIF.h"
@ -67,6 +68,7 @@ protected:
#if FSFW_OBJ_EVENT_TRANSLATION == 1
void printEvent(EventMessage *message);
void printUtility(sif::OutputTypes printType, EventMessage* message);
#endif
void lockMutex();

View File

@ -22,11 +22,11 @@ public:
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
//! No new messages on the queue
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(1);
//! No space left for more messages
//! [EXPORT] : [COMMENT] No space left for more messages
static const ReturnValue_t FULL = MAKE_RETURN_CODE(2);
//! Returned if a reply method was called without partner
//! [EXPORT] : [COMMENT] Returned if a reply method was called without partner
static const ReturnValue_t NO_REPLY_PARTNER = MAKE_RETURN_CODE(3);
//! Returned if the target destination is invalid.
//! [EXPORT] : [COMMENT] Returned if the target destination is invalid.
static constexpr ReturnValue_t DESTINATION_INVALID = MAKE_RETURN_CODE(4);
virtual ~MessageQueueIF() {}

View File

@ -4,7 +4,7 @@
#include "frameworkObjects.h"
#include "SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../serviceinterface/ServiceInterface.h"
/**
* @brief This class provides an interface to the global object manager.

View File

@ -1,10 +1,9 @@
#include "TcpIpBase.h"
#include "../../platform.h"
#ifdef __unix__
#ifdef PLATFORM_UNIX
#include <errno.h>
#include <unistd.h>
#endif
TcpIpBase::TcpIpBase() {
@ -37,17 +36,17 @@ TcpIpBase::~TcpIpBase() {
}
int TcpIpBase::closeSocket(socket_t socket) {
#ifdef _WIN32
#ifdef PLATFORM_WIN
return closesocket(socket);
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
return close(socket);
#endif
}
int TcpIpBase::getLastSocketError() {
#ifdef _WIN32
#ifdef PLATFORM_WIN
return WSAGetLastError();
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
return errno;
#endif
}

View File

@ -1,28 +1,25 @@
#ifndef FSFW_OSAL_COMMON_TCPIPIF_H_
#define FSFW_OSAL_COMMON_TCPIPIF_H_
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#ifdef _WIN32
#include "../../returnvalues/HasReturnvaluesIF.h"
#include "../../platform.h"
#ifdef PLATFORM_WIN
#include <winsock2.h>
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
#include <sys/socket.h>
#endif
class TcpIpBase {
protected:
#ifdef _WIN32
#ifdef PLATFORM_WIN
static constexpr int SHUT_RECV = SD_RECEIVE;
static constexpr int SHUT_SEND = SD_SEND;
static constexpr int SHUT_BOTH = SD_BOTH;
using socket_t = SOCKET;
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
using socket_t = int;
static constexpr int INVALID_SOCKET = -1;

View File

@ -1,15 +1,13 @@
#include "TcpTmTcServer.h"
#include "tcpipHelpers.h"
#include "../../platform.h"
#include "../../serviceinterface/ServiceInterface.h"
#ifdef _WIN32
#ifdef PLATFORM_WIN
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
#include <netdb.h>
#endif
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7301";

View File

@ -2,10 +2,11 @@
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
#include "TcpIpBase.h"
#include "../../platform.h"
#include "../../objectmanager/SystemObject.h"
#include "../../tasks/ExecutableObjectIF.h"
#ifdef __unix__
#ifdef PLATFORM_UNIX
#include <sys/socket.h>
#endif

View File

@ -1,17 +1,14 @@
#include "UdpTcPollingTask.h"
#include "tcpipHelpers.h"
#include "../../platform.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#ifdef _WIN32
#ifdef PLATFORM_WIN
#include <winsock2.h>
#else
#elif defined(PLATFORM_UNIX)
#include <sys/types.h>
#include <sys/socket.h>
#endif
//! Debugging preprocessor define.
@ -155,7 +152,7 @@ ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() {
}
void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
#ifdef _WIN32
#ifdef PLATFORM_WIN
DWORD timeoutMs = timeoutSeconds * 1000.0;
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
@ -165,7 +162,7 @@ void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
"receive timeout failed with " << strerror(errno) << std::endl;
#endif
}
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
timeval tval;
tval = timevalOperations::toTimeval(timeoutSeconds);
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,

View File

@ -1,18 +1,15 @@
#include "UdpTmTcBridge.h"
#include "tcpipHelpers.h"
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <fsfw/ipc/MutexGuard.h>
#include <fsfw/osal/common/UdpTmTcBridge.h>
#ifdef _WIN32
#include "../../platform.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../ipc/MutexGuard.h"
#ifdef PLATFORM_WIN
#include <ws2tcpip.h>
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
#include <netdb.h>
#include <arpa/inet.h>
#endif
//! Debugging preprocessor define.

View File

@ -2,16 +2,13 @@
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
#include "TcpIpBase.h"
#include "../../platform.h"
#include "../../tmtcservices/TmTcBridge.h"
#ifdef _WIN32
#ifdef PLATFORM_WIN
#include <ws2tcpip.h>
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
#include <sys/socket.h>
#endif
#include <string>

View File

@ -1,10 +1,12 @@
#include "../../serviceinterface/ServiceInterface.h"
#include "../../timemanager/Clock.h"
#include "../../platform.h"
#include <chrono>
#if defined(WIN32)
#if defined(PLATFORM_WIN)
#include <sysinfoapi.h>
#elif defined(LINUX)
#elif defined(PLATFORM_UNIX)
#include <fstream>
#endif
@ -46,7 +48,7 @@ ReturnValue_t Clock::setClock(const timeval* time) {
}
ReturnValue_t Clock::getClock_timeval(timeval* time) {
#if defined(WIN32)
#if defined(PLATFORM_WIN)
auto now = std::chrono::system_clock::now();
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
auto epoch = now.time_since_epoch();
@ -54,7 +56,7 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
auto fraction = now - secondsChrono;
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(fraction).count();
return HasReturnvaluesIF::RETURN_OK;
#elif defined(LINUX)
#elif defined(PLATFORM_UNIX)
timespec timeUnix;
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
if(status!=0){
@ -85,14 +87,14 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
timeval Clock::getUptime() {
timeval timeval;
#if defined(WIN32)
#if defined(PLATFORM_WIN)
auto uptime = std::chrono::milliseconds(GetTickCount64());
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
timeval.tv_sec = secondsChrono.count();
auto fraction = uptime - secondsChrono;
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
fraction).count();
#elif defined(LINUX)
#elif defined(PLATFORM_UNIX)
double uptimeSeconds;
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds)
{
@ -119,7 +121,6 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
/* Do some magic with chrono (C++20!) */
/* Right now, the library doesn't have the new features to get the required values yet.

View File

@ -1,4 +1,5 @@
#include "taskHelpers.h"
#include "../../platform.h"
#include "../../osal/host/FixedTimeslotTask.h"
#include "../../ipc/MutexFactory.h"
#include "../../osal/host/Mutex.h"
@ -9,10 +10,10 @@
#include <thread>
#include <chrono>
#if defined(WIN32)
#if defined(PLATFORM_WIN)
#include <windows.h>
#include "../windows/winTaskHelpers.h"
#elif defined(LINUX)
#elif defined(PLATFORM_UNIX)
#include <pthread.h>
#endif

View File

@ -2,6 +2,7 @@
#include "PeriodicTask.h"
#include "taskHelpers.h"
#include "../../platform.h"
#include "../../ipc/MutexFactory.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tasks/ExecutableObjectIF.h"
@ -9,10 +10,10 @@
#include <thread>
#include <chrono>
#if defined(WIN32)
#if defined(PLATFORM_WIN)
#include <processthreadsapi.h>
#include <fsfw/osal/windows/winTaskHelpers.h>
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
#include <pthread.h>
#endif
@ -24,9 +25,9 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
// It is probably possible to set task priorities by using the native
// task handles for Windows / Linux
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
#if defined(_WIN32)
#if defined(PLATFORM_WIN)
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
// TODO: We could reuse existing code here.
#endif
tasks::insertTaskName(mainThread.get_id(), taskName);

10
platform.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef FSFW_PLATFORM_H_
#define FSFW_PLATFORM_H_
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
#define PLATFORM_UNIX
#elif defined(_WIN32)
#define PLATFORM_WIN
#endif
#endif /* FSFW_PLATFORM_H_ */

View File

@ -5,9 +5,9 @@
#include "serviceInterfaceDefintions.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include "ServiceInterfaceStream.h"
#else
#include <fsfw/serviceinterface/ServiceInterfacePrinter.h>
#include "ServiceInterfacePrinter.h"
#endif
#endif /* FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_ */