Merge pull request 'v2.3.0' (#5) from devel into stable
Reviewed-on: #5
This commit is contained in:
commit
31a4da2773
6 changed files with 85 additions and 50 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -639,7 +639,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "seymour_life_rust"
|
name = "seymour_life_rust"
|
||||||
version = "2.2.0"
|
version = "2.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "seymour_life_rust"
|
name = "seymour_life_rust"
|
||||||
version = "2.2.0"
|
version = "2.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
13
notes.md
13
notes.md
|
@ -1,8 +1,7 @@
|
||||||
Boot time isn't static.
|
Auto-serial:
|
||||||
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.
|
|
||||||
|
|
||||||
Can check for reboot completed by reading in serial, check for `reboot: Restarting System`
|
`echo 'y1q' | python3 -m debugmenu` contains the serial number. Search keyword is: "DtCtrlCfgDeviceSerialNum"
|
||||||
once done, read for `login:`
|
split on `\n`, collect into Vec<&str>. Iterate over Vec:
|
||||||
|
if doesn't contain colon, continue
|
||||||
First command sent to shell gets dropped (possibly due to timing issue?)
|
split_once on colon
|
||||||
|
if first half is keyword, trim second half, remove `"` characters, save as serial
|
||||||
|
|
|
@ -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,36 @@ 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);
|
||||||
|
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.load_values();
|
||||||
self.save_values();
|
self.save_values();
|
||||||
return self;
|
return self;
|
||||||
|
@ -405,14 +434,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 +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
|
||||||
|
@ -436,7 +465,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 +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
|
||||||
|
@ -464,7 +493,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
|
||||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -15,7 +15,7 @@ struct Args{
|
||||||
debug:bool
|
debug:bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const VERSION:&str="2.2.0";
|
const VERSION:&str="2.3.0";
|
||||||
|
|
||||||
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(">>>");
|
||||||
|
@ -56,6 +56,16 @@ fn main(){
|
||||||
log::debug!("Debug enabled!");
|
log::debug!("Debug enabled!");
|
||||||
}
|
}
|
||||||
loop{
|
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();
|
let gpio = &mut GpioPins::new();
|
||||||
match std::fs::read_dir("/dev/serial/by-path"){
|
match std::fs::read_dir("/dev/serial/by-path"){
|
||||||
Ok(available_ttys)=>{
|
Ok(available_ttys)=>{
|
||||||
|
@ -81,6 +91,7 @@ fn main(){
|
||||||
match new_device{
|
match new_device{
|
||||||
Ok(mut device) => {
|
Ok(mut device) => {
|
||||||
device.darken_screen();
|
device.darken_screen();
|
||||||
|
device.set_serial();
|
||||||
Some(device)
|
Some(device)
|
||||||
},
|
},
|
||||||
Err(_) => None
|
Err(_) => None
|
||||||
|
@ -115,30 +126,16 @@ 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);
|
log::info!("Checking probe well of device {}",device.get_serial());
|
||||||
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 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;
|
||||||
|
|
||||||
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: "));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
src/tty.rs
30
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 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),
|
("DtCtrlCfgDeviceSerialNum",Response::Serial(None)),
|
||||||
("root@",Response::ShellPrompt),
|
("root@",Response::ShellPrompt),
|
||||||
|
("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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue