
Show HN: Cantools – an extensive set of CAN bus tools - eerimoq
https://github.com/eerimoq/cantools
======
jmiskovic
Thank you for making cantools. I'm using it daily and enjoying how easy and
powerful it is.

Two other projects also deserve to be mentioned. The opendbc is attempt to
make sense of CAN traffic in different cars, they reverse-engineer messages
and provide descriptions to each. It's part of comma.ai open source autonomous
driving effort. The other project is CANboat which does similar thing for
NMEA2000 protocol used on boats.

The industry so far is very closed and rejects concept of interoperability.
It's nice that somebody is taking steps in right direction.

~~~
ACS_Solver
> The industry so far is very closed and rejects concept of interoperability.
> It's nice that somebody is taking steps in right direction.

Sadly very true. I've worked in the industry, and while there has been a lot
of standardization, there's definitely not a lot of interoperability. Car
makers and tier 1 suppliers in my experience are very insistent on keeping
their knowledge in-house, distrustful of open source tools and extremely
unwilling to share any technical information that could lead to greater
interoperability.

------
monocasa
Throwing out there that Wireshark has CAN parsing ability. For any else of
y'all that have been stuck with a legacy non standard CAN protocol running on
industrial automation, writing a Lua protocol parser and a little script to
convert whatever internal format you've been using to pcap-ng will be an
afternoon or two very well spent.

~~~
PinguTS
In industrial automation there are mainly 2 standard protocols, which can
obtain easily: DeviceNet and CANopen.

~~~
monocasa
There's also an ton of shops using literally no standard above the
8bytes+IDbits that CAN controllers spit out and accept.

------
fullstop
If you work with J1939 there is a can-j1939 kernel module which was mainlined
in the 5.4 Linux kernel. It handles address negotiation and other time-
sensitive matters which would have had to be done in user space previously.

[https://github.com/linux-can/can-
utils/blob/master/can-j1939...](https://github.com/linux-can/can-
utils/blob/master/can-j1939-kickstart.md)

~~~
irishcoffee
Welp this makes my day-job a touch simpler now. Thank you for the heads up!

------
nocman
I would like to suggest that in your "About" suggestion you provide a short
description what a "CAN bus" is (with links to
[https://en.wikipedia.org/wiki/CAN_bus](https://en.wikipedia.org/wiki/CAN_bus)
\- or whatever you feel is appropriate ).

I'm a very technical person, and I honestly don't think I'd ever heard of it.
I spent a decent bit of time looking on the site trying to figure out what it
was before resorting to Google.

It's not a huge deal, but seems to me like it would be helpful, and worth the
effort.

~~~
samreight
If you saw a library for say Image Processing or cattle husbandry for Java/JVM
would you insist that the project provide a description of “Java”? I’m going
to guess if you’re being honest you’d say no. CAN really is not an obscure
thing at all. Also it is ones of those things that if you don’t know what it
is, you probably don’t need this. Otherwise the google burden is minimal for
the curious.

~~~
kingosticks
Obscure or not, I think the latter part of this comment is the important part.
If you don't know what it is, you are not the target audience and you won't
become the target audience by suddenly knowing what a CAN bus is.

So no, I'd say it's actually not worth the effort to add an explanation. It
may even give real users the wrong idea.

~~~
reaperducer
_If you don 't know what it is, you are not the target audience and you won't
become the target audience by suddenly knowing what a CAN bus is._

So you've never visited a web site, read a bit about a topic you knew nothing
about, and then thought, "Wow, that sounds like something I'd like to get
into?"

There are a lot of people out there who are curious about the world around
them and enjoy expanding what they know instead of stagnating in a knowledge
silo.

~~~
bibabaloo
Sure, but I don't think this is meant to be pedagogical tool to teach you
about CAN. You're always free to look up anything you don't know, yourself.

------
prostodata
Here is another project for working with CAN:

[https://github.com/hardbyte/python-can](https://github.com/hardbyte/python-
can)

I used it (as well as Cantools) for importing various CAN-specific data
formats.

------
contingencies
Has anyone taken canbus and deployed it on a greenfield non-automotive system?
If so, what was the thought process to justify use of this protocol vs.
something like ethernet? The selling point seems to be 'save copper' but the
associated overheads (tooling, training, reduced throughput[0], larger
connectors, multidrop bus debug drawbacks, etc.) seem like they would _far_
outweigh any nominal savings in all but the highest volume production
scenarios.

[0]
[https://en.wikipedia.org/wiki/ELM327#Protocols_supported_by_...](https://en.wikipedia.org/wiki/ELM327#Protocols_supported_by_ELM327)

~~~
crtlaltdel
Yes.

It was used as an industrial communications bus to coordinate slave devices
from a master controller. Drop-length was a non-issue as the majority of our
devices used an in-rail (DIN mounted) interconnect bus. The larger "drops"
were often a under 10" and just jumped one DIN rail to the next DIN rail in
the cabinet.

This was selected for the following reasons:

1\. These devices were installed in HEAVY EM environments (think in close
proximity to very large electric motors) and the electrical characteristics

2\. The system topology physically supported multi-drop

3\. We had a good deal of talent with CAN experience

4\. Our device was already supporting a bunch of wired and wireless protocols
(rs422, rs485, ethernet, btle, wifi, etc) and tbh CAN support was a gimme on
the SOM we used as the device's core, so initially it made it into
consideration by chance

~~~
contingencies
Interesting. I wasn't aware of any EMI benefit. I wonder if this is true with
shielded ethernet cables at lower data rates (eg. 10BaseT)? It seems maximum
CAN drop length is far shorter than ethernet, which I guess could become a
consideration in industrial deployments.

~~~
kube-system
The EMI resilience is one of the big reasons why it's used for automotive
applications.

Many (all?) CAN standards transmit on redundant copper, in opposing
polarities, making it really easy to identify a signal vs noise.
[https://en.wikipedia.org/wiki/CAN_bus#/media/File:CAN-Bus-
fr...](https://en.wikipedia.org/wiki/CAN_bus#/media/File:CAN-Bus-
frame_in_base_format_without_stuffbits.svg)

It's like a one-wire serial signal, but redundant.

~~~
crtlaltdel
yeah, differential data lines; common in serial applications where you want to
protect from noise. a lot of the higher level dialects are built off something
like (if not the) rs485 electrical layer.

------
floathub
This looks well designed and thought out. Does anyone know if it has been
applied to NMEA-2000 (a marine electronics flavor of CANbus)?

~~~
novakinblood
I was thinking the same question. I could only find C++ implementation at
[https://github.com/ttlappalainen/NMEA2000](https://github.com/ttlappalainen/NMEA2000)
which I assume you have found as well.

~~~
floathub
Yes. And that ttlappalainen project generally inherits from the CANBoat
project.

------
zro
Thanks for all your hard work! We used this constantly at $oldjob and it saved
us a ton of time and effort.

------
jmt_
I'm very interested in beginning to monitor some information on my vehicle. Is
the usual workflow involve pulling a dbc file off the vehicle with a CAN bus
reader and using software to look into it? Or is it more complicated? Anyone
have recommendations as to the reader itself?

~~~
selpop
You can get away with ELM327 based readers (the cheap bluetooth/Wi-Fi OBDII
readers you see on Amazon/eBay) if you want fairly standard data like speed,
and some manufacturer specific data in the form of PIDs
([https://en.wikipedia.org/wiki/OBD-
II_PIDs](https://en.wikipedia.org/wiki/OBD-II_PIDs))

If you want more involved data, or to send messages, it's mostly sniffing,
doing an action, and seeing what changes.

`can-utils` has a nice UI for this, which lets you filter messages that don't
change easily.

(Also, I've actually never seen a `.dbc` file before, but it looks like a map
of PIDs, usually you [or the community for your car] have to reverse engineer
those with the sniffing method, afaik)

-

The ELM327 can technically stream all the CAN messages on the bus and do that
type of sniffing, but it has a very small buffer and gets completely hosed
with chatty cars.

I personally use the MCP2515 with a Raspberry PI for more involved car
hacking.

[https://www.raspberrypi.org/forums/viewtopic.php?t=141052](https://www.raspberrypi.org/forums/viewtopic.php?t=141052)

The electrical modification mentioned is needed for the most common MCP2515
modules because the PI isn't 5v tolerant, but it's an easy enough fix

I have two of them hooked up to a Raspberry PI (one for each of my car's CAN
busses, some cars have more), and that with `can-utils` has gotten me pretty
far.

~~~
beering
People should be aware that many of the cheapo "ELM327" readers on Amazon/eBay
are counterfeit chips that merely identify themselves as ELM327. They do not
perform as well as the real chip, but may be good enough for reading your
check-engine code. For example, I had a fake one that choked if I tried
querying engine RPM in a loop, while the real deal had no issues.

~~~
selpop
I've had success with clone ELM327 for reading stuff like RPM in real time,
but it is hit or miss.

They're just generally slower and usually missing features of the newest
ELM327 revisions.

The problem is if you just search for ELM327, most of them will be clones, so
I just use the MCP2515 when I need lots of data, and use the ELM327 for basic
stuff

~~~
raocon
If it's in the budget, I would highly recommend the Macchina M2[1], especially
if you need to access more than one bus at a time. It's based on the Arduino
Due, with dual CAN transceivers (and LIN). It has a lot of bells and whistles
- but can be simplified down to just a can sniffer if needed. I'm currently
using one with SavvyCan to reverse engineer a vehicle for a project, and it
has no problem keeping up with the high-speed network.

[1][https://www.macchina.cc/m2-introduction](https://www.macchina.cc/m2-introduction)

------
rationalthug
For those interested in CAN bus for UAVs, there is
[https://github.com/uavcan](https://github.com/uavcan) as well.

------
dmd
Ugh, where was this when I needed it in 2013? At $OLDJOB my boss and I wrote
pretty much this entire thing, in an unholy mix of bash and Tcl, much more
poorly.

~~~
phkahler
I cant tell you how many times I've seen this type of thing done at different
companies. Many of those projects died.

The last one was a LIN tool written in python. My coworker wrote it. He wanted
to open source it, so I talked our boss, the local IP guy and eventually the
legal department. Legal thought I wanted them to write a license. No, that's
not useful, I needed to know which of GPL, MIT, BSD the company would approve.
They came with some of the misguided concerns companies tend to have. The
other question I could not get answered is who in management needed to OK it.
Oh and would the copyright belong to the company or the guy who wrote it. None
of my questions could seem to find definitive answers. The guy who wrote the
tool quit and it became abandon ware inside the company. I had mentioned that
nobody stays around forever and the author would have done some maintenance
after he's gone. I said this well before he left as an argument in favor of
open sourcing it.

Anyway, I hope a lot of people bring this to life so we can all stop
reinventing this wheel or paying certain companies to rent theirs.

Related: Busmaster, but its Windows only.

~~~
kapep
> Legal thought I wanted them to write a license.

I'm not surprised. I once had a conversation with some business lawyers that
were specialized on what is easiest described as "IT law" [1] (mostly
intellectual property, licensing, contract law, data privacy) who were working
in the field of IT/software. You could talk with them about client-server and
p2p systems or even basic encryption and data security, so they definitely
knew a bit about technology.

They knew about open source software but I was surprised that they had never
heard about source licenses nor about the creative common license. I tried to
explain the basics to them but they didn't seem to get the concept of a
license that could be reused by more than one licenser and were confused why a
license would need a name (like 'MIT license'). In their view, licenses were
always individual drafted documents with terms that needed to be negotiated
with business partners or were imposed on customers. They didn't believe me
that you don't create your own custom license for open source projects and
thought that I was talking about copy&pasting bad license templates from the
internet. When I told them the basic concept of the GPL they thought I was
bullshitting them.

[1]:
[https://en.wikipedia.org/wiki/IT_law](https://en.wikipedia.org/wiki/IT_law)

~~~
rusk
Whats that saying about a person not being able to learn something that
threatens their livlihood?

------
thbr99
We have been using proprietary CANoe for well over 6 years. Will evaluate
this. But don't know if corporate will like it or not.

~~~
DoingIsLearning
Different use cases in my opinion.

As it is described this would more likely meet the use-cases of CANalizer
(sniffing, logging, lightweight scripting) but not CANoe (bus simulation, node
simulation full on HIL Simulation).

------
seren
This seems to work with a candump format input, does it works with canalyzer
*.asc format ?

~~~
saterHater
Yeah, using -L you can shell redirect to a workable log file. I've done this a
few times. They also build the asc2bin conversion utility to convert any logs
to the more common *.bin format.

------
t34543
Beautiful - I’ve been using Intrepid Vehicle Spy for awhile but the cost is
hard to justify for a hobbyist.

------
m3kw9
What’s missing is a can bus sim

~~~
sulZ
I've recently become interested in a can bus sim, actually. If you know of any
resources I would appreciate any pointers.

~~~
ocdtrekkie
There are some basic simulators out there that use single board computers.
I've been meaning to try to build one at some point.

[https://github.com/carloop/simulator](https://github.com/carloop/simulator)
(RasPi)

[https://github.com/limiter121/esp32-obd2-emulator](https://github.com/limiter121/esp32-obd2-emulator)
(ESP32)

~~~
sulZ
Thanks. I'll check them out.

