use crate::common::ram_command::{Command, RamCommand, RamOps};
use crate::common::serial_io::{for_tool, sleep_with_cancel};
use crate::{Result, SifliToolTrait};
use std::time::Duration;
pub struct SpeedOps;
impl SpeedOps {
pub fn set_speed<T>(tool: &mut T, speed: u32) -> Result<()>
where
T: SifliToolTrait + RamCommand,
{
tool.command(Command::SetBaud {
baud: speed,
delay: 10,
})?;
sleep_with_cancel(&tool.base().cancel_token, Duration::from_millis(50))?;
let mut io = for_tool(tool);
io.set_baud_rate(speed)?;
io.clear(serialport::ClearBuffer::All)?;
RamOps::wait_for_shell_prompt(&mut io, b"msh >", 200, 5)?;
Ok(())
}
}