Skip to content

Commit 4da45e2

Browse files
committed
Add command to monitor DTX events
1 parent 97054fc commit 4da45e2

File tree

4 files changed

+397
-101
lines changed

4 files changed

+397
-101
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ indoc = "1.0.3"
1717
nix = "0.20.0"
1818
thiserror = "1.0.24"
1919
anyhow = "1.0.38"
20+
smallvec = "1.6.1"
2021

2122
[build-dependencies]
2223
clap = "2.33.3"
2324
indoc = "1.0.3"
2425
nix = "0.20.0"
2526
thiserror = "1.0.24"
2627
anyhow = "1.0.38"
28+
smallvec = "1.6.1"
2729

2830
[profile.release]
2931
lto = true

src/cli/dtx.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ impl DynCommand for Command {
4444
.subcommand(SubCommand::with_name("get-latchstatus")
4545
.about("Query the current latch status")
4646
.display_order(9))
47+
.subcommand(SubCommand::with_name("monitor")
48+
.about("Monitor DTX events")
49+
.display_order(10))
4750
}
4851

4952
fn execute(&self, m: &clap::ArgMatches) -> Result<()> {
@@ -57,6 +60,7 @@ impl DynCommand for Command {
5760
("get-base", Some(m)) => self.get_base_info(m),
5861
("get-devicemode", Some(m)) => self.get_device_mode(m),
5962
("get-latchstatus", Some(m)) => self.get_latch_status(m),
63+
("monitor", Some(m)) => self.monitor(m),
6064
_ => unreachable!(),
6165
}
6266
}
@@ -193,4 +197,22 @@ impl Command {
193197

194198
Ok(())
195199
}
200+
201+
fn monitor(&self, _m: &clap::ArgMatches) -> Result<()> {
202+
let mut device = sys::dtx::Device::open()
203+
.context("Failed to open DTX device")?;
204+
205+
let events = device.events()
206+
.context("Failed to set up event stream")?;
207+
208+
for event in events {
209+
let event = event
210+
.map_err(|source| sys::Error::IoError { source })
211+
.context("Error reading event")?;
212+
213+
println!("{:?}", event);
214+
}
215+
216+
Ok(())
217+
}
196218
}

0 commit comments

Comments
 (0)