From adbe09b9d2b9bc93e18b15187c41c30194f558b0 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Sun, 1 Feb 2026 20:06:17 -0800 Subject: [PATCH] prs10: intermediate work --- Cargo.lock | 11 ++++++++++- Cargo.toml | 2 +- config.toml.dist | 9 ++++++++- src/lib.rs | 25 +++++++++++++++++++++++++ src/main.rs | 25 ++++++++++++++++++++++++- 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c6bbc9..3eb956b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,6 +195,15 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "bit-struct" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "270fbbb014407467f7a2c9b1fa0b74057d5cbc452f18bac3bb5aad601e590521" +dependencies = [ + "num-traits", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -259,6 +268,7 @@ dependencies = [ "async-stream", "async-trait", "backoff", + "bit-struct", "bitflags 1.3.2", "byteorder", "bytes", @@ -272,7 +282,6 @@ dependencies = [ "influxdb2", "itertools 0.14.0", "libc", - "log", "serde", "serde_derive", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 352ad7a..e5cba21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ influxdb2 = { version = "0.3.3", features = [ ], default-features = false } tokio = { version = "1", features = ["rt", "io-util"] } clap = { version = "4.0", features = ["derive"] } -log = "0.4" figment = { version = "0.10", features = ["toml"] } gethostname = "0.3" futures = "0.3.24" @@ -36,6 +35,7 @@ backoff = { version = "0.4.0", features = ["tokio"] } serde_repr = "0.1.20" tracing = "0.1.44" tracing-subscriber = { version = "0.3.22", features = ["fmt"] } +bit-struct = { version = "0.3.2", default-features = false } [dependencies.chrony-candm] git = "https://github.com/aws/chrony-candm" diff --git a/config.toml.dist b/config.toml.dist index 387ecef..67d94e4 100644 --- a/config.toml.dist +++ b/config.toml.dist @@ -23,6 +23,13 @@ port = "/dev/ttyUSB0" status_interval = 10 measurement = "uccm_gpsdo" + + [sources.prs10] + enabled = true + port = "/dev/ttyUSB0" + status_interval = 10 + stats_interval = 10 + measurement = "prs10_gpsdo" [targets] @@ -38,4 +45,4 @@ token = "" [influxdb.tags] # host = "qubit" # default is the local hostname -# arbitrary = "tags" # are allowed \ No newline at end of file +# arbitrary = "tags" # are allowed diff --git a/src/lib.rs b/src/lib.rs index f309d48..cf731e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod chrony; pub mod chrony_refclock; pub mod gpsd; pub mod hwmon; +pub mod prs10; pub mod uccm; use async_trait::async_trait; @@ -127,6 +128,29 @@ impl Default for GpsdConfig { } } +#[derive(Serialize, Deserialize, Clone)] +pub struct Prs10Config { + pub enabled: bool, + pub port: String, + pub baud: u32, + pub timeout: std::time::Duration, + pub status_interval: std::time::Duration, + pub stats_interval: std::time::Duration, +} + +impl Default for Prs10Config { + fn default() -> Self { + Prs10Config { + enabled: false, + port: "/dev/ttyS0".into(), + baud: 9600, + timeout: std::time::Duration::from_secs(1), + status_interval: std::time::Duration::from_secs(10), + stats_interval: std::time::Duration::from_secs(10), + } + } +} + #[derive(Clone, Debug)] pub struct TimeReport { pub system_time: DateTime, @@ -226,6 +250,7 @@ pub struct SourcesConfig { pub hwmon: HwmonConfig, pub uccm: UCCMConfig, pub gpsd: GpsdConfig, + pub prs10: Prs10Config, } #[derive(Serialize, Deserialize, Clone, Default)] diff --git a/src/main.rs b/src/main.rs index 3098ea6..dbd3c85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,10 @@ use tokio::sync::broadcast; use tracing::{Instrument, debug, error, info, info_span, warn}; use tracing_subscriber; -use crate::{chrony::*, chrony_refclock::ChronySockServer, hwmon::HwmonSource, uccm::UCCMMonitor}; +use crate::{ + chrony::*, chrony_refclock::ChronySockServer, hwmon::HwmonSource, prs10::Prs10Monitor, + uccm::UCCMMonitor, +}; use chimemon::{gpsd::GpsdSource, *}; const PROGRAM_NAME: &str = "chimemon"; @@ -138,6 +141,19 @@ async fn main() -> Result<(), Box> { )) } + let prs10 = if config.sources.prs10.enabled { + Some(Prs10Monitor::new(config.sources.prs10)) + } else { + None + }; + if let Some(prs10) = prs10 { + tasks.push(tokio::spawn( + prs10 + .run(sourcechan.clone()) + .instrument(info_span!("prs10-task")), + )) + } + if tasks.len() == 0 { error!("No tasks configured, exiting."); return Ok(()); // not an error, but exit before starting a dummy task @@ -152,6 +168,13 @@ async fn main() -> Result<(), Box> { loop { while let Ok(m) = chan.recv().await { info!("received {m:?}"); + match m { + ChimemonMessage::SourceReport(report) => { + let metrics = report.details.to_metrics(); + info!("metrics: {metrics:?}"); + } + _ => {} + } } } }