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
- CAN socket
- CanGroup
- Type for receiving data from multiple CAN devices. This type also supports timeouts.
- Msg
- CAN message type.
Constants§
- EFF_
FLAG - if set, indicate 29 bit extended format
- EFF_
MASK - valid bits in extended frame id
- ERR_
FLAG - error flag
- ERR_
MASK - valid bits in error frame
- ERR_
MASK_ ALL - an error mask that will cause SocketCAN to report all errors
- ERR_
MASK_ NONE - an error mask that will cause SocketCAN to silently drop all errors
- RTR_
FLAG - remote transmission request flag
- SFF_
MASK - valid bits in standard frame id