PtpDevice

Struct PtpDevice 

Source
pub struct PtpDevice(/* private fields */);
Expand description

A safe wrapper for PTP hardware clock devices

Implementations§

Source§

impl PtpDevice

Source

pub fn new(path: PathBuf) -> Result<PtpDevice>

Create a new PTP device from a path

Examples found in repository?
examples/demo.rs (line 20)
9fn main() {
10    let args: Vec<String> = std::env::args().collect();
11    if args.len() < 2 {
12        println!("Example usage:");
13        println!("$ sudo ./target/debug/examples/demo /dev/ptp0");
14        return;
15    }
16
17    let path = PathBuf::from(&args[1]); // path to PTP device
18
19    println!("Opening PTP device {}", path.display());
20    let device = match PtpDevice::new(path) {
21        Ok(device) => device,
22        Err(e) => {
23            eprintln!("Could not open PTP device: {}", e);
24            return;
25        }
26    };
27
28    // Get clock capabilities
29    println!("\n=== Getting Clock Capabilities ===");
30    match device.get_caps() {
31        Ok(caps) => {
32            println!("Clock capabilities:");
33            println!("  max_adj: {}", caps.max_adj);
34            println!("  n_alarm: {}", caps.n_alarm);
35            println!("  n_ext_ts: {}", caps.n_ext_ts);
36            println!("  n_per_out: {}", caps.n_per_out);
37            println!("  pps: {}", caps.pps);
38            println!("  n_pins: {}", caps.n_pins);
39            println!("  cross_timestamping: {}", caps.cross_timestamping);
40            println!("  adjust_phase: {}", caps.adjust_phase);
41            println!("  max_phase_adj: {}", caps.max_phase_adj);
42        }
43        Err(e) => {
44            eprintln!("Could not get capabilities: {}", e);
45        }
46    }
47
48    // Get system offset
49    println!("\n=== Getting System Offset ===");
50    match device.get_sys_offset() {
51        Ok(offset) => {
52            println!("System offset ({} samples):", offset.n_samples);
53            println!("  First timestamp pair: {}.{:09} -> {}.{:09}",
54                offset.ts[0].sec, offset.ts[0].nsec,
55                offset.ts[1].sec, offset.ts[1].nsec);
56        }
57        Err(e) => {
58            eprintln!("Could not get system offset: {}", e);
59        }
60    }
61
62    // Get precise system offset
63    println!("\n=== Getting Precise System Offset ===");
64    match device.get_sys_offset_precise() {
65        Ok(offset) => {
66            println!("Precise system offset:");
67            println!("  Device time: {}.{:09}", offset.device.sec, offset.device.nsec);
68            println!("  System realtime: {}.{:09}", offset.sys_realtime.sec, offset.sys_realtime.nsec);
69            println!("  System monotonic raw: {}.{:09}", offset.sys_monoraw.sec, offset.sys_monoraw.nsec);
70        }
71        Err(e) => {
72            eprintln!("Could not get precise system offset: {}", e);
73        }
74    }
75
76    // Get extended system offset
77    println!("\n=== Getting Extended System Offset ===");
78    match device.get_sys_offset_extended() {
79        Ok(offset) => {
80            println!("Extended system offset ({} samples):", offset.n_samples);
81            println!("  First timestamp triplet: {}.{:09} -> {}.{:09} -> {}.{:09}",
82                offset.ts[0][0].sec, offset.ts[0][0].nsec,
83                offset.ts[0][1].sec, offset.ts[0][1].nsec,
84                offset.ts[0][2].sec, offset.ts[0][2].nsec);
85        }
86        Err(e) => {
87            eprintln!("Could not get extended system offset: {}", e);
88        }
89    }
90
91    println!("\nDemo completed successfully!");
92}
Source

pub fn get_caps(&self) -> Result<ptp_clock_caps>

Get the clock capabilities

