This commit is contained in:
Keenan Tims 2025-05-03 23:12:15 -07:00
parent d7c57cf23a
commit cef472d2c5
Signed by: ktims
GPG Key ID: 11230674D69038D4
4 changed files with 17 additions and 43 deletions

View File

@ -114,8 +114,8 @@ impl ChronyClient {
} }
} }
async fn query(&self, request: RequestBody) -> Result<reply::Reply, std::io::Error> { async fn query(&self, request: RequestBody) -> Result<reply::Reply, std::io::Error> {
let server = self.server.clone(); let server = self.server;
let client_options = self.client_options.clone(); let client_options = self.client_options;
tokio::task::spawn_blocking(move || blocking_query(request, client_options, &server)) tokio::task::spawn_blocking(move || blocking_query(request, client_options, &server))
.await .await
.map_err(|e| { .map_err(|e| {

View File

@ -42,16 +42,8 @@ impl ChimemonTarget for ChronySockServer {
{ {
let frame = ChronyTimeReport { let frame = ChronyTimeReport {
tv: timeval { tv: timeval {
tv_sec: tr tv_sec: tr.system_time.timestamp(),
.system_time tv_usec: tr.system_time.timestamp(),
.timestamp()
.try_into()
.unwrap_or_default(),
tv_usec: tr
.system_time
.timestamp()
.try_into()
.unwrap_or_default(),
}, },
offset: tr.offset.num_nanoseconds().unwrap() as f64 / 1e9, offset: tr.offset.num_nanoseconds().unwrap() as f64 / 1e9,
leap: if tr.leap_flag { 1 } else { 0 }, leap: if tr.leap_flag { 1 } else { 0 },

View File

@ -68,11 +68,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else { } else {
None None
}; };
match chrony { if let Some(c) = chrony {
Some(c) => {
tasks.push(tokio::spawn(c.run(sourcechan.clone()))); tasks.push(tokio::spawn(c.run(sourcechan.clone())));
}
None => (),
}; };
let hwmon = if config.sources.hwmon.enabled { let hwmon = if config.sources.hwmon.enabled {
@ -80,11 +77,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else { } else {
None None
}; };
match hwmon { if let Some(hwmon) = hwmon {
Some(hwmon) => {
tasks.push(tokio::spawn(hwmon.run(sourcechan.clone()))); tasks.push(tokio::spawn(hwmon.run(sourcechan.clone())));
}
None => (),
}; };
let uccm = if config.sources.uccm.enabled { let uccm = if config.sources.uccm.enabled {
@ -94,11 +88,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("UCCMMonitor not configured"); info!("UCCMMonitor not configured");
None None
}; };
match uccm { if let Some(uccm) = uccm {
Some(uccm) => {
tasks.push(tokio::spawn(uccm.run(sourcechan.clone()))); tasks.push(tokio::spawn(uccm.run(sourcechan.clone())));
}
None => (),
}; };
let chrony_refclock = if config.targets.chrony.enabled { let chrony_refclock = if config.targets.chrony.enabled {
@ -106,11 +97,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else { } else {
None None
}; };
match chrony_refclock { if let Some(chrony_refclock) = chrony_refclock {
Some(chrony_refclock) => {
tasks.push(tokio::spawn(chrony_refclock.run(sourcechan.subscribe()))); tasks.push(tokio::spawn(chrony_refclock.run(sourcechan.subscribe())));
}
None => (),
}; };
let mut influxrx = sourcechan.subscribe(); let mut influxrx = sourcechan.subscribe();

View File

@ -206,7 +206,7 @@ impl TryFrom<&[u8]> for UCCMTODReport {
fn try_from(strbuf: &[u8]) -> Result<Self, Self::Error> { fn try_from(strbuf: &[u8]) -> Result<Self, Self::Error> {
debug!("TOD buffer: `{:#?}`", String::from_utf8(strbuf.to_vec())); debug!("TOD buffer: `{:#?}`", String::from_utf8(strbuf.to_vec()));
let resp: Vec<u8> = strbuf let resp: Vec<u8> = strbuf
.split(|c| *c == ' ' as u8) .split(|c| *c == b' ')
.map(|x| u8::from_str_radix(str::from_utf8(x).unwrap_or(""), 16).unwrap_or(0)) .map(|x| u8::from_str_radix(str::from_utf8(x).unwrap_or(""), 16).unwrap_or(0))
.collect(); .collect();
let mut rdr = Cursor::new(resp); let mut rdr = Cursor::new(resp);
@ -257,9 +257,7 @@ impl TryFrom<&str> for UCCMLoopDiagReport {
"No lines!", "No lines!",
))??; ))??;
let ocxo_val = ocxo_line let ocxo_val = ocxo_line
.split(':') .split(':').nth(1)
.skip(1)
.next()
.ok_or(std::io::Error::new( .ok_or(std::io::Error::new(
std::io::ErrorKind::InvalidData, std::io::ErrorKind::InvalidData,
"no colon!", "no colon!",
@ -282,7 +280,7 @@ impl TryFrom<&str> for UCCMGPSSatsReport {
"Invalid response (expected `NSATS CNOS`)", "Invalid response (expected `NSATS CNOS`)",
))?; ))?;
let nsats = nsats.parse::<u8>().map_err(|e| { let nsats = nsats.parse::<u8>().map_err(|e| {
std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid number of sats") std::io::Error::new(std::io::ErrorKind::InvalidData, format!("Invalid number of sats ({e})"))
})?; })?;
let tracked_svs = cnos let tracked_svs = cnos
.split(',') .split(',')
@ -321,7 +319,7 @@ impl UCCMMonitor {
rx, rx,
tx, tx,
info: None, info: None,
config: config, config,
} }
} }
@ -422,11 +420,7 @@ impl UCCMMonitor {
system_time: sysnow, system_time: sysnow,
offset, offset,
leaps: tod.leaps as isize, leaps: tod.leaps as isize,
leap_flag: if tod.flags.contains(UCCMFlags::LEAP_FLAG) { leap_flag: tod.flags.contains(UCCMFlags::LEAP_FLAG),
true
} else {
false
},
valid, valid,
})) }))
.expect("Unable to send to channel"); .expect("Unable to send to channel");