Continue reconfiguring for new cycle structure
Some checks failed
Basic Cargo Checks / docker-build (push) Failing after 53s
Basic Cargo Checks / docker-check (push) Failing after 2m34s

This commit is contained in:
Blizzard Finnegan 2023-06-13 09:26:25 -04:00
parent 5845642101
commit c1757ce169
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
3 changed files with 66 additions and 39 deletions

View file

@ -2,8 +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 BOOT_TIME:Duration = Duration::new(50, 0);
const BP_RUN:Duration = Duration::new(60, 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 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: ";
@ -29,6 +31,7 @@ pub struct Device{
current_state: State, current_state: State,
reboots: u64, reboots: u64,
temps: u64, temps: u64,
init_temps: u64,
bps: u64 bps: u64
} }
@ -108,8 +111,7 @@ impl Device{
Response::Other | Response::Empty | Response::ShellPrompt Response::Other | Response::Empty | Response::ShellPrompt
| Response::LoginPrompt | Response::Rebooting => | Response::LoginPrompt | Response::Rebooting =>
initial_state = State::LoginPrompt, initial_state = State::LoginPrompt,
Response::BPOn | Response::BPOff | Response::TempFailed Response::BPOn | Response::BPOff | Response::TempCount(_) =>
| Response::TempSuccess =>
initial_state = State::LifecycleMenu, initial_state = State::LifecycleMenu,
Response::DebugMenuReady | Response::DebugMenuWithContinuedMessage=> Response::DebugMenuReady | Response::DebugMenuWithContinuedMessage=>
initial_state = State::DebugMenu, initial_state = State::DebugMenu,
@ -130,6 +132,7 @@ impl Device{
current_state: initial_state, current_state: initial_state,
reboots: 0, reboots: 0,
temps: 0, temps: 0,
init_temps: 0,
bps: 0 bps: 0
}; };
if !output.load_values(){ if !output.load_values(){
@ -257,7 +260,8 @@ impl Device{
output_data.push_str(&self.bps.to_string()); output_data.push_str(&self.bps.to_string());
output_data.push_str("\n"); output_data.push_str("\n");
output_data.push_str(TEMP_SECTION); output_data.push_str(TEMP_SECTION);
output_data.push_str(&self.temps.to_string()); let saved_temps = self.temps - self.init_temps;
output_data.push_str(&saved_temps.to_string());
output_data.push_str("\n"); output_data.push_str("\n");
let temp = file_name.write_all(output_data.as_bytes()); let temp = file_name.write_all(output_data.as_bytes());
match temp{ match temp{
@ -326,27 +330,46 @@ impl Device{
_ = self.usb_tty.read_from_device(None); _ = self.usb_tty.read_from_device(None);
return self; return self;
} }
pub fn is_temp_running(&mut self) -> bool { pub fn update_temp_count(&mut self) -> u64 {
self.go_to_lifecycle_menu(); self.go_to_lifecycle_menu();
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::TempSuccess => return true, Response::TempCount(count) => return count,
Response::TempFailed => return false,
_ => {}, _ => {},
} }
} }
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::TempSuccess => return true, Response::TempCount(count) => return count,
Response::TempFailed => return false,
_ => {}, _ => {},
} }
} }
log::error!("Temp read failed!!!"); log::error!("Temp read failed!!!");
return false; return 0;
} }
pub fn init_temp_count(&mut self){
self.go_to_lifecycle_menu();
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 ,
_ => {},
}
}
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 ,
_ => {},
}
}
log::error!("Temp read failed!!!");
//return 0;
}
pub fn is_bp_running(&mut self) -> bool { pub fn is_bp_running(&mut self) -> bool {
self.go_to_lifecycle_menu(); self.go_to_lifecycle_menu();
self.usb_tty.write_to_device(Command::CheckBPState); self.usb_tty.write_to_device(Command::CheckBPState);
@ -360,7 +383,6 @@ impl Device{
} }
} }
pub fn reboot(&mut self) -> () { pub fn reboot(&mut self) -> () {
//self.go_to_login_prompt();
self.usb_tty.write_to_device(Command::Quit); self.usb_tty.write_to_device(Command::Quit);
while self.usb_tty.read_from_device(None) != Response::Rebooting {} while self.usb_tty.read_from_device(None) != Response::Rebooting {}
self.current_state = State::Shutdown; self.current_state = State::Shutdown;
@ -378,11 +400,9 @@ impl Device{
return true; return true;
} }
} }
pub fn test_cycle(&mut self, bp_cycles: Option<u64>, temp_cycles: Option<u64>) -> () { pub fn test_cycle(&mut self, bp_cycles: Option<u64>, _temp_cycles: Option<u64>) -> () {
let local_bp_cycles: u64 = bp_cycles.unwrap_or(3); let local_bp_cycles: u64 = bp_cycles.unwrap_or(3);
let local_temp_cycles: u64 = temp_cycles.unwrap_or(2);
if self.current_state != State::LoginPrompt { self.reboot(); } if self.current_state != State::LoginPrompt { self.reboot(); }
thread::sleep(BOOT_TIME);
self.go_to_lifecycle_menu(); self.go_to_lifecycle_menu();
_ = self.usb_tty.read_from_device(Some("[")); _ = self.usb_tty.read_from_device(Some("["));
for _bp_count in 1..=local_bp_cycles{ for _bp_count in 1..=local_bp_cycles{
@ -390,7 +410,13 @@ impl Device{
self.start_bp(); self.start_bp();
let bp_start = self.is_bp_running(); let bp_start = self.is_bp_running();
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); thread::sleep(BP_RUN_1);
self.start_temp();
thread::sleep(TEMP_WAIT);
self.stop_temp();
thread::sleep(BP_RUN_2);
let bp_end = self.is_bp_running(); let bp_end = self.is_bp_running();
log::trace!("Has bp ended on device {}? : {:?}",self.serial,bp_end); log::trace!("Has bp ended on device {}? : {:?}",self.serial,bp_end);
if bp_start != bp_end { if bp_start != bp_end {
@ -399,16 +425,6 @@ impl Device{
self.save_values(); self.save_values();
} }
} }
for _temp_count in 1..=local_temp_cycles{
log::info!("Running temp {} on device {} ...",(self.temps+1),self.serial);
let temp_start = self.start_temp().is_temp_running();
let temp_end = self.stop_temp().is_temp_running();
if temp_start != temp_end {
self.temps +=1;
log::debug!("Increasing temp count for device {} to {}",self.serial,self.temps);
self.save_values();
}
}
log::info!("Rebooting {} for the {}th time",self.serial, self.reboots); log::info!("Rebooting {} for the {}th time",self.serial, self.reboots);
self.reboot(); self.reboot();
self.reboots += 1; self.reboots += 1;

View file

@ -49,8 +49,8 @@ fn input_filtering(prompt:Option<&str>) -> String{
} }
fn main(){ fn main(){
setup_logs();
let args = Args::parse(); let args = Args::parse();
setup_logs(&args.debug);
log::info!("Seymour Life Testing version: {}",VERSION); log::info!("Seymour Life Testing version: {}",VERSION);
if args.debug{ if args.debug{
log::debug!("Debug enabled!"); log::debug!("Debug enabled!");
@ -181,7 +181,7 @@ fn find_gpio(device:&mut Device,gpio:&mut GpioPins) -> bool{
return false; return false;
} }
pub fn setup_logs(){ pub fn setup_logs(debug:&bool){
let chrono_now: DateTime<Local> = Local::now(); let chrono_now: DateTime<Local> = Local::now();
if ! Path::new("logs").is_dir(){ if ! Path::new("logs").is_dir(){
_ = fs::create_dir("logs"); _ = fs::create_dir("logs");
@ -204,10 +204,15 @@ pub fn setup_logs(){
chrono_now.format("%Y-%m-%d_%H.%M").to_string() chrono_now.format("%Y-%m-%d_%H.%M").to_string()
)).unwrap()), )).unwrap()),
) )
.chain( .chain({
fern::Dispatch::new() let mut stdout_logger = fern::Dispatch::new();
.level(log::LevelFilter::Info) if *debug {
.chain(std::io::stdout()) stdout_logger = stdout_logger.level(log::LevelFilter::Trace);
) }
else {
stdout_logger = stdout_logger.level(log::LevelFilter::Info);
}
stdout_logger.chain(std::io::stdout())
})
.apply(); .apply();
} }

