Add additional CLI arguments, serial fallback
All checks were successful
Basic Cargo Checks / docker-check (push) Successful in 1m53s
Basic Cargo Checks / docker-build (push) Successful in 2m10s

This commit is contained in:
Blizzard Finnegan 2023-06-20 09:43:04 -04:00
parent 31a4da2773
commit 10606b14ed
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
2 changed files with 37 additions and 9 deletions

View file

@ -346,7 +346,7 @@ impl Device{
} }
return true return true
} }
pub fn set_serial(&mut self) -> &mut Self{ pub fn auto_set_serial(&mut self) -> bool{
self.reboot(); self.reboot();
self.usb_tty.write_to_device(Command::Login); self.usb_tty.write_to_device(Command::Login);
while self.usb_tty.read_from_device(None) != Response::ShellPrompt {} while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}
@ -368,7 +368,7 @@ impl Device{
Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; } Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; }
_ => { _ => {
log::error!("Bad value: {:?}",return_value); log::error!("Bad value: {:?}",return_value);
todo!(); return false
}, },
} }
} }
@ -378,9 +378,15 @@ impl Device{
self.reboot(); self.reboot();
self.load_values(); self.load_values();
self.save_values(); self.save_values();
return true
}
pub fn manual_set_serial(&mut self, serial:&str) -> &mut Self{
self.serial = serial.to_string();
self.load_values();
self.save_values();
return self; return self;
} }
pub fn get_serial(&mut self) -> &str{ pub fn get_serial(&self) -> &str{
&self.serial &self.serial
} }
pub fn get_location(&mut self) -> String{ pub fn get_location(&mut self) -> String{

View file

@ -11,11 +11,22 @@ use clap::Parser;
#[derive(Parser,Debug)] #[derive(Parser,Debug)]
#[command(author,version,about)] #[command(author,version,about)]
struct Args{ struct Args{
/// Print all logs to screen. Sets iteration count to 50000
#[arg(short,long,action)] #[arg(short,long,action)]
debug:bool debug:bool,
/// Force manually setting serial numbers
#[arg(short,long,action)]
manual:bool,
/// Set iteration count from command line
#[arg(short,long)]
iterations:Option<u64>
} }
const VERSION:&str="2.3.0"; const VERSION:&str="2.3.0";
const DEBUG_ITERATION_COUNT:u64=50000;
fn int_input_filtering(prompt:Option<&str>) -> u64{ fn int_input_filtering(prompt:Option<&str>) -> u64{
let internal_prompt = prompt.unwrap_or(">>>"); let internal_prompt = prompt.unwrap_or(">>>");
@ -58,7 +69,10 @@ fn main(){
loop{ loop{
let mut iteration_count:u64 = 0; let mut iteration_count:u64 = 0;
if args.debug { if args.debug {
iteration_count = 10000; iteration_count = DEBUG_ITERATION_COUNT;
}
else if let Some(value) = args.iterations{
iteration_count = value;
} }
else { else {
while iteration_count < 1{ while iteration_count < 1{
@ -91,7 +105,9 @@ fn main(){
match new_device{ match new_device{
Ok(mut device) => { Ok(mut device) => {
device.darken_screen(); device.darken_screen();
device.set_serial(); if !args.manual {
device.auto_set_serial();
}
Some(device) Some(device)
}, },
Err(_) => None Err(_) => None
@ -114,9 +130,13 @@ fn main(){
possible_devices.push(output); possible_devices.push(output);
} }
let mut serials_set:bool = true;
let mut devices:Vec<Device> = Vec::new(); let mut devices:Vec<Device> = Vec::new();
for possible_device in possible_devices.into_iter(){ for possible_device in possible_devices.into_iter(){
if let Some(device) = possible_device{ if let Some(device) = possible_device{
if device.get_serial().eq("uninitialised"){
serials_set = false;
}
devices.push(device); devices.push(device);
} }
} }
@ -126,9 +146,11 @@ fn main(){
log::info!("--------------------------------------\n\n"); log::info!("--------------------------------------\n\n");
for device in devices.iter_mut(){ for device in devices.iter_mut(){
//device.brighten_screen(); if !serials_set || args.manual {
//device.set_serial(); device.brighten_screen();
//device.darken_screen(); device.manual_set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string());
device.darken_screen();
}
log::info!("Checking probe well of device {}",device.get_serial()); log::info!("Checking probe well of device {}",device.get_serial());
log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len()); log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len());
if !find_gpio(device, gpio){ if !find_gpio(device, gpio){