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

毫秒时间戳 / Millisecond timestamp More...

#include <libxr_time.hpp>

Data Structures

class  Duration
 毫秒时长 / Duration in milliseconds More...
 

Public Member Functions

 MillisecondTimestamp ()=default
 创建零值毫秒时间戳 / Construct a zero millisecond timestamp
 
 MillisecondTimestamp (uint32_t millisecond)
 从毫秒计数构造时间戳 / Construct a timestamp from millisecond ticks
 
 operator uint32_t () const
 转换为毫秒计数值 / Convert to the raw millisecond tick count
 
Duration operator- (const MillisecondTimestamp &old_timestamp) const
 计算时间差,支持时间基准回绕 / Compute elapsed time with timebase wraparound
 

Private Attributes

uint32_t millisecond_ = 0
 

Detailed Description

毫秒时间戳 / Millisecond timestamp

Definition at line 162 of file libxr_time.hpp.

Constructor & Destructor Documentation

◆ MillisecondTimestamp()

LibXR::MillisecondTimestamp::MillisecondTimestamp ( uint32_t millisecond)
inline

从毫秒计数构造时间戳 / Construct a timestamp from millisecond ticks

Parameters
millisecond毫秒计数值 / Millisecond tick count

Definition at line 174 of file libxr_time.hpp.

174: millisecond_(millisecond) {}

Member Function Documentation

◆ operator uint32_t()

LibXR::MillisecondTimestamp::operator uint32_t ( ) const
inline

转换为毫秒计数值 / Convert to the raw millisecond tick count

Returns
毫秒计数值 / Raw millisecond tick count

Definition at line 180 of file libxr_time.hpp.

180{ return millisecond_; }

◆ operator-()

Duration LibXR::MillisecondTimestamp::operator- ( const MillisecondTimestamp & old_timestamp) const
inlinenodiscard

计算时间差,支持时间基准回绕 / Compute elapsed time with timebase wraparound

Parameters
old_timestamp旧时间戳 / Older timestamp
Returns
当前时间戳相对旧时间戳的时长 / Elapsed duration from the older timestamp
Note
若当前时间戳小于旧时间戳,则按一次时间基准回绕处理,回绕上界由 当前已配置的毫秒时间基准有效上界指定。 / If the current timestamp is smaller than the older one, the function treats it as one wraparound event whose upper bound is defined by the currently configured millisecond timebase limit.

Definition at line 248 of file libxr_time.hpp.

249 {
250 uint32_t elapsed = 0;
251 const uint32_t max_valid = Detail::TimebaseMaxValidMs();
252
253 if (millisecond_ >= old_timestamp.millisecond_)
254 {
255 elapsed = millisecond_ - old_timestamp.millisecond_;
256 }
257 else
258 {
259 elapsed = millisecond_ + (max_valid - old_timestamp.millisecond_) + 1U;
260 }
261
262 ASSERT(elapsed <= max_valid);
263
264 return Duration(elapsed);
265 }

Field Documentation

◆ millisecond_

uint32_t LibXR::MillisecondTimestamp::millisecond_ = 0
private

Definition at line 268 of file libxr_time.hpp.


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