Make sure there are no pending packages in buffer before sending one

This commit is contained in:
clerie 2024-12-27 12:59:30 +01:00
parent aea6105268
commit 0288b49319
2 changed files with 13 additions and 0 deletions

View File

@ -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 {

View File

@ -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;