Electronics > Microcontrollers

CANdb++ .dbc to C/C++ .h converter

(1/5) > >>

Hi everybody,

I would like to share a tool with you that I have recently built at work and think is worth sharing.
It's a universal .dbc to .h converter. The idea is that embedded systems developers/programmers shouldn't have to manually maintain their code to match the requirements, messages and signals of the current CAN bus project.

As these projects are very often being maintained using Vector's CANdb++ tool to define messages, signals, nodes, etc - I set off to create a convenient way to import that information into C source code.
After some experimenting, I found a good way to structure the information in a most useful way for C. My main goal was to enable auto-completion (e.g. in eclipse) so that I could easily get a list of available messages and signals, their meta-information (ID, length, position, IDE bit, etc).

I then also implemented a generic way to extract specific signal values by name - also autocomplete supported. This is done using a macro that links a struct pointer to the uint8_t[8] array. The comments contain usage examples and should help understanding the concept. It's all very simple to use.
And most important of all, it is easy to use -> simply import the .h file into your project and off you go.

(I had to make the structs static, unfortunately - otherwise I'd have to split the whole thing up into a .c/.h pair and it wouldn't be as portable. I checked compiled code sizes, though and it seems as if the code size is unaffected by this. If you experience any issues, please let me know and you're free to un-static the structs and split them up into a .c/.h pair)
This has been tested successfully on the STM32 family using Atollic TrueStudio IDE. It requires the raw CAN data to be received in the form of a little endian uint_t8 array, just like it is the case per default on STM32 HAL.

Usage example:

--- Code: --- io::CAN_message_CPP msg;
auto const& dbc = DBC_IMED_HELMBUS_MSG_M_assignID;
DBC_setup(dbc, msg);
DBC_makeSignalAccessor(dbc, msg, msg_access);
msg_access->UID = pNode->getUID();
msg_access->AssignedID = aid;

--- End code ---

--- Code: --- {
uint8_t uid;
uint8_t RxMessage[8];
DBC_makeSignalAccessor(DBC_IME_AI_MSG_CAN_IMED_MSG_PA_SP, RxMessage, msg_access);
uid = msg_access->UID;
msg_access->AssignedID = 42;

--- End code ---
For anything else, please read the comments as they contain usage examples and should get you up and running. If anything is unclear, please let me know in here.

Download: click the attached dbc2h.zip at the bottom of this post.

I hope that this little tool is of help for all you CAN afficionados out there - it most definitely is a LOT for me ;)



I stopped using dbc when I stopped using Vector products, but pretty interesting and I'll keep it in mind.

What are you using when you are working in dbc?

At the moment: nothing. Only my STM32 project.
But I find it much more convenient to define messages, signals and their positions in CANdb++ than doing it manually, e.g. in an excel sheet.

Also that .dbc file then helps e.g. in debugging as some of those can viewers support dbc imports and convert signals to their physical values on the fly...

We have released a free public beta of the tool. Please try it out and report back to me  :-+


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod