From b2853bf55d8af1c71c89a46b5a416f14a2aae455 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Fri, 20 Oct 2023 13:27:05 -0700 Subject: [PATCH] add: FlasherInfoRs.info() to print info like bossac --info --- examples/uid.rs | 3 ++ src/lib.rs | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/examples/uid.rs b/examples/uid.rs index 7e2bb69..bd8a412 100644 --- a/examples/uid.rs +++ b/examples/uid.rs @@ -36,5 +36,8 @@ pub fn main() -> std::process::ExitCode { println!("{:#?}", info); println!("Unique Id: {}", info.unique_id()); + // Print FlasherInfoRs info + println!("{}", info.info()); + std::process::ExitCode::SUCCESS } diff --git a/src/lib.rs b/src/lib.rs index 6d1051f..c2e7998 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,4 +161,140 @@ impl lib::FlasherInfoRs { } id } + + /// Info as the same format bossa prints + pub fn info(&self) -> String { + let mut out = String::new(); + let align = 12; + out.push_str( + format!( + "{key: String { + let mut out = String::new(); + let mut any_locked = false; + for (i, locked) in self.lockRegions.iter().enumerate() { + if *locked { + if !any_locked { + any_locked = true; + out.push_str(format!("{}", i).as_str()); + } else { + out.push_str(format!(",{}", i).as_str()); + } + } + } + + // No regions locked + if !any_locked { + out = "none".to_string(); + } + out + } }