Merge pull request 'v2.3.0' () from devel into stable

Reviewed-on: 
This commit is contained in:
Blizzard Finnegan 2023-06-19 15:34:17 -04:00
commit 31a4da2773
6 changed files with 85 additions and 50 deletions

2
Cargo.lock generated
View file

@ -639,7 +639,7 @@ dependencies = [
[[package]]
name = "seymour_life_rust"
version = "2.2.0"
version = "2.3.0"
dependencies = [
"chrono",
"clap",

View file

@ -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

View file

@ -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

View file

@ -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,36 @@ 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);
loop{
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::<Vec<&str>>(){
if !line.contains(':') { continue; }
let (section,value) = line.split_once(':').unwrap();
if section.contains(SERIAL_HEADER){
self.serial = value.trim().replace("\"","");
}
}
log::info!("Serial found for device {}",self.serial);
break;
},
Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; }
_ => {
log::error!("Bad value: {:?}",return_value);
todo!();
},
}
}
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();
return self;
@ -405,14 +434,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 +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
@ -436,7 +465,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 +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
@ -464,7 +493,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

View file

@ -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(">>>");
@ -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)=>{
@ -81,6 +91,7 @@ fn main(){
match new_device{
Ok(mut device) => {
device.darken_screen();
device.set_serial();
Some(device)
},
Err(_) => None
@ -115,30 +126,16 @@ 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::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 {}. 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;
if args.debug {
iteration_count = 10000;
}
else {
while iteration_count < 1{
iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: "));
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;
}
}

View file

@ -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<u64>),
LoginPrompt,
DebugMenu,
Rebooting,
@ -44,6 +48,7 @@ pub enum Response{
PreShellPrompt,
EmptyNewline,
DebugInit,
Serial(Option<String>),
}
@ -62,21 +67,23 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = 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),
("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),
("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::<u64>(){
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);