Expand description
§tokio-socketcan-isotp
This library creates asynchronous wrapper around socketcan-isotp
Currently not dependent on the original, but rather on the modified of the socketcan-isotp libary, which adds read_to_vec method, in order to prevent mutable borrowing of the socket, when reading.
You may experience busy waiting, or soft locks when two consecutive locks. This is due to the error in Linux Kernel, which is now solved, but the maintainer of your Linux kernel might not have shipped it yet. I tested it on the mainline Kernel 6.6.5 and everything worked correctly. If you experience mentioned errors and cannot upgrade to newer kernel, refer to the src/lib.rs file to the poll method of the IsoTpWriteFuture, where a edit is suggested that might help with your situation.
The API is provided by the struct IsoTpSocket
Example of basic echoing server on vcan0:
use tokio_socketcan_isotp::{IsoTpSocket, StandardId, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut socket = IsoTpSocket::open(
"vcan0",
StandardId::new(0x123).expect("Invalid src id"),
StandardId::new(0x321).expect("Invalid src id")
)?;
while let Ok(packet) = socket.read_packet()?.await {
println!("{:?}", packet);
let rx = socket.write_packet(packet)?.await;
}
}To setup vcan0 run following commands:
sudo modprobe can
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0Structs§
- Extended
Id - Extended 29-bit CAN Identifier (
0..=1FFF_FFFF). - Flow
Control Options - Flow control options aka
can_isotp_fc_options - IsoTp
Behaviour - IsoTp
Options - ISO-TP otions aka
can_isotp_options - IsoTp
Read Future - Future for reading data from IsoTpSocket
- IsoTp
Socket - An asynchronous I/O wrapped socketcan_isotp::IsoTpSocket For reading and writting to the socket use IsoTpSocket::read_packet and IsoTpSocket::write_packet respectively.
- IsoTp
Write Future - Future for writing data to IsoTpSocket
- Link
Layer Options - Link layer options aka
can_isotp_ll_options - Standard
Id - Standard 11-bit CAN Identifier (
0..=0x7FF). - TxFlags
Enums§
Constants§
- AF_CAN
- CAN address family
- CAN_
ISOTP - ISO 15765-2 Transport Protocol
- CAN_
ISOTP_ LL_ OPTS - pass struct
LinkLayerOptions - CAN_
ISOTP_ OPTS - pass struct
IsoTpOptions - CAN_
ISOTP_ RECV_ FC - pass struct
FlowControlOptions - CAN_
ISOTP_ RX_ STMIN - pass __u32 value in nano secs ignore received CF frames which timestamps differ less than val
- CAN_
ISOTP_ TX_ STMIN - pass __u32 value in nano secs use this time instead of value provided in FC from the receiver
- CAN_
MAX_ DLEN CAN_MAX_DLENAccording to ISO 11898-1- 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
- PF_CAN
- CAN protocol family
- RECV_
BUFFER_ SIZE - Size of buffer allocated for reading TP data
- RTR_
FLAG - remote transmission request flag
- SFF_
MASK - valid bits in standard frame id
- SOL_
CAN_ BASE - undocumented can.h constant
- SOL_
CAN_ ISOTP - undocumented isotp.h constant