Skip to content

Commit da3b64e

Browse files
committed
Add documentation and update changelog
1 parent b14a937 commit da3b64e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Implement `PartialOrd`, `Ord`, `Hash` for `can::StandardId`, `can::ExtendedId` and `can::Id` according to CAN bus arbitration rules
11+
1012
## [v1.0.0-alpha.8] - 2022-04-15
1113

1214
*** This is (also) an alpha release with breaking changes (sorry) ***

src/can/id.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ pub enum Id {
9494
Extended(ExtendedId),
9595
}
9696

97+
/// Implement `Ord` according to the CAN arbitration rules
98+
///
99+
/// When performing arbitration, frames are looked at bit for bit starting
100+
/// from the beginning. A bit with the value 0 is dominant and a bit with
101+
/// value of 1 is recessive.
102+
///
103+
/// When two devices are sending frames at the same time, as soon as the first
104+
/// bit is found which differs, the frame with the corresponding dominant
105+
/// 0 bit will win and get to send the rest of the frame.
106+
///
107+
/// This implementation of `Ord` for `Id` will take this into consideration
108+
/// and when comparing two different instances of `Id` the "smallest" will
109+
/// always be the id which would form the most dominant frame, all other
110+
/// things being equal.
97111
impl Ord for Id {
98112
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
99113
let split_id = |id: &Id| {

0 commit comments

Comments
 (0)