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 group default qlen 10
link/can
# ip link set can0 type can help
# ip link set can0 type can bitrate 500000
# ip link set can0 txqueuelen 1000
# ip -detail link show can0
12: can0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can state STOPPED restart-ms 0
bitrate 500000 sample-point 0.875
tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 brp 6
gs_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..1024 brp_inc 1
clock 48000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536 parentbus usb parentdev 3-6.2.4:1.0
# 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 framecandump
: recording frames from one or more CAN interfacescanplayer
: replay from recording… and others …
⟶ testing!
Installation
# dnf install can-utils
# 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
…