Examples found in repository?
examples/demo.rs (line 30)
9fn main() {
10    let args: Vec<String> = std::env::args().collect();
11    if args.len() < 2 {
12        println!("Example usage:");
13        println!("$ sudo ./target/debug/examples/demo /dev/ptp0");
14        return;
15    }
16
17    let path = PathBuf::from(&args[1]); // path to PTP device
18
19    println!("Opening PTP device {}", path.display());
20    let device = match PtpDevice::new(path) {
21        Ok(device) => device,
22        Err(e) => {
23            eprintln!("Could not open PTP device: {}", e);
24            return;
25        }
26    };
27
28    // Get clock capabilities
29    println!("\n=== Getting Clock Capabilities ===");
30    match device.get_caps() {
31        Ok(caps) => {
32            println!("Clock capabilities:");
33            println!("  max_adj: {}", caps.max_adj);
34            println!("  n_alarm: {}", caps.n_alarm);
35            println!("  n_ext_ts: {}", caps.n_ext_ts);
36            println!("  n_per_out: {}", caps.n_per_out);
37            println!("  pps: {}", caps.pps);
38            println!("  n_pins: {}", caps.n_pins);
39            println!("  cross_timestamping: {}", caps.cross_timestamping);
40            println!("  adjust_phase: {}", caps.adjust_phase);
41            println!("  max_phase_adj: {}", caps.max_phase_adj);
42        }
43        Err(e) => {
44            eprintln!("Could not get capabilities: {}", e);
45        }
46    }
47
48    // Get system offset
49    println!("\n=== Getting System Offset ===");
50    match device.get_sys_offset() {
51        Ok(offset) => {
52            println!("System offset ({} samples):", offset.n_samples);
53            println!("  First timestamp pair: {}.{:09} -> {}.{:09}",
54                offset.ts[0].sec, offset.ts[0].nsec,
55                offset.ts[1].sec, offset.ts[1].nsec);
56        }
57        Err(e) => {
58            eprintln!("Could not get system offset: {}", e);
59        }
60    }
61
62    // Get precise system offset
63    println!("\n=== Getting Precise System Offset ===");
64    match device.get_sys_offset_precise() {
65        Ok(offset) => {
66            println!("Precise system offset:");
67            println!("  Device time: {}.{:09}", offset.device.sec, offset.device.nsec);
68            println!("  System realtime: {}.{:09}", offset.sys_realtime.sec, offset.sys_realtime.nsec);
69            println!("  System monotonic raw: {}.{:09}", offset.sys_monoraw.sec, offset.sys_monoraw.nsec);
70        }
71        Err(e) => {
72            eprintln!("Could not get precise system offset: {}", e);
73        }
74    }
75
76    // Get extended system offset
77    println!("\n=== Getting Extended System Offset ===");
78    match device.get_sys_offset_extended() {
79        Ok(offset) => {
80            println!("Extended system offset ({} samples):", offset.n_samples);
81            println!("  First timestamp triplet: {}.{:09} -> {}.{:09} -> {}.{:09}",
82                offset.ts[0][0].sec, offset.ts[0][0].nsec,
83                offset.ts[0][1].sec, offset.ts[0][1].nsec,
84                offset.ts[0][2].sec, offset.ts[0][2].nsec);
85        }
86        Err(e) => {
87            eprintln!("Could not get extended system offset: {}", e);
88        }
89    }
90
91    println!("\nDemo completed successfully!");
92}
Source

pub fn get_sys_offset(&self) -> Result<ptp_sys_offset>

Get system offset measurements

