{"id":13741277,"url":"https://github.com/howerj/dbcc","last_synced_at":"2025-12-26T23:44:31.312Z","repository":{"id":37336592,"uuid":"69908726","full_name":"howerj/dbcc","owner":"howerj","description":"CAN DBC to C (and CSV, JSON and XML) compiler using the mpc parser combinator library","archived":false,"fork":false,"pushed_at":"2024-07-04T18:10:25.000Z","size":393,"stargazers_count":360,"open_issues_count":2,"forks_count":133,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-08-04T04:07:37.231Z","etag":null,"topics":["automotive","c","code-generation","code-generator","dbc","misra","xml"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/howerj.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"howerj","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2016-10-03T20:34:32.000Z","updated_at":"2024-08-03T08:39:03.000Z","dependencies_parsed_at":"2024-01-03T03:56:25.584Z","dependency_job_id":"3ba3fc4f-add0-41d3-8555-75f38ed54628","html_url":"https://github.com/howerj/dbcc","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howerj%2Fdbcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howerj%2Fdbcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howerj%2Fdbcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howerj%2Fdbcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/howerj","download_url":"https://codeload.github.com/howerj/dbcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224774731,"owners_count":17367784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automotive","c","code-generation","code-generator","dbc","misra","xml"],"created_at":"2024-08-03T04:00:57.421Z","updated_at":"2025-12-26T23:44:31.305Z","avatar_url":"https://github.com/howerj.png","language":"C","readme":"# dbcc\n## DBC converter/compiler \n\nThis program turns a [DBC][] file into a number of different formats.\n\nFor the professional version of DBCC visit:\n\n\u003chttps://subleq.co.uk/\u003e\n\nFor pricing and contact information. The professional version includes support\nfor CAN-FD, as well as other languages, and better MISRA-C support.\n\n## Introduction\n\n**dbcc** is a program for converting a [DBC][] file primarily into into [C][]\ncode that can serialize and deserialize [CAN][] messages into structures that\nrepresent those messages and signals. It is also possible to print out the\ninformation contained in a structure.\n\n## Building, Licenses and Dependencies \n\nSee the [license][] file for details of the license for *this* program, it is\nreleased under the [MIT][] license. Dependencies, if linked against, may have\ntheir own license and their own set of restrictions if built against.\n\nThe sources file [mpc.c][] and [mpc.h][] originate from a parser combinator\nwritten in [C][] called [MPC][] and are licensed under the [3 Clause BSD][] \nlicense.\n\nTo build, you only need a C (C99) compiler and Make (probably GNU make, I make no\neffort to support other Make implementations). The dbcc program itself it\nwritten in what should be portable C with the only external dependency being\nyour platforms C library.\n\nYou should be able to type:\n\n\tmake\n\nTo build, an executable called 'dbcc' is produced. To test run the tests, \n[xmllint][] is required. \n\n## C Coding Standards\n\n* When in doubt, format with [indent][] with the \"-linux\" option. \n* Use tabs, not spaces for formatting\n* Use assertions where possible (not for error checking, for checking pre/post\nconditions and invariants).\n* The tool should run on Windows and Linux with no modification. The project is\nwritten in pure [C][].\n* No external dependencies should brought into the project.\n\n## Notes on generated code\n\n* If you want a specific format in the generated code, integrate [indent][]\ninto you toolchain instead of trying to change the code generator.\n* The output of the generated code is generally not stable, it may change from commit to\ncommit, download and maintain a specific version if you want stability.\n* That said, the `-n` option can be used to specify the output version which might give you access\n  to previous behaviour if backwards compatibility has been implemented.\n\n## Generated output versions\n\nYou can specify the version to use on a command line with the `-n` option.\nThe latest version will be used by default.\n\n**Version 1:**\n\nLegacy/original behaviour. Note that this still won't provide a stable output, but will have\na better chance of not having breaking changes.\n\n**Version 2:**\n\n- Latest version\n\n- Enum names are qualified with the CAN message name\n- encode/decode function names are also qualified with the message name\n\n## How to use the generated code\n\nThe code generator can make code to unpack a message (turn some bytes into a\ndata structure), decode a message (apply a scaling/offset minimum and maximum\nvalues to the values in a data structure), and the inverse can be done\n(pack/encode).\n\nYou can look at the code generated from the DBC files within the project to get\nan understanding of how it should work. \n\nIf you want to process a CAN message that you have received you will need to\ncall the 'unpack\\_message'. The code generate is agnostic to the CPUs byte\norder, it takes a 'uint64\\_t' value containing a single CAN packet (along with\nthe CAN ID and the DLC for the that packet) and unpacks that into a structure\nit generates. The first byte of the CAN packet should be put in the least\nsignificant byte of the 'uint64\\_t'.\n\nYou can use the following functions to convert to/from a CAN message:\n\n\tstatic uint64_t u64_from_can_msg(const uint8_t m[8]) {\n\t\treturn ((uint64_t)m[7] \u003c\u003c 56) | ((uint64_t)m[6] \u003c\u003c 48) | ((uint64_t)m[5] \u003c\u003c 40) | ((uint64_t)m[4] \u003c\u003c 32) \n\t\t\t| ((uint64_t)m[3] \u003c\u003c 24) | ((uint64_t)m[2] \u003c\u003c 16) | ((uint64_t)m[1] \u003c\u003c 8) | ((uint64_t)m[0] \u003c\u003c 0);\n\t}\n\n\tstatic void u64_to_can_msg(const uint64_t u, uint8_t m[8]) {\n\t\tm[7] = u \u003e\u003e 56;\n\t\tm[6] = u \u003e\u003e 48;\n\t\tm[5] = u \u003e\u003e 40;\n\t\tm[4] = u \u003e\u003e 32;\n\t\tm[3] = u \u003e\u003e 24;\n\t\tm[2] = u \u003e\u003e 16;\n\t\tm[1] = u \u003e\u003e  8;\n\t\tm[0] = u \u003e\u003e  0;\n\t}\n\nThe code generator will make a structure based on the file name of the DBC\nfile, so for the example DBC file 'ex1.dbc' a data structure called\n'can\\_obj\\_ex1\\_h\\_t' is made. This structure contains all of the CAN message\nstructures, which in turn contain all of the signals. Having all of the\nmessages/signals in one structure has advantages and disadvantages, one of the\nthings it makes easier is defining the data structures needed.\n\n\t/* reminder of the 'unpack_message' prototype */\n\tint unpack_message(can_obj_ex1_h_t *o, const unsigned long id, uint64_t data, uint8_t dlc);\n\n\tstatic can_obj_ex1_h_t ex1;\n\n\tuint8_t can_message_raw[8];\n\tunsigned long id = 0;\n\tuint8_t dlc = 0;\n\tyour_function_to_receive_a_can_message(can_message_raw, \u0026id, \u0026dlc);\n\tif (unpack_message(\u0026ex1, id, can_message_u64, dlc) \u003c 0) {\n\t\t// Error Condition; something went wrong\n\t\treturn -1;\n\t}\n\n'unpack\\_message' calls the correct unpack function for that ID, as an example\nfor ID '0x020':\n\n\tcase 0x020: return unpack_can_0x020_MagicCanNode1RBootloaderAddress(\u0026o-\u003ecan_0x020_MagicCanNode1RBootloaderAddress, data, dlc);\n\nThe unpack function populates the message object in the 'can\\_obj\\_ex1\\_h\\_t'\nstructure for that ID. The individual signals can then be decoded with the\nappropriate functions for that signal. For example:\n\n\tuint16_t b = 0;\n\tif (decode_can_0x020_MagicNode1R_BLAddy(o, \u0026b)) {\n\t\t/* error */\n\t}\n\nTo transmit a message, each signal has to be encoded, then the pack function\nwill return a packed message. \n\nSome other notes:\n\n* Asserts can be disabled with a command line option\n* An option to force the encode/decode function to only use the double width\nfloating point type has been added, so different function types do not have to be\ndealt with by the programmer.\n* You can remove the message number from the functions and values generated,\nwhich is useful if your message numbers are changing a lot, however the names\nfor each message and signal must then be unique.\n\n## DBC file specification\n\nFor a specification, as I understand it, of the DBC file format, see [dbc.md][]. \nThis is a work in progress.\n\n## DBC VIM syntax file\n\nThere is a [Vim][] syntax file for DBC files in the project, called [dbc.vim][]\n\n## XML Generation\n\nAs well as [C][], [XML][] can be generated, the project contains an [XSD][] and\n[XSLT][] file for the generated XML.\n\n## BSM (beSTORM Module) Generation\n\nAn XML based file that can be imported into Beyond Security's beSTORM and used to test CAN BUS infrastructure.\n\n* Note: May be replaced with an [XSLT][] in the future, deriving from the\n[XML][] output. The BSM output is itself and XML file.\n\n## CSV Generation\n\nA flat CSV file can be generated, which is easier to import into Excel.\n\n## JSON Generation\n\nA JSON file can be generated, which is what all the cool kids use nowadays.\n\n## Operation\n\nConsult the [manual page][] for more information about the precise operation of the\nprogram.\n\n## Bugs / To Do\n\n* Generated manual page from this markdown \"readme.md\" file.\n* For versions going forward, especially versions that break the generated C\ncode, it might be nice to have an option to generate previous versions of the\ncode.\n* Support CAN-FD (big task).\n* Make definitions for message-ids and Data-Length-Codes so the user\ndoes not have to make them as either an enumeration or a define.\n* Make the bit-fields more useful\n* The floating point conversion routines assume your platform is using\n[IEEE-754][] floats. If it does not, then tough.\n* A lot of the DBC file format is not dealt with:\n  - Special values\n  - Timeouts \n  - Error frames\n  - ...\n* The generated code is not [MISRA C][] compliant.\n* Integers that cannot be represented in a double width floating point number\nshould be packed/unpacked correctly, however the encode/decode and printing\nfunctions will not as they use doubles for calculations (pack/unpack do not).\nThis affects numbers larger than 2^53. \n* There are two pieces of information that are useful to any CAN stack for\nreceived messages; the time stamp of the received message, and the status\n(error CRC/timeout, message okay, or message never set). This information could\nbe included in the generated C code.\n* Enumeration values could be checked for and only correct values should\nbe decoded, and encoded. There is more stuff that can be done with the\nenumeration values, along with command line options to enumeration generation.\n* A mechanism for callbacks for custom code for floating point encoding and\ndecoding, and other callbacks in general, could be added. Packing and unpacking\nfloats is done in what should be a portable, but not fast, way.\n* A mechanism and system for error handling should be added, that is, a simple\ncommunications manager that does the following:\n  - Each signal should have three values associated with it; Unknown (the\n    signal has never been set), Valid, and Error (for *any* error).\n  - If the time out for a message goes out, or a CRC check fails, then\n    all of the messages child messages should get invalidated and set the\n    error state.\n  - If the signal contains an invalid value, it gets set to an Error state.\n  - All signal access functions should check the Unknown/Error value, returning\n    success only on a Valid signal.\nThere are a few other details that would need to be sorted out, like how\nCRC and time outs could be calculated.\n* The code generator makes code for packing/encoding and unpacking/decoding,\nthis could be done in one step to simplify the code and data structures, it\nmeans decoded/encoded values do not need to recalculated.\n\nIt would be possible to generate nice (ASCII ART) images that show how a message is\nstructured, which helps in understanding the message in question, and is useful\nfor documentation purposes, for example, something like:\n\n\n\tMessage Name: Example-1\n\tMessage ID: 0x10, 16\n\tDLC: 1 (8-bits)\n\t+-----+-----.-----.-----.-----+-----.-----+-----+\n\t|     |                       |           |     |\n\t|     |                       |           |     |\n\t+-----+-----.-----.-----.-----+-----.-----+-----+\n\t   0     1     2     3     4     5     6     7\n\tBit     0: Signal-Name-1, 1 bit signal, scalar 1.0, offset 0\n\tBits  1-2: Signal-Name-2, 4 bit signal, signed, Motorola, ...\n\t... etcetera ...\n\nOr something similar. This would be another output module.\n\n\n[DBC]: http://vector.com/vi_candb_en.html\n[C]: https://en.wikipedia.org/wiki/C_%28programming_language%29\n[CAN]: https://en.wikipedia.org/wiki/CAN_bus\n[license]: LICENSE\n[manual page]: dbcc.1\n[MIT]: https://en.wikipedia.org/wiki/MIT_License\n[3 Clause BSD]: https://en.wikipedia.org/wiki/BSD_licenses\n[MPC]: https://github.com/orangeduck/mpc\n[mpc.c]: mpc.c\n[mpc.h]: mpc.h\n[dbc.md]: dbc.md\n[dbc.vim]: dbc.vim\n[Vim]: http://www.vim.org/download.php\n[XML]: https://en.wikipedia.org/wiki/XML\n[XSD]: dbcc.xsd\n[XSLT]: dbcc.xslt\n[MISRA C]: https://misra.org.uk/\n[IEEE-754]: https://en.wikipedia.org/wiki/IEEE_754\n[indent]: https://www.gnu.org/software/indent/\n[xmllint]: http://xmlsoft.org/xmllint.html\n\n\u003cstyle type=\"text/css\"\u003e\n\tbody {\n\t\tmargin:40px auto;max-width:850px;line-height:1.6;font-size:16px;color:#444;padding:0 10px\n\t}\n\th1,h2,h3 {\n\t\tline-height:1.2\n\t}\n\u003c/style\u003e\n","funding_links":["https://github.com/sponsors/howerj"],"categories":["Libraries and Tools","CAN Database","C"],"sub_categories":["C","Converters and Parsers"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowerj%2Fdbcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhowerj%2Fdbcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowerj%2Fdbcc/lists"}