time_util.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016, The Regents of The University of Michigan.
2 All rights reserved.
3 This software was developed in the APRIL Robotics Lab under the
4 direction of Edwin Olson, ebolson@umich.edu. This software may be
5 available under alternative licensing terms; contact the address above.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 The views and conclusions contained in the software and documentation are those
24 of the authors and should not be interpreted as representing official policies,
25 either expressed or implied, of the Regents of The University of Michigan.
26 */
27 
28 #pragma once
29 
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <time.h>
33 
34 #ifdef _WIN32
35 #include <Winsock2.h>
36 typedef long long suseconds_t;
37 #endif
38 
39 #ifdef _MSC_VER
40 
41 inline int gettimeofday(struct timeval* tp, void* tzp)
42 {
43  (void)tzp;
44 
45  unsigned long t;
46  t = time(NULL);
47  tp->tv_sec = t / 1000;
48  tp->tv_usec = t % 1000;
49  return 0;
50 }
51 #else
52 #include <sys/time.h>
53 #include <unistd.h>
54 #endif
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 
64 int64_t utime_now(); // blacklist-ignore
65 int64_t utime_get_seconds(int64_t v);
66 int64_t utime_get_useconds(int64_t v);
67 void utime_to_timeval(int64_t v, struct timeval *tv);
68 void utime_to_timespec(int64_t v, struct timespec *ts);
69 
70 int32_t timeutil_usleep(int64_t useconds);
71 uint32_t timeutil_sleep(unsigned int seconds);
72 int32_t timeutil_sleep_hz(timeutil_rest_t *rest, double hz);
73 
77 bool timeutil_timer_timeout(timeutil_rest_t *rest, double timeout_s);
78 
79 int64_t time_util_hhmmss_ss_to_utime(double time);
80 
81 int64_t timeutil_ms_to_us(int32_t ms);
82 
83 #ifdef __cplusplus
84 }
85 #endif
timeutil_sleep
uint32_t timeutil_sleep(unsigned int seconds)
Definition: time_util.c:90
timeutil_timer_stop
void timeutil_timer_stop(timeutil_rest_t *rest)
Definition: time_util.c:126
timeutil_timer_timeout
bool timeutil_timer_timeout(timeutil_rest_t *rest, double timeout_s)
Definition: time_util.c:134
timeutil_rest_destroy
void timeutil_rest_destroy(timeutil_rest_t *rest)
Definition: time_util.c:44
timeutil_usleep
int32_t timeutil_usleep(int64_t useconds)
Definition: time_util.c:78
utime_to_timespec
void utime_to_timespec(int64_t v, struct timespec *ts)
Definition: time_util.c:72
time_util_hhmmss_ss_to_utime
int64_t time_util_hhmmss_ss_to_utime(double time)
Definition: time_util.c:140
timeutil_timer_reset
void timeutil_timer_reset(timeutil_rest_t *rest)
Definition: time_util.c:115
utime_to_timeval
void utime_to_timeval(int64_t v, struct timeval *tv)
Definition: time_util.c:66
utime_get_seconds
int64_t utime_get_seconds(int64_t v)
Definition: time_util.c:56
timeutil_timer_start
void timeutil_timer_start(timeutil_rest_t *rest)
Definition: time_util.c:121
timeutil_rest_create
timeutil_rest_t * timeutil_rest_create()
Definition: time_util.c:38
utime_get_useconds
int64_t utime_get_useconds(int64_t v)
Definition: time_util.c:61
timeutil_sleep_hz
int32_t timeutil_sleep_hz(timeutil_rest_t *rest, double hz)
Definition: time_util.c:101
utime_now
int64_t utime_now()
Definition: time_util.c:49
timeutil_ms_to_us
int64_t timeutil_ms_to_us(int32_t ms)
Definition: time_util.c:159
timeutil_rest
Definition: time_util.c:32


apriltag
Author(s): Edwin Olson , Max Krogius
autogenerated on Sun Apr 20 2025 02:08:47