Skip to content

Commit

Permalink
Enable clock synchronization with federates
Browse files Browse the repository at this point in the history
  • Loading branch information
chanijjani committed Mar 12, 2024
1 parent 2e41e50 commit 7423382
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 15 deletions.
4 changes: 4 additions & 0 deletions rust/rti/src/federate_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl FederateInfo {
&self.stream
}

pub fn stream_mut(&mut self) -> &mut Option<TcpStream> {
&mut self.stream
}

pub fn clock_synchronization_enabled(&self) -> bool {
self.clock_synchronization_enabled
}
Expand Down
18 changes: 18 additions & 0 deletions rust/rti/src/net_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub enum MsgType {
AddressAdvertisement,
P2pSendingFedId,
P2pTaggedMessage,
ClockSyncT1,
ClockSyncT3,
ClockSyncT4,
ClockSyncCodedProbe,
PortAbsent,
NeighborStructure,
Ignore,
Expand All @@ -129,6 +133,10 @@ impl MsgType {
MsgType::AddressAdvertisement => 14,
MsgType::P2pSendingFedId => 15,
MsgType::P2pTaggedMessage => 17,
MsgType::ClockSyncT1 => 19,
MsgType::ClockSyncT3 => 20,
MsgType::ClockSyncT4 => 21,
MsgType::ClockSyncCodedProbe => 22,
MsgType::PortAbsent => 23,
MsgType::NeighborStructure => 24,
MsgType::Ignore => 250,
Expand All @@ -150,6 +158,10 @@ impl MsgType {
12 => MsgType::StopGranted,
13 => MsgType::AddressQuery,
14 => MsgType::AddressAdvertisement,
19 => MsgType::ClockSyncT1,
20 => MsgType::ClockSyncT3,
21 => MsgType::ClockSyncT4,
22 => MsgType::ClockSyncCodedProbe,
23 => MsgType::PortAbsent,
_ => MsgType::Ignore,
}
Expand Down Expand Up @@ -182,3 +194,9 @@ impl ErrType {
}
}
}

#[derive(PartialEq, Clone)]
pub enum SocketType {
TCP,
UDP,
}
4 changes: 2 additions & 2 deletions rust/rti/src/net_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl NetUtil {
// println!("\n");
}

pub fn read_from_stream(stream: &mut TcpStream, buffer: &mut Vec<u8>, fed_id: u16) -> usize {
pub fn read_from_socket(stream: &mut TcpStream, buffer: &mut Vec<u8>, fed_id: u16) -> usize {
let mut bytes_read = 0;
while match stream.read(buffer) {
Ok(msg_size) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl NetUtil {
}
}

pub fn write_to_stream(mut stream: &TcpStream, buffer: &Vec<u8>, fed_id: u16) -> usize {
pub fn write_to_socket(mut stream: &TcpStream, buffer: &Vec<u8>, fed_id: u16) -> usize {
let mut bytes_written = 0;
match stream.write(&buffer) {
Ok(bytes_size) => {
Expand Down
4 changes: 4 additions & 0 deletions rust/rti/src/rti_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ impl RTIRemote {
self.clock_sync_global_status.clone()
}

pub fn clock_sync_period_ns(&self) -> u64 {
self.clock_sync_period_ns
}

pub fn stop_in_progress(&self) -> bool {
self.stop_in_progress
}
Expand Down
Loading

0 comments on commit 7423382

Please sign in to comment.