mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
feat: add daemon mode and systemd service
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
d55a11b074
commit
1d9bc1e25e
7 changed files with 244 additions and 281 deletions
|
|
@ -170,10 +170,33 @@ impl LtcState {
|
|||
&self.last_match_status
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_sync_status(delta_ms: i64, config: &Config) -> &'static str {
|
||||
if config.timeturner_offset.is_active() {
|
||||
"TIMETURNING"
|
||||
} else if delta_ms.abs() <= 8 {
|
||||
"IN SYNC"
|
||||
} else if delta_ms > 10 {
|
||||
"CLOCK AHEAD"
|
||||
} else {
|
||||
"CLOCK BEHIND"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_jitter_status(jitter_ms: i64) -> &'static str {
|
||||
if jitter_ms.abs() < 10 {
|
||||
"GOOD"
|
||||
} else if jitter_ms.abs() < 40 {
|
||||
"AVERAGE"
|
||||
} else {
|
||||
"BAD"
|
||||
}
|
||||
}
|
||||
// This module provides the logic for handling LTC (Linear Timecode) frames and maintaining state.
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::config::{Config, TimeturnerOffset};
|
||||
use chrono::{Local, Utc};
|
||||
|
||||
fn get_test_frame(status: &str, h: u32, m: u32, s: u32) -> LtcFrame {
|
||||
|
|
@ -332,4 +355,34 @@ mod tests {
|
|||
"Median of even numbers should be correct"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_sync_status() {
|
||||
let mut config = Config::default();
|
||||
assert_eq!(get_sync_status(0, &config), "IN SYNC");
|
||||
assert_eq!(get_sync_status(8, &config), "IN SYNC");
|
||||
assert_eq!(get_sync_status(-8, &config), "IN SYNC");
|
||||
assert_eq!(get_sync_status(9, &config), "CLOCK BEHIND");
|
||||
assert_eq!(get_sync_status(10, &config), "CLOCK BEHIND");
|
||||
assert_eq!(get_sync_status(11, &config), "CLOCK AHEAD");
|
||||
assert_eq!(get_sync_status(-9, &config), "CLOCK BEHIND");
|
||||
assert_eq!(get_sync_status(-100, &config), "CLOCK BEHIND");
|
||||
|
||||
// Test TIMETURNING status
|
||||
config.timeturner_offset = TimeturnerOffset { hours: 1, minutes: 0, seconds: 0, frames: 0 };
|
||||
assert_eq!(get_sync_status(0, &config), "TIMETURNING");
|
||||
assert_eq!(get_sync_status(100, &config), "TIMETURNING");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_jitter_status() {
|
||||
assert_eq!(get_jitter_status(5), "GOOD");
|
||||
assert_eq!(get_jitter_status(-5), "GOOD");
|
||||
assert_eq!(get_jitter_status(9), "GOOD");
|
||||
assert_eq!(get_jitter_status(10), "AVERAGE");
|
||||
assert_eq!(get_jitter_status(39), "AVERAGE");
|
||||
assert_eq!(get_jitter_status(-39), "AVERAGE");
|
||||
assert_eq!(get_jitter_status(40), "BAD");
|
||||
assert_eq!(get_jitter_status(-40), "BAD");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue