Skip to content

Compile DBC files into a plain-C const database - #9

Merged
ip332 merged 2 commits into
mainfrom
plain-c-dbc-database
Nov 19, 2026
Merged

ip332 merged 2 commits into
mainfrom
plain-c-dbc-database

Conversation

@ip332

@ip332 ip332 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • dbc_compiler -c_path db.c compiles a DBC into a const C11 database (sibling .h) for PGN, CAN ID, and SPN lookup. -pgn_path and -union_path are unchanged. -no-strings omits the name blob.
  • The parser records BA_ "SPN", BA_ "J1939Default", and multiplexed signals, including two signals that share a start bit. Identical layouts under one PGN become one generic row. Two different generic layouts for the same PGN fail the compiler.
  • Lookup and the codec live in j1939_db.c (j1939_db_find, j1939_signal_by_spn, j1939_signal_by_name, raw/phys/store). J1939Parser is unchanged. J1939DbParser is a thin C++ wrapper.

Fixes #3

Test plan

  • CI builds all_tests and the coverage job stays above the gcovr floors (97.8% line, 93.3% branch)
  • tests/dbc/j1939.dbc and tests/dbc/big_endian_database.dbc round-trip: generated C compiles with cc -std=c11 -Wall -Werror, and raw values match the C++ map
  • dbc_compiler -in tests/dbc/j1939.dbc -c_path db.c -no-strings still accepts -pgn_path on the same invocation

dbc_compiler -c_path writes sorted const tables for PGN, CAN ID, and SPN
lookup. The runtime in j1939_db.c is ISO C11: no constructors and no
malloc. Identical layouts collapse to one generic row. When layouts
differ, BA_ "J1939Default" marks the generic row. -no-strings omits the
name blob.

J1939Parser stays the C++ map path. J1939DbParser is a thin wrapper over
the C database so existing tests keep their entry point.
Keep the C database include path and the test-data folder definition.
@ip332
ip332 merged commit 07a100d into main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: compile DBC files into a plain-C const database for PGN, CAN ID, and SPN lookup

1 participant