# CAN Parser ###### tags: `firmware_hardware` `electrical_system` `NTURT` ## Introduction Forget about writting your own library when readily available ones are just within a **google search** away. I think that I have learned the lesson now after writing a complicated library for parsing can signals only to find out there are already dozens libraries that just do better:cry:. - Python tool to monitor CAN, parse DBC format into human readable format and generate c code from it: [cantools](https://cantools.readthedocs.io/en/latest/) ## DBC format - About can database format(easiest to understand but covers very little): [CAN DBC File Explained](https://www.csselectronics.com/pages/can-dbc-file-database-intro) - More advanced technique about DBC: [DBC Format](http://socialledge.com/sjsu/index.php/DBC_Format) - Complete documentation(but written poorly): [DBC File Format Documentation](http://mcu.so/Microcontroller/Automotive/DBC_File_Format_Documentation.pdf) - Common DBC file attributes: [Common DBC attributes](https://blog.csdn.net/lamanchas/article/details/122326861) - Online dbc editor: [DBC Editor for CAN Bus Database Files](https://www.csselectronics.com/pages/dbc-editor-can-bus-database) - VS code extension for DBC: [DBC Language Syntax](https://marketplace.visualstudio.com/items?itemName=lharri73.dbc) Overall, there's no a signle good place where every symbol is well documented with examples, only readily avalible file to guess the meanings from. Extra: - [Checksum and Livecounter in CAN](https://baijiahao.baidu.com/s?id=1656396925096307630) ## Code generator In embedded devices, loading a config file at runtime is almost not ideal since it requires dynamic allocation. Instead, statically generate the code from the config file is more ideal. The code generator I chose is [astand/c-coderdbc](https://github.com/astand/c-coderdbc) since it provides functions to transmit and receive frames, and does binary search when receiving. ## DBC file - [CM200 can database](https://app.box.com/s/vf9259qlaadhzxqiqrt5cco8xpsn84hk/file/955934085249) - DBC file of various cars: [commaai/opendbc](https://github.com/commaai/opendbc)