diff options
author | Kevron Rees <tripzero.kev@gmail.com> | 2015-04-06 08:33:33 -0700 |
---|---|---|
committer | Kevron Rees <tripzero.kev@gmail.com> | 2015-04-06 08:33:33 -0700 |
commit | 4279804ec1986e918af017c8110dd5caf64e4887 (patch) | |
tree | c6897aa13d102f53e380c07aa096658b0452530d /lib/timestamp.cpp | |
parent | 9e370e5052ec254aa80306f6741dbc12bfb6bd5c (diff) | |
parent | 947be368482abf6f5d38a79213d9ba9d1c5debd4 (diff) | |
download | automotive-message-broker-4279804ec1986e918af017c8110dd5caf64e4887.tar.gz |
Merge pull request #48 from CogentEmbedded/master
Fixes and improvements in CAN support
Diffstat (limited to 'lib/timestamp.cpp')
-rw-r--r-- | lib/timestamp.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/timestamp.cpp b/lib/timestamp.cpp index 33e01823..7b1f5931 100644 --- a/lib/timestamp.cpp +++ b/lib/timestamp.cpp @@ -1,5 +1,6 @@ #include "timestamp.h" +#include <math.h> #include <time.h> #include <iostream> #include <chrono> @@ -36,6 +37,11 @@ double amb::Timestamp::epochTime(double time) return startTimeEpoch + time; } +double amb::Timestamp::currentTime(double time) +{ + return time - startTimeEpoch; +} + double amb::Timestamp::epochTime() { auto tm = std::chrono::system_clock::now(); @@ -52,3 +58,13 @@ amb::Timestamp* amb::Timestamp::instance() return mInstance; } + +double amb::Timestamp::fromTimeval(const struct ::timeval &tv) +{ + return tv.tv_sec*1.0 + tv.tv_usec*1e-6; +} + +struct ::timeval amb::Timestamp::toTimeval(const double time) +{ + return { (__time_t) time, (__suseconds_t)fmod(time*1e6, 1e6) }; +} |