incremental improvements

This commit is contained in:
2026-02-02 01:37:47 -08:00
parent 7717aa9177
commit 430c1acdef
6 changed files with 91 additions and 18 deletions

View File

@@ -14,7 +14,7 @@ use tokio::sync::OnceCell;
use tokio::time::{interval, timeout};
use tokio_serial;
use tokio_serial::{SerialPort, SerialStream};
use tracing::{debug, error, info, warn};
use tracing::{debug, debug_span, error, info, instrument, warn};
#[derive(Debug)]
pub struct Prs10Info {
@@ -318,6 +318,7 @@ impl SourceReportDetails for Prs10Stats {
}
}
#[derive(Debug)]
pub struct Prs10Monitor {
rx: ReadHalf<SerialStream>,
tx: WriteHalf<SerialStream>,
@@ -354,15 +355,15 @@ impl Prs10Monitor {
self.info.get().expect("info() used before run()")
}
#[instrument(level = "debug", skip_all, fields(cmd = String::from_utf8_lossy(cmd).to_string()))]
pub async fn cmd_response(&mut self, cmd: &[u8]) -> Result<Vec<u8>, std::io::Error> {
debug!("cmd: `{:?}`", String::from_utf8_lossy(cmd));
self.tx.write_all(cmd).await.unwrap();
self.tx.write_u8(b'\r').await.unwrap();
let mut reader = BufReader::new(&mut self.rx);
let mut buf = Vec::new();
let read = timeout(self.config.timeout, reader.read_until(b'\r', &mut buf)).await??;
buf.truncate(buf.len() - 1); // strip "\r"
debug!("cmd response: ({read}) `{buf:?}`");
debug!("response: ({read}) `{buf:?}`");
Ok(buf)
}
@@ -461,7 +462,8 @@ impl Prs10Monitor {
debug!("polling stats");
let start = std::time::Instant::now();
let stats_span = debug_span!("get_stats_serial");
let stats_guard = stats_span.enter();
let ocxo_efc = self.get_ocxo_efc().await?;
let (error_signal_volts, detect_signal_volts) = self.get_detected_signals().await?;
let freq_offset_ppt = self.get_parsed(b"SF?").await?;
@@ -470,9 +472,7 @@ impl Prs10Monitor {
for i in 1u16..=19 {
analog_values[i as usize] = self.get_analog(i).await? * ANALOG_SCALING[i as usize]
}
let duration = std::time::Instant::now() - start;
debug!("stats polled in {}ms", duration.as_secs_f64() * 1000.0);
drop(stats_guard);
Ok(ChimemonMessage::SourceReport(SourceReport {
name: "prs10".into(),