![]() |
CommRaT 2.0.0
C++20 Real-Time Messaging Framework
|
Time utility class - abstraction over clock sources. More...
#include <commrat/platform/timestamp.hpp>
Public Types | |
| enum class | ClockSource { SYSTEM_CLOCK , STEADY_CLOCK , HIGH_RES_CLOCK , REALTIME_CLOCK , MONOTONIC_CLOCK } |
| Clock source types. More... | |
Static Public Member Functions | |
| static Timestamp | now () noexcept |
| Get current timestamp in nanoseconds. | |
| static Timestamp | get_timestamp (ClockSource source=ClockSource::STEADY_CLOCK) noexcept |
| Get current timestamp from specific clock source. | |
| static void | set_clock_source (ClockSource source) noexcept |
| Set default clock source for all future now() calls. | |
| template<typename Rep , typename Period > | |
| static constexpr Timestamp | to_nanoseconds (std::chrono::duration< Rep, Period > duration) noexcept |
| Convert std::chrono::duration to nanoseconds. | |
| template<typename Duration > | |
| static constexpr Duration | from_nanoseconds (Timestamp ns) noexcept |
| Convert nanoseconds to std::chrono::duration. | |
| static constexpr Timestamp | milliseconds_to_ns (uint64_t ms) noexcept |
| Convert milliseconds to nanoseconds. | |
| static constexpr Timestamp | microseconds_to_ns (uint64_t us) noexcept |
| Convert microseconds to nanoseconds. | |
| static constexpr uint64_t | ns_to_milliseconds (Timestamp ns) noexcept |
| Convert nanoseconds to milliseconds. | |
| static constexpr uint64_t | ns_to_microseconds (Timestamp ns) noexcept |
| Convert nanoseconds to microseconds. | |
| static constexpr Timestamp | diff (Timestamp t1, Timestamp t2) noexcept |
| Calculate absolute time difference between two timestamps. | |
| static constexpr bool | is_within_tolerance (Timestamp timestamp, Timestamp target, Timestamp tolerance_ns) noexcept |
| Check if timestamp is within tolerance of target. | |
| static void | sleep_ns (Timestamp ns) noexcept |
| Sleep for specified nanoseconds. | |
| template<typename Rep , typename Period > | |
| static void | sleep (std::chrono::duration< Rep, Period > duration) noexcept |
| Sleep for specified duration. | |
Time utility class - abstraction over clock sources.
Provides unified interface for getting timestamps and converting units. Can be configured to use different clock sources (system, monotonic, realtime).
Thread-safe: All methods are const and stateless.
Definition at line 52 of file timestamp.hpp.
|
strong |
Clock source types.
Definition at line 57 of file timestamp.hpp.
|
inlinestaticconstexprnoexcept |
Calculate absolute time difference between two timestamps.
| t1 | First timestamp |
| t2 | Second timestamp |
Definition at line 166 of file timestamp.hpp.
Referenced by is_within_tolerance().
|
inlinestaticconstexprnoexcept |
Convert nanoseconds to std::chrono::duration.
Definition at line 127 of file timestamp.hpp.
|
inlinestaticnoexcept |
Get current timestamp from specific clock source.
| source | Clock source to use |
Definition at line 82 of file timestamp.hpp.
References HIGH_RES_CLOCK, MONOTONIC_CLOCK, REALTIME_CLOCK, STEADY_CLOCK, and SYSTEM_CLOCK.
Referenced by now().
|
inlinestaticconstexprnoexcept |
Check if timestamp is within tolerance of target.
| timestamp | Timestamp to check |
| target | Target timestamp |
| tolerance_ns | Tolerance in nanoseconds |
Definition at line 178 of file timestamp.hpp.
References diff().
|
inlinestaticconstexprnoexcept |
Convert microseconds to nanoseconds.
Definition at line 141 of file timestamp.hpp.
Referenced by commrat::literals::operator""_us().
|
inlinestaticconstexprnoexcept |
Convert milliseconds to nanoseconds.
Definition at line 134 of file timestamp.hpp.
Referenced by commrat::literals::operator""_ms(), and commrat::literals::operator""_s().
|
inlinestaticnoexcept |
Get current timestamp in nanoseconds.
Real-time safe: Yes (if using MONOTONIC_CLOCK)
Definition at line 72 of file timestamp.hpp.
References get_timestamp().
Referenced by commrat::LoopExecutor< ModuleType >::free_loop(), and commrat::LoopExecutor< ModuleType >::periodic_loop().
|
inlinestaticconstexprnoexcept |
Convert nanoseconds to microseconds.
Definition at line 155 of file timestamp.hpp.
|
inlinestaticconstexprnoexcept |
Convert nanoseconds to milliseconds.
Definition at line 148 of file timestamp.hpp.
|
inlinestaticnoexcept |
Set default clock source for all future now() calls.
| source | Clock source to use |
Not thread-safe: Should be called once at initialization
Definition at line 109 of file timestamp.hpp.
|
inlinestaticnoexcept |
Sleep for specified duration.
Definition at line 201 of file timestamp.hpp.
Referenced by commrat::module_main().
|
inlinestaticnoexcept |
Sleep for specified nanoseconds.
Uses high-resolution sleep if available.
| ns | Nanoseconds to sleep |
Real-time safe: Depends on OS scheduler
Definition at line 193 of file timestamp.hpp.
|
inlinestaticconstexprnoexcept |
Convert std::chrono::duration to nanoseconds.
Definition at line 117 of file timestamp.hpp.