Add chrony SOCK refclock and initial UCCM source
This commit is contained in:
84
src/lib.rs
84
src/lib.rs
@@ -1,6 +1,7 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::NaiveDateTime;
|
||||
use figment::{
|
||||
providers::{Format, Serialized, Toml},
|
||||
providers::{Data, Format, Serialized, Toml},
|
||||
util::map,
|
||||
value::Map,
|
||||
Figment,
|
||||
@@ -8,7 +9,7 @@ use figment::{
|
||||
use gethostname::gethostname;
|
||||
use influxdb2::models::DataPoint;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
use std::{path::Path, time::Duration};
|
||||
use tokio::sync::broadcast::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
@@ -60,6 +61,21 @@ impl Default for ChronyConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct ChronySockConfig {
|
||||
pub enabled: bool,
|
||||
pub sock: String,
|
||||
}
|
||||
|
||||
impl Default for ChronySockConfig {
|
||||
fn default() -> Self {
|
||||
ChronySockConfig {
|
||||
enabled: false,
|
||||
sock: "".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct HwmonSensorConfig {
|
||||
pub name: String,
|
||||
@@ -84,25 +100,85 @@ impl Default for HwmonConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TimeReport {
|
||||
pub system_time: NaiveDateTime,
|
||||
pub offset: chrono::Duration,
|
||||
pub leaps: isize,
|
||||
pub leap_flag: bool,
|
||||
pub valid: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct UCCMConfig {
|
||||
pub enabled: bool,
|
||||
pub port: String,
|
||||
pub baud: u32,
|
||||
pub status_interval: std::time::Duration,
|
||||
pub timeout: std::time::Duration,
|
||||
}
|
||||
|
||||
impl Default for UCCMConfig {
|
||||
fn default() -> Self {
|
||||
UCCMConfig {
|
||||
enabled: false,
|
||||
port: "/dev/ttyS0".into(),
|
||||
baud: 57600,
|
||||
status_interval: std::time::Duration::from_secs(10),
|
||||
timeout: std::time::Duration::from_secs(1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
pub struct SourcesConfig {
|
||||
pub chrony: ChronyConfig,
|
||||
pub hwmon: HwmonConfig,
|
||||
pub uccm: UCCMConfig,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
pub struct TargetsConfig {
|
||||
pub chrony: ChronySockConfig,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
pub struct Config {
|
||||
pub influxdb: InfluxConfig,
|
||||
pub sources: SourcesConfig,
|
||||
pub targets: TargetsConfig,
|
||||
}
|
||||
|
||||
pub fn load_config(filename: &Path) -> Figment {
|
||||
Figment::from(Serialized::defaults(Config::default())).merge(Toml::file(filename))
|
||||
}
|
||||
|
||||
pub type ChimemonSourceChannel = Sender<DataPoint>;
|
||||
pub type ChimemonTargetChannel = Receiver<DataPoint>;
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ChimemonMessage {
|
||||
DataPoint(DataPoint),
|
||||
DataPoints(Vec<DataPoint>),
|
||||
TimeReport(TimeReport),
|
||||
}
|
||||
|
||||
impl From<DataPoint> for ChimemonMessage {
|
||||
fn from(dp: DataPoint) -> Self {
|
||||
ChimemonMessage::DataPoint(dp)
|
||||
}
|
||||
}
|
||||
impl From<Vec<DataPoint>> for ChimemonMessage {
|
||||
fn from(dps: Vec<DataPoint>) -> Self {
|
||||
ChimemonMessage::DataPoints(dps)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TimeReport> for ChimemonMessage {
|
||||
fn from(tr: TimeReport) -> Self {
|
||||
ChimemonMessage::TimeReport(tr)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ChimemonSourceChannel = Sender<ChimemonMessage>;
|
||||
pub type ChimemonTargetChannel = Receiver<ChimemonMessage>;
|
||||
|
||||
#[async_trait]
|
||||
pub trait ChimemonSource {
|
||||
|
||||
Reference in New Issue
Block a user