Asynchronous Linux SocketCAN sockets with tokio

Overview

crates.io badge documentation

tokio-socketcan

SocketCAN support for tokio based on the socketcan crate.

Example echo server

use futures_util::stream::StreamExt;
use tokio_socketcan::{CANSocket, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let mut socket_rx = CANSocket::open("vcan0")?;
    let socket_tx = CANSocket::open("vcan0")?;
    while let Some(Ok(frame)) = socket_rx.next().await {
        socket_tx.write_frame(frame)?.await?;
    }
    Ok(())
}

Testing

Integrating the test into a CI system is non-trivial as it relies on a vcan0 virtual can device existing. Adding one to most linux systems is pretty easy with root access but attaching a vcan device to a container for CI seems difficult to find support for.

To run the tests locally, though, setup should be simple:

sudo modprobe vcan
sudo ip link add vcan0 type vcan
sudo ip link set vcan0 up
cargo test

Changelog

0.1.3

  • Fixed error events being effectively delayed in delivery until the next non-error arrived.

0.1.2

  • Added futures::sink::Sink implementation for the CANSocket
Comments
  • Migrate to async await and futures-0.3

    Migrate to async await and futures-0.3

    Ok I also migrated the tests and docs. There is currently still one false positive in the test. Nevertheless I thought it's worth sharing. What I kind of still dislike but have no idea how to work around is that this will currently only work with tokio. Given that the crate is called tokio-socketcan I assume that's fine, but I think it would be great if we could figure out how to make this executor agnostic so it also forks with e.g. the futures-executor and async-std.

    opened by marcelbuesing 16
  • UDS messages

    UDS messages

    Would it make sense to implement CANMessage struct or similar on top of this crate or the underlying socketcan-rs crate? I'm thinking about sending the typical UDS session negotiation (reset, establish session, ask for seed challenge, etc..), i.e:

        let uds_security_session = &["021101", "021001", "021003", "022701"];
    

    Sending those byte by byte via CANFrames looks a bit tedious? Or perhaps there are other higher level crates I could use that you know of?

    Thanks in advance!

    opened by brainstorm 3
  • reexport CANFilter

    reexport CANFilter

    This is used in public API pub fn set_filter(&self, filters: &[CANFilter]) -> io::Result<()>. So it is useful if CANFilter can be imported straight from here.

    opened by andresv 2
  • New Maintainers?

    New Maintainers?

    Hello and thank you for building this amazing crate! It's proven to be extremely useful for some projects I've been working on. However, I've noticed it's a bit inactive unfortunately. Is this project open to taking on new maintainers?

    opened by rdelfin 0
  • Time-out support

    Time-out support

    Hello. I have test code:

        let mut socket_rx = CANSocket::open("vcan0").unwrap();
        let socket_tx = CANSocket::open("vcan0").unwrap();
    
        while let Some(Ok(frame)) = socket_rx.next().await
        {
            println!("frame: {:?}", frame);
            socket_tx.write_frame(frame).unwrap().await.unwrap();
        }
    

    but I have a problem. I would like a timeout.

    opened by hanusek 0
  • Add support for CAN FD

    Add support for CAN FD

    NOTE: After the can-fd branch in socketcan-rs repo (https://github.com/j4r0u53k/socketcan-rs) is merged, one should edit Cargo.toml in this project appropriately to point to the upstream.

    opened by j4r0u53k 0
Releases(0.3.1)
  • 0.3.1(Nov 17, 2021)

  • 0.3.0(Feb 10, 2021)

  • 0.2.0(Nov 12, 2020)

    0.2.0 - 2020-11-12

    • [BREAKING CHANGE] Migrate code to tokio 0.2, futures 0.3 and therefore make it possible to use async/await syntax for reading and writing frames :rocket:.
    • [BREAKING CHANGE] Add dependency to thiserror 1.0 and introduce common error type Error.
    • Update examples to async/await syntax.
    Source code(tar.gz)
    Source code(zip)
Owner
Terry
Terry
Asynchronous Linux SocketCAN - Broadcast Manager support (BCM) with tokio

tokio-socketcan-bcm The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in k

Marcel 4 Nov 8, 2022
A super minimal wrapper around unix sockets for IPC on top of tokio.

tokio-unix-ipc This crate implements a minimal abstraction over UNIX domain sockets for the purpose of IPC on top of tokio.

Armin Ronacher 26 Nov 18, 2022
Linux SocketCAN access in Rust

Rust SocketCAN support Maintenance status: This crate is in the process of entering renewed joint maintainership with @fpagliughi. Please stay patient

Marc Brinkmann 61 Dec 30, 2022
An easy-to-use SocketCAN library for Python and C++, built in Rust.

JCAN An easy-to-use SocketCAN library for Python and C++, built in Rust, using cxx-rs and pyo3. Warning: I have never used Rust before and I don't kno

Leigh Oliver 4 Feb 9, 2023
Advanced configuration options for sockets.

socket2-rs Documentation License This project is licensed under either of Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licens

Nedim Zečić 0 Dec 23, 2021
Streaming data over unix sockets, in Rust

Unix-socket based client/server In order to dig into Sōzu channels, I had to dig into the workings of unix sockets. What this repo contains a small so

Emmanuel Bosquet 3 Nov 28, 2022
Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated

raslib Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated All tests are made on Raspberry PI 4B+ on Raspbia

Anтo 5 Apr 12, 2022
An asynchronous IO utilities crate powered by tokio.

An asynchronous IO utilities crate powered by tokio.

Harry 2 Aug 18, 2022
dark-std an Implementation of asynchronous containers build on tokio

dark-std dark-std is an Implementation of asynchronous containers build on tokio. It uses a read-write separation design borrowed from Golang SyncHash

darkrpc 4 Dec 13, 2022
Awesome books, tutorials, courses, and resources for the Tokio asynchronous runtime ecosystem. ⚡

Awesome Tokio Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing network applicati

Marcus Cvjeticanin 59 Oct 27, 2023
Simple crate that wraps a tokio::process into a tokio::stream

tokio-process-stream tokio-process-stream is a simple crate that wraps a tokio::process into a tokio::stream Having a stream interface to processes is

Leandro Lisboa Penz 8 Sep 13, 2022
Utilities for tokio/tokio-uring based async IO

dbs-fuse The dbs-fuse is a utility crate to support fuse-backend-rs. Wrappers for Rust async io It's challenging to support Rust async io, and it's ev

OpenAnolis Community 6 Oct 23, 2022
BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust

BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust This library provides an asynchronous, fully featured interface to the Bluetooth Low Energy

Sebastian Urban 40 Oct 21, 2021
TMM is a Linux native game modding tool. it allows to install and depoly mods for Linux native and wine games.

Tux Mod Manager TMM is a Linux native mod manager made with the Tauri toolkit. It can install, load, remove and deploy mods for both Linux native and

Mathiew May 119 Dec 27, 2022
Zero-cost asynchronous programming in Rust

Zero-cost asynchronous programming in Rust Documentation | Website futures-rs is a library providing the foundations for asynchronous programming in R

The Rust Programming Language 4.7k Jan 1, 2023
Empowering everyone to build asynchronous software

Runtime Empowering everyone to build asynchronous software. API Docs | Contributing | Chat Built with ⛵ by The Rust Async Ecosystem WG ⚠️ Deprecation

Rust Async (archived) 867 Dec 9, 2022
A fully asynchronous, futures-based Kafka client library for Rust based on librdkafka

rust-rdkafka A fully asynchronous, futures-enabled Apache Kafka client library for Rust based on librdkafka. The library rust-rdkafka provides a safe

Federico Giraud 1.1k Jan 8, 2023
A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...

Tokio A runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. It is: Fast: Tokio's zero-cost abstracti

Tokio 18.7k Dec 30, 2022
Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.

delay-timer Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.

BinCheng 255 Dec 30, 2022
Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.

Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.

null 62 Dec 27, 2022