Remove reboot from auto_serial
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
We have a whole state machine here. Might as well use it.
This commit is contained in:
parent
a59a3c590d
commit
1300e040d7
1 changed files with 44 additions and 26 deletions
|
@ -353,38 +353,56 @@ impl Device{
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
pub fn auto_set_serial(&mut self) -> bool{
|
pub fn auto_set_serial(&mut self) -> bool{
|
||||||
self.reboot();
|
loop {
|
||||||
self.usb_tty.write_to_device(Command::Login);
|
match self.current_state {
|
||||||
while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}
|
State::LoginPrompt => {
|
||||||
self.usb_tty.write_to_device(Command::GetSerial);
|
self.usb_tty.write_to_device(Command::Login);
|
||||||
loop{
|
while self.usb_tty.read_from_device(None) != Response::ShellPrompt {};
|
||||||
let return_value = self.usb_tty.read_from_device(None);
|
self.current_state = State::ShellPrompt;
|
||||||
match return_value{
|
},
|
||||||
Response::Serial(Some(contains_serial)) =>{
|
State::Shutdown => {
|
||||||
for line in contains_serial.split("\n").collect::<Vec<&str>>(){
|
while self.usb_tty.read_from_device(None) != Response::LoginPrompt{};
|
||||||
if !line.contains(':') { continue; }
|
self.current_state = State::LoginPrompt;
|
||||||
let (section,value) = line.split_once(':').unwrap();
|
},
|
||||||
if section.contains(SERIAL_HEADER){
|
State::DebugMenu | State::LifecycleMenu | State::BrightnessMenu => {
|
||||||
self.serial = value.trim().replace("\"","");
|
self.usb_tty.write_to_device(Command::Quit);
|
||||||
|
_ = self.usb_tty.read_from_device(None);
|
||||||
|
self.current_state = State::ShellPrompt;
|
||||||
|
},
|
||||||
|
State::ShellPrompt => {
|
||||||
|
self.usb_tty.write_to_device(Command::GetSerial);
|
||||||
|
loop{
|
||||||
|
let return_value = self.usb_tty.read_from_device(None);
|
||||||
|
match return_value{
|
||||||
|
Response::Serial(Some(contains_serial)) =>{
|
||||||
|
for line in contains_serial.split("\n").collect::<Vec<&str>>(){
|
||||||
|
if !line.contains(':') { continue; }
|
||||||
|
let (section,value) = line.split_once(':').unwrap();
|
||||||
|
if section.contains(SERIAL_HEADER){
|
||||||
|
self.serial = value.trim().replace("\"","");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log::info!("Serial found for device {}",self.serial);
|
||||||
|
break;
|
||||||
|
},
|
||||||
|
Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; }
|
||||||
|
_ => {
|
||||||
|
log::error!("Bad value: {:?}",return_value);
|
||||||
|
return false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::info!("Serial found for device {}",self.serial);
|
self.usb_tty.write_to_device(Command::DebugMenu);
|
||||||
break;
|
while self.usb_tty.read_from_device(None) != Response::DebugMenu {}
|
||||||
},
|
self.current_state = State::DebugMenu;
|
||||||
Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; }
|
self.load_values();
|
||||||
_ => {
|
self.save_values();
|
||||||
log::error!("Bad value: {:?}",return_value);
|
return true
|
||||||
return false
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.usb_tty.write_to_device(Command::DebugMenu);
|
|
||||||
while self.usb_tty.read_from_device(None) != Response::DebugMenu {}
|
|
||||||
self.current_state = State::DebugMenu;
|
|
||||||
self.load_values();
|
|
||||||
self.save_values();
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn manual_set_serial(&mut self, serial:&str) -> &mut Self{
|
pub fn manual_set_serial(&mut self, serial:&str) -> &mut Self{
|
||||||
self.serial = serial.to_string();
|
self.serial = serial.to_string();
|
||||||
self.load_values();
|
self.load_values();
|
||||||
|
|
Loading…
Add table
Reference in a new issue