From fe7cd6d5106d3338a656ce213f73fd90b2605d42 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Tue, 13 Jun 2023 15:46:09 -0400 Subject: [PATCH] Finish temp algorithm, update login algorithm Bash often drops beginning characters in the first command sent if it is sent too soon after being logged in. Solution is to wait 1s after logging in --- notes.md | 2 ++ src/device.rs | 48 ++++++++++++++++++++++++++++++++++-------------- src/tty.rs | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/notes.md b/notes.md index da1f519..9c5d16e 100644 --- a/notes.md +++ b/notes.md @@ -4,3 +4,5 @@ Clearing the screen of all vitals is theoretically possible in the UI menu, with 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?) diff --git a/src/device.rs b/src/device.rs index ab33e84..9ba594a 100755 --- a/src/device.rs +++ b/src/device.rs @@ -2,10 +2,10 @@ use std::{fs::{self, File}, path::Path, io::Write, thread, time::Duration}; use crate::tty::{TTY, Response,Command}; use rppal::gpio::{Gpio,OutputPin}; -//const BOOT_TIME:Duration = Duration::new(50, 0); -const BP_RUN_1:Duration = Duration::new(29, 0); -const TEMP_WAIT:Duration = Duration::new(3,0); -const BP_RUN_2:Duration = Duration::new(28, 0); +const BP_RUN_1:Duration = Duration::from_secs(29); +const TEMP_WAIT:Duration = Duration::from_secs(3); +const BP_RUN_2:Duration = Duration::from_secs(28); +const LOGIN_WAIT:Duration = Duration::from_secs(1); const REBOOTS_SECTION: &str = "Reboots: "; const BP_SECTION: &str = "Successful BP tests: "; const TEMP_SECTION: &str = "Successful temp tests: "; @@ -165,6 +165,7 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); + thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); @@ -195,6 +196,7 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); + thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); @@ -227,6 +229,7 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); + thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); @@ -336,14 +339,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(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(count) => return count != self.init_temps , _ => {}, } } @@ -356,18 +359,24 @@ 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, + Response::TempCount(count) => { + log::trace!("Count for device {} updated to {}",self.serial,count); + return count + }, _ => {}, } } 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, + Response::TempCount(count) => { + log::trace!("Count for device {} updated to {}",self.serial,count); + return count + }, _ => {}, } } - log::error!("Temp read failed!!!"); + log::error!("Update temp count on device {} failed!!!",self.serial); return 0; } @@ -376,18 +385,26 @@ 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) => self.init_temps = count , + Response::TempCount(count) => { + log::trace!("init temp count set to {} on device {}",count,self.serial); + self.init_temps = count; + return + }, _ => {}, } - } + }; self.usb_tty.write_to_device(Command::ReadTemp); for _ in 0..10{ match self.usb_tty.read_from_device(None){ - Response::TempCount(count) => self.init_temps = count , + Response::TempCount(count) => { + log::trace!("init temp count set to {} on device {}",count,self.serial); + self.init_temps = count; + return + }, _ => {}, } - } - log::error!("Temp read failed!!!"); + }; + log::error!("init temp count failed on device {}!!!",self.serial); } pub fn is_bp_running(&mut self) -> bool { @@ -425,6 +442,7 @@ impl Device{ if self.current_state != State::LoginPrompt { self.reboot(); } self.go_to_lifecycle_menu(); _ = self.usb_tty.read_from_device(Some("[")); + self.update_temp_count(); for _bp_count in 1..=local_bp_cycles{ log::info!("Running bp {} on device {} ...",(self.bps+1),self.serial); self.start_bp(); @@ -432,8 +450,10 @@ impl Device{ log::trace!("Has bp started on device {}? : {:?}",self.serial,bp_start); thread::sleep(BP_RUN_1); + log::trace!("Starting temp on device {}",self.serial); self.start_temp(); thread::sleep(TEMP_WAIT); + log::trace!("Stopping temp on device {}",self.serial); self.stop_temp(); thread::sleep(BP_RUN_2); diff --git a/src/tty.rs b/src/tty.rs index 7910857..49df070 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -126,13 +126,23 @@ impl TTY{ log::debug!("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){ - match read_line.rsplit_once(' '){ - None => return enum_value, - Some((_,temp_count)) => return Response::TempCount(temp_count.parse().unwrap_or(0)) + let mut lines = read_line.lines(); + while let Some(single_line) = lines.next(){ + if single_line.contains(string){ + let trimmed_line = single_line.trim(); + match trimmed_line.rsplit_once(' '){ + None => return enum_value, + Some((header,temp_count)) => { + log::trace!("Header: {}",header); + log::trace!("Temp count: {}",temp_count); + return Response::TempCount(temp_count.parse().unwrap_or(0)) + } + } + } } } else{ - return enum_value; + return enum_value; } } }