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.
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);
}
Notice: async/await currently requires nightly rust and the tokio async-await-preview
feature.
```Rust
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); () } }, ); } ```