Timer.cpp
Go to the documentation of this file.
1 //
2 // Timer.cpp
3 //
4 
5 
6 #include "Timer.hpp"
7 //#include "Time.hpp"
8 #include <sys/time.h>
9 
10 
12 {
13  restart();
14 }
15 
17 {
18 }
19 
20 //
21 // Startet den Watchdog-Timer, und legt das Timeout-Intervall fest.
22 //
24 {
25  m_watchdogTime = watchdogTime;
26  restart();
27 }
28 
29 //
30 //
31 //
33 {
34  Time t = Time::now();
35 
36  if (t >= (m_startTime + m_watchdogTime))
37  {
38  // Timer ist abgelaufen
39  return true;
40  }
41 
42  return false;
43 }
44 
45 //
46 // Alias fuer restart().
47 //
49 {
50  restart();
51 }
52 
53 //
54 // Restart the timer. Also serves to reset the watchdog.
55 //
57 {
58  timeval t;
59  gettimeofday(&t, NULL);
60  m_startTime.set(t);
61 }
62 
66 /*
67 timeval Timer::now()
68 {
69  timeval now;
70  gettimeofday(&now, NULL);
71  return now;
72 }
73 */
74 
79 {
80 // timeval now;
81 // UINT32 seconds, useconds;
82  TimeDuration duration;
83 
84  Time now = Time::now(); // gettimeofday(&now, NULL);
85  Time diff = now - m_startTime;
86 // seconds = now.tv_sec - m_startTime.m_time.tv.sec;
87 // useconds = now.tv_usec - m_startTime.tv_usec;
88  duration = diff.seconds(); // (double)seconds + ((double)useconds / 1000000.0);
89  return duration;
90 }
91 
96 {
97  TimeDuration elapsedTime = elapsed();
98  UINT32 ms = elapsedTime.total_milliseconds();
99  return ms;
100 }
101 
106 {
107  TimeDuration elapsedTime = elapsed();
108  UINT32 us = (UINT32)((elapsedTime.m_duration * 1000000.0) + 0.5);
109  return us;
110 }
111 
112 
131 {
133  restart();
134  return ms;
135 }
136 
137 
142 {
144  restart();
145  return us;
146 }
147 
double seconds()
Definition: Time.cpp:102
UINT32 total_milliseconds()
Definition: Time.hpp:37
UINT32 elapsedMicrosecondsSinceLastCall()
Elapsed us since the last call of this function.
Definition: Timer.cpp:141
UINT32 elapsedMillisecondsSinceLastCall()
Elapsed ms since the last call of this function.
Definition: Timer.cpp:130
void reset()
Definition: Timer.cpp:48
virtual ~Timer()
Destructor.
Definition: Timer.cpp:16
Time m_startTime
Definition: Timer.hpp:64
Definition: Time.hpp:44
TimeDuration elapsed() const
Definition: Timer.cpp:78
uint32_t UINT32
UINT32 elapsedMicroseconds() const
Returns the elapsed time in microseconds since the timer was started or restarted.
Definition: Timer.cpp:105
void set(double time)
Definition: Time.cpp:69
Timer()
Constructor.
Definition: Timer.cpp:11
double m_duration
Definition: Time.hpp:26
TimeDuration m_watchdogTime
Definition: Timer.hpp:65
UINT32 elapsedMilliseconds() const
Returns the elapsed time in milliseconds since the timer was started or restarted.
Definition: Timer.cpp:95
void startWatchdog(TimeDuration watchdogTime)
Definition: Timer.cpp:23
void restart()
Restarts the timer.
Definition: Timer.cpp:56
bool isElapsed()
Definition: Timer.cpp:32
static Time now()
Definition: Time.cpp:168


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Mon Oct 26 2020 03:27:30