|
10 | 10 | from .diagcodedtype import DiagCodedType
|
11 | 11 | from .dopbase import DopBase
|
12 | 12 | from .encodestate import EncodeState
|
13 |
| -from .exceptions import DecodeError, EncodeError, odxraise, odxrequire |
| 13 | +from .exceptions import EncodeError, odxraise, odxrequire |
14 | 14 | from .internalconstr import InternalConstr
|
15 | 15 | from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef
|
16 | 16 | from .odxtypes import AtomicOdxType, ParameterValue
|
@@ -136,11 +136,17 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
|
136 | 136 |
|
137 | 137 | if self.compu_method.is_valid_internal_value(internal):
|
138 | 138 | return self.compu_method.convert_internal_to_physical(internal)
|
139 |
| - else: |
140 |
| - # TODO: How to prevent this? |
141 |
| - raise DecodeError( |
142 |
| - f"DOP {self.short_name} could not convert the coded value " |
143 |
| - f" {repr(internal)} to physical type {self.physical_type.base_data_type}.") |
| 139 | + |
| 140 | + internal_to_phys = self.compu_method.compu_internal_to_phys |
| 141 | + default_value = internal_to_phys.compu_default_value if internal_to_phys else None |
| 142 | + |
| 143 | + if default_value is not None: |
| 144 | + return str(default_value) |
| 145 | + |
| 146 | + odxraise(f"DOP {self.short_name} could not convert the coded value " |
| 147 | + f"{repr(internal)} to physical type {self.physical_type.base_data_type}.") |
| 148 | + |
| 149 | + return None |
144 | 150 |
|
145 | 151 | def is_valid_physical_value(self, physical_value: ParameterValue) -> bool:
|
146 | 152 | return self.compu_method.is_valid_physical_value(cast(AtomicOdxType, physical_value))
|
0 commit comments