Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: recognize information about chip based on image #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ edition = "2018"

[dependencies]
anyhow = "*"
bardecoder = "*"
clap = "*"
clap-nested = "*"
dirs = "*"
image = "*"
json = "*"
md5 = "*"
num_cpus = "*"
Expand Down
47 changes: 47 additions & 0 deletions src/chip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use clap::Arg;
use clap_nested::{Command, Commander, MultiCommand};

fn get_identify_runner(_args: &str, matches: &clap::ArgMatches<'_>) -> std::result::Result<(), clap::Error> {
let image_file = matches.value_of("image").unwrap().to_string();

println!("Decoding: {}", image_file);
let img = image::open(image_file).unwrap();

// Use default decoder
let decoder = bardecoder::default_decoder();

let results = decoder.decode(&img);

for result in results {
println!("{}", result.unwrap());
}

Ok(())
}


pub fn get_indentify_cmd<'a>() -> Command<'a, str> {
Command::new("identify")
.description("Identify chip")
.options(|app| {
app.arg(
Arg::with_name("image")
.short("i")
.long("image")
.help("Picture file with chip")
.takes_value(true)
)
})
.runner(|_args, matches| get_identify_runner(_args, matches) )
}

pub fn get_multi_cmd<'a>() -> MultiCommand<'a, str, str> {
let multi_cmd: MultiCommand<str, str> = Commander::new()
.add_cmd(get_indentify_cmd())
.into_cmd("chip")

// Optionally specify a description
.description("Identify chip");

return multi_cmd;
}
2 changes: 2 additions & 0 deletions src/idf_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod idf;
mod launcher;
mod package;
mod shell;
mod chip;

async fn app() -> Result<()> {
Commander::new()
Expand All @@ -25,6 +26,7 @@ async fn app() -> Result<()> {
})
.args(|_args, matches| matches.value_of("environment").unwrap_or("dev"))
.add_cmd(antivirus::get_multi_cmd())
.add_cmd(chip::get_multi_cmd())
.add_cmd(companion::get_multi_cmd())
.add_cmd(config::get_multi_cmd())
.add_cmd(driver::get_multi_cmd())
Expand Down