TimeStamp.hh
Go to the documentation of this file.
1 
42 #ifndef CRL_MULTISENSE_TIMESTAMP_HH
43 #define CRL_MULTISENSE_TIMESTAMP_HH
44 
45 #if defined(WIN32)
46 #ifndef WIN32_LEAN_AND_MEAN
47 #define WIN32_LEAN_AND_MEAN 1
48 #endif
49 
50 #include <windows.h>
51 #include <winsock2.h> // Provides a declaration for struct timeval
52 #else
53 #include <sys/time.h>
54 #endif
55 #include <stdint.h>
56 
57 namespace crl {
58 namespace multisense {
59 namespace details {
60 namespace utility {
61 
62 //
63 // This is a simple class that helps manage time for the rest of the system,
64 // abstracting it away into something that is more usable.
65 //
66 
67 class TimeStamp
68 {
69 private:
70 
71  //
72  // The stored time.
73  //
74 
75  struct timeval time;
76 
77  //
78  // The time synchronization offset. This offset is recalculated each time
79  // we receive a PPS timestamp set. It is applied to all times returned by
80  // calling getCurrentTime().
81  //
82 
84 #if defined (WIN32)
85  static ULARGE_INTEGER offsetSecondsSince1970;
86 #endif
87 
88 public:
89 
90  //
91  // Static routines, for the singleton version of the TimeStamp.
92  //
93 
94  static TimeStamp getCurrentTime();
95 
96  static void setTimeAtPps(TimeStamp& local, TimeStamp& remote);
97  static void setTimeAtPps(struct timeval& local, struct timeval& remote);
98  static double getTimeSynchronizationOffset();
99 
100  //
101  // Public constructor. Initializes from a timestamp.
102  //
103 
104  TimeStamp();
105  TimeStamp(struct timeval& value);
106  TimeStamp(double value);
107 
108  //
109  // For setting the timestamp.
110  //
111 
112  void set(struct timeval& value);
113 
114  //
115  // For getting precise values from the timestamp.
116  //
117 
118  uint32_t getSeconds() const;
119  uint32_t getMicroSeconds() const;
120 
121  //
122  // Operator overloads, for working with time.
123  //
124 
125  operator double() const;
126  TimeStamp& operator=(double timeStamp);
127  TimeStamp& operator+=(TimeStamp const& other);
128  TimeStamp& operator-=(TimeStamp const& other);
129 
130  //
131  // Make sure internal state is consistent. Use this if you set
132  // the TimeStamp using a timeval struct that had an unchecked
133  // microseconds value, such as a negative number.
134  //
135 
136  void normalize();
137 };
138 
139 
140 //
141 // Arithmetic operators are mostly handled by implicit conversion to
142 // and from double.
143 //
144 
145 // TimeStamp operator +(TimeStamp const& arg0, TimeStamp const& arg1);
146 // TimeStamp operator -(TimeStamp const& arg0, TimeStamp const& arg1);
147 
148 }}}} // namespaces
149 
150 #endif /* #ifndef CRL_MULTISENSE_TIMESTAMP_HH */
TimeStamp & operator=(double timeStamp)
Definition: TimeStamp.cc:258
TimeStamp & operator+=(TimeStamp const &other)
Definition: TimeStamp.cc:271
TimeStamp & operator-=(TimeStamp const &other)
Definition: TimeStamp.cc:280
Definition: channel.cc:56
static void setTimeAtPps(TimeStamp &local, TimeStamp &remote)
Definition: TimeStamp.cc:127


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46