prs10: intermediate work

This commit is contained in:
2026-02-01 20:06:17 -08:00
parent ea412f4a66
commit adbe09b9d2
5 changed files with 68 additions and 4 deletions

11
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"

View File

@@ -24,6 +24,13 @@
status_interval = 10
measurement = "uccm_gpsdo"
[sources.prs10]
enabled = true
port = "/dev/ttyUSB0"
status_interval = 10
stats_interval = 10
measurement = "prs10_gpsdo"
[targets]
[targets.chrony]

View File

@@ -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<Utc>,
@@ -226,6 +250,7 @@ pub struct SourcesConfig {
pub hwmon: HwmonConfig,
pub uccm: UCCMConfig,
pub gpsd: GpsdConfig,
pub prs10: Prs10Config,
}
#[derive(Serialize, Deserialize, Clone, Default)]

View File

@@ -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<dyn std::error::Error>> {
))
}
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<dyn std::error::Error>> {
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:?}");
}
_ => {}
}
}
}
}