mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: Adapt to statime v0.4.0 API changes
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
7cd86ad9f4
commit
eba5b450bb
1 changed files with 24 additions and 22 deletions
46
src/ptp.rs
46
src/ptp.rs
|
|
@ -8,9 +8,10 @@ use statime::{
|
||||||
},
|
},
|
||||||
filters::BasicFilter,
|
filters::BasicFilter,
|
||||||
port::PortAction,
|
port::PortAction,
|
||||||
OverlayClock, PtpInstance, SharedClock,
|
time::{Duration as PtpDuration, Interval},
|
||||||
|
Clock, OverlayClock, PtpInstance, SharedClock,
|
||||||
};
|
};
|
||||||
use statime_linux::{clock::SystemClock, net::LinuxUdpHandles};
|
use statime_linux::{net::LinuxUdpHandles, SystemClock};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::{sleep, Instant};
|
use tokio::time::{sleep, Instant};
|
||||||
|
|
@ -64,41 +65,46 @@ async fn run_ptp_session(
|
||||||
|
|
||||||
// 1. Create configs
|
// 1. Create configs
|
||||||
let instance_config = InstanceConfig {
|
let instance_config = InstanceConfig {
|
||||||
clock_identity: ClockIdentity::from_mac_address(&[0x00, 0x11, 0x22, 0xFF, 0xFE, 0x33, 0x44, 0x55]),
|
clock_identity: ClockIdentity::from_mac_address([0x00, 0x11, 0x22, 0x33, 0x44, 0x55]),
|
||||||
priority_1: 128,
|
priority_1: 128,
|
||||||
priority_2: 128,
|
priority_2: 128,
|
||||||
domain_number: 0,
|
domain_number: 0,
|
||||||
slave_only: false,
|
slave_only: false,
|
||||||
sdo_id: Default::default(),
|
sdo_id: Default::default(),
|
||||||
path_trace: false,
|
path_trace: false,
|
||||||
clock_quality: ClockQuality::default(),
|
|
||||||
};
|
};
|
||||||
let time_properties_ds =
|
let time_properties_ds =
|
||||||
TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
|
TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
|
||||||
|
|
||||||
// 2. Create PtpInstance
|
// 2. Create PtpInstance
|
||||||
let mut ptp_instance = PtpInstance::<BasicFilter>::new(instance_config, time_properties_ds);
|
let mut ptp_instance = PtpInstance::<BasicFilter>::new(instance_config, time_properties_ds);
|
||||||
|
ptp_instance.set_clock_quality(ClockQuality::default());
|
||||||
|
|
||||||
// 3. Create PortConfig
|
// 3. Create PortConfig
|
||||||
let port_config = PortConfig {
|
let port_config = PortConfig {
|
||||||
iface: interface.into(),
|
|
||||||
use_hardware_timestamping: false,
|
|
||||||
acceptable_master_list: AcceptAnyMaster,
|
acceptable_master_list: AcceptAnyMaster,
|
||||||
delay_mechanism: DelayMechanism::EndToEnd,
|
delay_mechanism: DelayMechanism::E2E,
|
||||||
|
announce_interval: Interval::from_log2(0).unwrap(),
|
||||||
|
announce_receipt_timeout: 2,
|
||||||
|
sync_interval: Interval::from_log2(0).unwrap(),
|
||||||
|
master_only: false,
|
||||||
|
delay_asymmetry: PtpDuration::default(),
|
||||||
|
minor_ptp_version: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 4. Create Clock and Filter
|
// 4. Create Clock and Filter
|
||||||
let clock = SharedClock::new(OverlayClock::new(SystemClock::new()));
|
let clock = SharedClock::new(OverlayClock::new(SystemClock));
|
||||||
let filter_config = ();
|
let filter_config = 0.1; // Filter coefficient
|
||||||
|
|
||||||
// 5. Add port and run BMCA
|
// 5. Create network handles
|
||||||
let mut port = ptp_instance.add_port(port_config.clone(), filter_config, clock, thread_rng())?;
|
let (mut event_handle, mut general_handle) =
|
||||||
|
LinuxUdpHandles::new(&port_config, &interface)?;
|
||||||
|
|
||||||
|
// 6. Add port and run BMCA
|
||||||
|
let mut port = ptp_instance.add_port(port_config, filter_config, clock, thread_rng())?;
|
||||||
ptp_instance.bmca(&mut [&mut port]);
|
ptp_instance.bmca(&mut [&mut port]);
|
||||||
let mut running_port = port.end_bmca()?;
|
let mut running_port = port.end_bmca()?;
|
||||||
|
|
||||||
// 6. Create network handles
|
|
||||||
let (mut event_handle, mut general_handle) = LinuxUdpHandles::new(&port_config)?;
|
|
||||||
|
|
||||||
let mut last_state_update = Instant::now();
|
let mut last_state_update = Instant::now();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -139,21 +145,17 @@ async fn run_ptp_session(
|
||||||
|
|
||||||
for action in actions {
|
for action in actions {
|
||||||
match action {
|
match action {
|
||||||
PortAction::Send {
|
PortAction::SendMessage(message) => {
|
||||||
destination,
|
let handle = if message.event {
|
||||||
data,
|
|
||||||
event,
|
|
||||||
} => {
|
|
||||||
let handle = if event {
|
|
||||||
&mut event_handle
|
&mut event_handle
|
||||||
} else {
|
} else {
|
||||||
&mut general_handle
|
&mut general_handle
|
||||||
};
|
};
|
||||||
if let Err(e) = handle.send(data, destination).await {
|
if let Err(e) = handle.send(message.data, message.destination).await {
|
||||||
log::error!("Error sending PTP packet: {}", e);
|
log::error!("Error sending PTP packet: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PortAction::Reset => {
|
PortAction::ToBmca => {
|
||||||
log::warn!("PTP port is resetting");
|
log::warn!("PTP port is resetting");
|
||||||
ptp_instance.bmca(&mut [&mut running_port.start_bmca()]);
|
ptp_instance.bmca(&mut [&mut running_port.start_bmca()]);
|
||||||
running_port = running_port.start_bmca().end_bmca()?;
|
running_port = running_port.start_bmca().end_bmca()?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue