diff --git a/CMakeLists.txt b/CMakeLists.txt index 09760f8e..02849ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,30 +3,42 @@ cmake_minimum_required(VERSION 3.13) set(LIB_FSFW_NAME fsfw) add_library(${LIB_FSFW_NAME}) -# Set options for FSFW OSAL selection. -if(UNIX) -set(OS_FSFW "linux" CACHE STRING "OS abstraction layer used in the FSFW") -elseif(WIN32) -set(OS_FSFW "host" CACHE STRING "OS abstraction layer used in the FSFW") -endif() - set_property(CACHE OS_FSFW PROPERTY STRINGS host linux rtems freertos) -if(${OS_FSFW} STREQUAL host) -set(OS_FSFW_NAME "Host") -elseif(${OS_FSFW} STREQUAL linux) -set(OS_FSFW_NAME "Linux") -elseif(${OS_FSFW} STREQUAL freertos) -set(OS_FSFW_NAME "FreeRTOS") -elseif(${OS_FSFW} STREQUAL rtems) -set(OS_FSFW_NAME "RTEMS") -else() -message(WARNING "Invalid operating system for FSFW specified! Setting to host..") -set(OS_FSFW_NAME "Host") -set(OS_FSFW "host") +if(NOT OS_FSFW) + message(STATUS "No OS for FSFW via OS_FSFW set. Assuming host OS") + # Assume host OS and autodetermine from OS_FSFW + if(UNIX) + set(OS_FSFW "linux" + CACHE STRING + "OS abstraction layer used in the FSFW" + ) + elseif(WIN32) + set(OS_FSFW "host" + CACHE STRING "OS abstraction layer used in the FSFW" + ) + endif() + endif() -message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system") +if(${OS_FSFW} STREQUAL host) + set(OS_FSFW_NAME "Host") +elseif(${OS_FSFW} STREQUAL linux) + set(OS_FSFW_NAME "Linux") +elseif(${OS_FSFW} STREQUAL freertos) + set(OS_FSFW_NAME "FreeRTOS") + target_link_libraries(${LIB_FSFW_NAME} ${LIB_OS_NAME}) +elseif(${OS_FSFW} STREQUAL rtems) + set(OS_FSFW_NAME "RTEMS") +else() + message(WARNING + "Invalid operating system for FSFW specified! Setting to host.." + ) + set(OS_FSFW_NAME "Host") + set(OS_FSFW "host") +endif() + +message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.") # Options to exclude parts of the FSFW from compilation. option(FSFW_USE_RMAP "Compile with RMAP" ON) @@ -36,7 +48,11 @@ add_subdirectory(action) add_subdirectory(container) add_subdirectory(controller) add_subdirectory(coordinates) -add_subdirectory(datalinklayer) + +if(FSFW_USE_DATALINKLAYER) + add_subdirectory(datalinklayer) +endif() + add_subdirectory(datapool) add_subdirectory(datapoollocal) add_subdirectory(housekeeping) @@ -57,7 +73,7 @@ add_subdirectory(power) add_subdirectory(pus) if(FSFW_USE_RMAP) -add_subdirectory(rmap) + add_subdirectory(rmap) endif() add_subdirectory(serialize) @@ -75,13 +91,53 @@ add_subdirectory(tmtcservices) # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. # If this is not given, we include the default configuration and emit a warning. if(NOT FSFW_CONFIG_PATH) -message(WARNING "Flight Software Framework configuration path not set!") -message(WARNING "Setting default configuration!") -add_subdirectory(defaultcfg/fsfwconfig) + message(WARNING "Flight Software Framework configuration path not set!") + message(WARNING "Setting default configuration!") + add_subdirectory(defaultcfg/fsfwconfig) +endif() + +# FSFW might be part of a possibly complicated folder structure, so we +# extract the absolute path of the fsfwconfig folder. +if(IS_ABSOLUTE ${FSFW_CONFIG_PATH}) + set(FSFW_CONFIG_PATH_ABSOLUTE ${FSFW_CONFIG_PATH}) +else() + get_filename_component(FSFW_CONFIG_PATH_ABSOLUTE + ${FSFW_CONFIG_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR} + ) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX) + set(WARNING_FLAGS + -Wall + -Wextra + -Wshadow=local + -Wimplicit-fallthrough=1 + -Wno-unused-parameter + -Wno-psabi + ) +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(COMPILER_FLAGS "/permissive-") endif() # Required include paths to compile the FSFW -target_include_directories(${LIB_FSFW_NAME} - INTERFACE - ${FSFW_CONFIG_PATH} +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_SOURCE_DIR} + ${FSFW_CONFIG_PATH_ABSOLUTE} +) + +# Includes path required to compile FSFW itself as well +# We assume that the fsfwconfig folder uses include relative to the project +# root here! +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_SOURCE_DIR} + ${FSFW_CONFIG_PATH_ABSOLUTE} +) + +# Machine specific options can be set with the ABI_FLAGS variable. +target_compile_options(${LIB_FSFW_NAME} PRIVATE + ${WARNING_FLAGS} + ${COMPILER_FLAGS} + ${ABI_FLAGS} ) diff --git a/coordinates/Sgp4Propagator.h b/coordinates/Sgp4Propagator.h index 3949547e..f813c6f4 100644 --- a/coordinates/Sgp4Propagator.h +++ b/coordinates/Sgp4Propagator.h @@ -1,7 +1,9 @@ #ifndef SGP4PROPAGATOR_H_ #define SGP4PROPAGATOR_H_ +#ifndef WIN32 #include +#endif #include "../contrib/sgp4/sgp4unit.h" #include "../returnvalues/HasReturnvaluesIF.h" diff --git a/globalfunctions/timevalOperations.h b/globalfunctions/timevalOperations.h index 3977d5d9..db68f330 100644 --- a/globalfunctions/timevalOperations.h +++ b/globalfunctions/timevalOperations.h @@ -2,7 +2,12 @@ #define TIMEVALOPERATIONS_H_ #include + +#ifdef WIN32 +#include +#else #include +#endif timeval& operator+=(timeval& lhs, const timeval& rhs); diff --git a/osal/Endiness.h b/osal/Endiness.h index 65cc0a10..9d3fdef0 100644 --- a/osal/Endiness.h +++ b/osal/Endiness.h @@ -22,9 +22,23 @@ #else #error "Can't decide which end is which!" #endif +#else + +#ifdef WIN32 +#include +#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN +#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN +#else +#define BYTE_ORDER_SYSTEM BIG_ENDIAN +#endif + + #else #error __BYTE_ORDER__ not defined #endif + +#endif + #endif diff --git a/osal/FreeRTOS/CMakeLists.txt b/osal/FreeRTOS/CMakeLists.txt new file mode 100644 index 00000000..95462010 --- /dev/null +++ b/osal/FreeRTOS/CMakeLists.txt @@ -0,0 +1,30 @@ +target_sources(${LIB_FSFW_NAME} + PRIVATE + Clock.cpp + FixedTimeslotTask.cpp + BinarySemaphore.cpp + BinSemaphUsingTask.cpp + CountingSemaphore.cpp + CountingSemaphUsingTask.cpp + MessageQueue.cpp + Mutex.cpp + MutexFactory.cpp + PeriodicTask.cpp + QueueFactory.cpp + SemaphoreFactory.cpp + TaskFactory.cpp + Timekeeper.cpp + TaskManagement.cpp +) + +# FreeRTOS is required to link the FSFW now. It is recommended to compile +# FreeRTOS as a static library and set LIB_OS_NAME to the target name of the +# library. +if(NOT LIB_OS_NAME) + message(FATAL_ERROR + "FreeRTOS needs to be linked as a target and " + "LIB_OS_NAME needs to be set to the target" + ) +endif() + +target_link_libraries(${LIB_FSWFW_NAME} ${LIB_OS_NAME}) \ No newline at end of file diff --git a/osal/host/CMakeLists.txt b/osal/host/CMakeLists.txt index d73e6f27..aa32990b 100644 --- a/osal/host/CMakeLists.txt +++ b/osal/host/CMakeLists.txt @@ -13,9 +13,9 @@ target_sources(${LIB_FSFW_NAME} ) if(UNIX) - add_definitions(-pthread) target_link_libraries(${LIB_FSFW_NAME} PRIVATE rt + pthread ) endif() \ No newline at end of file diff --git a/osal/windows/TcWinUdpPollingTask.cpp b/osal/windows/TcWinUdpPollingTask.cpp index 7b54bb2c..06deafd1 100644 --- a/osal/windows/TcWinUdpPollingTask.cpp +++ b/osal/windows/TcWinUdpPollingTask.cpp @@ -119,7 +119,7 @@ void TcWinUdpPollingTask::setTimeout(double timeoutSeconds) { int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&timeoutMs), sizeof(DWORD)); if(result == -1) { - sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting " + sif::error << "TcWinUdpPollingTask::TcSocketPollingTask: Setting " "receive timeout failed with " << strerror(errno) << std::endl; } } @@ -128,17 +128,22 @@ void TcWinUdpPollingTask::handleReadError() { int error = WSAGetLastError(); switch(error) { case(WSANOTINITIALISED): { - sif::info << "TmTcWinUdpBridge::handleReadError: WSANOTINITIALISED: " + sif::info << "TcWinUdpPollingTask::handleReadError: WSANOTINITIALISED: " << "WSAStartup(...) call " << "necessary" << std::endl; break; } case(WSAEFAULT): { - sif::info << "TmTcWinUdpBridge::handleReadError: WSADEFAULT: " + sif::info << "TcWinUdpPollingTask::handleReadError: WSADEFAULT: " << "Bad address " << std::endl; break; } + case(WSAEINVAL): { + sif::info << "TcWinUdpPollingTask::handleReadError: WSAEINVAL: " + << "Invalid input parameters. " << std::endl; + break; + } default: { - sif::info << "TmTcWinUdpBridge::handleReadError: Error code: " + sif::info << "TcWinUdpPollingTask::handleReadError: Error code: " << error << std::endl; break; } diff --git a/timemanager/Clock.h b/timemanager/Clock.h index d8b06fda..fcc602a2 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -6,7 +6,12 @@ #include "../globalfunctions/timevalOperations.h" #include + +#ifdef WIN32 +#include +#else #include +#endif //! Don't use these for time points, type is not large enough for UNIX epoch. using dur_millis_t = uint32_t;