mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
feat: add EWMA clock delta and adjtimex nudge controls
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
6a45660e03
commit
cc782fcd7e
7 changed files with 152 additions and 59 deletions
|
|
@ -104,6 +104,33 @@ pub fn trigger_sync(frame: &LtcFrame, config: &Config) -> Result<String, ()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn nudge_clock(microseconds: i64) -> Result<(), ()> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let success = Command::new("sudo")
|
||||
.arg("adjtimex")
|
||||
.arg("--singleshot")
|
||||
.arg(microseconds.to_string())
|
||||
.status()
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false);
|
||||
|
||||
if success {
|
||||
log::info!("Nudged clock by {} us", microseconds);
|
||||
Ok(())
|
||||
} else {
|
||||
log::error!("Failed to nudge clock with adjtimex");
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
let _ = microseconds;
|
||||
log::warn!("Clock nudging is only supported on Linux.");
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -179,4 +206,10 @@ mod tests {
|
|||
assert_eq!(target_time.second(), 20);
|
||||
assert_eq!(target_time.nanosecond(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nudge_clock_on_non_linux() {
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
assert!(nudge_clock(1000).is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue