From e70e9e3f1f67e007245ab457c1e2f685d5450697 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 18 Sep 2020 12:57:30 +0200 Subject: [PATCH] added uptime seconds functions --- osal/FreeRTOS/Clock.cpp | 7 +++++++ osal/host/Clock.cpp | 5 +++++ osal/linux/Clock.cpp | 14 ++++++++++++-- timemanager/Clock.h | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index d556444c..42f060b4 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -67,6 +67,13 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { return HasReturnvaluesIF::RETURN_OK; } + +uint32_t Clock::getUptimeSeconds() { + timeval uptime = getUptime(); + return uptime.tv_sec; +} + + ReturnValue_t Clock::getClock_usecs(uint64_t* time) { timeval time_timeval; ReturnValue_t result = getClock_timeval(&time_timeval); diff --git a/osal/host/Clock.cpp b/osal/host/Clock.cpp index 41321eeb..17d98ba8 100644 --- a/osal/host/Clock.cpp +++ b/osal/host/Clock.cpp @@ -106,6 +106,11 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { return HasReturnvaluesIF::RETURN_OK; } +uint32_t Clock::getUptimeSeconds() { + timeval uptime = getUptime(); + return uptime.tv_sec; +} + ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { // do some magic with chrono (C++20!) diff --git a/osal/linux/Clock.cpp b/osal/linux/Clock.cpp index 6f2faedb..468fcb80 100644 --- a/osal/linux/Clock.cpp +++ b/osal/linux/Clock.cpp @@ -1,3 +1,4 @@ +#include #include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../timemanager/Clock.h" @@ -76,8 +77,7 @@ timeval Clock::getUptime() { ReturnValue_t Clock::getUptime(timeval* uptime) { //TODO This is not posix compatible and delivers only seconds precision - // is the OS not called Linux? - //Linux specific file read but more precise + // Linux specific file read but more precise. double uptimeSeconds; if(std::ifstream("/proc/uptime",std::ios::in) >> uptimeSeconds){ uptime->tv_sec = uptimeSeconds; @@ -86,6 +86,16 @@ ReturnValue_t Clock::getUptime(timeval* uptime) { return HasReturnvaluesIF::RETURN_OK; } +uint32_t Clock::getUptimeSeconds() { + //TODO This is not posix compatible and delivers only seconds precision + struct sysinfo sysInfo; + int result = sysinfo(&sysInfo); + if(result != 0){ + return HasReturnvaluesIF::RETURN_FAILED; + } + return sysInfo.uptime; +} + ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { timeval uptime; ReturnValue_t result = getUptime(&uptime); diff --git a/timemanager/Clock.h b/timemanager/Clock.h index acb68e2e..1ad88305 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -67,6 +67,8 @@ public: static timeval getUptime(); + static uint32_t getUptimeSeconds(); + /** * Get the time since boot in milliseconds *