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
This commit is contained in:
parent
7a601ebc6e
commit
fe7cd6d510
3 changed files with 50 additions and 18 deletions
2
notes.md
2
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`
|
Can check for reboot completed by reading in serial, check for `reboot: Restarting System`
|
||||||
once done, read for `login:`
|
once done, read for `login:`
|
||||||
|
|
||||||
|
First command sent to shell gets dropped (possibly due to timing issue?)
|
||||||
|
|
|
@ -2,10 +2,10 @@ use std::{fs::{self, File}, path::Path, io::Write, thread, time::Duration};
|
||||||
use crate::tty::{TTY, Response,Command};
|
use crate::tty::{TTY, Response,Command};
|
||||||
use rppal::gpio::{Gpio,OutputPin};
|
use rppal::gpio::{Gpio,OutputPin};
|
||||||
|
|
||||||
//const BOOT_TIME:Duration = Duration::new(50, 0);
|
const BP_RUN_1:Duration = Duration::from_secs(29);
|
||||||
const BP_RUN_1:Duration = Duration::new(29, 0);
|
const TEMP_WAIT:Duration = Duration::from_secs(3);
|
||||||
const TEMP_WAIT:Duration = Duration::new(3,0);
|
const BP_RUN_2:Duration = Duration::from_secs(28);
|
||||||
const BP_RUN_2:Duration = Duration::new(28, 0);
|
const LOGIN_WAIT:Duration = Duration::from_secs(1);
|
||||||
const REBOOTS_SECTION: &str = "Reboots: ";
|
const REBOOTS_SECTION: &str = "Reboots: ";
|
||||||
const BP_SECTION: &str = "Successful BP tests: ";
|
const BP_SECTION: &str = "Successful BP tests: ";
|
||||||
const TEMP_SECTION: &str = "Successful temp tests: ";
|
const TEMP_SECTION: &str = "Successful temp tests: ";
|
||||||
|
@ -165,6 +165,7 @@ impl Device{
|
||||||
},
|
},
|
||||||
State::LoginPrompt => {
|
State::LoginPrompt => {
|
||||||
self.usb_tty.write_to_device(Command::Login);
|
self.usb_tty.write_to_device(Command::Login);
|
||||||
|
thread::sleep(LOGIN_WAIT);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
|
@ -195,6 +196,7 @@ impl Device{
|
||||||
},
|
},
|
||||||
State::LoginPrompt => {
|
State::LoginPrompt => {
|
||||||
self.usb_tty.write_to_device(Command::Login);
|
self.usb_tty.write_to_device(Command::Login);
|
||||||
|
thread::sleep(LOGIN_WAIT);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
|
@ -227,6 +229,7 @@ impl Device{
|
||||||
},
|
},
|
||||||
State::LoginPrompt => {
|
State::LoginPrompt => {
|
||||||
self.usb_tty.write_to_device(Command::Login);
|
self.usb_tty.write_to_device(Command::Login);
|
||||||
|
thread::sleep(LOGIN_WAIT);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
|
@ -336,14 +339,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(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(count) => return count != self.init_temps ,
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,18 +359,24 @@ 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,
|
Response::TempCount(count) => {
|
||||||
|
log::trace!("Count for device {} updated to {}",self.serial,count);
|
||||||
|
return count
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,18 +385,26 @@ 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) => 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);
|
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) => 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 {
|
pub fn is_bp_running(&mut self) -> bool {
|
||||||
|
@ -425,6 +442,7 @@ impl Device{
|
||||||
if self.current_state != State::LoginPrompt { self.reboot(); }
|
if self.current_state != State::LoginPrompt { self.reboot(); }
|
||||||
self.go_to_lifecycle_menu();
|
self.go_to_lifecycle_menu();
|
||||||
_ = self.usb_tty.read_from_device(Some("["));
|
_ = self.usb_tty.read_from_device(Some("["));
|
||||||
|
self.update_temp_count();
|
||||||
for _bp_count in 1..=local_bp_cycles{
|
for _bp_count in 1..=local_bp_cycles{
|
||||||
log::info!("Running bp {} on device {} ...",(self.bps+1),self.serial);
|
log::info!("Running bp {} on device {} ...",(self.bps+1),self.serial);
|
||||||
self.start_bp();
|
self.start_bp();
|
||||||
|
@ -432,8 +450,10 @@ impl Device{
|
||||||
log::trace!("Has bp started on device {}? : {:?}",self.serial,bp_start);
|
log::trace!("Has bp started on device {}? : {:?}",self.serial,bp_start);
|
||||||
thread::sleep(BP_RUN_1);
|
thread::sleep(BP_RUN_1);
|
||||||
|
|
||||||
|
log::trace!("Starting temp on device {}",self.serial);
|
||||||
self.start_temp();
|
self.start_temp();
|
||||||
thread::sleep(TEMP_WAIT);
|
thread::sleep(TEMP_WAIT);
|
||||||
|
log::trace!("Stopping temp on device {}",self.serial);
|
||||||
self.stop_temp();
|
self.stop_temp();
|
||||||
|
|
||||||
thread::sleep(BP_RUN_2);
|
thread::sleep(BP_RUN_2);
|
||||||
|
|
18
src/tty.rs
18
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);
|
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;
|
self.failed_read_count = 0;
|
||||||
if enum_value == Response::TempCount(0){
|
if enum_value == Response::TempCount(0){
|
||||||
match read_line.rsplit_once(' '){
|
let mut lines = read_line.lines();
|
||||||
None => return enum_value,
|
while let Some(single_line) = lines.next(){
|
||||||
Some((_,temp_count)) => return Response::TempCount(temp_count.parse().unwrap_or(0))
|
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{
|
else{
|
||||||
return enum_value;
|
return enum_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue