Timer.cpp
Go to the documentation of this file.
00001 //
00002 // Timer.cpp
00003 //
00004 
00005 
00006 #include "Timer.hpp"
00007 //#include "Time.hpp"
00008 #include <sys/time.h>
00009 
00010 
00011 Timer::Timer()
00012 {
00013         restart();
00014 }
00015 
00016 Timer::~Timer ()
00017 {
00018 }
00019 
00020 //
00021 // Startet den Watchdog-Timer, und legt das Timeout-Intervall fest.
00022 //
00023 void Timer::startWatchdog(TimeDuration watchdogTime)
00024 {
00025         m_watchdogTime = watchdogTime;
00026         restart();
00027 }
00028 
00029 //
00030 //
00031 //
00032 bool Timer::isElapsed()
00033 {
00034         Time t = Time::now();
00035         
00036         if (t >= (m_startTime + m_watchdogTime))
00037         {
00038                 // Timer ist abgelaufen
00039                 return true;
00040         }
00041         
00042         return false;
00043 }
00044 
00045 //
00046 // Alias fuer restart().
00047 //
00048 void Timer::reset()
00049 {
00050         restart();
00051 }
00052 
00053 //
00054 // Restart the timer. Also serves to reset the watchdog.
00055 //
00056 void Timer::restart()
00057 {
00058         timeval t;
00059         gettimeofday(&t, NULL);
00060         m_startTime.set(t);
00061 }
00062 
00066 /*
00067 timeval Timer::now()
00068 {
00069         timeval now;
00070         gettimeofday(&now, NULL);
00071         return now;
00072 }
00073 */
00074 
00078 TimeDuration Timer::elapsed () const
00079 {
00080 //      timeval now;
00081 //      UINT32 seconds, useconds;
00082         TimeDuration duration;
00083         
00084         Time now = Time::now(); // gettimeofday(&now, NULL);
00085         Time diff = now - m_startTime;
00086 //      seconds  = now.tv_sec  - m_startTime.m_time.tv.sec;
00087 //      useconds = now.tv_usec - m_startTime.tv_usec;
00088         duration = diff.seconds();      //  (double)seconds + ((double)useconds / 1000000.0);
00089         return duration;
00090 }
00091 
00095 UINT32 Timer::elapsedMilliseconds () const
00096 {
00097         TimeDuration elapsedTime = elapsed();
00098         UINT32 ms = elapsedTime.total_milliseconds();
00099         return ms;
00100 }
00101 
00105 UINT32 Timer::elapsedMicroseconds () const
00106 {
00107         TimeDuration elapsedTime = elapsed();
00108         UINT32 us = (UINT32)((elapsedTime.m_duration * 1000000.0) + 0.5);
00109         return us;
00110 }
00111 
00112 
00130 UINT32 Timer::elapsedMillisecondsSinceLastCall()
00131 {
00132         UINT32 ms = elapsedMilliseconds();
00133         restart();
00134         return ms;
00135 }
00136 
00137 
00141 UINT32 Timer::elapsedMicrosecondsSinceLastCall()
00142 {
00143         UINT32 us = elapsedMicroseconds();
00144         restart();
00145         return us;
00146 }
00147 


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Thu Jun 6 2019 21:02:36