tokio-socketcan-bcm

LICENSE VERSION docs

The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in kernel space. Filtering messages in kernel space may significantly reduce the load in an application.

A BCM socket is not intended for sending individual CAN frames. To send invidiual frames use the tokio-socketcan crate.

This crate would not have been possible without the socketcan crate.

Example 1

Rust use futures::stream::Stream; use std::time; use tokio_socketcan_bcm::*; fn main() { let socket = BCMSocket::open_nb("vcan0").unwrap(); // Throttle messages in kernel space to max every 5 seconds let ival = time::Duration::from_secs(5); let f = socket .filter_id_incoming_frames(0x123.into(), ival, ival) .unwrap() .map_err(|err| eprintln!("IO error {:?}", err)) .for_each(|frame| { println!("Frame {:?}", frame); Ok(()) }); tokio::run(f); }

Example 2 (async/await)

Notice: async/await currently requires nightly rust and the tokio async-await-preview feature.

```Rust

![feature(awaitmacro, asyncawait, futures_api)]

[macro_use]

extern crate tokio; use std::time; use tokio::prelude::; use tokio_socketcan_bcm::; fn main() { tokio::runasync( async { let socket = BCMSocket::opennb("vcan0").unwrap(); let ival = time::Duration::frommillis(0); // create a stream of messages that filters by the can frame id 0x123 let mut canframestream = socket .filteridincomingframes(0x123.into(), ival, ival) .unwrap(); while let Some(frame) = await!(canframestream.next()) { println!("Frame {:?}", frame); () } }, ); } ```