Skip to content

Commit c4c1077

Browse files
authored
Merge pull request #669 from us-irs/can-raw-id-getter
CAN: raw ID getter function
2 parents 368b5dc + bd66331 commit c4c1077

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

embedded-can/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Bumped `defmt` to v1
1313
- `defmt-03` feature is now named `defmt`
1414

15+
### Added
16+
17+
- `as_raw_unchecked` getter function for `Id`
18+
1519
## [v0.4.1] - 2022-09-28
1620

1721
### Removed

embedded-can/src/id.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ pub enum Id {
104104
Extended(ExtendedId),
105105
}
106106

107+
impl Id {
108+
/// Returns the CAN Identifier as a raw 32-bit integer, ignoring the distinction between
109+
/// standard ID and extended ID.
110+
///
111+
/// This function ignores that a standard ID and an extended ID are different IDs, even
112+
/// if their numerical values are the same. It should only be used if the raw numerical value
113+
/// is required and the distinction between standard ID and extended ID is irrelevant.
114+
///
115+
/// In all other cases, it is recommended to de-structure the ID with a match statement.
116+
#[inline]
117+
pub const fn as_raw_unchecked(&self) -> u32 {
118+
match self {
119+
Id::Standard(id) => id.as_raw() as u32,
120+
Id::Extended(id) => id.as_raw(),
121+
}
122+
}
123+
}
124+
107125
/// Implement `Ord` according to the CAN arbitration rules
108126
///
109127
/// When performing arbitration, frames are looked at bit for bit starting

0 commit comments

Comments
 (0)