View file

@ -32,8 +32,7 @@ pub enum Response{
ShellPrompt, ShellPrompt,
BPOn, BPOn,
BPOff, BPOff,
TempFailed, TempCount(u64),
TempSuccess,
LoginPrompt, LoginPrompt,
DebugMenuReady, DebugMenuReady,
DebugMenuWithContinuedMessage, DebugMenuWithContinuedMessage,
@ -51,7 +50,7 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = Lazy::new(||HashMap::from([
(Command::BrightnessMenu, "B"), (Command::BrightnessMenu, "B"),
(Command::BrightnessHigh, "0"), (Command::BrightnessHigh, "0"),
(Command::BrightnessLow, "1"), (Command::BrightnessLow, "1"),
(Command::ReadTemp, "h"), (Command::ReadTemp, "H"),
(Command::UpMenuLevel, "\\"), (Command::UpMenuLevel, "\\"),
(Command::Login,"root\n"), (Command::Login,"root\n"),
(Command::RedrawMenu,"?"), (Command::RedrawMenu,"?"),
@ -59,15 +58,14 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = Lazy::new(||HashMap::from([
(Command::Newline,"\n"), (Command::Newline,"\n"),
])); ]));
const RESPONSES:[(&str,Response);10] = [ const RESPONSES:[(&str,Response);9] = [
("reboot: Restarting",Response::Rebooting), ("reboot: Restarting",Response::Rebooting),
("login:",Response::LoginPrompt), ("login:",Response::LoginPrompt),
("Password:",Response::PasswordPrompt), ("Password:",Response::PasswordPrompt),
("root@",Response::ShellPrompt), ("root@",Response::ShellPrompt),
("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),
("Temp: 0",Response::TempFailed), ("SureTemp Probe Pulls:",Response::TempCount(0)),
("Temp:",Response::TempSuccess),
("> ",Response::DebugMenuWithContinuedMessage), ("> ",Response::DebugMenuWithContinuedMessage),
(">",Response::DebugMenuReady), (">",Response::DebugMenuReady),
]; ];
@ -127,7 +125,15 @@ impl TTY{
if read_line.contains(string){ if read_line.contains(string){
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){
match read_line.rsplit_once(' '){
None => return enum_value,
Some((_,temp_count)) => return Response::TempCount(temp_count.parse().unwrap_or(0))
}
}
else{
return enum_value; return enum_value;
}
} }
} }
return Response::Other; return Response::Other;