Attempt to reduce init time
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
To be tested
This commit is contained in:
parent
108132ef9e
commit
c403dfa7c1
2 changed files with 24 additions and 22 deletions
|
@ -16,7 +16,8 @@ pub enum State{
|
|||
LoginPrompt,
|
||||
DebugMenu,
|
||||
LifecycleMenu,
|
||||
BrightnessMenu
|
||||
BrightnessMenu,
|
||||
ShellPrompt
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -112,6 +113,10 @@ impl Device{
|
|||
usb_port.write_to_device(Command::Newline);
|
||||
_ = usb_port.read_from_device(None);
|
||||
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::Other | Response::Empty | Response::ShellPrompt | Response::FailedDebugMenu | Response::DebugInit |
|
||||
|
@ -126,9 +131,7 @@ impl Device{
|
|||
initial_state = State::LoginPrompt;
|
||||
},
|
||||
Response::ShellPrompt => {
|
||||
usb_port.write_to_device(Command::Shutdown);
|
||||
while usb_port.read_from_device(None) != Response::LoginPrompt {}
|
||||
initial_state = State::LoginPrompt;
|
||||
initial_state = State::ShellPrompt;
|
||||
},
|
||||
_ => {
|
||||
log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port);
|
||||
|
@ -199,13 +202,15 @@ impl Device{
|
|||
Response::ShellPrompt => break,
|
||||
_ => {
|
||||
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);
|
||||
//break;
|
||||
},
|
||||
};
|
||||
};
|
||||
//_ = self.usb_tty.read_from_device(None);
|
||||
self.current_state = State::ShellPrompt;
|
||||
},
|
||||
State::ShellPrompt => {
|
||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||
loop {
|
||||
match self.usb_tty.read_from_device(None) {
|
||||
|
@ -219,14 +224,11 @@ impl Device{
|
|||
Response::DebugMenu =>
|
||||
break,
|
||||
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);
|
||||
},
|
||||
_ => {
|
||||
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);
|
||||
//break;
|
||||
},
|
||||
|
@ -276,6 +278,9 @@ impl Device{
|
|||
},
|
||||
};
|
||||
};
|
||||
self.current_state = State::ShellPrompt;
|
||||
},
|
||||
State::ShellPrompt => {
|
||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||
loop {
|
||||
let read_in = self.usb_tty.read_from_device(None);
|
||||
|
@ -283,16 +288,11 @@ impl Device{
|
|||
Response::PreShellPrompt | Response::Empty | Response::ShuttingDown |
|
||||
Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {},
|
||||
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);
|
||||
},
|
||||
Response::DebugMenu =>
|
||||
break,
|
||||
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);
|
||||
},
|
||||
_ => {
|
||||
|
@ -381,7 +381,6 @@ impl Device{
|
|||
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.save_values();
|
||||
return true
|
||||
|
@ -529,6 +528,7 @@ impl Device{
|
|||
}
|
||||
pub fn reboot(&mut self) -> () {
|
||||
self.usb_tty.write_to_device(Command::Quit);
|
||||
self.usb_tty.write_to_device(Command::Reboot);
|
||||
let mut successful_reboot:bool = false;
|
||||
//let mut exited_menu:bool = false;
|
||||
loop{
|
||||
|
|
14
src/tty.rs
14
src/tty.rs
|
@ -26,7 +26,7 @@ pub enum Command{
|
|||
Login,
|
||||
DebugMenu,
|
||||
Newline,
|
||||
Shutdown,
|
||||
Reboot,
|
||||
GetSerial,
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ pub enum Response{
|
|||
EmptyNewline,
|
||||
DebugInit,
|
||||
Serial(Option<String>),
|
||||
UBoot,
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,26 +65,27 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = Lazy::new(||HashMap::from([
|
|||
(Command::UpMenuLevel, "\\"),
|
||||
(Command::Login,"root\n"),
|
||||
(Command::RedrawMenu,"?"),
|
||||
(Command::DebugMenu," python3 -m debugmenu; shutdown -r now\n"),
|
||||
(Command::DebugMenu,"python3 -m debugmenu\n"),
|
||||
(Command::Newline,"\n"),
|
||||
(Command::Shutdown,"shutdown -r now\n"),
|
||||
(Command::Reboot,"shutdown -r now\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),
|
||||
("reboot: Restarting",Response::Rebooting),
|
||||
("command not found",Response::FailedDebugMenu),
|
||||
("login:",Response::LoginPrompt),
|
||||
("Password:",Response::PasswordPrompt),
|
||||
("DtCtrlCfgDeviceSerialNum",Response::Serial(None)),
|
||||
(">",Response::DebugMenu),
|
||||
("Loading App-Framework",Response::DebugInit),
|
||||
("root@",Response::ShellPrompt),
|
||||
("EXIT Debug menu",Response::ShuttingDown),
|
||||
("Check NIBP In Progress: True",Response::BPOn),
|
||||
("Check NIBP In Progress: False",Response::BPOff),
|
||||
("SureTemp Probe Pulls:",Response::TempCount(None)),
|
||||
(">",Response::DebugMenu),
|
||||
("Loading App-Framework",Response::DebugInit),
|
||||
];
|
||||
|
||||
pub struct TTY{
|
||||
|
|
Loading…
Add table
Reference in a new issue