prs10: fix signedness for parsing some values

This commit is contained in:
2026-02-03 19:37:36 -08:00
parent 430c1acdef
commit 2e8e731d80

View File

@@ -1,3 +1,4 @@
use std::any::type_name;
use std::str::FromStr;
use std::sync::Arc;
@@ -225,7 +226,7 @@ pub struct Prs10Stats {
pub ocxo_efc: u32,
pub error_signal_volts: f64,
pub detect_signal_volts: f64,
pub freq_offset_ppt: u16,
pub freq_offset_ppt: i16,
pub mag_efc: u16,
pub heat_volts: f64,
pub elec_volts: f64,
@@ -363,7 +364,10 @@ impl Prs10Monitor {
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!("response: ({read}) `{buf:?}`");
debug!(
"raw response: ({read}) `{}`",
str::from_utf8(&buf).unwrap_or("<garbage>")
);
Ok(buf)
}
@@ -391,13 +395,11 @@ impl Prs10Monitor {
}
pub async fn get_analog(&mut self, id: u16) -> Result<f64, Box<dyn std::error::Error>> {
debug!("Getting analog value {id}");
let mut cmd = b"AD".to_vec();
cmd.extend_from_slice(id.to_string().as_bytes());
cmd.push(b'?');
let resp = self.cmd_response(&cmd).await?;
let value = str::from_utf8(&resp)?.parse::<f64>()?;
let value = self.get_parsed(&cmd).await?;
debug!("Got: {value}");
Ok(value)
}
@@ -408,7 +410,11 @@ impl Prs10Monitor {
where
T::Err: std::error::Error + 'static,
{
debug!("Getting int value for command {cmd:?}");
debug!(
"Getting parsed <{}> value for command {}",
type_name::<T>(),
str::from_utf8(cmd).unwrap_or("<garbage>"),
);
let resp = self.cmd_response(cmd).await?;
let val = str::from_utf8(&resp)?.parse::<T>()?;
Ok(val)
@@ -430,18 +436,18 @@ impl Prs10Monitor {
}
pub async fn get_detected_signals(&mut self) -> Result<(f64, f64), Box<dyn std::error::Error>> {
debug!("Getting detected signals pair");
debug!("Getting i16,i16 -> f64,f64 detected signals pair");
let resp = self.cmd_response(b"DS?").await?;
let (error, signal) = resp
.splitn(2, |c| *c == b',')
.map(|s| str::from_utf8(s).unwrap().parse::<u16>())
.map(|s| str::from_utf8(s).unwrap().parse::<i16>())
.collect_tuple()
.ok_or("Not enough values in response to DS?".to_string())?;
Ok((error? as f64 * 0.15e-6, signal? as f64 * 0.001))
}
#[instrument(skip_all)]
async fn status_poll(&mut self) -> Result<ChimemonMessage, Box<dyn std::error::Error>> {
debug!("polling status");
let status = self.get_status().await?;
Ok(ChimemonMessage::SourceReport(SourceReport {
name: "prs10".into(),
@@ -454,14 +460,13 @@ impl Prs10Monitor {
}))
}
#[instrument(skip_all)]
async fn stats_poll(&mut self) -> Result<ChimemonMessage, Box<dyn std::error::Error>> {
const ANALOG_SCALING: [f64; 20] = [
0.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, 1.0, 4.0, 100.0, 1.0, 1.0, 1.0, 1.0, 1.0,
4.0, 4.0, 4.0, 1.0,
];
debug!("polling stats");
let stats_span = debug_span!("get_stats_serial");
let stats_guard = stats_span.enter();
let ocxo_efc = self.get_ocxo_efc().await?;