-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from atlas-aero/3-implement-message-receive
3 implement message receive
- Loading branch information
Showing
10 changed files
with
743 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ mockall = "0.11.0" | |
|
||
[features] | ||
default = [] | ||
strict = [] | ||
strict = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::message::{EXTENDED_IDENTIFIER_MASK, STANDARD_IDENTIFIER_MASK}; | ||
use crate::registers::{FilterMaskReg, FilterObjectReg}; | ||
use embedded_can::{ExtendedId, Id, StandardId}; | ||
|
||
/// Struct representing a filter object | ||
#[derive(Default, Debug)] | ||
pub struct Filter { | ||
/// filter & mask index | ||
pub index: u8, | ||
/// mask register bitfield | ||
pub mask_bits: FilterMaskReg, | ||
/// filter register bitfield | ||
pub filter_bits: FilterObjectReg, | ||
} | ||
|
||
impl Filter { | ||
/// Create new filter from embedded_can::Id and index, no mask | ||
pub fn new(identifier: Id, index: u8) -> Option<Self> { | ||
if index > 31 { | ||
return None; | ||
} | ||
|
||
let mut filter = Self::default(); | ||
|
||
filter.set_id(identifier); | ||
filter.index = index; | ||
|
||
Some(filter) | ||
} | ||
|
||
/// Set mask for extended Id | ||
pub fn set_mask_extended_id(&mut self, mask: u32) { | ||
self.set_mask(Id::Extended(ExtendedId::new(mask).unwrap())); | ||
} | ||
|
||
/// Set mask for standard Id | ||
pub fn set_mask_standard_id(&mut self, mask: u16) { | ||
self.set_mask(Id::Standard(StandardId::new(mask).unwrap())); | ||
} | ||
|
||
/// Set filter and mask so that only messages with Standard Id match | ||
pub fn match_standard_only(&mut self) { | ||
self.mask_bits.set_mide(true); | ||
self.filter_bits.set_exide(false); | ||
} | ||
|
||
/// Set filter and mask so that only messages with Extended Id match | ||
pub fn match_extended_only(&mut self) { | ||
self.mask_bits.set_mide(true); | ||
self.filter_bits.set_exide(true); | ||
} | ||
|
||
fn set_id(&mut self, identifier: Id) { | ||
match identifier { | ||
Id::Standard(sid) => self.filter_bits.set_sid(sid.as_raw()), | ||
Id::Extended(eid) => { | ||
self.filter_bits.set_eid(eid.as_raw() & EXTENDED_IDENTIFIER_MASK); | ||
self.filter_bits.set_sid((eid.as_raw() >> 18) as u16 & STANDARD_IDENTIFIER_MASK); | ||
} | ||
} | ||
} | ||
|
||
fn set_mask(&mut self, identifier: Id) { | ||
match identifier { | ||
Id::Standard(sid) => self.mask_bits.set_msid(sid.as_raw()), | ||
Id::Extended(eid) => { | ||
self.mask_bits.set_meid(eid.as_raw() & EXTENDED_IDENTIFIER_MASK); | ||
self.mask_bits.set_msid((eid.as_raw() >> 18) as u16 & STANDARD_IDENTIFIER_MASK); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.