-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathattribute_structs.rs
More file actions
68 lines (57 loc) · 1.93 KB
/
Copy pathattribute_structs.rs
File metadata and controls
68 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Demonstrates [`Config::attribute_structs`].
//! Emits constants for AUTOSAR E2E / SecOC-style metadata from DBC 'BA_' attributes.
use dbc_codegen::{AttributeField, AttributeScope, AttributeStruct, Config, FieldSource};
const DBC: &str = r#"VERSION ""
NS_ :
BS_:
BU_: ECU1
BO_ 256 Protected: 8 ECU1
SG_ Speed_CRC : 16|8@1+ (1,0) [0|255] "" ECU1
BA_DEF_ BO_ "SCP_FreshnessValueId" INT 0 65535;
BA_DEF_ SG_ "E2EDataId" INT 0 65535;
BA_DEF_ SG_ "E2EDataLength" INT 0 65535;
BA_DEF_ SG_ "E2EProfile" STRING ;
BA_DEF_DEF_ "SCP_FreshnessValueId" 0;
BA_DEF_DEF_ "E2EDataId" 0;
BA_DEF_DEF_ "E2EDataLength" 0;
BA_DEF_DEF_ "E2EProfile" "none";
BA_ "SCP_FreshnessValueId" BO_ 256 1002;
BA_ "E2EDataId" SG_ 256 Speed_CRC 373;
BA_ "E2EDataLength" SG_ 256 Speed_CRC 48;
BA_ "E2EProfile" SG_ 256 Speed_CRC "P01";
"#;
fn field(name: &'static str, source: FieldSource<'static>) -> AttributeField<'static> {
AttributeField { name, source }
}
fn main() {
let e2e = AttributeStruct {
type_path: "data_protection::E2EDataIdInfo",
const_name: "E2E",
scope: AttributeScope::Signal,
require: "E2EDataId",
fields: &[
field("data_id", FieldSource::Attr("E2EDataId")),
field("start_byte", FieldSource::StartByte),
field("width_bit", FieldSource::Attr("E2EDataLength")),
field("profile", FieldSource::Attr("E2EProfile")),
],
};
let secoc = AttributeStruct {
type_path: "data_protection::SecOcInfo",
const_name: "SEC_OC",
scope: AttributeScope::Message,
require: "SCP_FreshnessValueId",
fields: &[field(
"freshness_id",
FieldSource::Attr("SCP_FreshnessValueId"),
)],
};
let code = Config::builder()
.dbc_name("example")
.dbc_content(DBC)
.attribute_structs(&[e2e, secoc])
.build()
.generate()
.expect("generate");
println!("{code}");
}