|
|
|
@ -92,22 +92,8 @@ impl AppConfig for Config { |
|
|
|
|
clap::Arg::with_name("cycle") |
|
|
|
|
.long("cycle") |
|
|
|
|
.short("C") |
|
|
|
|
.value_name("MILLIS") |
|
|
|
|
.help("Cycle time (ms)") |
|
|
|
|
.validator(|s| { |
|
|
|
|
let t = s.trim(); |
|
|
|
|
if t.is_empty() { |
|
|
|
|
Err("cycle time requires an argument".into()) |
|
|
|
|
} else { |
|
|
|
|
if t.chars() |
|
|
|
|
.find(|c| !c.is_ascii_digit()) |
|
|
|
|
.is_some() { |
|
|
|
|
Err("cycle time requires an integer number".into()) |
|
|
|
|
} else { |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.value_name("MICROS") |
|
|
|
|
.help("Cycle time (us, append \"s\" or \"ms\" for coarser time)") |
|
|
|
|
.takes_value(true), |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -115,8 +101,23 @@ impl AppConfig for Config { |
|
|
|
|
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> { |
|
|
|
|
self.program_file = clap.value_of("input").unwrap().to_string(); |
|
|
|
|
self.assemble_only = clap.is_present("asm-only"); |
|
|
|
|
if let Some(c) = clap.value_of("cycle") { |
|
|
|
|
self.cycle_time = Duration::from_millis(c.parse().unwrap()); |
|
|
|
|
if let Some(t) = clap.value_of("cycle") { |
|
|
|
|
let (t, mul) = if t.ends_with("us") { |
|
|
|
|
(&t[..(t.len()-2)], 1) |
|
|
|
|
} else if t.ends_with("ms") { |
|
|
|
|
(&t[..(t.len()-2)], 1000) |
|
|
|
|
} else if t.ends_with("m") { |
|
|
|
|
(&t[..(t.len()-1)], 1000) |
|
|
|
|
} else if t.ends_with("u") { |
|
|
|
|
(&t[..(t.len()-1)], 1) |
|
|
|
|
} else if t.ends_with("s") { |
|
|
|
|
(&t[..(t.len()-1)], 1000_000) |
|
|
|
|
} else { |
|
|
|
|
(t, 1) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
self.cycle_time = Duration::from_micros(t.parse::<u64>().expect("parse -C value") * mul); |
|
|
|
|
println!("ct = {:?}", self.cycle_time); |
|
|
|
|
} |
|
|
|
|
Ok(self) |
|
|
|
|
} |
|
|
|
|