First rough shot at using built-in serial
All checks were successful
Basic Cargo Checks / docker-build (push) Successful in 1m28s
Basic Cargo Checks / docker-check (push) Successful in 3m35s

This commit is contained in:
Blizzard Finnegan 2023-06-19 14:16:14 -04:00
parent 9c1d2ad049
commit 9a7700dee4
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
3 changed files with 53 additions and 30 deletions

View file

@ -8,6 +8,7 @@ const BP_SECTION: &str = "Successful BP tests: ";
const TEMP_SECTION: &str = "Successful temp tests: "; const TEMP_SECTION: &str = "Successful temp tests: ";
const OUTPUT_FOLDER: &str = "output/"; const OUTPUT_FOLDER: &str = "output/";
const UNINITIALISED_SERIAL: &str = "uninitialised"; const UNINITIALISED_SERIAL: &str = "uninitialised";
const SERIAL_HEADER: &str = "DtCtrlCfgDeviceSerialNum";
#[derive(PartialEq,Debug)] #[derive(PartialEq,Debug)]
pub enum State{ pub enum State{
Shutdown, Shutdown,
@ -130,7 +131,7 @@ impl Device{
} }
}; };
}, },
Response::EmptyNewline => { Response::Serial(_) | Response::EmptyNewline => {
log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port);
return Err("Failed TTY init. Unknown state, cannot trust.".to_string()); return Err("Failed TTY init. Unknown state, cannot trust.".to_string());
}, },
@ -345,8 +346,25 @@ impl Device{
} }
return true return true
} }
pub fn set_serial(&mut self, serial:&str) -> &mut Self{ pub fn set_serial(&mut self) -> &mut Self{
self.serial = serial.to_string(); 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::<Vec<&str>>(){
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.load_values();
self.save_values(); self.save_values();
return self; return self;
@ -405,14 +423,14 @@ impl Device{
self.usb_tty.write_to_device(Command::ReadTemp); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10 { for _ in 0..10 {
match self.usb_tty.read_from_device(None){ 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); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10{ for _ in 0..10{
match self.usb_tty.read_from_device(None){ 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); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10 { for _ in 0..10 {
match self.usb_tty.read_from_device(None){ 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); log::trace!("Count for device {} updated to {}",self.serial,count);
self.temps = count; self.temps = count;
return count return count
@ -436,7 +454,7 @@ impl Device{
self.usb_tty.write_to_device(Command::ReadTemp); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10{ for _ in 0..10{
match self.usb_tty.read_from_device(None){ 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); log::trace!("Count for device {} updated to {}",self.serial,count);
self.temps = count; self.temps = count;
return count return count
@ -453,7 +471,7 @@ impl Device{
self.usb_tty.write_to_device(Command::ReadTemp); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10 { for _ in 0..10 {
match self.usb_tty.read_from_device(None){ 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); log::trace!("init temp count set to {} on device {}",count,self.serial);
self.init_temps = count; self.init_temps = count;
return return
@ -464,7 +482,7 @@ impl Device{
self.usb_tty.write_to_device(Command::ReadTemp); self.usb_tty.write_to_device(Command::ReadTemp);
for _ in 0..10{ for _ in 0..10{
match self.usb_tty.read_from_device(None){ 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); log::trace!("init temp count set to {} on device {}",count,self.serial);
self.init_temps = count; self.init_temps = count;
return return

View file

@ -115,20 +115,15 @@ 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(); //device.brighten_screen();
if args.debug{ device.set_serial();
let location = device.get_location(); //device.darken_screen();
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();
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){
device.set_pin_address(21); 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;
} }
} }

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 once_cell::sync::Lazy;
use serialport::SerialPort; use serialport::SerialPort;
use derivative::Derivative; use derivative::Derivative;
@ -24,16 +27,17 @@ pub enum Command{
DebugMenu, DebugMenu,
Newline, Newline,
Shutdown, Shutdown,
GetSerial,
} }
#[derive(Clone,Eq,Derivative,Debug)] #[derive(Clone,Eq,Derivative,Debug)]
#[derivative(Copy,PartialEq, Hash)] #[derivative(PartialEq, Hash)]
pub enum Response{ pub enum Response{
PasswordPrompt, PasswordPrompt,
ShellPrompt, ShellPrompt,
BPOn, BPOn,
BPOff, BPOff,
TempCount(u64), TempCount(Option<u64>),
LoginPrompt, LoginPrompt,
DebugMenu, DebugMenu,
Rebooting, Rebooting,
@ -44,6 +48,7 @@ pub enum Response{
PreShellPrompt, PreShellPrompt,
EmptyNewline, EmptyNewline,
DebugInit, 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::DebugMenu," python3 -m debugmenu; shutdown -r now\n"),
(Command::Newline,"\n"), (Command::Newline,"\n"),
(Command::Shutdown,"shutdown -r now\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), ("Last login:",Response::PreShellPrompt),
("reboot: Restarting",Response::Rebooting), ("reboot: Restarting",Response::Rebooting),
("command not found",Response::FailedDebugMenu), ("command not found",Response::FailedDebugMenu),
("login:",Response::LoginPrompt), ("login:",Response::LoginPrompt),
("Password:",Response::PasswordPrompt), ("Password:",Response::PasswordPrompt),
("EXIT Debug menu",Response::ShuttingDown),
("root@",Response::ShellPrompt), ("root@",Response::ShellPrompt),
("DtCtrlCfgDeviceSerialNum",Response::Serial(None)),
("EXIT Debug menu",Response::ShuttingDown),
("Check NIBP In Progress: True",Response::BPOn), ("Check NIBP In Progress: True",Response::BPOn),
("Check NIBP In Progress: False",Response::BPOff), ("Check NIBP In Progress: False",Response::BPOff),
("SureTemp Probe Pulls:",Response::TempCount(0)), ("SureTemp Probe Pulls:",Response::TempCount(None)),
(">",Response::DebugMenu), (">",Response::DebugMenu),
("Loading App-Framework",Response::DebugInit) ("Loading App-Framework",Response::DebugInit),
]; ];
pub struct TTY{ 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); 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; self.failed_read_count = 0;
if enum_value == Response::TempCount(0){ if enum_value == Response::TempCount(None){
let mut lines = read_line.lines(); let mut lines = read_line.lines();
while let Some(single_line) = lines.next(){ while let Some(single_line) = lines.next(){
if single_line.contains(string){ if single_line.contains(string){
@ -155,12 +162,12 @@ impl TTY{
match temp_count.trim().parse::<u64>(){ match temp_count.trim().parse::<u64>(){
Err(_) => { Err(_) => {
log::error!("String {} from device {} unable to be parsed!",temp_count,self.tty.name().unwrap_or("unknown shell".to_string())); 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) => { Ok(parsed_temp_count) => {
//log::trace!("Header: {}",header); //log::trace!("Header: {}",header);
log::trace!("parsed temp count for device {}: {}",self.tty.name().unwrap_or("unknown shell".to_string()),temp_count); 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 { 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())); 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); self.write_to_device(Command::Newline);