Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit fc04180

Browse files
author
Alex Helfet
committed
Accept a stimulus port from the command line.
1 parent 33aa229 commit fc04180

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/bin/itmdump.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,29 @@ fn main() {
7878
fn run() -> Result<()> {
7979
let matches = App::new("itmdump")
8080
.version(include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")))
81-
.arg(Arg::with_name("PATH").help("Named pipe to use").required(true))
81+
.arg(Arg::with_name("PATH")
82+
.help("Named pipe to use")
83+
.required(true))
84+
.arg(Arg::with_name("port")
85+
.long("stimulus")
86+
.short("s")
87+
.help("Stimulus port to extract ITM data for.")
88+
.takes_value(true)
89+
.default_value("0")
90+
.validator(|s| match s.parse::<u8>() {
91+
Ok(_) => Ok(()),
92+
Err(e) => Err(e.to_string())
93+
}))
8294
.get_matches();
8395

8496
let pipe = PathBuf::from(matches.value_of("PATH").unwrap());
8597
let pipe_ = pipe.display();
8698

99+
let stim_port = matches.value_of("port")
100+
.unwrap() // We supplied a default value
101+
.parse::<u8>()
102+
.expect("Arg validator should ensure this parses");
103+
87104
if pipe.exists() {
88105
try!(fs::remove_file(&pipe)
89106
.chain_err(|| format!("couldn't remove {}", pipe_)));
@@ -130,8 +147,8 @@ fn run() -> Result<()> {
130147
try!(stream.read_exact(ref_slice_mut(&mut header)));
131148
let port = header >> 3;
132149

133-
// Ignore all the packets that don't come from the stimulus port 0
134-
if port != 0 {
150+
// Ignore packets not from the chosen stimulus port
151+
if port != stim_port {
135152
return Ok(());
136153
}
137154

0 commit comments

Comments
 (0)