An opinionated formatter for Vector DBC files, using the cantools library.
usage: dbc_format.py [-h] [-o OUTPUT] paths [paths ...]
DBC formatter
positional arguments:
paths Input .dbc file(s) and/or folder(s)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Specify output path instead of overwriting the original
I consider this tool "finished" as it suits my needs. Issues and pull requests will be considered, but don't expect much support.
All string sorting is naturally sorted using the natsort library, so "Node10"
will be sorted after "Node2".
Sorted alphabetically
Unformatted:
BU_: Car Bus Bicycle
Formatted:
BU_: Bicycle Bus Car
Sorted by message CAN ID
Sorted by unmuxed signals first, then muxed signals, in order of start bit.
Unformatted:
BO_ 1111 Voltage: 8 Car
SG_ Voltage1 m0 : 32|32@1- (1,0) [0|0] "V" Vector__XXX
SG_ Voltage2 m1 : 32|32@1- (1,0) [0|0] "V" Vector__XXX
SG_ VoltageMux M : 0|8@1+ (1,0) [0|0] "" Vector__XXX
Formatted:
BO_ 1111 Voltage: 8 Car
SG_ VoltageMux M : 0|8@1+ (1,0) [0|0] "" Vector__XXX
SG_ Voltage1 m0 : 32|32@1- (1,0) [0|0] "V" Vector__XXX
SG_ Voltage2 m1 : 32|32@1- (1,0) [0|0] "V" Vector__XXX
Sorted by message CAN ID, then signal name, then backwards by value.
Formatted:
VAL_ 911 BusMode 3 "RESET" 2 "VOLTAGE" 1 "CURRENT" 0 "IDLE";
- All runs of more than 2 space characters are squashed to 1. Semicolons are put at the end of their line with no extra space.
- Newlines are Unix (\n) format.
- All runs of more than 2 newlines are squashed to 1
All definitions first, then defaults, then values. In order of Bus, Node, Signal attributes, then sorted alphabetically by attribute name, then by Node (for node attributes), then by CAN ID (if one exists), then by signal name.
Formatted:
BA_DEF_ "BusType" STRING;
BA_DEF_ BO_ "IsAlbatross" ENUM "No","Yes";
BA_DEF_ BO_ "IsSane" ENUM "No","Yes";
BA_DEF_ BO_ "NodeAttr" HEX 0 65535;
BA_DEF_ BO_ "timeout" INT 0 60000;
BA_DEF_DEF_ "BusType" "";
BA_DEF_DEF_ "IsAlbatross" "Yes";
BA_DEF_DEF_ "IsSane" "Yes";
BA_DEF_DEF_ "NodeAttr" 0;
BA_DEF_DEF_ "timeout" 1000;
BA_ "BusType" "CAN";
BA_ "NodeAttr" BU_ Bus 555;
BA_ "timeout" BO_ 888 20000;
BA_ "timeout" BO_ 999 20000;
BA_ "IsSane" SG_ 888 InsaneValue 0;
BA_ "IsSane" SG_ 888 InsaneValue2 0;
BA_ "IsAlbatross" SG_ 111 BirdVal 0;
Sorted by comments for Bus, Node, Message, Signal, then by message CAN ID (if one exists), then alphabetically.
- Lowercase
echaracter for exponent - No 0 padding for exponent
Unformatted:
BA_DEF_ SG_ "GenSigStartValue" FLOAT -1E+099 1E+099;
Formatted:
BA_DEF_ SG_ "GenSigStartValue" FLOAT -1e+99 1e+99;
Long names and the SystemSignalLongSymbol attribute used for them are not
used. All signals use their full length name.