infineon4engineers Facebook

infineon@google+ Google+

infineon@linkedin linkedin

infineon4engi@twitter twitter

infineon@youtube youtube

+ Reply to Thread
Results 1 to 3 of 3

Thread: Generating C-Code from Vector CANdb++ .dbc files

  1. #1
    New Member New Member kamikaze will become famous soon enough kamikaze's Avatar
    Join Date
    Nov 2011
    Location
    /Europe/Germany/Karlsruhe
    Posts
    94
    Points
    124.1015625

    Generating C-Code from Vector CANdb++ .dbc files

    I developed a parser for .dbc files that can use a set of templates to output a subset of contained information into arbitrary formats.

    The information it is currently able to output:
    • Databases (multiple .dbc files can be combined)
    • ECUs
    • Signal Groups
    • Messages
    • Signals
    • Timeouts (an ECU → Signal relation)

    The possible output contains all the relations between databases, ECUs, Signal Groups, Messages, Signals etc.; this is very useful to generate documentation.

    The (well documented) script can be found here:
    https://github.com/lonkamikaze/hsk-l...ipts/dbc2c.awk
    Download link: https://raw.githubusercontent.com/lo...ipts/dbc2c.awk

    The set of templates I use can be found here:
    https://github.com/lonkamikaze/hsk-l...emplates.dbc2c

    It contains templates to generate static code to read and write signals from and to character arrays (useful for 8-bit platforms). The generated code looks like this:
    Code:
    12290 /**
    12291  * Get signal FCU_BRAKE_BALANCE from buffer.
    12292  *
    12293  * @param buf
    12294  *      The can message buffer containing the signal
    12295  * @return
    12296  *      The raw signal
    12297  */
    12298 #define GET_FCU_BRAKE_BALANCE(buf) (0 \
    12299         | ((-((buf[2] >> 1) & 0x01)) << 18) \
    12300         | ((+((buf[0] >> 0) & 0xff)) << 0) \
    12301         | ((+((buf[1] >> 0) & 0xff)) << 8) \
    12302         | ((+((buf[2] >> 0) & 0x03)) << 16) \
    12303 )
    12304 
    12305 /**
    12306  * Set signal FCU_BRAKE_BALANCE in buffer.
    12307  *
    12308  * @param buf
    12309  *      The can message buffer to add the signal to
    12310  * @param val
    12311  *      The raw value to set the signal to
    12312  */
    12313 #define SET_FCU_BRAKE_BALANCE(buf, val) { \
    12314         buf[0] &= ~(0xff << 0); \
    12315         buf[0] |= (((val) >> 0) & 0xff) << 0; \
    12316         buf[1] &= ~(0xff << 0); \
    12317         buf[1] |= (((val) >> 8) & 0xff) << 0; \
    12318         buf[2] &= ~(0x03 << 0); \
    12319         buf[2] |= (((val) >> 16) & 0x03) << 0; \
    12320 }
    It can handle Intel and Motorola style signals as well as signed and unsigned signals.

    In order to run the script an AWK interpreter is required. GNU AWK (default in many GNU/Linux distributions, very slow!), nawk (default on OS-X and BSDs) and mawk (default on Ubuntu GNU/Linux, very fast, available for Windows) are supported.

    The script is released under the beerware do-anything-you-please license.
    https://github.com/lonkamikaze/hsk-l...master/LICENSE

    What I'd like to see in return are any of your .dbc's that cause problems with the script. If so desired I can guarantee confidential treatment.

    kamikaze@bsdforen.de
    GPG fingerprint: FDCD7B3A84C0FE21E21FF1E767BD05D6DCBF78A6
    Last edited by kamikaze; Aug 9th, 2016 at 06:39 AM. Reason: Project move to GitHub
    [ kamikaze@bsdforen.de - XC878 libraries (GitHub) - XC878 ECU project stub (GitHub) - High Speed Karlsruhe ]
    - - - -
    Primary platform: XC878CM-16FFA
    Custom library: ~10k lines of code, ~300 pages of documentation

  2. #2
    gauze
    Guest
    Very interesting code!

    Do you have any document descriving DBC file format?

    thanks

  3. #3
    New Member New Member kamikaze will become famous soon enough kamikaze's Avatar
    Join Date
    Nov 2011
    Location
    /Europe/Germany/Karlsruhe
    Posts
    94
    Points
    124.1015625
    Quote Originally Posted by gauze View Post
    Very interesting code!

    Do you have any document descriving DBC file format?

    thanks
    I guess I should pick up the habit of checking this forum more often.

    Any way, no I do not have documentation. This is a reverse engineering effort.

    The code is written to fail if something unknown is encountered. In the past people have sent me DBC files that make it fail and I've used those to extend the parser.
    [ kamikaze@bsdforen.de - XC878 libraries (GitHub) - XC878 ECU project stub (GitHub) - High Speed Karlsruhe ]
    - - - -
    Primary platform: XC878CM-16FFA
    Custom library: ~10k lines of code, ~300 pages of documentation

+ Reply to Thread
Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.