BCMSocket

Struct BCMSocket 

Source
pub struct BCMSocket {
    pub fd: c_int,
}
Expand description

A socket for a CAN device, specifically for broadcast manager operations.

Fields§

§fd: c_int

Implementations§

Source§

impl BCMSocket

Source

pub fn open_nb(ifname: &str) -> Result<BCMSocket>

Open a named CAN device non blocking.

Usually the more common case, opens a socket can device by name, such as “vcan0” or “socan0”.

Source

pub fn open_if_nb(if_index: c_uint) -> Result<BCMSocket>

Open CAN device by interface number non blocking.

Opens a CAN device by kernel interface number.

Source

pub fn filter_id( &self, can_id: CANMessageId, ival1: Duration, ival2: Duration, ) -> Result<()>

Create a content filter subscription, filtering can frames by can_id.

Source

pub fn filter_id_incoming_frames( self, can_id: CANMessageId, ival1: Duration, ival2: Duration, ) -> Result<BcmFrameStream>

Combination of BCMSocket::filter_id and BCMSocket::incoming_frames.

use std::time;
use tokio_socketcan_bcm::*;
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() {
    let socket = BCMSocket::open_nb("vcan0").unwrap();
    let ival = time::Duration::from_millis(0);

    // create a stream of messages that filters by the can frame id 0x123
    let mut can_frame_stream = socket
        .filter_id_incoming_frames(0x123.into(), ival, ival)
        .unwrap();

    while let Some(frame) = can_frame_stream.next().await {
        println!("Frame {:?}", frame);
        ()
    }
}
Source

pub fn incoming_msg(self) -> Result<BcmStream>

Stream of incoming BcmMsgHeads that apply to the filter criteria.

use std::time;
use tokio_socketcan_bcm::*;
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() {
    let socket = BCMSocket::open_nb("vcan0").unwrap();
    let ival = time::Duration::from_millis(0);

    // create a stream of messages that filters by the can frame id 0x123
    let mut can_frame_stream = socket
        .incoming_msg()
        .unwrap();

    while let Some(frame) = can_frame_stream.next().await {
        println!("Frame {:?}", frame);
        ()
    }
}
Source

pub fn incoming_frames(self) -> Result<BcmFrameStream>

Stream of incoming frames that apply to the filter criteria.

use std::time;
use tokio_socketcan_bcm::*;
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() {
    let socket = BCMSocket::open_nb("vcan0").unwrap();
    let ival = time::Duration::from_millis(0);

    // create a stream of messages that filters by the can frame id 0x123
    let mut can_frame_stream = socket
        .incoming_frames()
        .unwrap();

    while let Some(frame) = can_frame_stream.next().await {
        println!("Frame {:?}", frame);
        ()
    }
}
Source

pub fn filter_delete(&self, can_id: CANMessageId) -> Result<()>

Remove a content filter subscription.

Source

pub fn read_msg(&self) -> Result<BcmMsgHead>

Read a single bcm message.

Trait Implementations§

Source§

impl Debug for BCMSocket

Source§

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

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

impl Drop for BCMSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Evented for BCMSocket

Source§

fn register( &self, poll: &Poll, token: Token, interest: Ready, opts: PollOpt, ) -> Result<()>

Register self with the given Poll instance. Read more
Source§

fn reregister( &self, poll: &Poll, token: Token, interest: Ready, opts: PollOpt, ) -> Result<()>

Re-register self with the given Poll instance. Read more
Source§

fn deregister(&self, poll: &Poll) -> Result<()>

Deregister self from the given Poll instance Read more

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> 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, 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.
Source§

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

Source§

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

Source§

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