Crate socketcan2

source ·
Expand description

SocketCAN support.

Features

  • Receive can frames
  • Accurate timestamps (timestamps also support multi threading in contrast to receiving the TIMESTAMP via an ioctl call, which does not support mt)
  • epoll-support (allows to wait on multiple CAN devices in the same thread)
  • Send CAN frames (not implemented yet)
  • Filter CAN frames (not implemented yet)

Usage example

#[cfg(test)]
fn on_recv(msg: &Box<Msg>, _user_data: &u64) {
  println!("timestamp: {:?}", msg.timestamp());
  print!("received CAN frame (id: {}): ", msg.can_id());
  for i in 0..msg.len() {
    print!("{} ", msg[i as usize]);
  }
  println!("");
}
 
#[cfg(test)]
mod tests {
  use super::*;
  #[test]
  fn it_works() {
    let can = Can::open("vcan0").unwrap();
    let mut cg = CanGroup::<u64>::new();
    cg.add(can, 0).unwrap();
    match cg.next(Duration::milliseconds(-1), on_recv) {
      Ok(no_timeout) => if !no_timeout { panic!("timeout"); },
      Err(_) => panic!("error"),
    }
  }
}

Structs

CAN socket
Type for receiving data from multiple CAN devices. This type also supports timeouts.
CAN message type.

Constants

if set, indicate 29 bit extended format
valid bits in extended frame id
error flag
valid bits in error frame
an error mask that will cause SocketCAN to report all errors
an error mask that will cause SocketCAN to silently drop all errors
remote transmission request flag
valid bits in standard frame id