From 32e061a3f95de6b22ae40064a76b01ae01cff9a3 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Wed, 4 Mar 2026 10:55:45 -0500 Subject: [PATCH 1/4] Allow unknown sensor types --- cmd/sensors/src/lib.rs | 9 +-------- humility-core/src/hubris.rs | 39 +++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/cmd/sensors/src/lib.rs b/cmd/sensors/src/lib.rs index 1edc755d..25e557e9 100644 --- a/cmd/sensors/src/lib.rs +++ b/cmd/sensors/src/lib.rs @@ -556,14 +556,7 @@ fn sensors(context: &mut ExecutionContext) -> Result<()> { let mut rval = HashSet::new(); for t in types { - match HubrisSensorKind::from_string(t) { - Some(kind) => { - rval.insert(kind); - } - None => { - bail!("unrecognized sensor kind \"{}\"", t); - } - } + rval.insert(HubrisSensorKind::from_string(t)); } Some(rval) diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs index 0688eea0..75900fa3 100644 --- a/humility-core/src/hubris.rs +++ b/humility-core/src/hubris.rs @@ -40,7 +40,7 @@ const OXIDE_NT_HUBRIS_ARCHIVE: u32 = OXIDE_NT_BASE + 1; const OXIDE_NT_HUBRIS_REGISTERS: u32 = OXIDE_NT_BASE + 2; const OXIDE_NT_HUBRIS_TASK: u32 = OXIDE_NT_BASE + 3; -const MAX_HUBRIS_VERSION: u32 = 10; +const MAX_HUBRIS_VERSION: u32 = 11; #[derive(Default, Debug, Serialize)] pub struct HubrisManifest { @@ -340,7 +340,7 @@ pub struct HubrisI2cDevice { pub removable: bool, } -#[derive(Copy, Clone, Deserialize, Debug, PartialEq, Eq, Hash, Serialize)] +#[derive(Clone, Deserialize, Debug, PartialEq, Eq, Hash, Serialize)] #[serde(rename_all = "kebab-case")] pub enum HubrisSensorKind { Temperature, @@ -350,6 +350,10 @@ pub enum HubrisSensorKind { InputCurrent, InputVoltage, Speed, + Pwm, + + /// Catch-all for unknown sensor kinds, for forward compatibility + Other(String), } #[derive(Clone, Debug, PartialOrd, Ord, Eq, PartialEq, Serialize)] @@ -375,19 +379,22 @@ impl HubrisSensorKind { HubrisSensorKind::InputCurrent => "input-current", HubrisSensorKind::InputVoltage => "input-voltage", HubrisSensorKind::Speed => "speed", + HubrisSensorKind::Pwm => "pwm", + HubrisSensorKind::Other(s) => s, } } - pub fn from_string(kind: &str) -> Option { + pub fn from_string(kind: &str) -> Self { match kind { - "temp" | "temperature" => Some(HubrisSensorKind::Temperature), - "power" => Some(HubrisSensorKind::Power), - "current" => Some(HubrisSensorKind::Current), - "voltage" => Some(HubrisSensorKind::Voltage), - "input-current" => Some(HubrisSensorKind::InputCurrent), - "input-voltage" => Some(HubrisSensorKind::InputVoltage), - "speed" => Some(HubrisSensorKind::Speed), - _ => None, + "temp" | "temperature" => HubrisSensorKind::Temperature, + "power" => HubrisSensorKind::Power, + "current" => HubrisSensorKind::Current, + "voltage" => HubrisSensorKind::Voltage, + "input-current" => HubrisSensorKind::InputCurrent, + "input-voltage" => HubrisSensorKind::InputVoltage, + "speed" => HubrisSensorKind::Speed, + "pwm" => HubrisSensorKind::Pwm, + s => HubrisSensorKind::Other(s.to_owned()), } } } @@ -840,9 +847,7 @@ impl HubrisArchive { for i in 0..count { self.manifest.sensors.push(HubrisSensor { name: device.name.clone(), - kind: HubrisSensorKind::from_string(kind).ok_or_else( - || anyhow!("Unknown sensor kind {kind}"), - )?, + kind: HubrisSensorKind::from_string(kind), device: HubrisSensorDevice::Other( device.device.clone(), i, @@ -883,7 +888,7 @@ impl HubrisArchive { let sensor_name = |d: &HubrisConfigI2cDevice, idx: usize, - kind: HubrisSensorKind| + kind: &HubrisSensorKind| -> Result { if let Some(pmbus) = &d.pmbus { if let Some(rails) = &pmbus.rails { @@ -899,7 +904,7 @@ impl HubrisArchive { .unwrap() .sensors .as_ref() - .is_none_or(|s| s.contains(&kind)) + .is_none_or(|s| s.contains(kind)) && let Some(rails) = &d.power.as_ref().unwrap().rails { if idx < rails.len() { @@ -936,7 +941,7 @@ impl HubrisArchive { ndx: usize, kind: HubrisSensorKind| -> Result { - let name = sensor_name(d, i, kind)?; + let name = sensor_name(d, i, &kind)?; Ok(HubrisSensor { name, kind, From 3903d40ccb77c257aedeff8711a40975c4527408 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 6 Mar 2026 09:18:30 -0500 Subject: [PATCH 2/4] Bump Humility version --- Cargo.lock | 2 +- humility-bin/Cargo.toml | 2 +- humility-bin/tests/cmd/chip.trycmd | 4 ++-- humility-bin/tests/cmd/version.trycmd | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 727984e6..0feff764 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "humility-bin" -version = "0.12.14" +version = "0.12.15" dependencies = [ "anyhow", "bitfield", diff --git a/humility-bin/Cargo.toml b/humility-bin/Cargo.toml index a65cba31..ee0cd784 100644 --- a/humility-bin/Cargo.toml +++ b/humility-bin/Cargo.toml @@ -18,7 +18,7 @@ [package] name = "humility-bin" edition.workspace = true -version = "0.12.14" +version = "0.12.15" license = "MPL-2.0" [build-dependencies] diff --git a/humility-bin/tests/cmd/chip.trycmd b/humility-bin/tests/cmd/chip.trycmd index 5628e928..cac66693 100644 --- a/humility-bin/tests/cmd/chip.trycmd +++ b/humility-bin/tests/cmd/chip.trycmd @@ -13,7 +13,7 @@ For more information try --help ``` $ humility --chip this-can-be-anything -V -humility 0.12.14 +humility 0.12.15 ``` @@ -28,7 +28,7 @@ For more information try --help ``` $ humility -c apx432 -V -humility 0.12.14 +humility 0.12.15 ``` diff --git a/humility-bin/tests/cmd/version.trycmd b/humility-bin/tests/cmd/version.trycmd index 4bfae1d4..df08a468 100644 --- a/humility-bin/tests/cmd/version.trycmd +++ b/humility-bin/tests/cmd/version.trycmd @@ -2,7 +2,7 @@ Long version flag: ``` $ humility --version -humility 0.12.14 +humility 0.12.15 ``` @@ -10,6 +10,6 @@ Short version flag: ``` $ humility -V -humility 0.12.14 +humility 0.12.15 ``` From 4add7dbf2323c7d9a872758ddef91ea8c5d8d8ab Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 6 Mar 2026 09:26:01 -0500 Subject: [PATCH 3/4] More idiomatic to/from string conversions --- cmd/sensors/src/lib.rs | 2 +- humility-core/src/hubris.rs | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cmd/sensors/src/lib.rs b/cmd/sensors/src/lib.rs index 25e557e9..8fb06d70 100644 --- a/cmd/sensors/src/lib.rs +++ b/cmd/sensors/src/lib.rs @@ -556,7 +556,7 @@ fn sensors(context: &mut ExecutionContext) -> Result<()> { let mut rval = HashSet::new(); for t in types { - rval.insert(HubrisSensorKind::from_string(t)); + rval.insert(HubrisSensorKind::from(t.as_str())); } Some(rval) diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs index 75900fa3..b8bfbc11 100644 --- a/humility-core/src/hubris.rs +++ b/humility-core/src/hubris.rs @@ -369,22 +369,28 @@ pub struct HubrisSensor { pub device: HubrisSensorDevice, } -impl HubrisSensorKind { - pub fn to_string(&self) -> &str { - match self { - HubrisSensorKind::Temperature => "temp", - HubrisSensorKind::Power => "power", - HubrisSensorKind::Current => "current", - HubrisSensorKind::Voltage => "voltage", - HubrisSensorKind::InputCurrent => "input-current", - HubrisSensorKind::InputVoltage => "input-voltage", - HubrisSensorKind::Speed => "speed", - HubrisSensorKind::Pwm => "pwm", - HubrisSensorKind::Other(s) => s, - } +impl fmt::Display for HubrisSensorKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + HubrisSensorKind::Temperature => "temp", + HubrisSensorKind::Power => "power", + HubrisSensorKind::Current => "current", + HubrisSensorKind::Voltage => "voltage", + HubrisSensorKind::InputCurrent => "input-current", + HubrisSensorKind::InputVoltage => "input-voltage", + HubrisSensorKind::Speed => "speed", + HubrisSensorKind::Pwm => "pwm", + HubrisSensorKind::Other(s) => s, + } + ) } +} - pub fn from_string(kind: &str) -> Self { +impl From<&str> for HubrisSensorKind { + fn from(kind: &str) -> Self { match kind { "temp" | "temperature" => HubrisSensorKind::Temperature, "power" => HubrisSensorKind::Power, @@ -847,7 +853,7 @@ impl HubrisArchive { for i in 0..count { self.manifest.sensors.push(HubrisSensor { name: device.name.clone(), - kind: HubrisSensorKind::from_string(kind), + kind: HubrisSensorKind::from(kind.as_str()), device: HubrisSensorDevice::Other( device.device.clone(), i, From 9a5ae23283699aa4279eac7c346cc7d017fd0e82 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 6 Mar 2026 10:11:22 -0500 Subject: [PATCH 4/4] Clippy fixes --- cmd/manifest/src/lib.rs | 5 +---- humility-bin/tests/cli_tests.rs | 11 +++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cmd/manifest/src/lib.rs b/cmd/manifest/src/lib.rs index 9f0502c2..61aec019 100644 --- a/cmd/manifest/src/lib.rs +++ b/cmd/manifest/src/lib.rs @@ -239,10 +239,7 @@ fn manifestcmd(context: &mut ExecutionContext) -> Result<()> { }; println!( " {:3} {:23} {:11} {}", - ndx, - s.name, - device, - s.kind.to_string() + ndx, s.name, device, s.kind, ); } } diff --git a/humility-bin/tests/cli_tests.rs b/humility-bin/tests/cli_tests.rs index e237bff9..3f82f067 100644 --- a/humility-bin/tests/cli_tests.rs +++ b/humility-bin/tests/cli_tests.rs @@ -74,12 +74,11 @@ fn make_tests(tests: &[Test], kind: Kind) -> Result<()> { let path = entry.path(); - if let Some(f) = path.file_name() { - if let Some(s) = f.to_str() { - if let Some(name) = s.strip_prefix(kind.prefix()) { - input.push((name.to_string(), s.to_string())); - } - } + if let Some(f) = path.file_name() + && let Some(s) = f.to_str() + && let Some(name) = s.strip_prefix(kind.prefix()) + { + input.push((name.to_string(), s.to_string())); } }