Skip to content

Commit

Permalink
Merge pull request fmckeogh#13 from sjoerdsimons/handle-unknown-pdo
Browse files Browse the repository at this point in the history
Gracefully handle unknown pdo aspects when parsing
  • Loading branch information
okhsunrog committed Jun 18, 2024
2 parents 3e16c52 + 49266ef commit 588f848
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions usb-pd/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ impl Message {
0b01 => {
AugmentedPowerDataObject::EPR(EPRAdjustableVoltageSupply(pdo.0))
}
_ => unreachable!(),
_ => {
warn!("Unknown AugmentedPowerDataObject supply");
AugmentedPowerDataObject::Unknown(pdo.0)
}
}
}),
_ => unreachable!(),
_ => {
warn!("Unknown PowerDataObject kind");
PowerDataObject::Unknown(pdo)
}
})
.collect(),
),
Expand Down
4 changes: 3 additions & 1 deletion usb-pd/src/messages/pdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ pub enum PowerDataObject {
Battery(Battery),
VariableSupply(VariableSupply),
AugmentedPowerDataObject(AugmentedPowerDataObject),
Unknown(PowerDataObjectRaw),
}

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct PowerDataObjectRaw(pub u32): Debug, FromRaw, IntoRaw {
pub kind: u8 @ 30..=31,
}
Expand Down Expand Up @@ -79,6 +80,7 @@ bitfield! {
pub enum AugmentedPowerDataObject {
SPR(SPRProgrammablePowerSupply),
EPR(EPRAdjustableVoltageSupply),
Unknown(u32),
}

bitfield! {
Expand Down

0 comments on commit 588f848

Please sign in to comment.