libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Timebase Class Referenceabstract

时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps. More...

#include <timebase.hpp>

Inheritance diagram for LibXR::Timebase:
Collaboration diagram for LibXR::Timebase:

Public Member Functions

 Timebase (uint64_t max_valid_us=UINT64_MAX, uint32_t max_valid_ms=UINT32_MAX)
 默认构造函数,初始化全局时间基指针。 Default constructor, initializing the global timebase pointer.
 
virtual TimestampUS _get_microseconds ()=0
 纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds (implemented by derived classes).
 
virtual TimestampMS _get_milliseconds ()=0
 纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds (implemented by derived classes).
 

Static Public Member Functions

static TimestampUS GetMicroseconds ()
 获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
 
static TimestampMS GetMilliseconds ()
 获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
 

Static Public Attributes

static Timebasetimebase = nullptr
 静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
 

Detailed Description

时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.

该类提供了微秒和毫秒级的时间戳获取接口,并要求派生类实现具体的时间获取方法。 This class provides interfaces for obtaining timestamps in microseconds and milliseconds, and requires derived classes to implement the actual time retrieval methods.

Definition at line 17 of file timebase.hpp.

Constructor & Destructor Documentation

◆ Timebase()

LibXR::Timebase::Timebase ( uint64_t  max_valid_us = UINT64_MAX,
uint32_t  max_valid_ms = UINT32_MAX 
)
inline

默认构造函数,初始化全局时间基指针。 Default constructor, initializing the global timebase pointer.

该构造函数在实例化对象时,将 timebase 指针指向当前对象, 以便静态方法可以访问具体的时间基实例。 This constructor sets the timebase pointer to the current object when an instance is created, allowing static methods to access the specific timebase instance.

Definition at line 30 of file timebase.hpp.

31 {
32 libxr_timebase_max_valid_ms = max_valid_ms;
33 libxr_timebase_max_valid_us = max_valid_us;
34 timebase = this;
35 }
static Timebase * timebase
静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
Definition timebase.hpp:101
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

Member Function Documentation

◆ _get_microseconds()

virtual TimestampUS LibXR::Timebase::_get_microseconds ( )
pure virtual

纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds (implemented by derived classes).

该函数需要在派生类中实现,以提供具体的时间获取机制。 This function must be implemented in derived classes to provide the actual time retrieval mechanism.

Returns
返回当前的时间戳(单位:微秒)。 Returns the current timestamp (in microseconds).

Implemented in LibXR::LinuxTimebase, LibXR::STM32Timebase, and LibXR::STM32TimerTimebase.

◆ _get_milliseconds()

virtual TimestampMS LibXR::Timebase::_get_milliseconds ( )
pure virtual

纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds (implemented by derived classes).

该函数需要在派生类中实现,以提供具体的时间获取机制。 This function must be implemented in derived classes to provide the actual time retrieval mechanism.

Returns
返回当前的时间戳(单位:毫秒)。 Returns the current timestamp (in milliseconds).

Implemented in LibXR::LinuxTimebase, LibXR::STM32Timebase, and LibXR::STM32TimerTimebase.

◆ GetMicroseconds()

static TimestampUS LibXR::Timebase::GetMicroseconds ( )
inlinestatic

获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.

该函数通过静态方法调用 _get_microseconds(), 从 timebase 实例中获取当前时间。 This function calls _get_microseconds() via a static method to retrieve the current time from the timebase instance.

Returns
返回当前的时间戳(单位:微秒)。 Returns the current timestamp (in microseconds).

Definition at line 49 of file timebase.hpp.

49{ return timebase->_get_microseconds(); }
virtual TimestampUS _get_microseconds()=0
纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds...

◆ GetMilliseconds()

static TimestampMS LibXR::Timebase::GetMilliseconds ( )
inlinestatic

获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.

该函数通过静态方法调用 _get_milliseconds(), 从 timebase 实例中获取当前时间。 This function calls _get_milliseconds() via a static method to retrieve the current time from the timebase instance.

Returns
返回当前的时间戳(单位:毫秒)。 Returns the current timestamp (in milliseconds).

Definition at line 63 of file timebase.hpp.

63{ return timebase->_get_milliseconds(); }
virtual TimestampMS _get_milliseconds()=0
纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds...

Field Documentation

◆ timebase

Timebase* LibXR::Timebase::timebase = nullptr
inlinestatic

静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.

该指针指向当前生效的 Timebase 实例,所有静态时间函数都通过该指针访问实际实现。 This pointer refers to the currently active Timebase instance, and all static time functions access the actual implementation through this pointer.

Definition at line 101 of file timebase.hpp.


The documentation for this class was generated from the following file: