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
16
src/api.rs
16
src/api.rs
|
|
@ -8,8 +8,8 @@ use serde_json;
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::config::{self, Config};
|
||||
use crate::sync_logic::LtcState;
|
||||
use crate::ui;
|
||||
use crate::sync_logic::{self, LtcState};
|
||||
use crate::system;
|
||||
|
||||
// Data structure for the main status response
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
@ -20,8 +20,8 @@ struct ApiStatus {
|
|||
system_clock: String,
|
||||
timecode_delta_ms: i64,
|
||||
timecode_delta_frames: i64,
|
||||
sync_status: String,
|
||||
jitter_status: String,
|
||||
sync_status: &'static str,
|
||||
jitter_status: &'static str,
|
||||
lock_ratio: f64,
|
||||
ntp_active: bool,
|
||||
interfaces: Vec<String>,
|
||||
|
|
@ -64,11 +64,11 @@ async fn get_status(data: web::Data<AppState>) -> impl Responder {
|
|||
delta_frames = ((avg_delta as f64 / frame_ms).round()) as i64;
|
||||
}
|
||||
|
||||
let sync_status = ui::get_sync_status(avg_delta, &config).to_string();
|
||||
let jitter_status = ui::get_jitter_status(state.average_jitter()).to_string();
|
||||
let sync_status = sync_logic::get_sync_status(avg_delta, &config);
|
||||
let jitter_status = sync_logic::get_jitter_status(state.average_jitter());
|
||||
let lock_ratio = state.lock_ratio();
|
||||
|
||||
let ntp_active = ui::ntp_service_active();
|
||||
let ntp_active = system::ntp_service_active();
|
||||
let interfaces = get_if_addrs()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
|
|
@ -97,7 +97,7 @@ async fn manual_sync(data: web::Data<AppState>) -> impl Responder {
|
|||
let state = data.ltc_state.lock().unwrap();
|
||||
let config = data.config.lock().unwrap();
|
||||
if let Some(frame) = &state.latest {
|
||||
if ui::trigger_sync(frame, &config).is_ok() {
|
||||
if system::trigger_sync(frame, &config).is_ok() {
|
||||
HttpResponse::Ok().json(serde_json::json!({ "status": "success", "message": "Sync command issued." }))
|
||||
} else {
|
||||
HttpResponse::InternalServerError().json(serde_json::json!({ "status": "error", "message": "Sync command failed." }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue