diff --git a/examples/cli.rs b/examples/cli.rs index 9523cf6..6c6c3f5 100644 --- a/examples/cli.rs +++ b/examples/cli.rs @@ -20,6 +20,7 @@ fn main() { loop { inquire_and_send_command(&mut serial, &scheduler_path).unwrap(); println!("------------------------"); + std::thread::sleep(Duration::from_millis(100)); } } @@ -130,6 +131,7 @@ fn inquire_and_send_command(edu: &mut impl CommunicationHandle, path: &str) -> R match edu.receive_multi_packet() { Ok(data) => { std::fs::write(result_path, data)?; + edu.send_packet(&CEPPacket::Ack)?; println!("Wrote result to file"); }, Err(e) => println!("Received {:?}", e), diff --git a/src/communication/mod.rs b/src/communication/mod.rs index 944d81a..231cde2 100644 --- a/src/communication/mod.rs +++ b/src/communication/mod.rs @@ -115,12 +115,13 @@ pub trait CommunicationHandle: Read + Write { /// Try to receive an ACK packet with a given `timeout`. Resets the timeout to Duration::MAX afterwards fn await_ack(&mut self, timeout: Duration) -> ComResult<()> { self.set_timeout(timeout); - let ret = match self.receive_packet()? { + let result = self.receive_packet(); + self.set_timeout(Self::UNLIMITED_TIMEOUT); + let ret = match result? { CEPPacket::Ack => Ok(()), CEPPacket::Nack => Err(CommunicationError::NotAcknowledged), _ => Err(CommunicationError::PacketInvalidError), }; - self.set_timeout(Self::UNLIMITED_TIMEOUT); ret } }