Add timestamp to SimRequest #140

Merged
muellerr merged 8 commits from add-timestamp-to-sim-request into main 2024-05-08 14:58:14 +02:00
2 changed files with 6 additions and 4 deletions
Showing only changes of commit f00e6cf50c - Show all commits

View File

@ -49,18 +49,18 @@ impl SimController {
}
pub fn run(&mut self, start_time: MonotonicTime, udp_polling_interval_ms: u64) {
let mut t = start_time + Duration::from_millis(udp_polling_interval_ms);
self.sys_clock.synchronize(t);
let mut t = start_time;
loop {
let t_old = t;
// Check for UDP requests every millisecond. Shift the simulator ahead here to prevent
// replies lying in the past.
t += Duration::from_millis(udp_polling_interval_ms);
self.sys_clock.synchronize(t);
self.handle_sim_requests();
self.simulation
.step_until(t)
.expect("simulation step failed");
self.handle_sim_requests();
self.sys_clock.synchronize(t);
}
}

View File

@ -1,3 +1,4 @@
use asynchronix::time::MonotonicTime;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
@ -19,6 +20,7 @@ pub struct SimMessage {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SimRequest {
inner: SimMessage,
timestamp: MonotonicTime
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]