Crate tokio_socketcan_isotp

Crate tokio_socketcan_isotp 

Source
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 vcan0

Structs§

ExtendedId
Extended 29-bit CAN Identifier (0..=1FFF_FFFF).
FlowControlOptions
Flow control options aka can_isotp_fc_options
IsoTpBehaviour
IsoTpOptions
ISO-TP otions aka can_isotp_options
IsoTpReadFuture
Future for reading data from IsoTpSocket
IsoTpSocket
An asynchronous I/O wrapped socketcan_isotp::IsoTpSocket For reading and writting to the socket use IsoTpSocket::read_packet and IsoTpSocket::write_packet respectively.
IsoTpWriteFuture
Future for writing data to IsoTpSocket
LinkLayerOptions
Link layer options aka can_isotp_ll_options
StandardId
Standard 11-bit CAN Identifier (0..=0x7FF).
TxFlags

Enums§

Error
Possible errors
Id
A CAN Identifier (standard or extended).

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_DLEN According 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