Merge remote-tracking branch 'upstream/master' into mueller_CCSDSTime_Bugfix_Atmel

This commit is contained in:
2020-07-13 22:02:17 +02:00
150 changed files with 3954 additions and 2684 deletions

View File

@ -2,12 +2,15 @@
#define FRAMEWORK_TIMEMANAGER_CLOCK_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <stdint.h>
#include <sys/time.h>
#include <framework/ipc/MutexFactory.h>
#include <framework/globalfunctions/timevalOperations.h>
#include <cstdint>
#include <sys/time.h>
//! Don't use these for time points, type is not large enough for UNIX epoch.
typedef uint32_t dur_millis_t;
typedef double dur_seconds_t;
class Clock {
public:
@ -21,7 +24,7 @@ public:
uint32_t usecond; //!< Microseconds, 0 .. 999999
} TimeOfDay_t;
/**static Clock* TimeOfDay_t();
/**
* This method returns the number of clock ticks per second.
* In RTEMS, this is typically 1000.
* @return The number of ticks.
@ -33,22 +36,23 @@ public:
* This system call sets the system time.
* To set the time, it uses a TimeOfDay_t struct.
* @param time The struct with the time settings to set.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code
* is returned.
*/
static ReturnValue_t setClock(const TimeOfDay_t* time);
/**
* This system call sets the system time.
* To set the time, it uses a timeval struct.
* @param time The struct with the time settings to set.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t setClock(const timeval* time);
/**
* This system call returns the current system clock in timeval format.
* The timval format has the fields \c tv_sec with seconds and \c tv_usec with
* The timval format has the fields @c tv_sec with seconds and @c tv_usec with
* microseconds since an OS-defined epoch.
* @param time A pointer to a timeval struct where the current time is stored.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getClock_timeval(timeval* time);
@ -56,7 +60,7 @@ public:
* Get the time since boot in a timeval struct
*
* @param[out] time A pointer to a timeval struct where the uptime is stored.
* @return\c RETURN_OK on success. Otherwise, the OS failure code is returned.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*
* @deprecated, I do not think this should be able to fail, use timeval getUptime()
*/

57
timemanager/Stopwatch.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <framework/timemanager/Stopwatch.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <iomanip>
Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode): displayOnDestruction(
displayOnDestruction), displayMode(displayMode) {
// Measures start time on initialization.
Clock::getClock_timeval(&startTime);
}
void Stopwatch::start() {
Clock::getClock_timeval(&startTime);
}
dur_millis_t Stopwatch::stop() {
stopInternal();
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
}
dur_seconds_t Stopwatch::stopSeconds() {
stopInternal();
return timevalOperations::toDouble(elapsedTime);
}
void Stopwatch::display() {
if(displayMode == StopwatchDisplayMode::MILLIS) {
sif::info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 +
elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl;
}
else if(displayMode == StopwatchDisplayMode::SECONDS) {
sif::info <<"Stopwatch: Operation took " << std::setprecision(3)
<< std::fixed << timevalOperations::toDouble(elapsedTime)
<< " seconds" << std::endl;
}
}
Stopwatch::~Stopwatch() {
if(displayOnDestruction) {
stopInternal();
display();
}
}
void Stopwatch::setDisplayMode(StopwatchDisplayMode displayMode) {
this->displayMode = displayMode;
}
StopwatchDisplayMode Stopwatch::getDisplayMode() const {
return displayMode;
}
void Stopwatch::stopInternal() {
timeval endTime;
Clock::getClock_timeval(&endTime);
elapsedTime = endTime - startTime;
}

71
timemanager/Stopwatch.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#include <framework/timemanager/Clock.h>
enum class StopwatchDisplayMode {
MILLIS,
SECONDS
};
/**
* @brief Simple Stopwatch implementation to measure elapsed time
* @details
* This class can be used to measure elapsed times. It also displays elapsed
* times automatically on destruction if not explicitely deactivated in the
* constructor. The default time format is the elapsed time in miliseconds
* in seconds as a double.
* @author R. Mueller
*/
class Stopwatch {
public:
/**
* Default constructor. Call "Stopwatch stopwatch" without brackets if
* no parameters are required!
* @param displayOnDestruction If set to true, displays measured time on
* object destruction
* @param displayMode Display format is either MS rounded or MS as double
* format
* @param outputPrecision If using double format, specify precision here.
*/
Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode
= StopwatchDisplayMode::MILLIS);
virtual~ Stopwatch();
/**
* Caches the start time
*/
void start();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (rounded)
*/
dur_millis_t stop();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in seconds (double precision)
*/
dur_seconds_t stopSeconds();
/**
* Displays the elapsed times on the osstream, depending on internal display
* mode.
*/
void display();
StopwatchDisplayMode getDisplayMode() const;
void setDisplayMode(StopwatchDisplayMode displayMode);
bool displayOnDestruction = true;
private:
timeval startTime {0, 0};
timeval elapsedTime {0, 0};
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS;
void stopInternal();
};
#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */