Home:ALL Converter>Using cantools generated C files

Using cantools generated C files

Ask Time:2019-03-29T21:37:12         Author:spx305

Json Formatter

I'm using cantools in python for decoding some CAN messages read from socketcan. In python, I can read a message from the socket and decode it simply with:

message = can_bus.recv()
decoded_msg = db.decode_message(msg.arbitration_id, msg.data)

where can_bus is the socket and db is the dbc loaded file. Now i've generated the C files .h and .c starting from my .dbc file. How can I decode a CAN message received in C using the auto-generated files? I can read the message from socket in this way (in C):

nbytes = read(s, &frame, sizeof(struct can_frame));

where s is the socket and frame is where the recived frame is stored. How can I decode the received frame using the .h and .c autogenerated files?

Author:spx305,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55418695/using-cantools-generated-c-files
yy