Attempt to reduce init time
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

To be tested
This commit is contained in:
Blizzard Finnegan 2023-06-26 11:04:01 -04:00
parent 108132ef9e
commit c403dfa7c1
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
2 changed files with 24 additions and 22 deletions

View file

@ -16,7 +16,8 @@ pub enum State{
LoginPrompt, LoginPrompt,
DebugMenu, DebugMenu,
LifecycleMenu, LifecycleMenu,
BrightnessMenu BrightnessMenu,
ShellPrompt
} }
#[derive(Debug)] #[derive(Debug)]
@ -112,6 +113,10 @@ impl Device{
usb_port.write_to_device(Command::Newline); usb_port.write_to_device(Command::Newline);
_ = usb_port.read_from_device(None); _ = usb_port.read_from_device(None);
initial_state = State::LoginPrompt; initial_state = State::LoginPrompt;
},
Response::UBoot=>{
log::error!("A device was interrupted during the boot process! Please ensure all devices are completely booted and on the main screen, then restart this program.");
return Err("Failed TTY init. Device in u-boot state, must be manually rebooted.".to_string());
}, },
//Response::Empty parsing here is potentially in bad faith //Response::Empty parsing here is potentially in bad faith
Response::Other | Response::Empty | Response::ShellPrompt | Response::FailedDebugMenu | Response::DebugInit | Response::Other | Response::Empty | Response::ShellPrompt | Response::FailedDebugMenu | Response::DebugInit |
@ -126,9 +131,7 @@ impl Device{
initial_state = State::LoginPrompt; initial_state = State::LoginPrompt;
}, },
Response::ShellPrompt => { Response::ShellPrompt => {
usb_port.write_to_device(Command::Shutdown); initial_state = State::ShellPrompt;
while usb_port.read_from_device(None) != Response::LoginPrompt {}
initial_state = State::LoginPrompt;
}, },
_ => { _ => {
log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port);
@ -199,13 +202,15 @@ impl Device{
Response::ShellPrompt => break, Response::ShellPrompt => break,
_ => { _ => {
log::error!("Unexpected response from device {}!",self.serial); log::error!("Unexpected response from device {}!",self.serial);
log::debug!("brightness menu, catch-all, first loop, {}, {:?}",self.serial,self.usb_tty); log::debug!("brightness menu, catch-all, login loop, {}, {:?}",self.serial,self.usb_tty);
log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial); log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial);
//break; //break;
}, },
}; };
}; };
//_ = self.usb_tty.read_from_device(None); self.current_state = State::ShellPrompt;
},
State::ShellPrompt => {
self.usb_tty.write_to_device(Command::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
loop { loop {
match self.usb_tty.read_from_device(None) { match self.usb_tty.read_from_device(None) {
@ -219,14 +224,11 @@ impl Device{
Response::DebugMenu => Response::DebugMenu =>
break, break,
Response::FailedDebugMenu => { Response::FailedDebugMenu => {
while self.usb_tty.read_from_device(None) != Response::LoginPrompt {};
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::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
}, },
_ => { _ => {
log::error!("Unexpected response from device {}!", self.serial); log::error!("Unexpected response from device {}!", self.serial);
log::debug!("brightness menu, catch-all, second loop, {}, {:?}",self.serial,self.usb_tty); log::debug!("brightness menu, catch-all, shell prompt loop, {}, {:?}",self.serial,self.usb_tty);
log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial); log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial);
//break; //break;
}, },
@ -276,6 +278,9 @@ impl Device{
}, },
}; };
}; };
self.current_state = State::ShellPrompt;
},
State::ShellPrompt => {
self.usb_tty.write_to_device(Command::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
loop { loop {
let read_in = self.usb_tty.read_from_device(None); let read_in = self.usb_tty.read_from_device(None);
@ -283,16 +288,11 @@ impl Device{
Response::PreShellPrompt | Response::Empty | Response::ShuttingDown | Response::PreShellPrompt | Response::Empty | Response::ShuttingDown |
Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {}, Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {},
Response::LoginPrompt => { Response::LoginPrompt => {
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::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
}, },
Response::DebugMenu => Response::DebugMenu =>
break, break,
Response::FailedDebugMenu => { Response::FailedDebugMenu => {
while self.usb_tty.read_from_device(None) != Response::LoginPrompt {};
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::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
}, },
_ => { _ => {
@ -381,7 +381,6 @@ impl Device{
self.usb_tty.write_to_device(Command::DebugMenu); self.usb_tty.write_to_device(Command::DebugMenu);
while self.usb_tty.read_from_device(None) != Response::DebugMenu {} while self.usb_tty.read_from_device(None) != Response::DebugMenu {}
self.current_state = State::DebugMenu; self.current_state = State::DebugMenu;
self.reboot();
self.load_values(); self.load_values();
self.save_values(); self.save_values();
return true return true
@ -529,6 +528,7 @@ impl Device{
} }
pub fn reboot(&mut self) -> () { pub fn reboot(&mut self) -> () {
self.usb_tty.write_to_device(Command::Quit); self.usb_tty.write_to_device(Command::Quit);
self.usb_tty.write_to_device(Command::Reboot);
let mut successful_reboot:bool = false; let mut successful_reboot:bool = false;
//let mut exited_menu:bool = false; //let mut exited_menu:bool = false;
loop{ loop{

View file

@ -26,7 +26,7 @@ pub enum Command{
Login, Login,
DebugMenu, DebugMenu,
Newline, Newline,
Shutdown, Reboot,
GetSerial, GetSerial,
} }
@ -49,6 +49,7 @@ pub enum Response{
EmptyNewline, EmptyNewline,
DebugInit, DebugInit,
Serial(Option<String>), Serial(Option<String>),
UBoot,
} }
@ -64,26 +65,27 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = Lazy::new(||HashMap::from([
(Command::UpMenuLevel, "\\"), (Command::UpMenuLevel, "\\"),
(Command::Login,"root\n"), (Command::Login,"root\n"),
(Command::RedrawMenu,"?"), (Command::RedrawMenu,"?"),
(Command::DebugMenu," python3 -m debugmenu; shutdown -r now\n"), (Command::DebugMenu,"python3 -m debugmenu\n"),
(Command::Newline,"\n"), (Command::Newline,"\n"),
(Command::Shutdown,"shutdown -r now\n"), (Command::Reboot,"shutdown -r now\n"),
(Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"), (Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"),
])); ]));
const RESPONSES:[(&str,Response);13] = [ const RESPONSES:[(&str,Response);14] = [
("uboot=>",Response::UBoot),
("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),
("DtCtrlCfgDeviceSerialNum",Response::Serial(None)), ("DtCtrlCfgDeviceSerialNum",Response::Serial(None)),
(">",Response::DebugMenu),
("Loading App-Framework",Response::DebugInit),
("root@",Response::ShellPrompt), ("root@",Response::ShellPrompt),
("EXIT Debug menu",Response::ShuttingDown), ("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(None)), ("SureTemp Probe Pulls:",Response::TempCount(None)),
(">",Response::DebugMenu),
("Loading App-Framework",Response::DebugInit),
]; ];
pub struct TTY{ pub struct TTY{