Add looping option for main loop, if successful
This commit is contained in:
parent
39a5feff0f
commit
7fda440641
1 changed files with 93 additions and 88 deletions
181
src/main.rs
181
src/main.rs
|
@ -1,5 +1,10 @@
|
||||||
use seymour_poc_rust::{device::Device, tty::{self,TTY,Response},gpio_facade::GpioPins};
|
use seymour_poc_rust::{device::Device,
|
||||||
use std::{io::{stdin,stdout,Write},thread::{self, JoinHandle},path::Path,fs};
|
tty::{self,TTY,Response},
|
||||||
|
gpio_facade::GpioPins};
|
||||||
|
use std::{io::{stdin,stdout,Write},
|
||||||
|
thread::{self, JoinHandle},
|
||||||
|
path::Path,
|
||||||
|
fs};
|
||||||
use chrono::{DateTime,Local};
|
use chrono::{DateTime,Local};
|
||||||
|
|
||||||
const VERSION:&str="2.0.1";
|
const VERSION:&str="2.0.1";
|
||||||
|
@ -38,102 +43,102 @@ fn input_filtering(prompt:Option<&str>) -> String{
|
||||||
fn main(){
|
fn main(){
|
||||||
setup_logs();
|
setup_logs();
|
||||||
log::info!("Seymour Life Testing version: {}",VERSION);
|
log::info!("Seymour Life Testing version: {}",VERSION);
|
||||||
let gpio = &mut GpioPins::new();
|
loop{
|
||||||
match std::fs::read_dir("/dev/serial/by-path"){
|
let gpio = &mut GpioPins::new();
|
||||||
Ok(available_ttys)=>{
|
match std::fs::read_dir("/dev/serial/by-path"){
|
||||||
let mut possible_devices:Vec<Option<Device>> = Vec::new();
|
Ok(available_ttys)=>{
|
||||||
let mut tty_test_threads:Vec<JoinHandle<Option<Device>>> = Vec::new();
|
let mut possible_devices:Vec<Option<Device>> = Vec::new();
|
||||||
for possible_tty in available_ttys.into_iter(){
|
let mut tty_test_threads:Vec<JoinHandle<Option<Device>>> = Vec::new();
|
||||||
tty_test_threads.push(
|
for possible_tty in available_ttys.into_iter(){
|
||||||
thread::spawn(move ||{
|
tty_test_threads.push(
|
||||||
let tty_ref = possible_tty.as_ref();
|
thread::spawn(move ||{
|
||||||
match tty_ref{
|
let tty_ref = possible_tty.as_ref();
|
||||||
Ok(tty_real_ref)=>{
|
match tty_ref{
|
||||||
let tty_path = tty_real_ref.path();
|
Ok(tty_real_ref)=>{
|
||||||
let tty_name = tty_path.to_string_lossy();
|
let tty_path = tty_real_ref.path();
|
||||||
log::info!("Testing port {}. This may take a moment...",&tty_name);
|
let tty_name = tty_path.to_string_lossy();
|
||||||
let possible_port = TTY::new(&tty_name);
|
log::info!("Testing port {}. This may take a moment...",&tty_name);
|
||||||
match possible_port{
|
let possible_port = TTY::new(&tty_name);
|
||||||
Some(mut port) =>{
|
match possible_port{
|
||||||
port.write_to_device(tty::Command::Newline);
|
Some(mut port) =>{
|
||||||
let response = port.read_from_device(Some(":"));
|
port.write_to_device(tty::Command::Newline);
|
||||||
if response != Response::Empty{
|
let response = port.read_from_device(Some(":"));
|
||||||
log::debug!("{} is valid port!",tty_name);
|
if response != Response::Empty{
|
||||||
let new_device = Device::new(port,Some(response));
|
log::debug!("{} is valid port!",tty_name);
|
||||||
match new_device{
|
let new_device = Device::new(port,Some(response));
|
||||||
Ok(mut device) => {
|
match new_device{
|
||||||
device.darken_screen();
|
Ok(mut device) => {
|
||||||
Some(device)
|
device.darken_screen();
|
||||||
},
|
Some(device)
|
||||||
Err(_) => None
|
},
|
||||||
|
Err(_) => None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else { None }
|
||||||
else { None }
|
},
|
||||||
},
|
None=>{None}
|
||||||
None=>{None}
|
}
|
||||||
|
},
|
||||||
|
Err(error)=>{
|
||||||
|
log::debug!("{}",error);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(error)=>{
|
|
||||||
log::debug!("{}",error);
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
}));
|
|
||||||
}
|
|
||||||
for thread in tty_test_threads{
|
|
||||||
let output = thread.join().unwrap_or_else(|x|{log::trace!("{:?}",x); None});
|
|
||||||
possible_devices.push(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut devices:Vec<Device> = Vec::new();
|
|
||||||
for possible_device in possible_devices.into_iter(){
|
|
||||||
if let Some(device) = possible_device{
|
|
||||||
devices.push(device);
|
|
||||||
}
|
}
|
||||||
}
|
for thread in tty_test_threads{
|
||||||
|
let output = thread.join().unwrap_or_else(|x|{log::trace!("{:?}",x); None});
|
||||||
log::info!("\n\n--------------------------------------");
|
possible_devices.push(output);
|
||||||
log::info!("Number of devices detected: {}",devices.len());
|
|
||||||
log::info!("--------------------------------------\n\n");
|
|
||||||
|
|
||||||
//log::info!("Dimming all screens...");
|
|
||||||
//for device in devices.iter_mut(){
|
|
||||||
// device.darken_screen();
|
|
||||||
//}
|
|
||||||
|
|
||||||
for device in devices.iter_mut(){
|
|
||||||
device.brighten_screen()
|
|
||||||
.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string())
|
|
||||||
.darken_screen();
|
|
||||||
log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len());
|
|
||||||
if !find_gpio(device, gpio){
|
|
||||||
device.set_pin_address(21);
|
|
||||||
log::error!("Unable to find GPIO for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_location());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut iteration_count:u64 = 0;
|
let mut devices:Vec<Device> = Vec::new();
|
||||||
while iteration_count < 1{
|
for possible_device in possible_devices.into_iter(){
|
||||||
iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: "));
|
if let Some(device) = possible_device{
|
||||||
}
|
devices.push(device);
|
||||||
|
|
||||||
let mut iteration_threads = Vec::new();
|
|
||||||
while let Some(mut device) = devices.pop(){
|
|
||||||
iteration_threads.push(thread::spawn(move||{
|
|
||||||
for i in 1..=iteration_count{
|
|
||||||
log::info!("Starting iteration {} of {} for device {}...",
|
|
||||||
i,iteration_count,device.get_serial());
|
|
||||||
device.test_cycle(None, None);
|
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
|
||||||
|
log::info!("\n\n--------------------------------------");
|
||||||
|
log::info!("Number of devices detected: {}",devices.len());
|
||||||
|
log::info!("--------------------------------------\n\n");
|
||||||
|
|
||||||
|
for device in devices.iter_mut(){
|
||||||
|
device.brighten_screen()
|
||||||
|
.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string())
|
||||||
|
.darken_screen();
|
||||||
|
log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len());
|
||||||
|
if !find_gpio(device, gpio){
|
||||||
|
device.set_pin_address(21);
|
||||||
|
log::error!("Unable to find GPIO for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_location());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut iteration_count:u64 = 0;
|
||||||
|
while iteration_count < 1{
|
||||||
|
iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: "));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut iteration_threads = Vec::new();
|
||||||
|
while let Some(mut device) = devices.pop(){
|
||||||
|
iteration_threads.push(thread::spawn(move||{
|
||||||
|
for i in 1..=iteration_count{
|
||||||
|
log::info!("Starting iteration {} of {} for device {}...",
|
||||||
|
i,iteration_count,device.get_serial());
|
||||||
|
device.test_cycle(None, None);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for thread in iteration_threads{
|
||||||
|
thread.join().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for thread in iteration_threads{
|
Err(_)=>{
|
||||||
thread.join().unwrap();
|
log::error!("Invalid serial location! Please make sure that /dev/serial/by-path exists.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_)=>{
|
if input_filtering(Some("Would you like to run the tests again? (y/N): ")).to_string().contains("y") {}
|
||||||
log::error!("Invalid serial location! Please make sure that /dev/serial/by-path exists.");
|
else { break; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue