pub struct PtpDevice(/* private fields */);Expand description
A safe wrapper for PTP hardware clock devices
Implementations§
Source§impl PtpDevice
impl PtpDevice
Sourcepub fn new(path: PathBuf) -> Result<PtpDevice>
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}Sourcepub fn get_caps(&self) -> Result<ptp_clock_caps>
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}Sourcepub fn get_sys_offset(&self) -> Result<ptp_sys_offset>
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}Sourcepub fn get_sys_offset_precise(&self) -> Result<ptp_sys_offset_precise>
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}Sourcepub fn get_sys_offset_extended(&self) -> Result<ptp_sys_offset_extended>
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§
impl Freeze for PtpDevice
impl RefUnwindSafe for PtpDevice
impl Send for PtpDevice
impl Sync for PtpDevice
impl Unpin for PtpDevice
impl UnwindSafe for PtpDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more