use crate::SifliToolTrait;
use crate::common::ram_command::{Command, RamCommand};
use std::io::Write;
use std::time::Duration;
pub struct SpeedOps;
impl SpeedOps {
pub fn set_speed<T>(tool: &mut T, speed: u32) -> Result<(), std::io::Error>
where
T: SifliToolTrait + RamCommand,
{
tool.command(Command::SetBaud {
baud: speed,
delay: 500,
})?;
tool.port().set_baud_rate(speed)?;
std::thread::sleep(Duration::from_millis(300));
tool.port().write_all("\r\n".as_bytes())?;
tool.port().flush()?;
std::thread::sleep(Duration::from_millis(300));
tool.port().clear(serialport::ClearBuffer::All)?;
Ok(())
}
}