Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions cmd/manifest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/sensors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(t.as_str()));
}

Some(rval)
Expand Down
2 changes: 1 addition & 1 deletion humility-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 5 additions & 6 deletions humility-bin/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions humility-bin/tests/cmd/chip.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more information try --help

```
$ humility --chip this-can-be-anything -V
humility 0.12.14
humility 0.12.15

```

Expand All @@ -28,7 +28,7 @@ For more information try --help

```
$ humility -c apx432 -V
humility 0.12.14
humility 0.12.15

```

4 changes: 2 additions & 2 deletions humility-bin/tests/cmd/version.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Long version flag:

```
$ humility --version
humility 0.12.14
humility 0.12.15

```

Short version flag:

```
$ humility -V
humility 0.12.14
humility 0.12.15

```
67 changes: 39 additions & 28 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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)]
Expand All @@ -365,29 +369,38 @@ 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",
}
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) -> Option<Self> {
impl From<&str> for HubrisSensorKind {
fn from(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()),
}
}
}
Expand Down Expand Up @@ -840,9 +853,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(kind.as_str()),
device: HubrisSensorDevice::Other(
device.device.clone(),
i,
Expand Down Expand Up @@ -883,7 +894,7 @@ impl HubrisArchive {

let sensor_name = |d: &HubrisConfigI2cDevice,
idx: usize,
kind: HubrisSensorKind|
kind: &HubrisSensorKind|
-> Result<String> {
if let Some(pmbus) = &d.pmbus {
if let Some(rails) = &pmbus.rails {
Expand All @@ -899,7 +910,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() {
Expand Down Expand Up @@ -936,7 +947,7 @@ impl HubrisArchive {
ndx: usize,
kind: HubrisSensorKind|
-> Result<HubrisSensor> {
let name = sensor_name(d, i, kind)?;
let name = sensor_name(d, i, &kind)?;
Ok(HubrisSensor {
name,
kind,
Expand Down
Loading