sftool_lib/common/
speed.rs

1use crate::common::ram_command::{Command, RamCommand, RamOps};
2use crate::{Result, SifliToolTrait};
3use std::time::Duration;
4
5/// 通用的速度设置操作实现
6pub struct SpeedOps;
7
8impl SpeedOps {
9    /// 设置串口速度的通用实现
10    pub fn set_speed<T>(tool: &mut T, speed: u32) -> Result<()>
11    where
12        T: SifliToolTrait + RamCommand,
13    {
14        // 发送设置波特率命令
15        tool.command(Command::SetBaud {
16            baud: speed,
17            delay: 10,
18        })?;
19
20        // 等待一段时间让设置生效
21        std::thread::sleep(Duration::from_millis(50));
22
23        // 设置串口波特率
24        tool.port().set_baud_rate(speed)?;
25
26        tool.port().clear(serialport::ClearBuffer::All)?;
27
28        RamOps::wait_for_shell_prompt(tool.port(), b"msh >", 200, 5)?;
29
30        Ok(())
31    }
32}