-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate fetch functions for different blocking behaviors
- Loading branch information
1 parent
1df529d
commit 3b111e4
Showing
4 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use pps_time::{pps, PpsDevice}; | ||
use std::path::PathBuf; | ||
|
||
/// A simple PPS demo program | ||
/// | ||
/// Build with `cargo build --package pps-time --example non_blocking` | ||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 2 { | ||
println!("Example usage:"); | ||
println!("$ sudo ./target/debug/examples/non_blocking /dev/pps0"); | ||
return; | ||
} | ||
|
||
let path = PathBuf::from(&args[1]); // path to PPS device | ||
|
||
println!("Opening PPS device {}", path.display()); | ||
let pps = PpsDevice::new(path).expect("Could not open file!"); | ||
|
||
let capabilities = pps.get_cap().expect("Could not get capabilities!"); | ||
println!("Capabilities: {:#x}", capabilities); | ||
|
||
let mut params = pps.get_params().expect("Could not get params!"); | ||
println!("{:?}", params); | ||
|
||
// Turn on CAPTUREASSERT if available | ||
if capabilities & pps::PPS_CAPTUREASSERT != 0 { | ||
params.mode |= pps::PPS_CAPTUREASSERT as i32; | ||
} else { | ||
println!("Cannot CAPTUREASSERT"); | ||
} | ||
// Turn on CAPTURECLEAR if available | ||
if capabilities & pps::PPS_CAPTURECLEAR != 0 { | ||
params.mode |= pps::PPS_CAPTURECLEAR as i32; | ||
} else { | ||
println!("Cannot CAPTURECLEAR"); | ||
} | ||
|
||
pps.set_params(&mut params).expect("Could not set params!"); | ||
|
||
loop { | ||
let data = pps.fetch_non_blocking().expect("Could not fetch!"); | ||
println!("{:#?}", data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use pps_time::{pps, PpsDevice}; | ||
use std::path::PathBuf; | ||
|
||
/// A simple PPS demo program | ||
/// | ||
/// Build with `cargo build --package pps-time --example timeout` | ||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 2 { | ||
println!("Example usage:"); | ||
println!("$ sudo ./target/debug/examples/timeout /dev/pps0"); | ||
return; | ||
} | ||
|
||
let path = PathBuf::from(&args[1]); // path to PPS device | ||
|
||
println!("Opening PPS device {}", path.display()); | ||
let pps = PpsDevice::new(path).expect("Could not open file!"); | ||
|
||
let capabilities = pps.get_cap().expect("Could not get capabilities!"); | ||
println!("Capabilities: {:#x}", capabilities); | ||
|
||
let mut params = pps.get_params().expect("Could not get params!"); | ||
println!("{:?}", params); | ||
|
||
// Turn on CAPTUREASSERT if available | ||
if capabilities & pps::PPS_CAPTUREASSERT != 0 { | ||
params.mode |= pps::PPS_CAPTUREASSERT as i32; | ||
} else { | ||
println!("Cannot CAPTUREASSERT"); | ||
} | ||
// Turn on CAPTURECLEAR if available | ||
if capabilities & pps::PPS_CAPTURECLEAR != 0 { | ||
params.mode |= pps::PPS_CAPTURECLEAR as i32; | ||
} else { | ||
println!("Cannot CAPTURECLEAR"); | ||
} | ||
|
||
pps.set_params(&mut params).expect("Could not set params!"); | ||
|
||
loop { | ||
let data = pps.fetch_timeout(0, 500_000_000); | ||
println!("{:#?}", data); // half of these should be timeouts for 1PPS devices | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters