Try to further clean up logging
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
Blizzard Finnegan 2023-06-23 13:12:08 -04:00
parent abc0c5fb54
commit 7f8d0a8397
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E

View file

@ -87,7 +87,8 @@ const RESPONSES:[(&str,Response);13] = [
]; ];
pub struct TTY{ pub struct TTY{
tty: Box<dyn SerialPort> tty: Box<dyn SerialPort>,
last: Command,
} }
impl std::fmt::Debug for TTY{ impl std::fmt::Debug for TTY{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result{ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result{
@ -113,18 +114,22 @@ impl TTY{
pub fn new(serial_location:&str) -> Option<Self>{ pub fn new(serial_location:&str) -> Option<Self>{
let possible_tty = serialport::new(serial_location,BAUD_RATE).timeout(SERIAL_READ_TIMEOUT).open(); let possible_tty = serialport::new(serial_location,BAUD_RATE).timeout(SERIAL_READ_TIMEOUT).open();
if let Ok(tty) = possible_tty{ if let Ok(tty) = possible_tty{
Some(TTY{tty,}) Some(TTY{tty,last:Command::Quit})
} else{ } else{
None None
} }
} }
pub fn write_to_device(&mut self,command:Command) -> bool { pub fn write_to_device(&mut self,command:Command) -> bool {
log::debug!("writing {:?} to tty {}...", command, self.tty.name().unwrap_or("unknown".to_string())); if command == self.last{
log::trace!("retry send {}",self.tty.name().unwrap_or("unknown".to_string()));
}else{
log::debug!("writing {:?} to tty {}...", command, self.tty.name().unwrap_or("unknown".to_string()));
};
let output = self.tty.write_all(COMMAND_MAP.get(&command).unwrap().as_bytes()).is_ok(); let output = self.tty.write_all(COMMAND_MAP.get(&command).unwrap().as_bytes()).is_ok();
self.last = command;
_ = self.tty.flush(); _ = self.tty.flush();
if command == Command::Login { std::thread::sleep(std::time::Duration::from_secs(2)); } //std::thread::sleep(std::time::Duration::from_millis(500));
std::thread::sleep(std::time::Duration::from_millis(500));
return output; return output;
} }