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

WebAssembly 时间基准实现 / WebAssembly timebase implementation. More...

#include <webasm_timebase.hpp>

Inheritance diagram for LibXR::WebAsmTimebase:
[legend]
Collaboration diagram for LibXR::WebAsmTimebase:
[legend]

Public Member Functions

MicrosecondTimestamp _get_microseconds () override
 获取当前微秒计数 / Get current timestamp in microseconds
 
MillisecondTimestamp _get_milliseconds () override
 获取当前毫秒计数 / Get current timestamp in milliseconds
 
- Public Member Functions inherited from LibXR::Timebase
 Timebase (uint64_t max_valid_us=UINT64_MAX, uint32_t max_valid_ms=UINT32_MAX)
 默认构造函数,初始化全局时间基指针。 Default constructor, initializing the global timebase pointer.
 

Private Attributes

std::chrono::system_clock::time_point start_time_
 

Additional Inherited Members

- Static Public Member Functions inherited from LibXR::Timebase
static MicrosecondTimestamp GetMicroseconds ()
 获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
 
static MillisecondTimestamp GetMilliseconds ()
 获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
 
static void DelayMicroseconds (uint32_t us)
 微秒级延时 / Delay in microseconds
 
- Static Public Attributes inherited from LibXR::Timebase
static Timebasetimebase = nullptr
 静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
 

Detailed Description

WebAssembly 时间基准实现 / WebAssembly timebase implementation.

Definition at line 14 of file webasm_timebase.hpp.

Constructor & Destructor Documentation

◆ WebAsmTimebase()

LibXR::WebAsmTimebase::WebAsmTimebase ( )
inline

Definition at line 17 of file webasm_timebase.hpp.

18 {
19 // Initialize reference timestamp.
20 start_time_ = std::chrono::system_clock::now();
21 }

Member Function Documentation

◆ _get_microseconds()

MicrosecondTimestamp LibXR::WebAsmTimebase::_get_microseconds ( )
inlineoverridevirtual

获取当前微秒计数 / Get current timestamp in microseconds

Returns
MicrosecondTimestamp 微秒时间戳 / Microsecond timestamp

Implements LibXR::Timebase.

Definition at line 27 of file webasm_timebase.hpp.

28 {
29 auto now = std::chrono::system_clock::now();
30 auto us =
31 std::chrono::duration_cast<std::chrono::microseconds>(now - start_time_).count();
32 return static_cast<MicrosecondTimestamp>(us % UINT32_MAX);
33 }

◆ _get_milliseconds()

MillisecondTimestamp LibXR::WebAsmTimebase::_get_milliseconds ( )
inlineoverridevirtual

获取当前毫秒计数 / Get current timestamp in milliseconds

Returns
MillisecondTimestamp 毫秒时间戳 / Millisecond timestamp

Implements LibXR::Timebase.

Definition at line 39 of file webasm_timebase.hpp.

40 {
41 auto now = std::chrono::system_clock::now();
42 auto ms =
43 std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time_).count();
44 return static_cast<MillisecondTimestamp>(ms % UINT32_MAX);
45 }

Field Documentation

◆ start_time_

std::chrono::system_clock::time_point LibXR::WebAsmTimebase::start_time_
private

Definition at line 48 of file webasm_timebase.hpp.


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