Create a new feed forward time synchronization algorithm `local_capacity` should be the number of data-points to span an SKM window. For example, if the source is expected to sample once every second, the `local_capacity` should have a max value of 1024. # Panics Panics if poll duration is zero or greater than or equal to 512 seconds
(poll_period: Duration, max_dispersion: Skew)
| 51 | /// # Panics |
| 52 | /// Panics if poll duration is zero or greater than or equal to 512 seconds |
| 53 | pub fn new(poll_period: Duration, max_dispersion: Skew) -> Self { |
| 54 | const WINDOW: Duration = Duration::from_secs(100); |
| 55 | assert!(poll_period > Duration::ZERO, "poll period must be positive"); |
| 56 | assert!( |
| 57 | poll_period < WINDOW / 2, |
| 58 | "Must be able to get at least 2 samples in local buffer" |
| 59 | ); |
| 60 | let local_capacity = WINDOW.get() / poll_period.get(); |
| 61 | |
| 62 | // unwrap: input is bound and numerator is never 0 |
| 63 | let local_capacity = NonZeroUsize::new(local_capacity.try_into().unwrap()).unwrap(); |
| 64 | |
| 65 | // unwrap: input is bound and numerator is never 0 |
| 66 | let staging_capacity = event_buffer::Local::<Phc>::SKM_WINDOW.get() / poll_period.get(); |
| 67 | let staging_capacity = NonZeroUsize::new(staging_capacity.try_into().unwrap()).unwrap(); |
| 68 | |
| 69 | Self { |
| 70 | local: event_buffer::Local::with_window(local_capacity, WINDOW), |
| 71 | staging: event_buffer::Local::new(staging_capacity), |
| 72 | estimate: event_buffer::Estimate::new(), |
| 73 | clock_parameters: None, |
| 74 | uncorrected_clock: None, |
| 75 | max_dispersion, |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /// Feed an event into this algorithm |
| 80 | /// |