From 68ce8b5b0899aa907fe62daf8b289526620f3a16 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Sep 2022 21:46:11 +0200 Subject: [PATCH 1/9] tweaks to make windows build again --- src/fsfw/osal/host/Clock.cpp | 1 + src/fsfw/osal/windows/winTaskHelpers.cpp | 1 + src/fsfw/osal/windows/winTaskHelpers.h | 4 +++- src/fsfw/timemanager/ClockCommon.cpp | 8 +++++++- src/fsfw/timemanager/TimeReaderIF.h | 6 ++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/fsfw/osal/host/Clock.cpp b/src/fsfw/osal/host/Clock.cpp index 29c6c1a6..dbf6529c 100644 --- a/src/fsfw/osal/host/Clock.cpp +++ b/src/fsfw/osal/host/Clock.cpp @@ -8,6 +8,7 @@ #if defined(PLATFORM_WIN) #include +#define timegm _mkgmtime #elif defined(PLATFORM_UNIX) #include #endif diff --git a/src/fsfw/osal/windows/winTaskHelpers.cpp b/src/fsfw/osal/windows/winTaskHelpers.cpp index 206ee7a7..5b4feb86 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.cpp +++ b/src/fsfw/osal/windows/winTaskHelpers.cpp @@ -1,6 +1,7 @@ #include "fsfw/osal/windows/winTaskHelpers.h" #include +#include TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { return (static_cast(prioClass) << 16) | static_cast(prioNumber); diff --git a/src/fsfw/osal/windows/winTaskHelpers.h b/src/fsfw/osal/windows/winTaskHelpers.h index 87cd92ce..2d6ef9b4 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.h +++ b/src/fsfw/osal/windows/winTaskHelpers.h @@ -1,10 +1,12 @@ #include #include -#include "../../tasks/TaskFactory.h" +#include "fsfw/tasks/TaskFactory.h" #ifdef _WIN32 +#include + namespace tasks { enum PriorityClass : uint16_t { diff --git a/src/fsfw/timemanager/ClockCommon.cpp b/src/fsfw/timemanager/ClockCommon.cpp index 45755f35..d0ac9004 100644 --- a/src/fsfw/timemanager/ClockCommon.cpp +++ b/src/fsfw/timemanager/ClockCommon.cpp @@ -61,10 +61,16 @@ ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* if (result != returnvalue::OK) { return result; } - MutexGuard helper(timeMutex); // gmtime writes its output in a global buffer which is not Thread Safe // Therefore we have to use a Mutex here + MutexGuard helper(timeMutex); +#ifdef PLATFORM_WIN + time_t time; + time = from->tv_sec; + timeInfo = gmtime(&time); +#else timeInfo = gmtime(&from->tv_sec); +#endif to->year = timeInfo->tm_year + 1900; to->month = timeInfo->tm_mon + 1; to->day = timeInfo->tm_mday; diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 8fd7415f..6bd763c7 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -2,6 +2,12 @@ #define FSFW_TIMEMANAGER_TIMEREADERIF_H #include +#include "fsfw/platform.h" + +#ifdef PLATFORM_WIN +// wtf? Required for timeval! +#include +#endif #include "TimeStampIF.h" #include "fsfw/returnvalues/returnvalue.h" From b0ecf87580af6d22bd9535ab8e8782f2ffb89b4a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Sep 2022 23:57:58 +0200 Subject: [PATCH 2/9] last windows tweak --- src/fsfw_hal/common/gpio/gpioDefinitions.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/fsfw_hal/common/gpio/gpioDefinitions.h b/src/fsfw_hal/common/gpio/gpioDefinitions.h index eb90629e..9f5618e4 100644 --- a/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -5,6 +5,13 @@ #include #include +#ifdef PLATFORM_WIN +// What is this crap? +#undef IN +#undef OUT +#undef CALLBACK +#endif + using gpioId_t = uint16_t; namespace gpio { From 876815b1c9c897bab7a9d6cc6047957c778b30ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 28 Sep 2022 00:03:12 +0200 Subject: [PATCH 3/9] another small windows tweak --- src/fsfw/osal/common/TcpIpBase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/osal/common/TcpIpBase.cpp b/src/fsfw/osal/common/TcpIpBase.cpp index 7e989c36..de0a573d 100644 --- a/src/fsfw/osal/common/TcpIpBase.cpp +++ b/src/fsfw/osal/common/TcpIpBase.cpp @@ -1,5 +1,6 @@ #include "fsfw/osal/common/TcpIpBase.h" +#include "fsfw/serviceinterface.h" #include "fsfw/platform.h" #ifdef PLATFORM_UNIX From e0c780f21c7b2bb575c40b49b1d776d1b5d423a0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 28 Sep 2022 09:56:20 +0200 Subject: [PATCH 4/9] better comment --- src/fsfw_hal/common/gpio/gpioDefinitions.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fsfw_hal/common/gpio/gpioDefinitions.h b/src/fsfw_hal/common/gpio/gpioDefinitions.h index 9f5618e4..9f8b5e32 100644 --- a/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -6,7 +6,8 @@ #include #ifdef PLATFORM_WIN -// What is this crap? +// Defined in Windows header for whatever reason, and leads to nameclash issues with +// class enums which have entries of the same name. #undef IN #undef OUT #undef CALLBACK From 11a22577beac11a4e2d1809c3ccb0ae3444ef1e0 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 25 Oct 2022 11:28:13 +0200 Subject: [PATCH 5/9] defaultconfig did not build anymore --- misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 4d6e91f1..85a733b4 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -41,13 +40,9 @@ void Factory::setStaticFrameworkObjectIds() { CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::PUS_SERVICE_2_DEVICE_ACCESS; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - - TmPacketBase::timeStamperId = objects::NO_OBJECT; } From bee33526a16c565af38c04ef71fb9ae33f558ad4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Nov 2022 13:49:40 +0100 Subject: [PATCH 6/9] missing include --- src/fsfw/timemanager/TimeReaderIF.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 8fd7415f..be03fb2a 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H #define FSFW_TIMEMANAGER_TIMEREADERIF_H +#include #include #include "TimeStampIF.h" From c913fe40bf0c7ebcd395ccfb04b3b426a99f2916 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Nov 2022 17:54:08 +0100 Subject: [PATCH 7/9] tweaks --- CMakeLists.txt | 6 +- cmake/cmake-modules/bilke/CodeCoverage.cmake | 2 +- .../globalfunctions/timevalOperations.cpp | 9 +- src/fsfw/osal/common/TcpIpBase.cpp | 2 +- src/fsfw/osal/windows/winTaskHelpers.cpp | 3 +- .../ServiceInterfaceBuffer.cpp | 1 - src/fsfw/timemanager/TimeReaderIF.h | 1 + src/fsfw_hal/common/printChar.c | 2 +- .../globalfunctions/testTimevalOperations.cpp | 100 +++++++++--------- unittests/hal/CMakeLists.txt | 8 +- 10 files changed, 72 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2572b20..df3757ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,9 +340,9 @@ if(FSFW_BUILD_TESTS) -ftest-coverage) if(WIN32) - setup_target_for_coverage_gcovr_html( - NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} - DEPENDENCIES ${FSFW_TEST_TGT}) + #setup_target_for_coverage_gcovr_html( + # NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} + # DEPENDENCIES ${FSFW_TEST_TGT}) else() setup_target_for_coverage_lcov( NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} diff --git a/cmake/cmake-modules/bilke/CodeCoverage.cmake b/cmake/cmake-modules/bilke/CodeCoverage.cmake index aef3d943..c8b9e4ae 100644 --- a/cmake/cmake-modules/bilke/CodeCoverage.cmake +++ b/cmake/cmake-modules/bilke/CodeCoverage.cmake @@ -140,7 +140,7 @@ find_program( GCOV_PATH gcov ) find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) find_program( FASTCOV_PATH NAMES fastcov fastcov.py ) find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) -find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) +find_program( GCOVR_PATH gcovr ) find_program( CPPFILT_PATH NAMES c++filt ) if(NOT GCOV_PATH) diff --git a/src/fsfw/globalfunctions/timevalOperations.cpp b/src/fsfw/globalfunctions/timevalOperations.cpp index e2b35512..f9f0a5c6 100644 --- a/src/fsfw/globalfunctions/timevalOperations.cpp +++ b/src/fsfw/globalfunctions/timevalOperations.cpp @@ -1,9 +1,12 @@ #include "fsfw/globalfunctions/timevalOperations.h" +#include + timeval& operator+=(timeval& lhs, const timeval& rhs) { - int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec; - sum += rhs.tv_sec * 1000000. + rhs.tv_usec; - lhs.tv_sec = sum / 1000000; + int64_t sum = static_cast(lhs.tv_sec) * 1000000. + lhs.tv_usec; + sum += static_cast(rhs.tv_sec) * 1000000. + rhs.tv_usec; + int64_t tmp = sum / 1000000; + lhs.tv_sec = tmp; lhs.tv_usec = sum - lhs.tv_sec * 1000000; return lhs; } diff --git a/src/fsfw/osal/common/TcpIpBase.cpp b/src/fsfw/osal/common/TcpIpBase.cpp index de0a573d..486a5171 100644 --- a/src/fsfw/osal/common/TcpIpBase.cpp +++ b/src/fsfw/osal/common/TcpIpBase.cpp @@ -1,7 +1,7 @@ #include "fsfw/osal/common/TcpIpBase.h" -#include "fsfw/serviceinterface.h" #include "fsfw/platform.h" +#include "fsfw/serviceinterface.h" #ifdef PLATFORM_UNIX #include diff --git a/src/fsfw/osal/windows/winTaskHelpers.cpp b/src/fsfw/osal/windows/winTaskHelpers.cpp index 5b4feb86..235dca1e 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.cpp +++ b/src/fsfw/osal/windows/winTaskHelpers.cpp @@ -1,8 +1,9 @@ #include "fsfw/osal/windows/winTaskHelpers.h" -#include #include +#include + TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { return (static_cast(prioClass) << 16) | static_cast(prioNumber); } diff --git a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp index 23892dcc..0e73be83 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp @@ -3,7 +3,6 @@ #if FSFW_CPP_OSTREAM_ENABLED == 1 #include - #include #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 6bd763c7..8dce097f 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -2,6 +2,7 @@ #define FSFW_TIMEMANAGER_TIMEREADERIF_H #include + #include "fsfw/platform.h" #ifdef PLATFORM_WIN diff --git a/src/fsfw_hal/common/printChar.c b/src/fsfw_hal/common/printChar.c index 6e02c1df..24fba5c8 100644 --- a/src/fsfw_hal/common/printChar.c +++ b/src/fsfw_hal/common/printChar.c @@ -1,5 +1,5 @@ -#include #include +#include void __attribute__((weak)) printChar(const char* character, bool errStream) { if (errStream) { diff --git a/unittests/globalfunctions/testTimevalOperations.cpp b/unittests/globalfunctions/testTimevalOperations.cpp index 155e6b15..0f89338b 100644 --- a/unittests/globalfunctions/testTimevalOperations.cpp +++ b/unittests/globalfunctions/testTimevalOperations.cpp @@ -56,61 +56,65 @@ TEST_CASE("TimevalTest", "[timevalOperations]") { } SECTION("Operators") { timeval t1; - t1.tv_sec = 1648227422; - t1.tv_usec = 123456; - timeval t2; - t2.tv_sec = 1648227422; - t2.tv_usec = 123456; - timeval t3 = t1 - t2; - REQUIRE(t3.tv_sec == 0); - REQUIRE(t3.tv_usec == 0); - timeval t4 = t1 - t3; - REQUIRE(t4.tv_sec == 1648227422); - REQUIRE(t4.tv_usec == 123456); - timeval t5 = t3 - t1; - REQUIRE(t5.tv_sec == -1648227422); - REQUIRE(t5.tv_usec == -123456); + if (sizeof(t1.tv_sec) == 8) { + t1.tv_sec = 1648227422; + t1.tv_usec = 123456; + timeval t2; + t2.tv_sec = 1648227422; + t2.tv_usec = 123456; + timeval t3 = t1 - t2; + REQUIRE(t3.tv_sec == 0); + REQUIRE(t3.tv_usec == 0); + timeval t4 = t1 - t3; + REQUIRE(t4.tv_sec == 1648227422); + REQUIRE(t4.tv_usec == 123456); + timeval t5 = t3 - t1; + REQUIRE(t5.tv_sec == -1648227422); + REQUIRE(t5.tv_usec == -123456); - timeval t6; - t6.tv_sec = 1648227400; - t6.tv_usec = 999999; + timeval t6; + t6.tv_sec = 1648227400; + t6.tv_usec = 999999; - timeval t7 = t6 + t1; - REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull)); - REQUIRE(t7.tv_usec == 123455); + timeval t7 = t6 + t1; + // Overflow test + REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull)); - timeval t8 = t1 - t6; - REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1); - REQUIRE(t8.tv_usec == 123457); + REQUIRE(t7.tv_usec == 123455); - double scalar = 2; - timeval t9 = t1 * scalar; - REQUIRE(t9.tv_sec == 3296454844); - REQUIRE(t9.tv_usec == 246912); - timeval t10 = scalar * t1; - REQUIRE(t10.tv_sec == 3296454844); - REQUIRE(t10.tv_usec == 246912); - timeval t11 = t6 * scalar; - REQUIRE(t11.tv_sec == (3296454800 + 1)); - REQUIRE(t11.tv_usec == 999998); + timeval t8 = t1 - t6; + REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1); + REQUIRE(t8.tv_usec == 123457); - timeval t12 = t1 / scalar; - REQUIRE(t12.tv_sec == 824113711); - REQUIRE(t12.tv_usec == 61728); + double scalar = 2; + timeval t9 = t1 * scalar; + REQUIRE(t9.tv_sec == 3296454844); + REQUIRE(t9.tv_usec == 246912); + timeval t10 = scalar * t1; + REQUIRE(t10.tv_sec == 3296454844); + REQUIRE(t10.tv_usec == 246912); + timeval t11 = t6 * scalar; + REQUIRE(t11.tv_sec == (3296454800 + 1)); + REQUIRE(t11.tv_usec == 999998); - timeval t13 = t6 / scalar; - REQUIRE(t13.tv_sec == 824113700); - // Rounding issue - REQUIRE(t13.tv_usec == 499999); + timeval t12 = t1 / scalar; + REQUIRE(t12.tv_sec == 824113711); + REQUIRE(t12.tv_usec == 61728); - double scalar2 = t9 / t1; - REQUIRE(scalar2 == Catch::Approx(2.0)); - double scalar3 = t1 / t6; - REQUIRE(scalar3 == Catch::Approx(1.000000013)); - double scalar4 = t3 / t1; - REQUIRE(scalar4 == Catch::Approx(0)); - double scalar5 = t12 / t1; - REQUIRE(scalar5 == Catch::Approx(0.5)); + timeval t13 = t6 / scalar; + REQUIRE(t13.tv_sec == 824113700); + // Rounding issue + REQUIRE(t13.tv_usec == 499999); + + double scalar2 = t9 / t1; + REQUIRE(scalar2 == Catch::Approx(2.0)); + double scalar3 = t1 / t6; + REQUIRE(scalar3 == Catch::Approx(1.000000013)); + double scalar4 = t3 / t1; + REQUIRE(scalar4 == Catch::Approx(0)); + double scalar5 = t12 / t1; + REQUIRE(scalar5 == Catch::Approx(0.5)); + } } SECTION("timevalOperations::toTimeval") { diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index ee14a3aa..25691a47 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1,3 +1,5 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCommandExecutor.cpp -) +if(UNIX) + target_sources(${FSFW_TEST_TGT} PRIVATE + testCommandExecutor.cpp + ) +endif() From a9c6c088f25adf1b4b8fca1736276e5e5fe227ba Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:08:38 +0100 Subject: [PATCH 8/9] remove leftover debugging code --- src/fsfw/globalfunctions/timevalOperations.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fsfw/globalfunctions/timevalOperations.cpp b/src/fsfw/globalfunctions/timevalOperations.cpp index f9f0a5c6..79c07eaf 100644 --- a/src/fsfw/globalfunctions/timevalOperations.cpp +++ b/src/fsfw/globalfunctions/timevalOperations.cpp @@ -1,12 +1,9 @@ #include "fsfw/globalfunctions/timevalOperations.h" -#include - timeval& operator+=(timeval& lhs, const timeval& rhs) { int64_t sum = static_cast(lhs.tv_sec) * 1000000. + lhs.tv_usec; sum += static_cast(rhs.tv_sec) * 1000000. + rhs.tv_usec; - int64_t tmp = sum / 1000000; - lhs.tv_sec = tmp; + lhs.tv_sec = sum / 1000000; lhs.tv_usec = sum - lhs.tv_sec * 1000000; return lhs; } From 83a6f0b5f8b80392c54c708358245c1afc95002f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:12:26 +0100 Subject: [PATCH 9/9] reenable setup function call --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df3757ea..e2572b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,9 +340,9 @@ if(FSFW_BUILD_TESTS) -ftest-coverage) if(WIN32) - #setup_target_for_coverage_gcovr_html( - # NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} - # DEPENDENCIES ${FSFW_TEST_TGT}) + setup_target_for_coverage_gcovr_html( + NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} + DEPENDENCIES ${FSFW_TEST_TGT}) else() setup_target_for_coverage_lcov( NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT}