Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
time.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 *
9 * Parts copyright (c) 2008, Willow Garage, Inc., see time.cpp and the LICENSE file for details
10 * \endverbatim
11 *
12 * @file
13 * @brief Fixposition SDK: Time utilities
14 *
15 * @page FPSDK_COMMON_TIME Time utilities
16 *
17 * **API**: fpsdk_common/time.hpp and fpsdk::common::time
18 *
19 */
20#ifndef __FPSDK_COMMON_TIME_HPP__
21#define __FPSDK_COMMON_TIME_HPP__
22
23/* LIBC/STL */
24#include <cstdint>
25
26/* EXTERNAL */
27
28/* PACKAGE */
29
30namespace fpsdk {
31namespace common {
32/**
33 * @brief Time utilities
34 */
35namespace time {
36/* ****************************************************************************************************************** */
37
38/**
39 * @brief Get ticks [ms], monotonic time
40 *
41 * @returns the number of ticks
42 */
43uint64_t GetTicks();
44
45/**
46 * @brief Get seconds [s], monotonic time
47 *
48 * @returns the number of seconds
49 */
50double GetSecs();
51
52/**
53 * @brief Sleep for a bit
54 *
55 * @note The effective sleep duration is approximate only
56 *
57 * @param[in] duration Duration in [ms]
58 */
59void Sleep(const uint32_t duration);
60
61// ---------------------------------------------------------------------------------------------------------------------
62
63/**
64 * @brief Minimal ros::Time() / rplcpp::Time implementation (that doesn't throw)
65 */
66struct RosTime
67{
68 RosTime();
69 /**
70 * @brief Constructor
71 *
72 * @param[in] sec Time value seconds
73 * @param[in] nsec Time value nanoseconds
74 */
75 RosTime(const uint32_t sec, const uint32_t nsec);
76
77 /**
78 * @brief Convert to seconds
79 *
80 * @returns the time value (time since epoch) in [s]
81 */
82 double ToSec() const;
83
84 /**
85 * @brief Check if time is zero (invalid, unset)
86 *
87 * @returns true if time is zero (invalid, unset)
88 */
89 bool IsZero() const;
90
91 uint32_t sec_; //!< Seconds part of time
92 uint32_t nsec_; //!< Nanoseconds part of time (*should* be in range 0-999999999)
93};
94
95/* ****************************************************************************************************************** */
96} // namespace time
97} // namespace common
98} // namespace fpsdk
99#endif // __FPSDK_COMMON_TIME_HPP__
void Sleep(const uint32_t duration)
Sleep for a bit.
uint64_t GetTicks()
Get ticks [ms], monotonic time.
double GetSecs()
Get seconds [s], monotonic time.
Fixposition SDK.
Definition fpsdk_doc.hpp:20
Minimal ros::Time() / rplcpp::Time implementation (that doesn't throw)
Definition time.hpp:67
RosTime(const uint32_t sec, const uint32_t nsec)
Constructor.
uint32_t nsec_
Nanoseconds part of time (should be in range 0-999999999)
Definition time.hpp:92
uint32_t sec_
Seconds part of time.
Definition time.hpp:91
double ToSec() const
Convert to seconds.
bool IsZero() const
Check if time is zero (invalid, unset)