YDLIDAR SDK  V1.3.2
timer.h
1 #pragma once
2 #include "v8stdint.h"
3 #include <assert.h>
4 #include <time.h>
5 #include <inttypes.h>
6 
7 
8 
9 #define BEGIN_STATIC_CODE( _blockname_ ) \
10  static class _static_code_##_blockname_ { \
11  public: \
12  _static_code_##_blockname_ ()
13 
14 
15 #define END_STATIC_CODE( _blockname_ ) \
16  } _instance_##_blockname_;
17 
18 
19 #if defined(_WIN32)
20 #include <windows.h>
21 #define delay(x) ::Sleep(x)
22 #else
23 #include <sys/time.h>
24 #include <unistd.h>
25 
26 static inline void delay(uint32_t ms){
27  while (ms>=1000){
28  usleep(1000*1000);
29  ms-=1000;
30  };
31  if (ms!=0){
32  usleep(ms*1000);
33  }
34 }
35 #endif
36 
37 
38 
39 
40 
41 static inline TTimeStamp time_tToTimestamp(const time_t &t )
42 {
43  return uint64_t(t) * UINT64_C(10000000) + UINT64_C(116444736) * UINT64_C(1000000000);
44 }
45 
46 static inline TTimeStamp time_tToTimestamp(const double t )
47 {
48  return uint64_t(t*10000000.0)+ UINT64_C(116444736)*UINT64_C(1000000000);
49 }
50 
51 static inline double timestampTotime_t( const TTimeStamp t )
52 {
53  return double(t - UINT64_C(116444736)*UINT64_C(1000000000)) / 10000000.0;
54 }
55 
56 static inline TTimeStamp timestampAdd( const TTimeStamp tim, const double num_seconds)
57 {
58  return static_cast<TTimeStamp>(tim + static_cast<int64_t>(num_seconds*10000000.0));
59 }
60 
61 /*---------------------------------------------------------------
62  timeDifference
63  ---------------------------------------------------------------*/
64 static inline double timeDifference( const TTimeStamp t1, const TTimeStamp t2 )
65 {
66  assert(t1!=INVALID_TIMESTAMP);
67  assert(t2!=INVALID_TIMESTAMP);
68 
69  return (int64_t(t2)- int64_t(t1))/10000000.0;
70 }
71 
72 /*---------------------------------------------------------------
73  secondsToTimestamp
74  ---------------------------------------------------------------*/
75 static inline TTimeStamp secondsToTimestamp( const double nSeconds )
76 {
77  return (TTimeStamp)(nSeconds*10000000.0);
78 }
79 
80 namespace impl{
81 
82 #if defined(_WIN32)
83  void HPtimer_reset();
84 #endif
85  uint32_t getHDTimer();
86  TTimeStamp getCurrentTime();
87 }
88 
89 
90 #define getms() impl::getHDTimer()
91 #define getTime() impl::getCurrentTime()
Definition: timer.h:80