I am looking for a free API (in C or C++) for decoding CAN messages. I have all the information about the layout of data (Id, length, start bit, byte order, ... ) and I need now some functions to decode the hexadecimal values into human readable numbers.
As I said I have the layout of the data, I know the protocol and the assignment of each bit. I have the description of the CAN data in a DBC file (Vector Informatik GmbH format). So I am able to say that the bits 11 to 16 of the message Id 0x305 represents the measurement of the temperature for example.
We can think that the decoding is very easy but it is not the case, you have to deal with the problem of endianess, a data can be represented by n bits where n is not a multiple of 8, etc. And the amount of messages can be very heavy.
So before writing some C code, I would like to know if there is a library that can help me and/or do that directly. I think that this problem occurs very often for each person that wants to analyse binary data (not in an Ascii representation for giving an answer to your question).
You haven't made it exactly clear what you want, but I am going to assume you want something that takes the vector DBC file information and use it to generate the C for decoding the CAN signals.
Yes there is a tool that can do this from Vector Informatik, it produces all necessary code you need so that in your example the temperature is stored into a declared variable. It is useful if you are in the early stages and the database is undergoing a lot of change, you can automatically rebuild the code modules very quickly.
It however doesn't apply scaling. It doesn't convert your numbers into an ASCII representation so you can fire it out the serial port to a terminal program, you have to do this yourself. And finally it costs a very large amount of money.
I think the best you can do is to get on with the bit bashing. If your database is not changing much, if at all, then it's not really that big a problem to hand code it. To make it a bit easier it's worth making sure the layout of the signals in the CAN messages align as much as possible with byte boundaries and don't cross them without good reason.
As a matter of interest, how many messages and signals do you have?
Hi Dave and Stephen Thanks for your answers. This is a bad news that a free library seems not to exist. I think I will try to decode messages myself. Dave, about your question, the DB is stable and contains about 200 signals. Gerald
Thanks for your answers. This is a bad news that a free library seems not to exist. I think I will try to decode messages myself. Dave, about your question, the DB is stable and contains about 200 signals.