Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can: fix ack number with a high pid #278

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions mcu-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ pub trait MessagingInterface {
}

/// Create a unique ack number
/// - prefix with process ID
/// - prefix with process ID (16 bits, the least significant bits)
/// - suffix with counter
///
/// this added piece of information in the ack number is not strictly necessary
/// but helps filter out acks that are not for us (e.g. acks for other processes)
#[inline]
fn create_ack(counter: u16) -> u32 {
process::id() << 16 | counter as u32
(process::id() & 0xFFFF) << 16_u32 | counter as u32
}

/// Check that ack contains the process ID
/// Check that ack contains 16 least significant bits of the process ID
#[inline]
fn is_ack_for_us(ack_number: u32) -> bool {
ack_number >> 16 == process::id()
// cast looses the upper bits
((ack_number >> 16) as u16) == (process::id() as u16)
}

/// handle new main mcu message, reference implementation
Expand Down
Loading