MoonDBC: CAN / CAN FD DBC parsing, validation, multiplexed frame codec and CLI
Dependencies
> .\dist\moon-dbc.exe inspect tests/fixtures/basic.dbc
DBC database
Version: 1.0
Nodes: 2
Messages: 1
Signals: 2
Standard CAN messages: 1
Extended CAN messages: 0
Classic-sized messages: 1
CAN FD-sized messages: 0
Multiplexed messages: 0
Value descriptions: 2
Diagnostics: 0 errors, 0 warnings
> .\dist\moon-dbc.exe decode tests/fixtures/basic.dbc 0x123 E02E030000000000
Message: EngineData (DBC ID 291)
EngineSpeed: raw=12000 value=1500 rpm
Gear: raw=3 value=3 (Drive)
> .\dist\moon-dbc.exe diff tests/fixtures/basic.dbc tests/fixtures/revised.dbc
Semantic changes: 1
EngineData.EngineSpeed.factor: 0.125 -> 0.25| 结构 | 0.1.0 状态 |
|---|---|
| VERSION、BU_、BO_、SG_ | 支持文档化的核心语法 |
| NS_ | 支持命名空间声明;以 BS_ 结束 |
| BS_ | 仅空段;不支持位时序字段 |
| CM_ | database / node / message / signal |
| VAL_ | 支持;raw 标签键为 Int64 |
| BA_DEF_、BA_DEF_DEF_、BA_ | INT、HEX、FLOAT、STRING、ENUM;四种 scope |
| VAL_TABLE_、BO_TX_BU_、SIG_GROUP_、EV_ | 不作结构化解释;strict 拒绝,permissive 保留文本并警告 |
| SIG_VALTYPE_、SG_MUL_VAL_、SIG_TYPE_REF_ | 编解码关键扩展,两个模式均拒绝 |
moon version --all
moon update
moon check
moon test
moon fmt --check
moon build
moon info
pwsh -NoProfile -File scripts/build-cli.ps1let db = @dbc.parse_dbc(source)
let message = db.message_by_name("Engine").unwrap()
let encoded = @dbc.encode_message(message, [
{ name: "Speed", value: Physical(1500) },
])
let decoded = @dbc.decode_frame(db, encoded.frame)moon run examples/basic
moon run examples/multiplex.\dist\moon-dbc.exe inspect tests/fixtures/basic.dbc --message 0x123
.\dist\moon-dbc.exe validate tests/fixtures/basic.dbc
.\dist\moon-dbc.exe decode tests/fixtures/basic.dbc 0x123 E02E030000000000
.\dist\moon-dbc.exe decode tests/fixtures/motorola.dbc 292 0540FFF000000000 --json
.\dist\moon-dbc.exe encode tests/fixtures/basic.dbc 0x123 EngineSpeed=1500 Gear=3
.\dist\moon-dbc.exe encode tests/fixtures/basic.dbc 0x123 --raw EngineSpeed=12000 Gear=3
.\dist\moon-dbc.exe layout tests/fixtures/multiplex.dbc 293
.\dist\moon-dbc.exe diff tests/fixtures/basic.dbc tests/fixtures/revised.dbc
.\dist\moon-dbc.exe normalize tests/fixtures/attributes.dbcmoon run cmd/main -- inspect tests/fixtures/basic.dbc
moon run --target native cmd/main -- decode tests/fixtures/basic.dbc 0x123 E02E030000000000
moon run --target js cmd/main -- decode tests/fixtures/basic.dbc 0x123 E02E030000000000 --jsonmoon check --deny-warn
moon test --deny-warn
moon test --target native --deny-warn
moon test --target js --deny-warn
pwsh -NoProfile -File scripts/smoke.ps1
pwsh -NoProfile -File scripts/source-audit.ps1
moon bench --target native --release
moon packagepub(all) struct Attribute {
name : String
target : ObjectRef?
value : AttributeValue
location : SourceLocation
} derive(Eq, Debug)pub(all) struct AttributeDefinition {
name : String
scope : Scope
kind : AttributeType
location : SourceLocation
} derive(Eq, Debug)pub(all) struct Change {
kind : ChangeKind
message_id : UInt?
message_name : String?
signal_name : String?
field : String
before : String
after : String
breaking : Bool
} derive(Eq, Debug)pub(all) struct Command {
kind : CommandKind
path : String
second_path : String?
message_id : UInt?
hex : String
assignments : Array[String]
raw : Bool
permissive : Bool
json : Bool
} derive(Eq, Debug)pub(all) struct Comment {
target : ObjectRef
text : String
location : SourceLocation
} derive(Eq, Debug)fn CompiledMessage::decode(self : CompiledMessage, frame : CanFrame) -> DecodedMessage raise DbcErrorfn CompiledMessage::encode(self : CompiledMessage, assignments : Array[SignalAssignment], range_policy? : RangePolicy) -> EncodedMessage raise DbcErrorpub(all) struct Database {
version : String
nodes : Array[Node]
messages : Array[Message]
comments : Array[Comment]
attribute_definitions : Array[AttributeDefinition]
attributes : Array[Attribute]
unsupported : Array[UnsupportedStatement]
diagnostics : Array[Diagnostic]
}pub(all) struct DecodedMessage {
name : String
frame_id : FrameId
signals : Array[DecodedSignal]
diagnostics : Array[Diagnostic]
} derive(Eq, Debug)pub(all) struct Diagnostic {
severity : Severity
code : String
message : String
location : SourceLocation
message_name : String?
signal_name : String?
} derive(Eq, Debug)pub(all) struct EncodedMessage {
frame : CanFrame
diagnostics : Array[Diagnostic]
} derive(Eq, Debug)pub(all) struct Signal {
name : String
start_bit : Int
bit_length : Int
byte_order : ByteOrder
signed : Bool
factor : Double
offset : Double
minimum : Double
maximum : Double
unit : String
receivers : Array[String]
multiplex : MultiplexInfo
values : Array[ValueDescription]
location : SourceLocation
} derive(Eq, Debug)fn Signal::new(name : String, start_bit : Int, bit_length : Int, byte_order? : ByteOrder, signed? : Bool, factor? : Double, offset? : Double, minimum? : Double, maximum? : Double, unit? : String, receivers? : Array[String], multiplex? : MultiplexInfo) -> Signalpub(all) struct UnsupportedStatement {
keyword : String
text : String
location : SourceLocation
} derive(Eq, Debug)fn encode_message(message : Message, assignments : Array[SignalAssignment], range_policy? : RangePolicy) -> EncodedMessage raise DbcErrorfn physical_to_raw(signal : Signal, physical : Double, range_policy? : RangePolicy) -> RawValue raise DbcErrorInstall
Download zipMoonDBC: CAN / CAN FD DBC parsing, validation, multiplexed frame codec and CLI
Dependencies