Skip to content

Commit

Permalink
Fixed FD frame construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Apr 5, 2023
1 parent 329e9f4 commit fc091c7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ pub trait Frame: EmbeddedFrame {
/// Return the CAN ID as the embedded HAL Id type.
fn hal_id(&self) -> Id {
if self.is_extended() {
ExtendedId::new(self.id_word() & CAN_EFF_MASK).unwrap().into()
ExtendedId::new(self.id_word() & CAN_EFF_MASK)
.unwrap()
.into()
} else {
StandardId::new((self.id_word() & CAN_SFF_MASK) as u16).unwrap().into()
StandardId::new((self.id_word() & CAN_SFF_MASK) as u16)
.unwrap()
.into()
}
}

Expand Down Expand Up @@ -429,7 +433,7 @@ impl CanDataFrame {
frame.data[..n].copy_from_slice(data);
Ok(Self(frame))
}
_ => Err(ConstructionError::TooMuchData)
_ => Err(ConstructionError::TooMuchData),
}
}
}
Expand Down Expand Up @@ -515,7 +519,7 @@ impl Frame for CanDataFrame {
self.0.data[..n].copy_from_slice(data);
Ok(())
}
_ => Err(ConstructionError::TooMuchData)
_ => Err(ConstructionError::TooMuchData),
}
}
}
Expand Down Expand Up @@ -596,8 +600,7 @@ impl CanRemoteFrame {
if dlc <= CAN_MAX_DLEN {
self.0.can_dlc = dlc as u8;
Ok(())
}
else {
} else {
Err(ConstructionError::TooMuchData)
}
}
Expand Down Expand Up @@ -891,7 +894,7 @@ impl CanFdFrame {
fd_flags: FdFlags,
) -> Result<Self, ConstructionError> {
match data.len() {
n if n > CANFD_MAX_DLEN => {
n if n <= CANFD_MAX_DLEN => {
// TODO: Should this be a 'Wrong Frame Type' error?
flags.remove(IdFlags::RTR | IdFlags::ERR);

Expand All @@ -902,9 +905,8 @@ impl CanFdFrame {
frame.data[..n].copy_from_slice(data);
Ok(Self(frame))
}
_ => Err(ConstructionError::TooMuchData)
_ => Err(ConstructionError::TooMuchData),
}

}

/// Gets the flags for the FD frame.
Expand Down Expand Up @@ -1028,7 +1030,7 @@ impl Frame for CanFdFrame {
self.0.data[..n].copy_from_slice(data);
Ok(())
}
_ => Err(ConstructionError::TooMuchData)
_ => Err(ConstructionError::TooMuchData),
}
}
}
Expand Down

0 comments on commit fc091c7

Please sign in to comment.