When setting up and testing any new system some of the most common things I tend to want to do are:
- view raw output
- transmit raw input
- log the output
- re-play the logs
SocketCAN is no exception and the tools included with can-utils does just this. (Plus more.)
Debian based systems, I can’t speak for other versions of Linux, this is easy just issue the following command
$ apt-get install can-utils
Can-utils is a veritable Swiss Army Knife of tools and probably has a tool to get stones out of horses hoofs somewhere. I’ll go over the ones I have found most useful.
Candump probably the most useful of all the tools as it will dump information from the CANbus to stdout.
$ candump can0
Will then listen on the interface can0 and dump any CAN frames it sees to the terminal window. (note: ctrl+c will stop candump)
can0 1DFF6773  00 0B 3B 9F 03 02 04 5A can0 1DFF6773  01 A1 12 19 09 09 can0 0DF010A0  FF FF A9 3F 18 A8 C6 28 can0 15FD0773  00 C0 53 7A FF 7F FF FF can0 09F503A0  FF FF FF 60 01 FF FF FF can0 11F80E2B  00 1B 01 E0 53 7F 10 3F
Candump can also be set to log to file with the addition of a -l argument
$ candump -l can0 Disabled standard output while logging. Enabling Logfile 'candump-2017-05-19_112441.log'
below is an example of what would be recorded in the log file
(1495188791.945986) can0 0DF805A0#040000000010FC0A (1495188791.945993) can0 0DF805A0#055000FF7FFFFFFF (1495188791.946000) can0 0DF805A0#067F00 (1495188791.946015) can0 0DF809A0#A93FFCEDC428B400 (1495188791.946029) can0 09F50373#004E01FFFF00FFFF
Cansend is used to transmit individual frames directly onto the CANbus.
$ cansend can0 5A1#188.8.131.52.184.108.40.206
Gives us the following candump output.
$ candump can0 can0 5A1  11 22 33 44 55 66 77 88
By default canplayer will replay a logfile back onto the interface recorded in the log file.
$ canplayer -I candump-2017-05-19_101301.log
Using the log file below
$ cat candump-2017-05-19_101301.log (1495188791.945939) vcan1 0DF805A0#002B87A93FFCEDC4 (1495188791.945961) vcan1 0DF805A0#012800586711CFDB (1495188791.945970) vcan1 0DF805A0#02490800F41547C4 (1495188791.945979) vcan1 0DF805A0#03D26E0380662300
$ candump vcan1 vcan1 0DF805A0  00 2B 87 A9 3F FC ED C4 vcan1 0DF805A0  01 28 00 58 67 11 CF DB vcan1 0DF805A0  02 49 08 00 F4 15 47 C4 vcan1 0DF805A0  03 D2 6E 03 80 66 23 00
Note – in this instance we are using the virtual can interface vcan1
It is possible to tell canplayer to play messages recorded on one interface back on another interface.
$ canplayer -I candump-2017-05-19_101301.log can0=vcan1
will play messages recorded on vcan1 on can0 interface to produce
$ candump can0 can0 0DF805A0  00 2B 87 A9 3F FC ED C4 can0 0DF805A0  01 28 00 58 67 11 CF DB can0 0DF805A0  02 49 08 00 F4 15 47 C4 can0 0DF805A0  03 D2 6E 03 80 66 23 00
I hope that this brief introduction to can-utils is useful to readers, I have only scratched the surface of what they can do. I strongly recommend using the -h argument with each of the tools to discover the full extent of what each tool can do.