Skip to content

Commit

Permalink
Merge pull request #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
fmckeogh authored May 19, 2024
2 parents 58f8f32 + ee73726 commit daa333b
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 daa333b

Please sign in to comment.