realsense_rust/kind/timestamp_domain.rs
1//! Enumeration describing the different domains for timestamps acquired by a frame.
2//!
3//! **NOTE**: Arrival timestamps from the frame are always in system time, whereas other timestamps
4//! (presentation and middle-exposure) will be in the frame's specified timestamp domain.
5
6use num_derive::{FromPrimitive, ToPrimitive};
7use realsense_sys as sys;
8use std::ffi::CStr;
9
10/// Enumeration of possible timestamp domains that frame timestamps are delivered in.
11#[repr(i32)]
12#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum Rs2TimestampDomain {
14 /// Timestamp is measured in relation to the device's internal clock
15 HardwareClock = sys::rs2_timestamp_domain_RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK as i32,
16 /// Timestamp was measured in relation to the OS (host) system clock
17 SystemTime = sys::rs2_timestamp_domain_RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME as i32,
18 /// Timestamp was measured in relation to the device's clock converted to the system clock.
19 ///
20 /// The timestamp is measured directly relative to the device's internal clock, and then
21 /// converted to the OS (host) system clock by measuring the difference.
22 GlobalTime = sys::rs2_timestamp_domain_RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME as i32,
23 /* Not included since this just tells us the total number of domains
24 *
25 * Count = sys::rs2_timestamp_domain_RS2_TIMESTAMP_DOMAIN_COUNT, */
26}
27
28impl Rs2TimestampDomain {
29 /// Get the timestamp domain variant as a `&CStr`
30 pub fn as_cstr(&self) -> &'static CStr {
31 unsafe {
32 let ptr = sys::rs2_timestamp_domain_to_string(*self as sys::rs2_timestamp_domain);
33 CStr::from_ptr(ptr)
34 }
35 }
36
37 /// Get the timestamp domain variant as a `&str`
38 pub fn as_str(&self) -> &'static str {
39 self.as_cstr().to_str().unwrap()
40 }
41}
42
43impl ToString for Rs2TimestampDomain {
44 fn to_string(&self) -> String {
45 self.as_str().to_owned()
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use num_traits::FromPrimitive;
53
54 #[test]
55 fn all_variants_exist() {
56 for i in 0..sys::rs2_timestamp_domain_RS2_TIMESTAMP_DOMAIN_COUNT as i32 {
57 assert!(
58 Rs2TimestampDomain::from_i32(i).is_some(),
59 "Rs2TimestampDomain variant for ordinal {} does not exist.",
60 i,
61 );
62 }
63 }
64}