#socketcan #linux #bus

socketcan

Linux SocketCAN library. Send and receive CAN frames via CAN bus on Linux.

11 stable releases

Uses old Rust 2015

1.7.0 Jun 29, 2017
1.6.0 Jan 10, 2017
1.5.1 Dec 8, 2016
1.4.0 Sep 14, 2016
1.1.2 May 19, 2016
Download history 173/week @ 2020-12-18 52/week @ 2020-12-25 298/week @ 2021-01-01 559/week @ 2021-01-08 657/week @ 2021-01-15 674/week @ 2021-01-22 948/week @ 2021-01-29 735/week @ 2021-02-05 646/week @ 2021-02-12 748/week @ 2021-02-19 502/week @ 2021-02-26 286/week @ 2021-03-05 326/week @ 2021-03-12 467/week @ 2021-03-19 407/week @ 2021-03-26 270/week @ 2021-04-02

2,354 downloads per month
Used in 14 crates (12 directly)

MIT license

36KB
816 lines

Rust SocketCAN support

The Linux kernel supports using CAN-devices through a network-like API (see https://www.kernel.org/doc/Documentation/networking/can.txt). This crate allows easy access to this functionality without having to wrestle libc calls.

Please see the documentation for details.


lib.rs:

socketCAN support.

The Linux kernel supports using CAN-devices through a network-like API (see https://www.kernel.org/doc/Documentation/networking/can.txt). This crate allows easy access to this functionality without having to wrestle libc calls.

An introduction to CAN

The CAN bus was originally designed to allow microcontrollers inside a vehicle to communicate over a single shared bus. Messages called frames are multicast to all devices on the bus.

Every frame consists of an ID and a payload of up to 8 bytes. If two devices attempt to send a frame at the same time, the device with the higher ID will notice the conflict, stop sending and reattempt to sent its frame in the next time slot. This means that the lower the ID, the higher the priority. Since most devices have a limited buffer for outgoing frames, a single device with a high priority (== low ID) can block communication on that bus by sending messages too fast.

The Linux socketcan subsystem makes the CAN bus available as a regular networking device. Opening an network interface allows receiving all CAN messages received on it. A device CAN be opened multiple times, every client will receive all CAN frames simultaneously.

Similarly, CAN frames can be sent to the bus by multiple client simultaneously as well.

Hardware and more information

More information on CAN can be found on Wikipedia. When not running on an embedded platform with already integrated CAN components, Thomas Fischl's USBtin (see section 2.4) is one of many ways to get started.

RawFd

Raw access to the underlying file descriptor and construction through is available through the AsRawFd, IntoRawFd and FromRawFd implementations.

Dependencies

~1.5MB
~28K SLoC