TimeStamp.hh
Go to the documentation of this file.
00001 
00042 #ifndef CRL_MULTISENSE_TIMESTAMP_HH
00043 #define CRL_MULTISENSE_TIMESTAMP_HH
00044 
00045 #if defined(WIN32)
00046 #ifndef WIN32_LEAN_AND_MEAN
00047 #define WIN32_LEAN_AND_MEAN 1
00048 #endif
00049 
00050 #include <windows.h>
00051 #include <winsock2.h> // Provides a declaration for struct timeval
00052 #else
00053 #include <sys/time.h>
00054 #endif
00055 #include <stdint.h>
00056 
00057 namespace crl {
00058 namespace multisense {
00059 namespace details {
00060 namespace utility {
00061 
00062 //
00063 // This is a simple class that helps manage time for the rest of the system,
00064 // abstracting it away into something that is more usable.
00065 //
00066 
00067 class TimeStamp
00068 {
00069 private:
00070 
00071     //
00072     // The stored time.
00073     //
00074 
00075     struct timeval time;
00076 
00077     //
00078     // The time synchronization offset. This offset is recalculated each time
00079     // we receive a PPS timestamp set. It is applied to all times returned by
00080     // calling getCurrentTime().
00081     //
00082 
00083     static double timeSynchronizationOffset;
00084 #if defined (WIN32)
00085     static ULARGE_INTEGER offsetSecondsSince1970;
00086 #endif
00087 
00088 public:
00089 
00090     //
00091     // Static routines, for the singleton version of the TimeStamp.
00092     //
00093 
00094     static TimeStamp getCurrentTime();
00095 
00096     static void setTimeAtPps(TimeStamp& local, TimeStamp& remote);
00097     static void setTimeAtPps(struct timeval& local, struct timeval& remote);
00098     static double getTimeSynchronizationOffset();
00099 
00100     //
00101     // Public constructor. Initializes from a timestamp.
00102     //
00103 
00104     TimeStamp();
00105     TimeStamp(struct timeval& value);
00106     TimeStamp(double value);
00107 
00108     //
00109     // For setting the timestamp.
00110     //
00111 
00112     void set(struct timeval& value);
00113 
00114     //
00115     // For getting precise values from the timestamp.
00116     //
00117 
00118     uint32_t getSeconds() const;
00119     uint32_t getMicroSeconds() const;
00120 
00121     //
00122     // Operator overloads, for working with time.
00123     //
00124 
00125     operator double() const;
00126     TimeStamp& operator=(double timeStamp);
00127     TimeStamp& operator+=(TimeStamp const& other);
00128     TimeStamp& operator-=(TimeStamp const& other);
00129     
00130     //
00131     // Make sure internal state is consistent.  Use this if you set
00132     // the TimeStamp using a timeval struct that had an unchecked
00133     // microseconds value, such as a negative number.
00134     //
00135 
00136     void normalize();
00137 };
00138 
00139 
00140 //
00141 // Arithmetic operators are mostly handled by implicit conversion to
00142 // and from double.
00143 //
00144 
00145 // TimeStamp operator +(TimeStamp const& arg0, TimeStamp const& arg1);
00146 // TimeStamp operator -(TimeStamp const& arg0, TimeStamp const& arg1);
00147   
00148 }}}} // namespaces
00149 
00150 #endif /* #ifndef CRL_MULTISENSE_TIMESTAMP_HH */


multisense_lib
Author(s):
autogenerated on Fri Apr 5 2019 02:28:24