Debian Codegraph @

examples/blocking.rs

raw symbols SCIP
1 use pps_timerust-analyzer cargo pps-time 0.2.3 crate/::{ppsrust-analyzer cargo pps-time 0.2.3 pps/, PpsDevicerust-analyzer cargo pps-time 0.2.3 PpsDevice#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#;
3
4 /// A simple PPS demo program
5 ///
6 /// Build with `cargo build --package pps-time --example blocking`
7 fn mainrust-analyzer cargo pps-time 0.2.3 main().() {
8 let args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
9 if args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 {
10 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Example usage:");
11 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("$ sudo ./target/debug/examples/blocking /dev/pps0");
12 return;
13 }
14
15 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(&args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); // path to PPS device
16
17 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Opening PPS device {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
18 let pps = PpsDevicerust-analyzer cargo pps-time 0.2.3 PpsDevice#::newrust-analyzer cargo pps-time 0.2.3 impl#[PpsDevice]new().(path).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Could not open file!");
19
20 let capabilities = pps.get_caprust-analyzer cargo pps-time 0.2.3 impl#[PpsDevice]get_cap().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Could not get capabilities!");
21 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Capabilities: {:#x}", capabilities);
22
23 let mut params = pps.get_paramsrust-analyzer cargo pps-time 0.2.3 impl#[PpsDevice]get_params().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Could not get params!");
24 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", params);
25
26 // Turn on CAPTUREASSERT if available
27 if capabilities rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().ppsrust-analyzer cargo pps-time 0.2.3 pps/::PPS_CAPTUREASSERTrust-analyzer cargo pps-time 0.2.3 pps/PPS_CAPTUREASSERT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0 {
28 params.moderust-analyzer cargo pps-time 0.2.3 pps/pps_kparams#mode. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().ppsrust-analyzer cargo pps-time 0.2.3 pps/::PPS_CAPTUREASSERTrust-analyzer cargo pps-time 0.2.3 pps/PPS_CAPTUREASSERT. as i32;
29 } else {
30 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Cannot CAPTUREASSERT");
31 }
32 // Turn on CAPTURECLEAR if available
33 if capabilities rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().ppsrust-analyzer cargo pps-time 0.2.3 pps/::PPS_CAPTURECLEARrust-analyzer cargo pps-time 0.2.3 pps/PPS_CAPTURECLEAR. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0 {
34 params.moderust-analyzer cargo pps-time 0.2.3 pps/pps_kparams#mode. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().ppsrust-analyzer cargo pps-time 0.2.3 pps/::PPS_CAPTURECLEARrust-analyzer cargo pps-time 0.2.3 pps/PPS_CAPTURECLEAR. as i32;
35 } else {
36 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Cannot CAPTURECLEAR");
37 }
38
39 pps.set_paramsrust-analyzer cargo pps-time 0.2.3 impl#[PpsDevice]set_params().(&mut params).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Could not set params!");
40
41 if capabilities rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().ppsrust-analyzer cargo pps-time 0.2.3 pps/::PPS_CANWAITrust-analyzer cargo pps-time 0.2.3 pps/PPS_CANWAIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 {
42 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Cannot CANWAIT");
43 return;
44 }
45
46 loop {
47 let data = pps.fetch_blockingrust-analyzer cargo pps-time 0.2.3 impl#[PpsDevice]fetch_blocking().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Could not fetch!");
48 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:#?}", data);
49 }
50 }