added uptime seconds functions
This commit is contained in:
parent
19632b8fb1
commit
e70e9e3f1f
@ -67,6 +67,13 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t Clock::getUptimeSeconds() {
|
||||||
|
timeval uptime = getUptime();
|
||||||
|
return uptime.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||||
timeval time_timeval;
|
timeval time_timeval;
|
||||||
ReturnValue_t result = getClock_timeval(&time_timeval);
|
ReturnValue_t result = getClock_timeval(&time_timeval);
|
||||||
|
@ -106,6 +106,11 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Clock::getUptimeSeconds() {
|
||||||
|
timeval uptime = getUptime();
|
||||||
|
return uptime.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
|
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
|
||||||
// do some magic with chrono (C++20!)
|
// do some magic with chrono (C++20!)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <fsfw/timemanager/Stopwatch.h>
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../../timemanager/Clock.h"
|
#include "../../timemanager/Clock.h"
|
||||||
|
|
||||||
@ -76,8 +77,7 @@ timeval Clock::getUptime() {
|
|||||||
|
|
||||||
ReturnValue_t Clock::getUptime(timeval* uptime) {
|
ReturnValue_t Clock::getUptime(timeval* uptime) {
|
||||||
//TODO This is not posix compatible and delivers only seconds precision
|
//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;
|
double uptimeSeconds;
|
||||||
if(std::ifstream("/proc/uptime",std::ios::in) >> uptimeSeconds){
|
if(std::ifstream("/proc/uptime",std::ios::in) >> uptimeSeconds){
|
||||||
uptime->tv_sec = uptimeSeconds;
|
uptime->tv_sec = uptimeSeconds;
|
||||||
@ -86,6 +86,16 @@ ReturnValue_t Clock::getUptime(timeval* uptime) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
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) {
|
ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
||||||
timeval uptime;
|
timeval uptime;
|
||||||
ReturnValue_t result = getUptime(&uptime);
|
ReturnValue_t result = getUptime(&uptime);
|
||||||
|
@ -67,6 +67,8 @@ public:
|
|||||||
|
|
||||||
static timeval getUptime();
|
static timeval getUptime();
|
||||||
|
|
||||||
|
static uint32_t getUptimeSeconds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time since boot in milliseconds
|
* Get the time since boot in milliseconds
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user