|
|
@ -92,22 +92,8 @@ impl AppConfig for Config { |
|
|
|
clap::Arg::with_name("cycle") |
|
|
|
clap::Arg::with_name("cycle") |
|
|
|
.long("cycle") |
|
|
|
.long("cycle") |
|
|
|
.short("C") |
|
|
|
.short("C") |
|
|
|
.value_name("MILLIS") |
|
|
|
.value_name("MICROS") |
|
|
|
.help("Cycle time (ms)") |
|
|
|
.help("Cycle time (us, append \"s\" or \"ms\" for coarser time)") |
|
|
|
.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(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.takes_value(true), |
|
|
|
.takes_value(true), |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -115,8 +101,23 @@ impl AppConfig for Config { |
|
|
|
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> { |
|
|
|
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> { |
|
|
|
self.program_file = clap.value_of("input").unwrap().to_string(); |
|
|
|
self.program_file = clap.value_of("input").unwrap().to_string(); |
|
|
|
self.assemble_only = clap.is_present("asm-only"); |
|
|
|
self.assemble_only = clap.is_present("asm-only"); |
|
|
|
if let Some(c) = clap.value_of("cycle") { |
|
|
|
if let Some(t) = clap.value_of("cycle") { |
|
|
|
self.cycle_time = Duration::from_millis(c.parse().unwrap()); |
|
|
|
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) |
|
|
|
Ok(self) |
|
|
|
} |
|
|
|
} |
|
|
|