Skip to main content

Filter

Struct Filter 

Source
pub struct Filter { /* private fields */ }
Expand description

A frame a node keeps: one whose identifier, masked, equals the filter’s, and whose width, standard or extended, is the filter’s.

This is the SocketCAN filter, received_id & mask == id & mask, with the frame format always part of the match, so a filter for an extended identifier never passes a standard frame that happens to share its low bits.

§Examples

use pamoja_can::bus::Filter;
use pamoja_can::{CanId, J1939Id};

// Engine speed, parameter group 61444, from any engine controller at any priority.
let engine_speed = Filter::pgn(61_444);
assert!(engine_speed.matches(J1939Id::broadcast(3, 61_444, 0x00).to_id()));
assert!(engine_speed.matches(J1939Id::broadcast(6, 61_444, 0x01).to_id()));
assert!(!engine_speed.matches(J1939Id::broadcast(3, 61_443, 0x00).to_id()));

// One standard identifier and nothing else.
let motor = Filter::exact(CanId::standard(0x20A));
assert!(motor.matches(CanId::standard(0x20A)));
assert!(!motor.matches(CanId::extended(0x20A)));

Implementations§

Source§

impl Filter

Source

pub fn new(id: CanId, mask: u32) -> Filter

A filter on the identifier bits a mask selects.

§Arguments
  • id - the identifier to match, which also fixes the frame format.
  • mask - the identifier bits that have to match; bits outside the identifier’s width are dropped.
§Returns

The filter.

Source

pub fn exact(id: CanId) -> Filter

A filter that passes one identifier and nothing else.

§Arguments
  • id - the identifier.
§Returns

The filter.

Source

pub fn pgn(pgn: u32) -> Filter

A filter that passes one J1939 parameter group at any priority, from any source, and for an addressed group, to any destination.

§Arguments
  • pgn - the parameter group number.
§Returns

The filter.

Source

pub fn id(&self) -> CanId

Returns the identifier the filter matches.

Source

pub fn mask(&self) -> u32

Returns the identifier bits that have to match.

Source

pub fn matches(&self, id: CanId) -> bool

Reports whether a frame with an identifier passes the filter.

§Arguments
  • id - the frame’s identifier.
§Returns

true when the frame formats agree and the masked bits are equal.

Trait Implementations§

Source§

impl Clone for Filter

Source§

fn clone(&self) -> Filter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Filter

Source§

impl Debug for Filter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Filter

Source§

impl PartialEq for Filter

Source§

fn eq(&self, other: &Filter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Filter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.