mueller_stopwatch #30

Merged
muellerr merged 18 commits from KSat/fsfw:mueller_stopwatch into master 2020-07-07 12:05:04 +02:00
3 changed files with 7 additions and 6 deletions
Showing only changes of commit ef13249405 - Show all commits

View File

@ -8,8 +8,9 @@
#include <cstdint> #include <cstdint>
#include <sys/time.h> #include <sys/time.h>

Where are does types used?

Where are does types used?

stopwatch. could also be used somewhere else, is more explicit in my opinion. maybe also use it instead of uint32_t for all milliseconds related stuff?

stopwatch. could also be used somewhere else, is more explicit in my opinion. maybe also use it instead of uint32_t for all milliseconds related stuff?

Hm I think we should stick with timeval and the types defined there. Someday this might be replaced by timespec and uint32_t will be to small anyway.

Hm I think we should stick with timeval and the types defined there. Someday this might be replaced by timespec and uint32_t will be to small anyway.
typedef uint32_t millis_t; //! Don't use these for time points, type is not large enough for UNIX epoch.

Seconds are converted to double in timevalOperations::toDouble(elapsedTime), this would not fit to the float type.

Seconds are converted to double in timevalOperations::toDouble(elapsedTime), this would not fit to the float type.

second is double now

second is double now

I still don't think that those typedefs are a good idea. Maybe we should stick to the types timeval or timespec uses or even use the types C++11 uses in duration Link.

I still don't think that those typedefs are a good idea. Maybe we should stick to the types timeval or timespec uses or even use the types C++11 uses in duration [Link](https://www.cplusplus.com/reference/chrono/duration/).

Hmmm.. it just makes it a bit mor explicit. I guess you mean for example time_t ?

These typedefs were inteded to explicitely be used everywhere uint32_t is used to pass around millisecond values.

The new C++ types are a bit more complicated but the clock library will become more powerful soon anyway. I started to play around with the chrono library.
Maybe continue using uint32_t for now?

Hmmm.. it just makes it a bit mor explicit. I guess you mean for example time_t ? These typedefs were inteded to explicitely be used everywhere uint32_t is used to pass around millisecond values. The new C++ types are a bit more complicated but the clock library will become more powerful soon anyway. I started to play around with the chrono library. Maybe continue using uint32_t for now?

instead of writing something like uint32_t lockTimeout, I could write millis_t lockTimeout for example

instead of writing something like uint32_t lockTimeout, I could write millis_t lockTimeout for example
typedef double seconds_t; typedef uint32_t dur_millis_t;
typedef double dur_seconds_t;
class Clock { class Clock {
public: public:

View File

@ -13,12 +13,12 @@ void Stopwatch::start() {
Clock::getClock_timeval(&startTime); Clock::getClock_timeval(&startTime);
} }
millis_t Stopwatch::stop() { dur_millis_t Stopwatch::stop() {
stopInternal(); stopInternal();
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000; return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
} }
seconds_t Stopwatch::stopSeconds() { dur_seconds_t Stopwatch::stopSeconds() {
stopInternal(); stopInternal();
return timevalOperations::toDouble(elapsedTime); return timevalOperations::toDouble(elapsedTime);
} }

View File

@ -40,12 +40,12 @@ public:
* Calculates the elapsed time since start and returns it * Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (rounded) * @return elapsed time in milliseconds (rounded)
*/ */
millis_t stop(); dur_millis_t stop();
/** /**
* Calculates the elapsed time since start and returns it * Calculates the elapsed time since start and returns it
* @return elapsed time in seconds (double precision) * @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 * Displays the elapsed times on the osstream, depending on internal display