CAN Interfaces

CAN-Interface: Configuration

CAN is a network…

# ip link show
... all interfaces here ...
# ip link show can0
3: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT qlen 10
    link/can
# ip link set can0 type can help
# ip link set can0 bitrate 500000
# ip link set can0 bitrate 500000 listen-only on
# ip link set can0 up

CAN Utils

Nice little utilities …

  • Userspace relic of the SocketCAN project (⟶ make CAN a network)

  • cansend: send a frame

  • candump: recording frames from one or more CAN interfaces

  • canplayer: replay from recording

  • … and others …

  • ⟶ testing!

Installation

Fedora
# dnf install can-utils
Debian/Ubuntu
# apt install can-utils

CAN Utils: Usage (1)

Generating frames:

$ cansend can0 123#deadbeef
$ cangen -D deadbeef -L 4 can0
$ cangen -D deadbeef -L 4 -I 42 can0
$ cangen -D i -I 42 -L 8 -g 100 -p 100 can0

Sniffing frames:

$ candump can0
$ candump can0 can1 ...

CAN Utils: Usage (2)

Record, Replay:

$ candump -L can0 > can0.log
$ canplayer < ./can0.log

Changing the interface:

$ canplayer can1=can0 < ./can0.log

vcan: Virtual CAN-Bus

Problem:

  • CAN development traditionally needs hardware

  • … at least two participants (loopback on one controller possible))

  • ⟶ programming and testing as hard as can be

Lösung:

# modprobe vcan
# ip link add dev mein-test-can type vcan
# ip link set mein-test-can up
# canplayer mein-test-can=can0 < ./can0.log

Fantasy:

  • Programming and testing on the PC

  • Continuous integration