Examples found in repository?
examples/demo.rs (line 50)
9fn main() {
10    let args: Vec<String> = std::env::args().collect();
11    if args.len() < 2 {
12        println!("Example usage:");
13        println!("$ sudo ./target/debug/examples/demo /dev/ptp0");
14        return;
15    }
16
17    let path = PathBuf::from(&args[1]); // path to PTP device
18
19    println!("Opening PTP device {}", path.display());
20    let device = match PtpDevice::new(path) {
21        Ok(device) => device,
22        Err(e) => {
23            eprintln!("Could not open PTP device: {}", e);
24            return;
25        }
26    };
27
28    // Get clock capabilities
29    println!("\n=== Getting Clock Capabilities ===");
30    match device.get_caps() {
31        Ok(caps) => {
32            println!("Clock capabilities:");
33            println!("  max_adj: {}", caps.max_adj);
34            println!("  n_alarm: {}", caps.n_alarm);
35            println!("  n_ext_ts: {}", caps.n_ext_ts);
36            println!("  n_per_out: {}", caps.n_per_out);
37            println!("  pps: {}", caps.pps);
38            println!("  n_pins: {}", caps.n_pins);
39            println!("  cross_timestamping: {}", caps.cross_timestamping);
40            println!("  adjust_phase: {}", caps.adjust_phase);
41            println!("  max_phase_adj: {}", caps.max_phase_adj);
42        }
43        Err(e) => {
44            eprintln!("Could not get capabilities: {}", e);
45        }
46    }
47
48    // Get system offset
49    println!("\n=== Getting System Offset ===");
50    match device.get_sys_offset() {
51        Ok(offset) => {
52            println!("System offset ({} samples):", offset.n_samples);
53            println!("  First timestamp pair: {}.{:09} -> {}.{:09}",
54                offset.ts[0].sec, offset.ts[0].nsec,
55                offset.ts[1].sec, offset.ts[1].nsec);
56        }
57        Err(e) => {
58            eprintln!("Could not get system offset: {}", e);
59        }
60    }
61
62    // Get precise system offset
63    println!("\n=== Getting Precise System Offset ===");
64    match device.get_sys_offset_precise() {
65        Ok(offset) => {
66            println!("Precise system offset:");
67            println!("  Device time: {}.{:09}", offset.device.sec, offset.device.nsec);
68            println!("  System realtime: {}.{:09}", offset.sys_realtime.sec, offset.sys_realtime.nsec);
69            println!("  System monotonic raw: {}.{:09}", offset.sys_monoraw.sec, offset.sys_monoraw.nsec);
70        }
71        Err(e) => {
72            eprintln!("Could not get precise system offset: {}", e);
73        }
74    }
75
76    // Get extended system offset
77    println!("\n=== Getting Extended System Offset ===");
78    match device.get_sys_offset_extended() {
79        Ok(offset) => {
80            println!("Extended system offset ({} samples):", offset.n_samples);
81            println!("  First timestamp triplet: {}.{:09} -> {}.{:09} -> {}.{:09}",
82                offset.ts[0][0].sec, offset.ts[0][0].nsec,
83                offset.ts[0][1].sec, offset.ts[0][1].nsec,
84                offset.ts[0][2].sec, offset.ts[0][2].nsec);
85        }
86        Err(e) => {
87            eprintln!("Could not get extended system offset: {}", e);
88        }
89    }
90
91    println!("\nDemo completed successfully!");
92}
Source

pub fn get_sys_offset_precise(&self) -> Result<ptp_sys_offset_precise>

Get precise system offset measurements

Examples found in repository?
examples/demo.rs (line 64)
9fn main() {
10    let args: Vec<String> = std::env::args().collect();
11    if args.len() < 2 {
12        println!("Example usage:");
13        println!("$ sudo ./target/debug/examples/demo /dev/ptp0");
14        return;
15    }
16
17    let path = PathBuf::from(&args[1]); // path to PTP device
18
19    println!("Opening PTP device {}", path.display());
20    let device = match PtpDevice::new(path) {
21        Ok(device) => device,
22        Err(e) => {
23            eprintln!("Could not open PTP device: {}", e);
24            return;
25        }
26    };
27
28    // Get clock capabilities
29    println!("\n=== Getting Clock Capabilities ===");
30    match device.get_caps() {
31        Ok(caps) => {
32            println!("Clock capabilities:");
33            println!("  max_adj: {}", caps.max_adj);
34            println!("  n_alarm: {}", caps.n_alarm);
35            println!("  n_ext_ts: {}", caps.n_ext_ts);
36            println!("  n_per_out: {}", caps.n_per_out);
37            println!("  pps: {}", caps.pps);
38            println!("  n_pins: {}", caps.n_pins);
39            println!("  cross_timestamping: {}", caps.cross_timestamping);
40            println!("  adjust_phase: {}", caps.adjust_phase);
41            println!("  max_phase_adj: {}", caps.max_phase_adj);
42        }
43        Err(e) => {
44            eprintln!("Could not get capabilities: {}", e);
45        }
46    }
47
48    // Get system offset
49    println!("\n=== Getting System Offset ===");
50    match device.get_sys_offset() {
51        Ok(offset) => {
52            println!("System offset ({} samples):", offset.n_samples);
53            println!("  First timestamp pair: {}.{:09} -> {}.{:09}",
54                offset.ts[0].sec, offset.ts[0].nsec,
55                offset.ts[1].sec, offset.ts[1].nsec);
56        }
57        Err(e) => {
58            eprintln!("Could not get system offset: {}", e);
59        }
60    }
61
62    // Get precise system offset
63    println!("\n=== Getting Precise System Offset ===");
64    match device.get_sys_offset_precise() {
65        Ok(offset) => {
66            println!("Precise system offset:");
67            println!("  Device time: {}.{:09}", offset.device.sec, offset.device.nsec);
68            println!("  System realtime: {}.{:09}", offset.sys_realtime.sec, offset.sys_realtime.nsec);
69            println!("  System monotonic raw: {}.{:09}", offset.sys_monoraw.sec, offset.sys_monoraw.nsec);
70        }
71        Err(e) => {
72            eprintln!("Could not get precise system offset: {}", e);
73        }
74    }
75
76    // Get extended system offset
77    println!("\n=== Getting Extended System Offset ===");
78    match device.get_sys_offset_extended() {
79        Ok(offset) => {
80            println!("Extended system offset ({} samples):", offset.n_samples);
81            println!("  First timestamp triplet: {}.{:09} -> {}.{:09} -> {}.{:09}",
82                offset.ts[0][0].sec, offset.ts[0][0].nsec,
83                offset.ts[0][1].sec, offset.ts[0][1].nsec,
84                offset.ts[0][2].sec, offset.ts[0][2].nsec);
85        }
86        Err(e) => {
87            eprintln!("Could not get extended system offset: {}", e);
88        }
89    }
90
91    println!("\nDemo completed successfully!");
92}
Source

