libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
linux_timebase.hpp
1#include <time.h>
2
3#include "timebase.hpp"
4
5extern struct timespec libxr_linux_start_time_spec;
6
7namespace LibXR
8{
13class LinuxTimebase : public Timebase
14{
15 public:
22 {
23 return MicrosecondTimestamp(static_cast<uint64_t>(GetElapsedMicroseconds()));
24 }
25
32 {
33 return MillisecondTimestamp(static_cast<uint32_t>(GetElapsedMicroseconds() / 1000LL));
34 }
35
36 private:
37 static int64_t GetElapsedMicroseconds()
38 {
39 struct timespec ts = {};
40 clock_gettime(CLOCK_MONOTONIC, &ts);
41 return static_cast<int64_t>(ts.tv_sec - libxr_linux_start_time_spec.tv_sec) * 1000000LL +
42 static_cast<int64_t>(ts.tv_nsec - libxr_linux_start_time_spec.tv_nsec) / 1000LL;
43 }
44};
45} // namespace LibXR
Linux 时间基准实现 / Linux timebase implementation.
MicrosecondTimestamp _get_microseconds()
获取当前微秒计数 / Get current timestamp in microseconds
MillisecondTimestamp _get_milliseconds()
获取当前毫秒计数 / Get current timestamp in milliseconds
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
Definition timebase.hpp:18
LibXR 命名空间
Definition ch32_can.hpp:14