Skip to content

Commit e59953b

Browse files
authored
feature input quantity association (#46)
Added input quantity association for CHARACTERISTICS. Not implemented for AXIS_PTS and TYPEDEF_AXIS.
1 parent 183853b commit e59953b

File tree

6 files changed

+139
-17
lines changed

6 files changed

+139
-17
lines changed

src/registry/a2l/a2l_writer.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,26 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
150150
let x_dim = dim_type.get_dim()[0];
151151
let y_dim = dim_type.get_dim()[1];
152152

153+
let x_axis_input_quantity = if let Some(v) = &mc_support_data.x_axis_input_quantity {
154+
v.as_str()
155+
} else {
156+
"NO_INPUT_QUANTITY"
157+
};
158+
let y_axis_input_quantity = if let Some(v) = &mc_support_data.y_axis_input_quantity {
159+
v.as_str()
160+
} else {
161+
"NO_INPUT_QUANTITY"
162+
};
163+
153164
// MAP
154165
if x_dim > 1 || y_dim > 1 {
155166
if x_dim > 1 && y_dim > 1 {
156167
// X
157168
if let Some(x_axis_conv) = &mc_support_data.x_axis_conv {
158169
write!(
159170
writer,
160-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
171+
r#" /begin AXIS_DESCR FIX_AXIS {} {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
172+
x_axis_input_quantity,
161173
x_axis_conv,
162174
x_dim, // MaxAxisPoints
163175
x_dim - 1, // 0-UpperLimit
@@ -166,13 +178,14 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
166178
} else if let Some(x_axis_ref) = &mc_support_data.x_axis_ref {
167179
write!(
168180
writer,
169-
r#" /begin AXIS_DESCR COM_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
170-
x_dim, x_axis_ref
181+
r#" /begin AXIS_DESCR COM_AXIS {} NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
182+
x_axis_input_quantity, x_dim, x_axis_ref
171183
)?;
172184
} else {
173185
write!(
174186
writer,
175-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
187+
r#" /begin AXIS_DESCR FIX_AXIS {} NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
188+
x_axis_input_quantity,
176189
x_dim,
177190
x_dim - 1,
178191
x_dim
@@ -182,7 +195,8 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
182195
if let Some(y_axis_conv) = &mc_support_data.y_axis_conv {
183196
write!(
184197
writer,
185-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
198+
r#" /begin AXIS_DESCR FIX_AXIS {} {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
199+
y_axis_input_quantity,
186200
y_axis_conv,
187201
y_dim,
188202
y_dim - 1,
@@ -191,13 +205,14 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
191205
} else if let Some(y_axis_ref) = &mc_support_data.y_axis_ref {
192206
write!(
193207
writer,
194-
r#" /begin AXIS_DESCR COM_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
195-
y_dim, y_axis_ref
208+
r#" /begin AXIS_DESCR COM_AXIS {} NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
209+
y_axis_input_quantity, y_dim, y_axis_ref
196210
)?;
197211
} else {
198212
write!(
199213
writer,
200-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
214+
r#" /begin AXIS_DESCR FIX_AXIS {} NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
215+
y_axis_input_quantity,
201216
y_dim,
202217
y_dim - 1,
203218
y_dim
@@ -209,7 +224,8 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
209224
if let Some(x_axis_conv) = &mc_support_data.x_axis_conv {
210225
write!(
211226
writer,
212-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
227+
r#" /begin AXIS_DESCR FIX_AXIS {} {} {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
228+
x_axis_input_quantity,
213229
x_axis_conv,
214230
x_dim,
215231
x_dim - 1,
@@ -218,13 +234,14 @@ fn write_axis_descr(_name: &str, dim_type: &McDimType, mc_support_data: &McSuppo
218234
} else if let Some(x_axis_ref) = &mc_support_data.x_axis_ref {
219235
write!(
220236
writer,
221-
r#" /begin AXIS_DESCR COM_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
222-
x_dim, x_axis_ref
237+
r#" /begin AXIS_DESCR COM_AXIS {} NO_COMPU_METHOD {} 0.0 0.0 AXIS_PTS_REF {} /end AXIS_DESCR"#,
238+
x_axis_input_quantity, x_dim, x_axis_ref
223239
)?;
224240
} else {
225241
write!(
226242
writer,
227-
r#" /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
243+
r#" /begin AXIS_DESCR FIX_AXIS {} NO_COMPU_METHOD {} 0 {} FIX_AXIS_PAR_DIST 0 1 {} /end AXIS_DESCR"#,
244+
x_axis_input_quantity,
228245
x_dim,
229246
x_dim - 1,
230247
x_dim

src/registry/mc_support.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ pub struct McSupportData {
144144
#[serde(skip_serializing_if = "Option::is_none")]
145145
pub y_axis_ref: Option<McIdentifier>,
146146

147+
#[serde(skip_serializing_if = "Option::is_none")]
148+
pub x_axis_input_quantity: Option<McIdentifier>,
149+
150+
#[serde(skip_serializing_if = "Option::is_none")]
151+
pub y_axis_input_quantity: Option<McIdentifier>,
152+
147153
#[serde(skip_serializing_if = "Option::is_none")]
148154
pub x_axis_conv: Option<McIdentifier>,
149155

@@ -165,6 +171,8 @@ impl Default for McSupportData {
165171
step: None,
166172
x_axis_ref: None,
167173
y_axis_ref: None,
174+
x_axis_input_quantity: None,
175+
y_axis_input_quantity: None,
168176
x_axis_conv: None,
169177
y_axis_conv: None,
170178
}
@@ -186,6 +194,8 @@ impl Clone for McSupportData {
186194
step: self.step,
187195
x_axis_ref: self.x_axis_ref,
188196
y_axis_ref: self.y_axis_ref,
197+
x_axis_input_quantity: self.x_axis_input_quantity,
198+
y_axis_input_quantity: self.y_axis_input_quantity,
189199
x_axis_conv: self.x_axis_conv,
190200
y_axis_conv: self.y_axis_conv,
191201
}
@@ -223,6 +233,12 @@ impl std::fmt::Display for McSupportData {
223233
if self.y_axis_ref.is_some() {
224234
write!(f, " y_axis_ref={}", self.y_axis_ref.as_ref().unwrap())?;
225235
}
236+
if self.x_axis_input_quantity.is_some() {
237+
write!(f, " x_axis_input_quantity={}", self.x_axis_input_quantity.as_ref().unwrap())?;
238+
}
239+
if self.y_axis_input_quantity.is_some() {
240+
write!(f, " y_axis_input_quantity={}", self.y_axis_input_quantity.as_ref().unwrap())?;
241+
}
226242
if self.x_axis_conv.is_some() {
227243
write!(f, " x_axis_conv={}", self.x_axis_conv.as_ref().unwrap())?;
228244
}
@@ -251,6 +267,8 @@ impl McSupportData {
251267
step: None,
252268
x_axis_ref: None,
253269
y_axis_ref: None,
270+
x_axis_input_quantity: None,
271+
y_axis_input_quantity: None,
254272
x_axis_conv: None,
255273
y_axis_conv: None,
256274
}
@@ -347,6 +365,14 @@ impl McSupportData {
347365
self.y_axis_ref = y_axis_ref.map(|s| s.into());
348366
self
349367
}
368+
pub fn set_x_axis_input_quantity<T: Into<McIdentifier>>(mut self, x_axis_input_quantity: Option<T>) -> Self {
369+
self.x_axis_input_quantity = x_axis_input_quantity.map(|s| s.into());
370+
self
371+
}
372+
pub fn set_y_axis_input_quantity<T: Into<McIdentifier>>(mut self, y_axis_input_quantity: Option<T>) -> Self {
373+
self.y_axis_input_quantity = y_axis_input_quantity.map(|s| s.into());
374+
self
375+
}
350376
pub fn set_x_axis_conv<T: Into<McIdentifier>>(mut self, x_axis_conv: Option<T>) -> Self {
351377
self.x_axis_conv = x_axis_conv.map(|s| s.into());
352378
self
@@ -398,6 +424,16 @@ impl McSupportData {
398424
self.y_axis_ref
399425
}
400426

427+
/// Get the x-axis reference as McIdentifier
428+
pub fn get_x_axis_input_quantity(&self) -> Option<McIdentifier> {
429+
self.x_axis_input_quantity
430+
}
431+
432+
/// Get the y-axis reference as McIdentifier
433+
pub fn get_y_axis_input_quantity(&self) -> Option<McIdentifier> {
434+
self.y_axis_input_quantity
435+
}
436+
401437
/// Get the x-axis conversion as McIdentifier
402438
pub fn get_x_axis_conv(&self) -> Option<McIdentifier> {
403439
self.x_axis_conv

src/registry/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ where
165165
// .set_unit(field.unit()) // not needed if set_linear is used
166166
.set_linear(field.factor(), field.offset(), field.unit())
167167
.set_x_axis_ref(field.x_axis_ref())
168-
.set_y_axis_ref(field.y_axis_ref());
168+
.set_y_axis_ref(field.y_axis_ref())
169+
.set_x_axis_input_quantity(field.x_axis_input_quantity())
170+
.set_y_axis_input_quantity(field.y_axis_input_quantity());
169171
if field.is_volatile() {
170172
mc_support_data = mc_support_data.set_qualifier(McObjectQualifier::Volatile);
171173
}
@@ -220,7 +222,9 @@ where
220222
// .set_unit(field.unit()) // not needed if set_linear is used
221223
.set_linear(field.factor(), field.offset(), field.unit())
222224
.set_x_axis_ref(field.x_axis_ref())
223-
.set_y_axis_ref(field.y_axis_ref());
225+
.set_y_axis_ref(field.y_axis_ref())
226+
.set_x_axis_input_quantity(field.x_axis_input_quantity())
227+
.set_y_axis_input_quantity(field.y_axis_input_quantity());
224228
if field.is_volatile() {
225229
mc_support_data = mc_support_data.set_qualifier(McObjectQualifier::Volatile);
226230
}

xcp_type_description/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct FieldDescriptor {
3131
y_dim: u16,
3232
x_axis_ref: &'static str,
3333
y_axis_ref: &'static str,
34+
x_axis_input_quantity: &'static str,
35+
y_axis_input_quantity: &'static str,
3436
addr_offset: u16,
3537
}
3638

@@ -53,6 +55,8 @@ impl FieldDescriptor {
5355
y_dim: u16,
5456
x_axis_ref: &'static str,
5557
y_axis_ref: &'static str,
58+
x_axis_input_quantity: &'static str,
59+
y_axis_input_quantity: &'static str,
5660
addr_offset: u16,
5761
) -> Self {
5862
FieldDescriptor {
@@ -72,6 +76,8 @@ impl FieldDescriptor {
7276
y_dim,
7377
x_axis_ref,
7478
y_axis_ref,
79+
x_axis_input_quantity,
80+
y_axis_input_quantity,
7581
addr_offset,
7682
}
7783
}
@@ -123,6 +129,20 @@ impl FieldDescriptor {
123129
pub fn y_axis_ref(&self) -> Option<&'static str> {
124130
if self.is_axis() || self.y_axis_ref.is_empty() { None } else { Some(self.y_axis_ref) }
125131
}
132+
pub fn x_axis_input_quantity(&self) -> Option<&'static str> {
133+
if self.is_axis() || self.x_axis_input_quantity.is_empty() {
134+
None
135+
} else {
136+
Some(self.x_axis_input_quantity)
137+
}
138+
}
139+
pub fn y_axis_input_quantity(&self) -> Option<&'static str> {
140+
if self.is_axis() || self.y_axis_input_quantity.is_empty() {
141+
None
142+
} else {
143+
Some(self.y_axis_input_quantity)
144+
}
145+
}
126146

127147
pub fn is_measurement(&self) -> bool {
128148
self.classifier == "measurement"

xcp_type_description/xcp_type_description_derive/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ fn generate_type_description_impl(data_struct: syn::DataStruct, value_type: &syn
3333
// Field attributes
3434
// #[axis/characteristic/measurement(...)] attr = access_type, comment, min, max, step, factor, offset, unit, x_axis, y_axis
3535
let field_attributes = &field.attrs;
36-
let (classifier, qualifier, comment, min, max, step, factor, offset, unit, x_axis_ref, y_axis_ref) = parse_field_attributes(field_attributes, field_data_type);
36+
let (classifier, qualifier, comment, min, max, step, factor, offset, unit, x_axis_ref, y_axis_ref, x_axis_input_quantity, y_axis_input_quantity) =
37+
parse_field_attributes(field_attributes, field_data_type);
3738
let classifier_str = classifier.to_str(); // "characteristic" or "axis" or "undefined" from field attribute
3839
let min_token = syn::parse_str::<Expr>(format!("{:?}", min).as_str()).unwrap();
3940
let max_token = syn::parse_str::<Expr>(format!("{:?}", max).as_str()).unwrap();
@@ -74,6 +75,8 @@ fn generate_type_description_impl(data_struct: syn::DataStruct, value_type: &syn
7475
#y_dim,
7576
#x_axis_ref,
7677
#y_axis_ref,
78+
#x_axis_input_quantity,
79+
#y_axis_input_quantity,
7780
addr_offset,
7881
));
7982
}
@@ -99,6 +102,8 @@ fn generate_type_description_impl(data_struct: syn::DataStruct, value_type: &syn
99102
#y_dim,
100103
#x_axis_ref,
101104
#y_axis_ref,
105+
#x_axis_input_quantity,
106+
#y_axis_input_quantity,
102107
addr_offset,
103108
));
104109
}

xcp_type_description/xcp_type_description_derive/src/utils.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ impl FieldAttribute {
2323
pub fn parse_field_attributes(
2424
attributes: &Vec<Attribute>,
2525
_field_type: &Type,
26-
) -> (FieldAttribute, String, String, Option<f64>, Option<f64>, Option<f64>, f64, f64, String, String, String) {
26+
) -> (
27+
FieldAttribute,
28+
String,
29+
String,
30+
Option<f64>,
31+
Option<f64>,
32+
Option<f64>,
33+
f64,
34+
f64,
35+
String,
36+
String,
37+
String,
38+
String,
39+
String,
40+
) {
2741
// attribute
2842
let mut field_attribute: FieldAttribute = FieldAttribute::Undefined; // characteristic, axis, measurement
2943

@@ -38,6 +52,8 @@ pub fn parse_field_attributes(
3852
let mut unit = String::new();
3953
let mut x_axis = String::new();
4054
let mut y_axis = String::new();
55+
let mut x_axis_input_quantity = String::new();
56+
let mut y_axis_input_quantity = String::new();
4157

4258
for attribute in attributes {
4359
//
@@ -91,12 +107,36 @@ pub fn parse_field_attributes(
91107
parse_str(&value, &mut y_axis)
92108
}
93109
}
110+
"x_axis_inputQty" | "axis_inputQty" => {
111+
if field_attribute != FieldAttribute::Axis {
112+
parse_str(&value, &mut x_axis_input_quantity)
113+
}
114+
}
115+
"y_axis_inputQty" => {
116+
if field_attribute != FieldAttribute::Axis {
117+
parse_str(&value, &mut y_axis_input_quantity)
118+
}
119+
}
94120
_ => panic!("Unsupported type description attribute item: {}", key),
95121
}
96122
}
97123
}
98124

99-
(field_attribute, qualifier, comment, min, max, step, factor.unwrap(), offset.unwrap(), unit, x_axis, y_axis)
125+
(
126+
field_attribute,
127+
qualifier,
128+
comment,
129+
min,
130+
max,
131+
step,
132+
factor.unwrap(),
133+
offset.unwrap(),
134+
unit,
135+
x_axis,
136+
y_axis,
137+
x_axis_input_quantity,
138+
y_axis_input_quantity,
139+
)
100140
}
101141

102142
pub fn normalize_tokens(ts: proc_macro2::TokenStream) -> proc_macro2::TokenStream {

0 commit comments

Comments
 (0)