From fe246b9bca27038708bd2d0380d198966b951b9a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 11:43:37 +0200 Subject: [PATCH 01/14] fixed map improvements --- container/FixedMap.h | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 0b84bf4ea..7f3d28f7d 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -6,7 +6,11 @@ #include /** - * \ingroup container + * @brief Map implementation for maps with a pre-defined size. + * @details Can be initialized with desired maximum size. + * Iterator is used to access pair and + * iterate through map entries. Complexity O(n). + * @ingroup container */ template class FixedMap: public SerializeIF { @@ -52,12 +56,24 @@ public: return ArrayList, uint32_t>::Iterator::value->second; } + // -> operator overloaded, can be used to access value T *operator->() { return &ArrayList, uint32_t>::Iterator::value->second; } + // Can be used to access the key of the iterator + key_t first() { + return ArrayList, uint32_t>::Iterator::value->first; + } + + // Alternative to access value, similar to std::map implementation + T second() { + return ArrayList, uint32_t>::Iterator::value->second; + } }; + + Iterator begin() const { return Iterator(&theMap[0]); } @@ -72,10 +88,10 @@ public: ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) { if (exists(key) == HasReturnvaluesIF::RETURN_OK) { - return KEY_ALREADY_EXISTS; + return FixedMap::KEY_ALREADY_EXISTS; } if (_size == theMap.maxSize()) { - return MAP_FULL; + return FixedMap::MAP_FULL; } theMap[_size].first = key; theMap[_size].second = value; @@ -87,7 +103,7 @@ public: } ReturnValue_t insert(std::pair pair) { - return insert(pair.fist, pair.second); + return insert(pair.first, pair.second); } ReturnValue_t exists(key_t key) const { @@ -148,8 +164,17 @@ public: return theMap.maxSize(); } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + bool full() { + if(_size == theMap.maxSize()) { + return true; + } + else { + return false; + } + } + + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, buffer, size, max_size, bigEndian); uint32_t i = 0; @@ -163,7 +188,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { uint32_t printSize = sizeof(_size); uint32_t i = 0; @@ -176,7 +201,7 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, buffer, size, bigEndian); From 826e2bdb2dfbfad69919ccb856a7835219bc1075 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 15:10:23 +0200 Subject: [PATCH 02/14] Revert "fixed map improvements" This reverts commit fe246b9bca27038708bd2d0380d198966b951b9a. --- container/FixedMap.h | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 7f3d28f7d..0b84bf4ea 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -6,11 +6,7 @@ #include /** - * @brief Map implementation for maps with a pre-defined size. - * @details Can be initialized with desired maximum size. - * Iterator is used to access pair and - * iterate through map entries. Complexity O(n). - * @ingroup container + * \ingroup container */ template class FixedMap: public SerializeIF { @@ -56,24 +52,12 @@ public: return ArrayList, uint32_t>::Iterator::value->second; } - // -> operator overloaded, can be used to access value T *operator->() { return &ArrayList, uint32_t>::Iterator::value->second; } - // Can be used to access the key of the iterator - key_t first() { - return ArrayList, uint32_t>::Iterator::value->first; - } - - // Alternative to access value, similar to std::map implementation - T second() { - return ArrayList, uint32_t>::Iterator::value->second; - } }; - - Iterator begin() const { return Iterator(&theMap[0]); } @@ -88,10 +72,10 @@ public: ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) { if (exists(key) == HasReturnvaluesIF::RETURN_OK) { - return FixedMap::KEY_ALREADY_EXISTS; + return KEY_ALREADY_EXISTS; } if (_size == theMap.maxSize()) { - return FixedMap::MAP_FULL; + return MAP_FULL; } theMap[_size].first = key; theMap[_size].second = value; @@ -103,7 +87,7 @@ public: } ReturnValue_t insert(std::pair pair) { - return insert(pair.first, pair.second); + return insert(pair.fist, pair.second); } ReturnValue_t exists(key_t key) const { @@ -164,17 +148,8 @@ public: return theMap.maxSize(); } - bool full() { - if(_size == theMap.maxSize()) { - return true; - } - else { - return false; - } - } - - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, buffer, size, max_size, bigEndian); uint32_t i = 0; @@ -188,7 +163,7 @@ public: return result; } - virtual size_t getSerializedSize() const { + virtual uint32_t getSerializedSize() const { uint32_t printSize = sizeof(_size); uint32_t i = 0; @@ -201,7 +176,7 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, buffer, size, bigEndian); From 2a72e94d6f4fde6653c3ead47d0d9d26b90e6712 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 19:33:01 +0200 Subject: [PATCH 03/14] new stopwatch :-) --- osal/FreeRTOS/Clock.cpp | 4 +- osal/FreeRTOS/Timekeeper.cpp | 26 ++++++++----- osal/FreeRTOS/Timekeeper.h | 9 ++++- timemanager/Clock.h | 3 +- timemanager/Stopwatch.cpp | 61 +++++++++++++++++++++++++++++++ timemanager/Stopwatch.h | 71 ++++++++++++++++++++++++++++++++++++ 6 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 timemanager/Stopwatch.cpp create mode 100644 timemanager/Stopwatch.h diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index cffc2125e..5e597f258 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -3,8 +3,11 @@ #include #include "Timekeeper.h" +extern "C" { #include #include +} + //TODO sanitize input? //TODO much of this code can be reused for tick-only systems @@ -56,7 +59,6 @@ ReturnValue_t Clock::getUptime(timeval* uptime) { timeval Clock::getUptime() { TickType_t ticksSinceStart = xTaskGetTickCount(); - return Timekeeper::ticksToTimeval(ticksSinceStart); } diff --git a/osal/FreeRTOS/Timekeeper.cpp b/osal/FreeRTOS/Timekeeper.cpp index 81f7f9979..949e1df3c 100644 --- a/osal/FreeRTOS/Timekeeper.cpp +++ b/osal/FreeRTOS/Timekeeper.cpp @@ -1,20 +1,24 @@ -#include "Timekeeper.h" -#include +/** + * @file Timekeeper.cpp + * @date + */ -Timekeeper::Timekeeper() : - offset( { 0, 0 }) { - // TODO Auto-generated constructor stub +#include +extern "C" { +#include } -Timekeeper * Timekeeper::myinstance = NULL; +Timekeeper * Timekeeper::myinstance = nullptr; + +Timekeeper::Timekeeper() : offset( { 0, 0 }) {} const timeval& Timekeeper::getOffset() const { return offset; } Timekeeper* Timekeeper::instance() { - if (myinstance == NULL) { + if (myinstance == nullptr) { myinstance = new Timekeeper(); } return myinstance; @@ -24,9 +28,7 @@ void Timekeeper::setOffset(const timeval& offset) { this->offset = offset; } -Timekeeper::~Timekeeper() { - // TODO Auto-generated destructor stub -} +Timekeeper::~Timekeeper() {} timeval Timekeeper::ticksToTimeval(TickType_t ticks) { timeval uptime; @@ -40,3 +42,7 @@ timeval Timekeeper::ticksToTimeval(TickType_t ticks) { return uptime; } + +TickType_t Timekeeper::getTicks() { + return xTaskGetTickCount(); +} diff --git a/osal/FreeRTOS/Timekeeper.h b/osal/FreeRTOS/Timekeeper.h index 2ba3e4a9b..05f0f7011 100644 --- a/osal/FreeRTOS/Timekeeper.h +++ b/osal/FreeRTOS/Timekeeper.h @@ -2,8 +2,10 @@ #define FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ #include - +extern "C" { #include +} + /** * A Class to basically store the time difference between uptime and UTC @@ -25,6 +27,11 @@ public: virtual ~Timekeeper(); static timeval ticksToTimeval(TickType_t ticks); + /** + * Get elapsed time in system ticks. + * @return + */ + static TickType_t getTicks(); const timeval& getOffset() const; void setOffset(const timeval& offset); diff --git a/timemanager/Clock.h b/timemanager/Clock.h index af6572472..5f18de3ee 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -7,7 +7,8 @@ #include #include - +typedef uint32_t millis_t; +typedef float seconds_t; class Clock { public: diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp new file mode 100644 index 000000000..6c50f0de9 --- /dev/null +++ b/timemanager/Stopwatch.cpp @@ -0,0 +1,61 @@ +/** + * @file Stopwatch.cpp + * + * @date 08.04.2020 + */ + +#include +#include +#include + +Stopwatch::Stopwatch(bool displayOnDestruction, + StopwatchDisplayMode displayMode): displayMode(displayMode), + displayOnDestruction(displayOnDestruction) { + // Measures start time on initialization. + Clock::getUptime(&startTime); +} + +void Stopwatch::start() { + startTime = Clock::getUptime(); +} + +millis_t Stopwatch::stop() { + stopInternal(); + return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000; +} + +seconds_t Stopwatch::stopSeconds() { + stopInternal(); + return timevalOperations::toDouble(elapsedTime); +} + +void Stopwatch::display() { + if(displayMode == StopwatchDisplayMode::MILLIS) { + info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + + elapsedTime.tv_usec * 1000 << " milliseconds" << std::endl; + } + else if(displayMode == StopwatchDisplayMode::SECONDS) { + 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() { + elapsedTime = Clock::getUptime() - startTime; +} diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h new file mode 100644 index 000000000..786a9d571 --- /dev/null +++ b/timemanager/Stopwatch.h @@ -0,0 +1,71 @@ +/** + * @file Stopwatch.h + * + * @date 08.04.2020 + */ + +#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ +#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ +#include + +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 + * as a float. + */ +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) + */ + millis_t stop(); + seconds_t stopSeconds(); + + /** + * Displays the elapsed times on the osstream, depending on internal display + * mode. + */ + void display(); + + StopwatchDisplayMode getDisplayMode() const; + void setDisplayMode(StopwatchDisplayMode displayMode); +private: + timeval startTime {0, 0}; + timeval elapsedTime {0, 0}; + + StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS; + bool displayOnDestruction = true; + void stopInternal(); +}; + + + + +#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */ From 2b740a3c0f9f2b28173afb1b3eb1e4efa161551f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 9 Apr 2020 18:02:42 +0200 Subject: [PATCH 04/14] bugfix --- timemanager/Stopwatch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 6c50f0de9..3f0755fd7 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -12,7 +12,7 @@ Stopwatch::Stopwatch(bool displayOnDestruction, StopwatchDisplayMode displayMode): displayMode(displayMode), displayOnDestruction(displayOnDestruction) { // Measures start time on initialization. - Clock::getUptime(&startTime); + startTime = Clock::getUptime(); } void Stopwatch::start() { @@ -31,8 +31,8 @@ seconds_t Stopwatch::stopSeconds() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MILLIS) { - info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + - elapsedTime.tv_usec * 1000 << " milliseconds" << std::endl; + info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 + + elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl; } else if(displayMode == StopwatchDisplayMode::SECONDS) { info <<"Stopwatch: Operation took " << std::setprecision(3) From 684dd67f638040143c425df537d16ab13230b38d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 5 May 2020 19:14:51 +0200 Subject: [PATCH 05/14] seconds_t double now --- timemanager/Clock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timemanager/Clock.h b/timemanager/Clock.h index 5f18de3ee..2883878fc 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -8,7 +8,7 @@ #include typedef uint32_t millis_t; -typedef float seconds_t; +typedef double seconds_t; class Clock { public: From 25ff8784cf0554e85ed50ff0d073dbff56bf2d51 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 7 May 2020 20:00:42 +0200 Subject: [PATCH 06/14] corrected documentation --- timemanager/Stopwatch.cpp | 6 ------ timemanager/Stopwatch.h | 13 +++---------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 3f0755fd7..771b63dc7 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -1,9 +1,3 @@ -/** - * @file Stopwatch.cpp - * - * @date 08.04.2020 - */ - #include #include #include diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 786a9d571..19e1f92b6 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -1,9 +1,3 @@ -/** - * @file Stopwatch.h - * - * @date 08.04.2020 - */ - #ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ #define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ #include @@ -18,8 +12,7 @@ enum class StopwatchDisplayMode { * @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 - * as a float. + * constructor. The default time format is the elapsed time in miliseconds. */ class Stopwatch { public: @@ -28,8 +21,8 @@ public: * 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 displayMode Display format is either MS rounded or seconds as + * double format * @param outputPrecision If using double format, specify precision here. */ Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode From 7eb250a90ab432b8a5e5d10f78ec7598f13cdd45 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 25 May 2020 15:06:54 +0200 Subject: [PATCH 07/14] include testing --- osal/FreeRTOS/Clock.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index 5e597f258..a672076aa 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -4,8 +4,7 @@ #include "Timekeeper.h" extern "C" { -#include -#include +#include } From 35b9346c2bface422ad7943d66689a8c7da21ed0 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 25 May 2020 15:25:17 +0200 Subject: [PATCH 08/14] include improvements for clock, sif fixes --- osal/FreeRTOS/Clock.cpp | 1 + timemanager/Stopwatch.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index a672076aa..82c9e1702 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -5,6 +5,7 @@ extern "C" { #include +#include } diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 771b63dc7..2c85376d4 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -25,11 +25,11 @@ seconds_t Stopwatch::stopSeconds() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MILLIS) { - info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 + + sif::info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl; } else if(displayMode == StopwatchDisplayMode::SECONDS) { - info <<"Stopwatch: Operation took " << std::setprecision(3) + sif::info <<"Stopwatch: Operation took " << std::setprecision(3) << std::fixed << timevalOperations::toDouble(elapsedTime) << " seconds" << std::endl; } From 1cf5991101f9dc0e677911e1d7cfeffaa250285b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:43:06 +0200 Subject: [PATCH 09/14] getClock_timval used now --- timemanager/Stopwatch.cpp | 12 +++++++----- timemanager/Stopwatch.h | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 2c85376d4..bc8b4149c 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -3,14 +3,14 @@ #include Stopwatch::Stopwatch(bool displayOnDestruction, - StopwatchDisplayMode displayMode): displayMode(displayMode), - displayOnDestruction(displayOnDestruction) { + StopwatchDisplayMode displayMode): displayOnDestruction( + displayOnDestruction), displayMode(displayMode) { // Measures start time on initialization. - startTime = Clock::getUptime(); + Clock::getClock_timeval(&startTime); } void Stopwatch::start() { - startTime = Clock::getUptime(); + Clock::getClock_timeval(&startTime); } millis_t Stopwatch::stop() { @@ -51,5 +51,7 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const { } void Stopwatch::stopInternal() { - elapsedTime = Clock::getUptime() - startTime; + timeval endTime; + Clock::getClock_timeval(&endTime); + elapsedTime = endTime - startTime; } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 19e1f92b6..71580778f 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -8,11 +8,13 @@ enum class StopwatchDisplayMode { }; /** - * @brief Simple Stopwatch implementation to measure elapsed time + * @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. + * constructor. The default time format is the elapsed time in miliseconds + * in seconds as a double. + * @author R. Mueller */ class Stopwatch { public: @@ -21,8 +23,8 @@ public: * 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 seconds as - * double format + * @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 @@ -39,6 +41,10 @@ public: * @return elapsed time in milliseconds (rounded) */ millis_t stop(); + /** + * Calculates the elapsed time since start and returns it + * @return elapsed time in seconds (double precision) + */ seconds_t stopSeconds(); /** @@ -49,12 +55,13 @@ public: StopwatchDisplayMode getDisplayMode() const; void setDisplayMode(StopwatchDisplayMode displayMode); + bool displayOnDestruction = true; private: timeval startTime {0, 0}; timeval elapsedTime {0, 0}; StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS; - bool displayOnDestruction = true; + void stopInternal(); }; From 0be418a553a95971a56fc61a0f9e57276a345165 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:45:08 +0200 Subject: [PATCH 10/14] clock.h form improvements --- timemanager/Clock.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/timemanager/Clock.h b/timemanager/Clock.h index 2883878fc..19991b817 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -2,11 +2,12 @@ #define FRAMEWORK_TIMEMANAGER_CLOCK_H_ #include -#include -#include #include #include +#include +#include + typedef uint32_t millis_t; typedef double seconds_t; @@ -22,7 +23,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. @@ -34,22 +35,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); @@ -57,7 +59,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() */ From f15424be4fef0a280385fc4d3a5eae85beba9ec5 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:47:55 +0200 Subject: [PATCH 11/14] implemented missing static function --- osal/linux/Clock.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/osal/linux/Clock.cpp b/osal/linux/Clock.cpp index e24a4fe4b..630b2cf4c 100644 --- a/osal/linux/Clock.cpp +++ b/osal/linux/Clock.cpp @@ -1,10 +1,10 @@ -#include -#include +#include #include - +#include #include #include +#include #include //#include @@ -65,6 +65,15 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) { return HasReturnvaluesIF::RETURN_OK; } +timeval Clock::getUptime() { + timeval uptime; + auto result = getUptime(&uptime); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "Clock::getUptime: Error getting uptime" << std::endl; + } + return uptime; +} + ReturnValue_t Clock::getUptime(timeval* uptime) { //TODO This is not posix compatible and delivers only seconds precision struct sysinfo sysInfo; From c5bb18a7884a1b1f383581a854772ca0771cf04b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:49:39 +0200 Subject: [PATCH 12/14] include improvements, nullptr used --- osal/FreeRTOS/Clock.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index 82c9e1702..dce202657 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -1,19 +1,18 @@ #include #include -#include -#include "Timekeeper.h" +#include -extern "C" { #include #include -} +#include +#include //TODO sanitize input? //TODO much of this code can be reused for tick-only systems uint16_t Clock::leapSeconds = 0; -MutexIF* Clock::timeMutex = NULL; +MutexIF* Clock::timeMutex = nullptr; uint32_t Clock::getTicksPerSecond(void) { return 1000; @@ -130,7 +129,7 @@ ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) { ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval* tt) { //SHOULDDO: works not for dates in the past (might have less leap seconds) - if (timeMutex == NULL) { + if (timeMutex == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } From a9a23d76231564d2d5bc15836455686b618a546a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:51:15 +0200 Subject: [PATCH 13/14] include improvements --- osal/FreeRTOS/Timekeeper.cpp | 15 ++++----------- osal/FreeRTOS/Timekeeper.h | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/osal/FreeRTOS/Timekeeper.cpp b/osal/FreeRTOS/Timekeeper.cpp index 949e1df3c..643b27479 100644 --- a/osal/FreeRTOS/Timekeeper.cpp +++ b/osal/FreeRTOS/Timekeeper.cpp @@ -1,17 +1,12 @@ -/** - * @file Timekeeper.cpp - * @date - */ - #include -extern "C" { -#include -} +#include "FreeRTOSConfig.h" Timekeeper * Timekeeper::myinstance = nullptr; -Timekeeper::Timekeeper() : offset( { 0, 0 }) {} +Timekeeper::Timekeeper() : offset( { 0, 0 } ) {} + +Timekeeper::~Timekeeper() {} const timeval& Timekeeper::getOffset() const { return offset; @@ -28,8 +23,6 @@ void Timekeeper::setOffset(const timeval& offset) { this->offset = offset; } -Timekeeper::~Timekeeper() {} - timeval Timekeeper::ticksToTimeval(TickType_t ticks) { timeval uptime; uptime.tv_sec = ticks / configTICK_RATE_HZ; diff --git a/osal/FreeRTOS/Timekeeper.h b/osal/FreeRTOS/Timekeeper.h index 05f0f7011..7d3ca22b7 100644 --- a/osal/FreeRTOS/Timekeeper.h +++ b/osal/FreeRTOS/Timekeeper.h @@ -2,9 +2,9 @@ #define FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ #include -extern "C" { -#include -} + +#include +#include /** From ef1324940579d307b8ba62c1270c7db3fbaa9472 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 4 Jun 2020 13:01:59 +0200 Subject: [PATCH 14/14] typedef renamed --- timemanager/Clock.h | 5 +++-- timemanager/Stopwatch.cpp | 4 ++-- timemanager/Stopwatch.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/timemanager/Clock.h b/timemanager/Clock.h index 19991b817..121c63df9 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -8,8 +8,9 @@ #include #include -typedef uint32_t millis_t; -typedef double seconds_t; +//! 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: diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index bc8b4149c..52118d580 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -13,12 +13,12 @@ void Stopwatch::start() { Clock::getClock_timeval(&startTime); } -millis_t Stopwatch::stop() { +dur_millis_t Stopwatch::stop() { stopInternal(); return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000; } -seconds_t Stopwatch::stopSeconds() { +dur_seconds_t Stopwatch::stopSeconds() { stopInternal(); return timevalOperations::toDouble(elapsedTime); } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 71580778f..630202cc1 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -40,12 +40,12 @@ public: * Calculates the elapsed time since start and returns it * @return elapsed time in milliseconds (rounded) */ - millis_t stop(); + dur_millis_t stop(); /** * Calculates the elapsed time since start and returns it * @return elapsed time in seconds (double precision) */ - seconds_t stopSeconds(); + dur_seconds_t stopSeconds(); /** * Displays the elapsed times on the osstream, depending on internal display