[−][src]Crate tokio_socketcan_bcm
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.
Example 1
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.
#![feature(await_macro, async_await, futures_api)] #[macro_use] extern crate tokio; use std::time; use tokio::prelude::*; use tokio_socketcan_bcm::*; fn main() { tokio::run_async( async { 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) = await!(can_frame_stream.next()) { println!("Frame {:?}", frame); () } }, ); }
Structs
BCMSocket | A socket for a CAN device, specifically for broadcast manager operations. |
BcmFrameStream | |
BcmMsgHead | BcmMsgHead |
BcmMsgHeadFrameLess | BcmMsgHeadFrameLess |
BcmStream | |
CANAddr | |
CANFrame | CANFrame |
FrameFlags | |
TxMsg |
Enums
CANMessageId | 11-bit or 29-bit identifier of can frame. |
ConstructionError | Error that occurs when creating CAN packets |
Constants
AF_CAN | defined in socket.h |
CAN_BCM | |
CAN_FD_FRAME | |
MAX_NFRAMES | |
PF_CAN | defined in socket.h |
RX_ANNOUNCE_RESUM | refers also to the time-out supervision of the management RX_SETUP. By setting this flag, when an RX-outs occours, a RX_CHANGED will be generated when the (cyclic) receive restarts. This will happen even if the user data have not changed. |
RX_CHANGED | sent if the first or a revised CAN message was received |
RX_CHECK_DLC | A change of the DLC leads to an RX_CHANGED. |
RX_DELETE | remove RX content filter subscription |
RX_FILTER_ID | Filter by can_id alone, no frames required (nframes=0) |
RX_NO_AUTOTIMER | If the timer ival1 in the RX_SETUP has been set equal to zero, on receipt of the CAN message the timer for the timeout monitoring is automatically started. Setting this flag prevents the automatic start timer. |
RX_READ | read properties of RX content filter subscription |
RX_RTR_FRAME | the filter passed is used as CAN message to be sent when receiving an RTR frame. |
RX_SETUP | create RX content filter subscription |
RX_STATUS | reply to RX_READ request |
RX_TIMEOUT | cyclic message is absent |
SETTIMER | Flags |
SOCK_DGRAM | datagram (connection less) socket |
STARTTIMER | start the timer with the actual value of ival1, ival2 and count. Starting the timer leads simultaneously to emit a can_frame. |
TX_ANNOUNCE | A change of data by the process is emitted immediatly. (Requirement of 'Changing Now' - BAES) |
TX_COUNTEVT | create the message TX_EXPIRED when count expires |
TX_CP_CAN_ID | Copies the can_id from the message header to each subsequent frame in frames. This is intended only as usage simplification. |
TX_DELETE | remove (cyclic) transmission task |
TX_EXPIRED | notification on performed transmissions (count=0) |
TX_READ | read properties of (cyclic) transmission task |
TX_RESET_MULTI_ID | forces a reset of the index counter from the update to be sent by multiplex message even if it would not be necessary because of the length. |
TX_SEND | send one CAN frame |
TX_SETUP | OpCodes |
TX_STATUS | reply to TX_READ request |
Traits
IntoBcmStream |