pub struct BCMSocket {
pub fd: c_int,
}Expand description
A socket for a CAN device, specifically for broadcast manager operations.
Fields§
§fd: c_intImplementations§
Source§impl BCMSocket
impl BCMSocket
Sourcepub fn open_nb(ifname: &str) -> Result<BCMSocket>
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”.
Sourcepub fn open_if_nb(if_index: c_uint) -> Result<BCMSocket>
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.
Sourcepub fn filter_id(
&self,
can_id: CANMessageId,
ival1: Duration,
ival2: Duration,
) -> Result<()>
pub fn filter_id( &self, can_id: CANMessageId, ival1: Duration, ival2: Duration, ) -> Result<()>
Create a content filter subscription, filtering can frames by can_id.
Sourcepub fn filter_id_incoming_frames(
self,
can_id: CANMessageId,
ival1: Duration,
ival2: Duration,
) -> Result<BcmFrameStream>
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);
()
}
}Sourcepub fn incoming_msg(self) -> Result<BcmStream>
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);
()
}
}Sourcepub fn incoming_frames(self) -> Result<BcmFrameStream>
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);
()
}
}Sourcepub fn filter_delete(&self, can_id: CANMessageId) -> Result<()>
pub fn filter_delete(&self, can_id: CANMessageId) -> Result<()>
Remove a content filter subscription.
Sourcepub fn read_msg(&self) -> Result<BcmMsgHead>
pub fn read_msg(&self) -> Result<BcmMsgHead>
Read a single bcm message.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BCMSocket
impl RefUnwindSafe for BCMSocket
impl Send for BCMSocket
impl Sync for BCMSocket
impl Unpin for BCMSocket
impl UnwindSafe for BCMSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more