candev
SocketCAN based experimental library that implements proposed (PR) embedded-hal
CAN traits.
Running the examples
Prerequisites
- Make sure the
can-utils
package in installed on your system - Setup Virtual CAN device as follows:
Note that this can be automated at startup by:
- Adding a line with
vcan
in/etc/modules
- Adding the following to
/etc/network/interfaces
Receive
A simple example on how to receive a CAN frame
- Run
cargo run --example receive
in a terminal - Run
cansend vcan0 123#DEADBEEF
in another terminal
You should see 123#DEADBEEF
(or whatever id and data you passed to cansend) appear on the first terminal.
Transmit
A simple example on how to transmit a CAN frame.
- Run
candump vcan0
in a terminal - Run
cargo run --example transmit
in another terminal
You should see candump
output vcan0 001 [4] DE AD BE FF
.
Driver
A sample driver embedded-hal
CAN driver implementation that makes use of candev and simple echoes a message. In this example, two instances of the driver ping pong a message to each other.
To observe the behavior, do as follows:
- Run
candump vcan0
in a terminal - Run
cargo run --example driver
in another terminal
You'll be able to observe the interaction of the two driver instances on the first terminal.
Minimum Supported Rust Version (MSRV)
This crate is guaranteed to compile on stable Rust 1.40 and up. It might compile with older versions but that may change in any new patch release.
License
Licensed under either of
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or <#404>)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Credits
This project initial starting point was based off socketcan-rs.
Big thanks to Timo for his help and developing the CAN traits for the embedded-hal project.