Virtual CAN-BUS simulator (Virtual ECU)

Search for a command to run...

No comments yet. Be the first to comment.
I recently created a simple NextJS landing page for my contracting business and decided to host it using GitHub pages, Which is great because it's free and easy to implement. However, it doesn't come with any backend. Keeping with the themes of "free...

So you have a bunch of data that comes from some human source (Free text form fields, reviews, blogs, classified ads, social media) and you want to do some analysis on it. but with people being the way they are, you're going to have some problems: A...

NOTE: This article to assumes you have NGINX and local DNS configure correctly if not check out this article to get started. If you're building web applications, then you've probably run into this before. You need to run your local environment over ...

Estimated time: 5 mins My current PC setup includes 2 SSD’s, one for my Linux (Manjaro) installation and one for windows 10, I then have 2 spinning disks in raid 0 that I use for mass storage and backups etc. I switch between Linux and Windows regula...

While developing some monitoring applications for a Raspberry-Pi car computer, I found that writing code on my laptop while sitting in the front seat of my car is not the most productive way to do things. What's needed is some sort of virtual ECU, and i have just the solution.

This may be different for other cars but for my disco 3, I need to wait 5 minutes after turning the car off for the ECU to go to sleep. Once the ECU is asleep I start the recording.
candump can0 -l
I start the car and let it run for 5 minutes or so, later on I’ll redo this and take the car for a spin around the town but for now this is enough for me. so I CTL-C the recording and I get a file named candump-2020-04-14_202239.log. I rename this to something with a little more meaning (“candump-landrover-discovery-3-vcan0.log”)
The vcan device is basically another network device so configuring it is pretty straight forward.
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
Now i just need to replay my recording back into vcan0.
canplayer -I candump-landrover-discovery-3-vcan0.log -l i vcan0=slcan0
By default canplayer will replay the file via the same device that it was captured on (slcan0). to get around this i need to specify the vcan0 as new device, hence vcan0=slcan0
Finally I want to be able to start the simulation on demand. I do this by creating a systemd service config
sudo vim /lib/systemd/system/cansim.service
[Unit]
Description=Canbus simulator
After=network.target
[Service]
Label=cansim
Type=exec
Environment=CANDATA=/mnt/DATA/sharedfolder/candump-landrover-discovery-3-vcan0.log
Environment=LOG_INTERFACE=slcan0
ExecStartPre=modprobe vcan
ExecStartPre=-ip link add dev vcan0 type vcan
ExecStartPre=ip link set up vcan0
ExecStart=canplayer -I $CANDATA -l i vcan0=${LOG_INTERFACE}
ExecStop=/bin/kill -s TERM $MAINPID
PIDFile=/run/cansim/cansim.pid
TimeoutStopSec=0
Now I can start the simulation whenever I need it with
systemctl start cansim