From 4095be449ae4b6ebaf89fdcbfc5bc31b854594d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 12 May 2021 17:32:40 +0200 Subject: [PATCH] some more preprocessor replacements --- osal/common/TcpIpBase.h | 6 +----- osal/host/Clock.cpp | 10 +++++----- platform.h | 5 ----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/osal/common/TcpIpBase.h b/osal/common/TcpIpBase.h index 79eefad2b..fe6a763c2 100644 --- a/osal/common/TcpIpBase.h +++ b/osal/common/TcpIpBase.h @@ -5,13 +5,9 @@ #include "../../platform.h" #ifdef PLATFORM_WIN - #include - #elif defined(PLATFORM_UNIX) - #include - #endif class TcpIpBase { @@ -23,7 +19,7 @@ protected: 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; diff --git a/osal/host/Clock.cpp b/osal/host/Clock.cpp index b2e4c171b..ed5aab628 100644 --- a/osal/host/Clock.cpp +++ b/osal/host/Clock.cpp @@ -48,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(now); auto epoch = now.time_since_epoch(); @@ -56,7 +56,7 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) { auto fraction = now - secondsChrono; time->tv_usec = std::chrono::duration_cast(fraction).count(); return HasReturnvaluesIF::RETURN_OK; -#elif defined(__unix__) +#elif defined(PLATFORM_UNIX) timespec timeUnix; int status = clock_gettime(CLOCK_REALTIME,&timeUnix); if(status!=0){ @@ -87,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(uptime); timeval.tv_sec = secondsChrono.count(); auto fraction = uptime - secondsChrono; timeval.tv_usec = std::chrono::duration_cast( fraction).count(); -#elif defined(__unix__) +#elif defined(PLATFORM_UNIX) double uptimeSeconds; if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds) { @@ -121,7 +121,7 @@ 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. so we work around that for now. */ diff --git a/platform.h b/platform.h index 08260094d..4bca33984 100644 --- a/platform.h +++ b/platform.h @@ -2,14 +2,9 @@ #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_ */