Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBC Replacement - File Parsing #356

Open
BlakeFreer opened this issue Dec 26, 2024 · 1 comment
Open

DBC Replacement - File Parsing #356

BlakeFreer opened this issue Dec 26, 2024 · 1 comment

Comments

@BlakeFreer
Copy link
Contributor

Goals

  • Create a file representation of the database structure defined by DBC Replacement - Data Structure #355.

  • Convert all the racecar/firmware DBCs to this file format.

  • Parse the files in Python.

  • Write good Python. Data parsing is a really interesting project since there are a lot of ways to use first-class functions and decorators to improve the behaviour without cluttering the code.

    • At any point, if you feel that you are repeating code, conditions, loops, error handling, etc, find a way to abstract out that behaviour. Our parsing code should focus more on the data structure than parsing.

Non-goals

  • Write the bare file parser. Instead, choose a file format that has existing Python support like json, yaml, toml, etc.

Requirements

  • The data should be validated as it is parsed. For example, we should ensure that all Signal bits fit inside of the message's data length without overlap.

  • Any invalid / missing / unused value should cause an error during parsing.

Resources

We currently use cantools to parse our DBCs. Look for inspiration in their database code. https://github.com/cantools/cantools/tree/master/src/cantools/database/can

@AndrewI26 wrote this parser for the cangen yaml configuration. https://github.com/macformula/racecar/blob/main/scripts/cangen/cangen/config.py
Notice how it first reads the yaml to a dictionary, then parses the dictionary for keys. This is good design since we could easily switch from yaml to json because both can be read to a dictionary.

@BlakeFreer
Copy link
Contributor Author

BlakeFreer commented Jan 4, 2025

mkdocs is the framework which we use for our documentation website. It supports plugins which can have a structured configuration. For example, see the PrivacyConfig object in the "privacy" plugin from mkdocs-material

https://github.com/squidfunk/mkdocs-material/blob/master/src/plugins/privacy/config.py

You can look at the mkdocs imports and check out that repo to see how it implements the Config and Type classes.

The important part is each plugin only needs to describe the structure of its configuration scheme and a centralized function can handle all of the parsing

@BlakeFreer BlakeFreer changed the title DBC to JSON - File Parsing DBC Replacement - File Parsing Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant