diff --git a/src/api.rs b/src/api.rs index a622a0b..62f21a7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -242,6 +242,7 @@ mod tests { minutes: 2, seconds: 3, frames: 4, + is_drop_frame: false, frame_rate: Ratio::new(25, 1), timestamp: Utc::now(), }), diff --git a/src/serial_input.rs b/src/serial_input.rs index 10c3626..d1dea36 100644 --- a/src/serial_input.rs +++ b/src/serial_input.rs @@ -32,7 +32,7 @@ pub fn start_serial_thread( let reader = std::io::BufReader::new(port); let re = Regex::new( - r"\[(LOCK|FREE)\]\s+(\d{2}):(\d{2}):(\d{2})[:;](\d{2})\s+\|\s+([\d.]+)fps", + r"\[(LOCK|FREE)\]\s+(\d{2}):(\d{2}):(\d{2})([:;])(\d{2})\s+\|\s+([\d.]+)fps", ) .unwrap(); @@ -60,11 +60,12 @@ mod tests { use super::*; use std::sync::mpsc; use crate::sync_logic::LtcState; + use num_rational::Ratio; use regex::Regex; fn get_ltc_regex() -> Regex { Regex::new( - r"\[(LOCK|FREE)\]\s+(\d{2}):(\d{2}):(\d{2})[:;](\d{2})\s+\|\s+([\d.]+)fps", + r"\[(LOCK|FREE)\]\s+(\d{2}):(\d{2}):(\d{2})([:;])(\d{2})\s+\|\s+([\d.]+)fps", ).unwrap() } @@ -119,7 +120,7 @@ mod tests { assert_eq!(st.free_count, 1); let received_frame = rx.try_recv().unwrap(); assert_eq!(received_frame.status, "FREE"); - assert_eq!(received_frame.frame_rate, 29.97); + assert_eq!(received_frame.frame_rate, Ratio::new(30000, 1001)); } #[test] diff --git a/src/sync_logic.rs b/src/sync_logic.rs index 06b14f0..cc197b3 100644 --- a/src/sync_logic.rs +++ b/src/sync_logic.rs @@ -24,6 +24,7 @@ pub struct LtcFrame { pub minutes: u32, pub seconds: u32, pub frames: u32, + pub is_drop_frame: bool, pub frame_rate: Ratio, pub timestamp: DateTime, // arrival stamp } @@ -35,8 +36,9 @@ impl LtcFrame { hours: caps[2].parse().ok()?, minutes: caps[3].parse().ok()?, seconds: caps[4].parse().ok()?, - frames: caps[5].parse().ok()?, - frame_rate: get_frame_rate_ratio(&caps[6])?, + is_drop_frame: &caps[5] == ";", + frames: caps[6].parse().ok()?, + frame_rate: get_frame_rate_ratio(&caps[7])?, timestamp, }) } @@ -205,6 +207,7 @@ mod tests { minutes: m, seconds: s, frames: 0, + is_drop_frame: false, frame_rate: Ratio::new(25, 1), timestamp: Utc::now(), } diff --git a/src/system.rs b/src/system.rs index 0ce73aa..64205b4 100644 --- a/src/system.rs +++ b/src/system.rs @@ -49,10 +49,10 @@ pub fn calculate_target_time(frame: &LtcFrame, config: &Config) -> DateTime