Skip to main content

timeout/
timeout.rs

1use pps_time::{pps, PpsDevice};
2use std::path::PathBuf;
3
4/// A simple PPS demo program
5///
6/// Build with `cargo build --package pps-time --example timeout`
7fn main() {
8    let args: Vec<String> = std::env::args().collect();
9    if args.len() < 2 {
10        println!("Example usage:");
11        println!("$ sudo ./target/debug/examples/timeout /dev/pps0");
12        return;
13    }
14
15    let path = PathBuf::from(&args[1]); // path to PPS device
16
17    println!("Opening PPS device {}", path.display());
18    let pps = PpsDevice::new(path).expect("Could not open file!");
19
20    let capabilities = pps.get_cap().expect("Could not get capabilities!");
21    println!("Capabilities: {:#x}", capabilities);
22
23    let mut params = pps.get_params().expect("Could not get params!");
24    println!("{:?}", params);
25
26    // Turn on CAPTUREASSERT if available
27    if capabilities & pps::PPS_CAPTUREASSERT != 0 {
28        params.mode |= pps::PPS_CAPTUREASSERT as i32;
29    } else {
30        println!("Cannot CAPTUREASSERT");
31    }
32    // Turn on CAPTURECLEAR if available
33    if capabilities & pps::PPS_CAPTURECLEAR != 0 {
34        params.mode |= pps::PPS_CAPTURECLEAR as i32;
35    } else {
36        println!("Cannot CAPTURECLEAR");
37    }
38
39    pps.set_params(&mut params).expect("Could not set params!");
40
41    loop {
42        let data = pps.fetch_timeout(0, 500_000_000);
43        println!("{:#?}", data); // half of these should be timeouts for 1PPS devices
44    }
45}