Skip to content

Commit ede0fed

Browse files
committed
CodedConstParameters do not specify a DOP
(only a `DiagCodedType` and the value already is specified using the internal representation.) Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
1 parent a9a791f commit ede0fed

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

odxtools/environmentdatadescription.py

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -217,41 +217,51 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
217217

218218
def _get_numerical_dtc_from_parameter(self, param: Parameter,
219219
param_value: Optional[ParameterValue]) -> int:
220-
if not isinstance(param, ParameterWithDOP):
221-
odxraise(
222-
f"The parameter referenced by environment data descriptions "
223-
f"must use a parameter that specifies a DOP (encountered {type(param).__name__} "
224-
f"for reference '{self.param_snref}' of ENV-DATA-DESC '{self.short_name}')")
225-
return
226-
227-
prev_dop = param.dop
228-
if not isinstance(prev_dop, (StandardLengthType, DtcDop)):
229-
odxraise(f"The DOP of the parameter referenced by environment data descriptions "
230-
f"must use either be StandardLengthType or a DtcDop (encountered "
231-
f"{type(param).__name__} for parameter '{self.param.short_name}' "
232-
f"of ENV-DATA-DESC '{self.short_name}')")
233-
return
220+
if isinstance(param, ParameterWithDOP):
221+
dop = param.dop
222+
if not isinstance(dop, (StandardLengthType, DtcDop)):
223+
odxraise(f"The DOP of the parameter referenced by environment data descriptions "
224+
f"must use either be StandardLengthType or a DtcDop (encountered "
225+
f"{type(param).__name__} for parameter '{self.param.short_name}' "
226+
f"of ENV-DATA-DESC '{self.short_name}')")
227+
return
234228

235-
if prev_dop.diag_coded_type.base_data_type != DataType.A_UINT32:
236-
odxraise(f"The data type used by the DOP of the parameter referenced "
237-
f"by environment data descriptions must be A_UINT32 "
238-
f"(encountered '{prev_dop.diag_coded_type.base_data_type.value}')")
239-
return
229+
if dop.diag_coded_type.base_data_type != DataType.A_UINT32:
230+
odxraise(f"The data type used by the DOP of the parameter referenced "
231+
f"by environment data descriptions must be A_UINT32 "
232+
f"(encountered '{dop.diag_coded_type.base_data_type.value}')")
233+
return
240234

241-
if param_value is None:
242-
if isinstance(param, ValueParameter):
243-
param_value = param.physical_default_value
244-
elif isinstance(param, CodedConstParameter):
245-
param_value = param.coded_value
246-
elif isinstance(param, PhysicalConstantParameter):
247-
param_value = param.physical_constant_value
248-
else:
249-
odxraise() # make mypy happy...
235+
if param_value is None:
236+
if isinstance(param, ValueParameter):
237+
param_value = param.physical_default_value
238+
elif isinstance(param, PhysicalConstantParameter):
239+
param_value = param.physical_constant_value
240+
else:
241+
odxraise() # make mypy happy...
242+
return
243+
244+
if isinstance(dop, DtcDop):
245+
return dop.convert_to_numerical_trouble_code(odxrequire(param_value))
246+
elif isinstance(dop, DataObjectProperty):
247+
return dop.compu_method.convert_physical_to_internal(param_value)
248+
249+
odxraise() # not reachable
250+
251+
elif isinstance(param, CodedConstParameter):
252+
if param.diag_coded_type.base_data_type != DataType.A_UINT32:
253+
odxraise(f"The data type used by the parameter referenced "
254+
f"by environment data descriptions must be A_UINT32 "
255+
f"(encountered '{param.diag_coded_type.base_data_type.value}')")
250256
return
251257

252-
if isinstance(prev_dop, DtcDop):
253-
return prev_dop.convert_to_numerical_trouble_code(odxrequire(param_value))
254-
elif isinstance(prev_dop, DataObjectProperty):
255-
return prev_dop.compu_method.convert_physical_to_internal(param_value)
258+
assert isinstance(param.coded_value, int)
259+
260+
return param.coded_value
256261

257-
odxraise() # not reachable
262+
else:
263+
odxraise(f"The parameter referenced by environment data descriptions "
264+
f"must be a parameter that either specifies a DOP or a constant "
265+
f"(encountered {type(param).__name__} for reference '{self.param_snref}' of "
266+
f"ENV-DATA-DESC '{self.short_name}')")
267+
return

0 commit comments

Comments
 (0)