From f1a4b4b251124b98e1f610e04fd8e986d68d400f Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 13:42:26 -0400 Subject: [PATCH 01/12] Add notes for auto-serial check --- notes.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/notes.md b/notes.md index 9c5d16e..db3d9d9 100644 --- a/notes.md +++ b/notes.md @@ -1,8 +1,7 @@ -Boot time isn't static. -Boot time can (in theory) be sped up by forcing a clearing of the screen of all vitals before rebooting. -Clearing the screen of all vitals is theoretically possible in the UI menu, with a Spoof Touch, but I don't know the object name of the 'clear' button. +Auto-serial: -Can check for reboot completed by reading in serial, check for `reboot: Restarting System` -once done, read for `login:` - -First command sent to shell gets dropped (possibly due to timing issue?) +`echo 'y1q' | python3 -m debugmenu` contains the serial number. Search keyword is: "DtCtrlCfgDeviceSerialNum" +split on `\n`, collect into Vec<&str>. Iterate over Vec: + if doesn't contain colon, continue + split_once on colon + if first half is keyword, trim second half, remove `"` characters, save as serial -- 2.45.3 From 9a7700dee4d5f22f1c446ea7d4abc4e43d16ff9f Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:16:14 -0400 Subject: [PATCH 02/12] First rough shot at using built-in serial --- src/device.rs | 36 +++++++++++++++++++++++++++--------- src/main.rs | 17 ++++++----------- src/tty.rs | 30 ++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src/device.rs b/src/device.rs index 5f07a5d..076aaf8 100755 --- a/src/device.rs +++ b/src/device.rs @@ -8,6 +8,7 @@ const BP_SECTION: &str = "Successful BP tests: "; const TEMP_SECTION: &str = "Successful temp tests: "; const OUTPUT_FOLDER: &str = "output/"; const UNINITIALISED_SERIAL: &str = "uninitialised"; +const SERIAL_HEADER: &str = "DtCtrlCfgDeviceSerialNum"; #[derive(PartialEq,Debug)] pub enum State{ Shutdown, @@ -130,7 +131,7 @@ impl Device{ } }; }, - Response::EmptyNewline => { + Response::Serial(_) | Response::EmptyNewline => { log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); return Err("Failed TTY init. Unknown state, cannot trust.".to_string()); }, @@ -345,8 +346,25 @@ impl Device{ } return true } - pub fn set_serial(&mut self, serial:&str) -> &mut Self{ - self.serial = serial.to_string(); + pub fn set_serial(&mut self) -> &mut Self{ + self.reboot(); + self.usb_tty.write_to_device(Command::Login); + while self.usb_tty.read_from_device(None) != Response::ShellPrompt {} + self.usb_tty.write_to_device(Command::GetSerial); + match self.usb_tty.read_from_device(None){ + Response::Serial(Some(contains_serial)) =>{ + for line in contains_serial.split("\n").collect::>(){ + if !line.contains(':') { continue; } + let (section,value) = line.split_once(':').unwrap(); + if section.contains(SERIAL_HEADER){ + self.serial = value.replace("\"",""); + } + } + }, + _ => todo!(), + } + self.reboot(); + //self.serial = serial.to_string(); self.load_values(); self.save_values(); return self; @@ -405,14 +423,14 @@ impl Device{ self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10 { match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => return count != self.init_temps , + Response::TempCount(Some(count)) => return count != self.init_temps , _ => {}, } } self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10{ match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => return count != self.init_temps , + Response::TempCount(Some(count)) => return count != self.init_temps , _ => {}, } } @@ -425,7 +443,7 @@ impl Device{ self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10 { match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => { + Response::TempCount(Some(count)) => { log::trace!("Count for device {} updated to {}",self.serial,count); self.temps = count; return count @@ -436,7 +454,7 @@ impl Device{ self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10{ match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => { + Response::TempCount(Some(count)) => { log::trace!("Count for device {} updated to {}",self.serial,count); self.temps = count; return count @@ -453,7 +471,7 @@ impl Device{ self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10 { match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => { + Response::TempCount(Some(count)) => { log::trace!("init temp count set to {} on device {}",count,self.serial); self.init_temps = count; return @@ -464,7 +482,7 @@ impl Device{ self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10{ match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => { + Response::TempCount(Some(count)) => { log::trace!("init temp count set to {} on device {}",count,self.serial); self.init_temps = count; return diff --git a/src/main.rs b/src/main.rs index 3505a67..665204b 100755 --- a/src/main.rs +++ b/src/main.rs @@ -115,20 +115,15 @@ fn main(){ log::info!("--------------------------------------\n\n"); for device in devices.iter_mut(){ - device.brighten_screen(); - if args.debug{ - let location = device.get_location(); - log::info!("Init device {}...", location); - device.set_serial(&location); - } - else{ - device.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string()); - } - device.darken_screen(); + //device.brighten_screen(); + device.set_serial(); + //device.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()); + log::error!("Unable to find GPIO for device with bright screen. Please ensure that the probe well is installed properly, and the calibration key is plugged in."); + device.brighten_screen(); + return; } } diff --git a/src/tty.rs b/src/tty.rs index 335f69f..d9156d5 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -1,4 +1,7 @@ -use std::{collections::HashMap, io::{BufReader, Write, Read}, time::Duration}; +use std::{collections::HashMap, + io::{BufReader, Write, Read}, + boxed::Box, + time::Duration}; use once_cell::sync::Lazy; use serialport::SerialPort; use derivative::Derivative; @@ -24,16 +27,17 @@ pub enum Command{ DebugMenu, Newline, Shutdown, + GetSerial, } #[derive(Clone,Eq,Derivative,Debug)] -#[derivative(Copy,PartialEq, Hash)] +#[derivative(PartialEq, Hash)] pub enum Response{ PasswordPrompt, ShellPrompt, BPOn, BPOff, - TempCount(u64), + TempCount(Option), LoginPrompt, DebugMenu, Rebooting, @@ -44,6 +48,7 @@ pub enum Response{ PreShellPrompt, EmptyNewline, DebugInit, + Serial(Option), } @@ -62,21 +67,23 @@ const COMMAND_MAP:Lazy> = Lazy::new(||HashMap::from([ (Command::DebugMenu," python3 -m debugmenu; shutdown -r now\n"), (Command::Newline,"\n"), (Command::Shutdown,"shutdown -r now\n"), + (Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"), ])); -const RESPONSES:[(&str,Response);12] = [ +const RESPONSES:[(&str,Response);13] = [ ("Last login:",Response::PreShellPrompt), ("reboot: Restarting",Response::Rebooting), ("command not found",Response::FailedDebugMenu), ("login:",Response::LoginPrompt), ("Password:",Response::PasswordPrompt), - ("EXIT Debug menu",Response::ShuttingDown), ("root@",Response::ShellPrompt), + ("DtCtrlCfgDeviceSerialNum",Response::Serial(None)), + ("EXIT Debug menu",Response::ShuttingDown), ("Check NIBP In Progress: True",Response::BPOn), ("Check NIBP In Progress: False",Response::BPOff), - ("SureTemp Probe Pulls:",Response::TempCount(0)), + ("SureTemp Probe Pulls:",Response::TempCount(None)), (">",Response::DebugMenu), - ("Loading App-Framework",Response::DebugInit) + ("Loading App-Framework",Response::DebugInit), ]; pub struct TTY{ @@ -144,7 +151,7 @@ impl TTY{ log::trace!("Successful read of {:?} from tty {}, which matches pattern {:?}",read_line,self.tty.name().unwrap_or("unknown shell".to_string()),enum_value); }; self.failed_read_count = 0; - if enum_value == Response::TempCount(0){ + if enum_value == Response::TempCount(None){ let mut lines = read_line.lines(); while let Some(single_line) = lines.next(){ if single_line.contains(string){ @@ -155,12 +162,12 @@ impl TTY{ match temp_count.trim().parse::(){ Err(_) => { log::error!("String {} from device {} unable to be parsed!",temp_count,self.tty.name().unwrap_or("unknown shell".to_string())); - return Response::TempCount(0) + return Response::TempCount(None) }, Ok(parsed_temp_count) => { //log::trace!("Header: {}",header); log::trace!("parsed temp count for device {}: {}",self.tty.name().unwrap_or("unknown shell".to_string()),temp_count); - return Response::TempCount(parsed_temp_count) + return Response::TempCount(Some(parsed_temp_count)) } } } @@ -168,6 +175,9 @@ impl TTY{ } } } + else if enum_value == Response::Serial(None) { + return Response::Serial(Some(read_line)); + } else if enum_value == Response::PasswordPrompt { log::error!("Recieved password prompt on device {}! Something fell apart here. Check preceeding log lines.",self.tty.name().unwrap_or("unknown shell".to_string())); self.write_to_device(Command::Newline); -- 2.45.3 From 3070e429451d2abe55352fca45779b1e4f317bf8 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:19:09 -0400 Subject: [PATCH 03/12] Remember to trim string to remove whitespace --- src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.rs b/src/device.rs index 076aaf8..8c117d3 100755 --- a/src/device.rs +++ b/src/device.rs @@ -357,7 +357,7 @@ impl Device{ if !line.contains(':') { continue; } let (section,value) = line.split_once(':').unwrap(); if section.contains(SERIAL_HEADER){ - self.serial = value.replace("\"",""); + self.serial = value.trim().replace("\"",""); } } }, -- 2.45.3 From ebda011bc7dbb0b87915d8a5a8b7d12294e83ba4 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:28:03 -0400 Subject: [PATCH 04/12] Add parsing for DebugInit --- src/device.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/device.rs b/src/device.rs index 8c117d3..0cf30b8 100755 --- a/src/device.rs +++ b/src/device.rs @@ -351,17 +351,21 @@ impl Device{ self.usb_tty.write_to_device(Command::Login); while self.usb_tty.read_from_device(None) != Response::ShellPrompt {} self.usb_tty.write_to_device(Command::GetSerial); - match self.usb_tty.read_from_device(None){ - Response::Serial(Some(contains_serial)) =>{ - for line in contains_serial.split("\n").collect::>(){ - if !line.contains(':') { continue; } - let (section,value) = line.split_once(':').unwrap(); - if section.contains(SERIAL_HEADER){ - self.serial = value.trim().replace("\"",""); + loop{ + match self.usb_tty.read_from_device(None){ + Response::Serial(Some(contains_serial)) =>{ + for line in contains_serial.split("\n").collect::>(){ + if !line.contains(':') { continue; } + let (section,value) = line.split_once(':').unwrap(); + if section.contains(SERIAL_HEADER){ + self.serial = value.trim().replace("\"",""); + } } - } - }, - _ => todo!(), + break; + }, + Response::DebugInit => { continue; } + _ => todo!(), + } } self.reboot(); //self.serial = serial.to_string(); -- 2.45.3 From 5773952538504d6ab03fa3cb79530ecfeb3282db Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:31:14 -0400 Subject: [PATCH 05/12] Multithread serial acquisition --- src/device.rs | 2 +- src/main.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index 0cf30b8..7f8acd5 100755 --- a/src/device.rs +++ b/src/device.rs @@ -361,6 +361,7 @@ impl Device{ self.serial = value.trim().replace("\"",""); } } + log::info!("Serial found for device {}",self.serial); break; }, Response::DebugInit => { continue; } @@ -368,7 +369,6 @@ impl Device{ } } self.reboot(); - //self.serial = serial.to_string(); self.load_values(); self.save_values(); return self; diff --git a/src/main.rs b/src/main.rs index 665204b..70ec3ec 100755 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,7 @@ fn main(){ match new_device{ Ok(mut device) => { device.darken_screen(); + device.set_serial(); Some(device) }, Err(_) => None @@ -116,7 +117,7 @@ fn main(){ for device in devices.iter_mut(){ //device.brighten_screen(); - device.set_serial(); + //device.set_serial(); //device.darken_screen(); log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len()); if !find_gpio(device, gpio){ -- 2.45.3 From 94cbba27cf8f20f945e2a886b6adef85daf295fc Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:35:09 -0400 Subject: [PATCH 06/12] Change priority of serial --- src/tty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tty.rs b/src/tty.rs index d9156d5..42a680c 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -76,8 +76,8 @@ const RESPONSES:[(&str,Response);13] = [ ("command not found",Response::FailedDebugMenu), ("login:",Response::LoginPrompt), ("Password:",Response::PasswordPrompt), - ("root@",Response::ShellPrompt), ("DtCtrlCfgDeviceSerialNum",Response::Serial(None)), + ("root@",Response::ShellPrompt), ("EXIT Debug menu",Response::ShuttingDown), ("Check NIBP In Progress: True",Response::BPOn), ("Check NIBP In Progress: False",Response::BPOff), -- 2.45.3 From d24b0edcb00b372cb03af9af24b88378aa468a86 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:45:58 -0400 Subject: [PATCH 07/12] Start debugging partial function --- src/device.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index 7f8acd5..2005a7e 100755 --- a/src/device.rs +++ b/src/device.rs @@ -352,7 +352,8 @@ impl Device{ while self.usb_tty.read_from_device(None) != Response::ShellPrompt {} self.usb_tty.write_to_device(Command::GetSerial); loop{ - match self.usb_tty.read_from_device(None){ + let return_value = self.usb_tty.read_from_device(None); + match return_value{ Response::Serial(Some(contains_serial)) =>{ for line in contains_serial.split("\n").collect::>(){ if !line.contains(':') { continue; } @@ -365,7 +366,10 @@ impl Device{ break; }, Response::DebugInit => { continue; } - _ => todo!(), + _ => { + log::error!("Bad value: {:?}",return_value); + todo!(); + }, } } self.reboot(); -- 2.45.3 From ab560b926a9559f7131e3f7d86250323a64609ae Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:47:28 -0400 Subject: [PATCH 08/12] Properly exit get_serial --- src/device.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/device.rs b/src/device.rs index 2005a7e..2787b54 100755 --- a/src/device.rs +++ b/src/device.rs @@ -372,6 +372,7 @@ impl Device{ }, } } + self.usb_tty.write_to_device(Command::DebugMenu); self.reboot(); self.load_values(); self.save_values(); -- 2.45.3 From 6280603232f8ce30b82f218c228ffa757dcd91db Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:52:24 -0400 Subject: [PATCH 09/12] Add parsing for blank lines --- src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.rs b/src/device.rs index 2787b54..5cc49a7 100755 --- a/src/device.rs +++ b/src/device.rs @@ -365,7 +365,7 @@ impl Device{ log::info!("Serial found for device {}",self.serial); break; }, - Response::DebugInit => { continue; } + Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; } _ => { log::error!("Bad value: {:?}",return_value); todo!(); -- 2.45.3 From f1d8af8e3d37e822102e7bfd819219ea497cc988 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 14:58:15 -0400 Subject: [PATCH 10/12] Add end handling --- src/device.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/device.rs b/src/device.rs index 5cc49a7..a0b2f78 100755 --- a/src/device.rs +++ b/src/device.rs @@ -373,6 +373,8 @@ impl Device{ } } self.usb_tty.write_to_device(Command::DebugMenu); + while self.usb_tty.read_from_device(None) != Response::DebugMenu {} + self.current_state = State::DebugMenu; self.reboot(); self.load_values(); self.save_values(); -- 2.45.3 From d522fac9b82607370758ae70b02015a3b34a8495 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 15:09:56 -0400 Subject: [PATCH 11/12] Move iteration count ask to beginning of loop --- src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70ec3ec..ff5ab88 100755 --- a/src/main.rs +++ b/src/main.rs @@ -56,6 +56,16 @@ fn main(){ log::debug!("Debug enabled!"); } loop{ + let mut iteration_count:u64 = 0; + if args.debug { + iteration_count = 10000; + } + else { + while iteration_count < 1{ + iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: ")); + } + } + let gpio = &mut GpioPins::new(); match std::fs::read_dir("/dev/serial/by-path"){ Ok(available_ttys)=>{ @@ -128,16 +138,6 @@ fn main(){ } } - let mut iteration_count:u64 = 0; - if args.debug { - iteration_count = 10000; - } - else { - 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||{ -- 2.45.3 From b935fdf043afd77ffce489de7b59b113bc2c8365 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 19 Jun 2023 15:18:40 -0400 Subject: [PATCH 12/12] Increase verbosity in initialisation Also, version number bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc445d8..a2c6c09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "seymour_life_rust" -version = "2.2.0" +version = "2.3.0" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index ab9d269..ddf2de1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "seymour_life_rust" -version = "2.2.0" +version = "2.3.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index ff5ab88..de52323 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ struct Args{ debug:bool } -const VERSION:&str="2.2.0"; +const VERSION:&str="2.3.0"; fn int_input_filtering(prompt:Option<&str>) -> u64{ let internal_prompt = prompt.unwrap_or(">>>"); @@ -129,10 +129,11 @@ fn main(){ //device.brighten_screen(); //device.set_serial(); //device.darken_screen(); + log::info!("Checking probe well of device {}",device.get_serial()); 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 with bright screen. Please ensure that the probe well is installed properly, and the calibration key is plugged in."); + log::error!("Unable to find probe-well for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_serial()); device.brighten_screen(); return; } -- 2.45.3