Make sure there are no pending packages in buffer before sending one
This commit is contained in:
parent
aea6105268
commit
0288b49319
@ -90,6 +90,8 @@ async fn main() -> Result<()>{
|
||||
|
||||
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
|
||||
|
||||
serial_interface.drain_buffer();
|
||||
|
||||
serial_interface.send(&request_current_state_packet).context("Failed to send improv packet")?;
|
||||
|
||||
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
|
||||
@ -111,6 +113,8 @@ async fn main() -> Result<()>{
|
||||
|
||||
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
|
||||
|
||||
serial_interface.drain_buffer();
|
||||
|
||||
serial_interface.send(&send_wifi_settings_packet).context("Failed to send improv packet")?;
|
||||
|
||||
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
|
||||
@ -127,6 +131,8 @@ async fn main() -> Result<()>{
|
||||
|
||||
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
|
||||
|
||||
serial_interface.drain_buffer();
|
||||
|
||||
serial_interface.send(&request_device_information_packet).context("Failed to send improv packet")?;
|
||||
|
||||
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
|
||||
@ -143,6 +149,8 @@ async fn main() -> Result<()>{
|
||||
|
||||
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
|
||||
|
||||
serial_interface.drain_buffer();
|
||||
|
||||
serial_interface.send(&request_scanned_wifi_networks_packet).context("Failed to send improv packet")?;
|
||||
|
||||
loop {
|
||||
|
@ -127,6 +127,11 @@ impl SerialInterface {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn drain_buffer(&mut self) {
|
||||
let _ = self.fill_buffer();
|
||||
self.buffer = Vec::new();
|
||||
}
|
||||
|
||||
pub fn recv_bytes(&mut self) -> Result<Vec<u8>> {
|
||||
let retry_counter = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user