mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: Adapt PTP code to statime API changes
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
eba5b450bb
commit
b11c66016f
1 changed files with 11 additions and 18 deletions
29
src/ptp.rs
29
src/ptp.rs
|
|
@ -4,14 +4,14 @@ use rand::thread_rng;
|
||||||
use statime::{
|
use statime::{
|
||||||
config::{
|
config::{
|
||||||
AcceptAnyMaster, ClockIdentity, ClockQuality, DelayMechanism, InstanceConfig, PortConfig,
|
AcceptAnyMaster, ClockIdentity, ClockQuality, DelayMechanism, InstanceConfig, PortConfig,
|
||||||
TimePropertiesDS, TimeSource,
|
PtpMinorVersion, TimePropertiesDS, TimeSource,
|
||||||
},
|
},
|
||||||
filters::BasicFilter,
|
filters::BasicFilter,
|
||||||
port::PortAction,
|
port::{PortAction, SendMessage},
|
||||||
time::{Duration as PtpDuration, Interval},
|
time::{Duration as PtpDuration, Interval},
|
||||||
Clock, OverlayClock, PtpInstance, SharedClock,
|
OverlayClock, PtpInstance, SharedClock,
|
||||||
};
|
};
|
||||||
use statime_linux::{net::LinuxUdpHandles, SystemClock};
|
use statime_linux::{net_udp::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};
|
||||||
|
|
@ -78,18 +78,17 @@ async fn run_ptp_session(
|
||||||
|
|
||||||
// 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 {
|
||||||
acceptable_master_list: AcceptAnyMaster,
|
acceptable_master_list: AcceptAnyMaster,
|
||||||
delay_mechanism: DelayMechanism::E2E,
|
delay_mechanism: DelayMechanism::E2E(Interval::from_log_2(0)),
|
||||||
announce_interval: Interval::from_log2(0).unwrap(),
|
announce_interval: Interval::from_log_2(0),
|
||||||
announce_receipt_timeout: 2,
|
announce_receipt_timeout: 2,
|
||||||
sync_interval: Interval::from_log2(0).unwrap(),
|
sync_interval: Interval::from_log_2(0),
|
||||||
master_only: false,
|
master_only: false,
|
||||||
delay_asymmetry: PtpDuration::default(),
|
delay_asymmetry: PtpDuration::default(),
|
||||||
minor_ptp_version: 1,
|
minor_ptp_version: PtpMinorVersion::PTP_2_1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 4. Create Clock and Filter
|
// 4. Create Clock and Filter
|
||||||
|
|
@ -127,19 +126,13 @@ async fn run_ptp_session(
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = tokio::time::sleep_until(timer_instant) => {
|
_ = tokio::time::sleep_until(timer_instant) => {
|
||||||
if let Some(action) = running_port.handle_timer() {
|
actions.extend(running_port.handle_timer());
|
||||||
actions.push(action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok((message, source_address)) = event_handle.recv() => {
|
Ok((message, source_address)) = event_handle.recv() => {
|
||||||
if let Some(action) = running_port.handle_message(&message, source_address) {
|
actions.extend(running_port.handle_message(&message, source_address));
|
||||||
actions.push(action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok((message, source_address)) = general_handle.recv() => {
|
Ok((message, source_address)) = general_handle.recv() => {
|
||||||
if let Some(action) = running_port.handle_message(&message, source_address) {
|
actions.extend(running_port.handle_message(&message, source_address));
|
||||||
actions.push(action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue