Skip to content

Commit

Permalink
Fix resetting of timeout when ACK is not received
Browse files Browse the repository at this point in the history
This was uncovered by the cli tools lack of ACK response
  • Loading branch information
Florian Guggi committed May 3, 2024
1 parent 5702ab0 commit a263809
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() {
loop {
inquire_and_send_command(&mut serial, &scheduler_path).unwrap();
println!("------------------------");
std::thread::sleep(Duration::from_millis(100));
}
}

Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit a263809

Please sign in to comment.