pub fn get_sys_offset_extended(&self) -> Result<ptp_sys_offset_extended>

Get extended system offset measurements

Examples found in repository?
examples/demo.rs (line 78)
9fn main() {
10    let args: Vec<String> = std::env::args().collect();
11    if args.len() < 2 {
12        println!("Example usage:");
13        println!("$ sudo ./target/debug/examples/demo /dev/ptp0");
14        return;
15    }
16
17    let path = PathBuf::from(&args[1]); // path to PTP device
18
19    println!("Opening PTP device {}", path.display());
20    let device = match PtpDevice::new(path) {
21        Ok(device) => device,
22        Err(e) => {
23            eprintln!("Could not open PTP device: {}", e);
24            return;
25        }
26    };
27
28    // Get clock capabilities
29    println!("\n=== Getting Clock Capabilities ===");
30    match device.get_caps() {
31        Ok(caps) => {
32            println!("Clock capabilities:");
33            println!("  max_adj: {}", caps.max_adj);
34            println!("  n_alarm: {}", caps.n_alarm);
35            println!("  n_ext_ts: {}", caps.n_ext_ts);
36            println!("  n_per_out: {}", caps.n_per_out);
37            println!("  pps: {}", caps.pps);
38            println!("  n_pins: {}", caps.n_pins);
39            println!("  cross_timestamping: {}", caps.cross_timestamping);
40            println!("  adjust_phase: {}", caps.adjust_phase);
41            println!("  max_phase_adj: {}", caps.max_phase_adj);
42        }
43        Err(e) => {
44            eprintln!("Could not get capabilities: {}", e);
45        }
46    }
47
48    // Get system offset
49    println!("\n=== Getting System Offset ===");
50    match device.get_sys_offset() {
51        Ok(offset) => {
52            println!("System offset ({} samples):", offset.n_samples);
53            println!("  First timestamp pair: {}.{:09} -> {}.{:09}",
54                offset.ts[0].sec, offset.ts[0].nsec,
55                offset.ts[1].sec, offset.ts[1].nsec);
56        }
57        Err(e) => {
58            eprintln!("Could not get system offset: {}", e);
59        }
60    }
61
62    // Get precise system offset
63    println!("\n=== Getting Precise System Offset ===");
64    match device.get_sys_offset_precise() {
65        Ok(offset) => {
66            println!("Precise system offset:");
67            println!("  Device time: {}.{:09}", offset.device.sec, offset.device.nsec);
68            println!("  System realtime: {}.{:09}", offset.sys_realtime.sec, offset.sys_realtime.nsec);
69            println!("  System monotonic raw: {}.{:09}", offset.sys_monoraw.sec, offset.sys_monoraw.nsec);
70        }
71        Err(e) => {
72            eprintln!("Could not get precise system offset: {}", e);
73        }
74    }
75
76    // Get extended system offset
77    println!("\n=== Getting Extended System Offset ===");
78    match device.get_sys_offset_extended() {
79        Ok(offset) => {
80            println!("Extended system offset ({} samples):", offset.n_samples);
81            println!("  First timestamp triplet: {}.{:09} -> {}.{:09} -> {}.{:09}",
82                offset.ts[0][0].sec, offset.ts[0][0].nsec,
83                offset.ts[0][1].sec, offset.ts[0][1].nsec,
84                offset.ts[0][2].sec, offset.ts[0][2].nsec);
85        }
86        Err(e) => {
87            eprintln!("Could not get extended system offset: {}", e);
88        }
89    }
90
91    println!("\nDemo completed successfully!");
92}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.