SocketCAN is the Linux CAN networking stack and can-utils are a rich set of utilities to analyze CAN traffic. They are great all-purpose tools for car research and hacking.
You can now use your Carloop as a SocketCAN interface!
Carloop firmware
You’ll need special firmware on your Carloop to print received CAN messages to the USB serial port and allow transmitting CAN messages sent to the USB serial port.
Flash the SocketCAN serial firmware application to your Carloop. The easiest way is to go to https://build.particle.io, select Libraries on the left, search and select Carloop, then open the socketcan_serial.cpp
example, click the Use this example
button then flash to your device.
Linux computer setup
To use SocketCAN you’ll need a laptop running Linux. You could even do it from a Raspberry Pi.
Install the can-utils
package: sudo apt install can-utils
SocketCAN has drivers to talk to many different devices. Since the Photon/Electron creates a serial port when you connect it to your laptop we’ll use the serial line CAN driver (SLCAN).
Connect your Carloop to your computer through the USB connector. A serial port named /dev/ttyACM0
should now be available. Check with ls /dev/ttyACM*
Link the serial port with a CAN network interface with sudo slcand -o -c -s6 /dev/ttyACM0 can0
(slcand
comes from can-utils, s6
is the speed ttyACM0
is the serial port, can0
is the CAN network interface)
At this point you should see a CAN network when you do ip addr
3: can0: <NOARP> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
link/can
When you are ready to start analyzing traffic, you bring up the CAN network with sudo ip link can0 up
You can then use other canutils like candump, cansniffer and cansend.
Here’s for example what happens when I use candump can0
on my Ford Fiesta:
Here’s how I found out which message contains the accelerator pedal using cansniffer -cae can0
which progressively hides messages that don’t change. The pedal was in message 0xFD byte 3.
To stop the CAN interface, do sudo ip link can0 down
.
slcand
tends to keep running even after you stop the CAN interface. You can close it with sudo pkill slcand
References
For details about the SLCAN serial protocol used between SocketCAN and the Carloop firmware, see the source of the Carloop firmware on GitHub.
For more details about the can-utils programs, see the can-utils repository on GitHub. You can also search online for more info about a particular can-util program.
Some info about CAN on Linux and how to use different types of CAN interfaces.
The low-level documentation about SocketCAN (this was too detailed for my needs).
Here’s a lit of the CAN bus speed parameters that can be passed to slcand
:
-
-s0 10 kbit/s
-
-s1 20 kbit/s
-
-s2 50 kbit/s
-
-s3 100 kbit/s
-
-s4 125 kbit/s
-
-s5 250 kbit/s
-
-s6 500 kbit/s
-
-s7 800 kbit/s
-
-s8 1 Mbit/s
Next steps would be to implement a UDP server in the Particle Photon to send the data wirelessly. The socketcand would be a good place to start for the protocol.
Now get out there and do amazing things!