| 129 | type Error = TryFromPhcSampleError; |
| 130 | |
| 131 | fn try_from(sample: PhcSample) -> Result<Self, Self::Error> { |
| 132 | if sample.counter_post < sample.counter_pre { |
| 133 | return Err(TryFromPhcSampleError::InvalidCounterDiff); |
| 134 | } |
| 135 | if sample.ptp_clock_error_bound_nsec < 0 { |
| 136 | return Err(TryFromPhcSampleError::InvalidClockErrorBound); |
| 137 | } |
| 138 | |
| 139 | let builder = event::Phc::builder() |
| 140 | .tsc_pre(TscCount::new(sample.counter_pre.into())) |
| 141 | .tsc_post(TscCount::new(sample.counter_post.into())) |
| 142 | .data(PhcData { |
| 143 | time: Instant::from_time( |
| 144 | sample.ptp_clock_time.sec.into(), |
| 145 | sample.ptp_clock_time.nsec, |
| 146 | ), |
| 147 | clock_error_bound: Duration::from_nanos(sample.ptp_clock_error_bound_nsec.into()), |
| 148 | }); |
| 149 | |
| 150 | match builder.build() { |
| 151 | Some(phc) => Ok(phc), |
| 152 | None => Err(TryFromPhcSampleError::UnexpectedError), |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /// Contains data used to run PHC runner. |