odxtools 6.4.2__py3-none-any.whl → 6.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ # SPDX-License-Identifier: MIT
2
+ from dataclasses import dataclass
3
+ from enum import Enum
4
+ from typing import Optional
5
+ from xml.etree import ElementTree
6
+
7
+ from .compumethods.limit import Limit
8
+ from .exceptions import odxraise, odxrequire
9
+ from .odxtypes import DataType
10
+ from .utils import create_description_from_et
11
+
12
+
13
+ class ValidType(Enum):
14
+ VALID = "VALID"
15
+ NOT_VALID = "NOT-VALID"
16
+ NOT_DEFINED = "NOT-DEFINED"
17
+ NOT_AVAILABLE = "NOT-AVAILABLE"
18
+
19
+
20
+ @dataclass
21
+ class ScaleConstr:
22
+ """This class represents a SCALE-CONSTR.
23
+ """
24
+
25
+ short_label: Optional[str]
26
+ description: Optional[str]
27
+ lower_limit: Optional[Limit]
28
+ upper_limit: Optional[Limit]
29
+ validity: ValidType
30
+
31
+ @staticmethod
32
+ def from_et(et_element: ElementTree.Element, internal_type: DataType) -> "ScaleConstr":
33
+ short_label = et_element.findtext("SHORT-LABEL")
34
+ description = create_description_from_et(et_element.find("DESC"))
35
+
36
+ lower_limit = Limit.from_et(et_element.find("LOWER-LIMIT"), internal_type=internal_type)
37
+ upper_limit = Limit.from_et(et_element.find("UPPER-LIMIT"), internal_type=internal_type)
38
+
39
+ validity_str = odxrequire(et_element.get("VALIDITY"))
40
+ try:
41
+ validity = ValidType(validity_str)
42
+ except ValueError:
43
+ odxraise(f"Encountered unknown Validity '{validity_str}'")
44
+
45
+ return ScaleConstr(
46
+ short_label=short_label,
47
+ description=description,
48
+ lower_limit=lower_limit,
49
+ upper_limit=upper_limit,
50
+ validity=validity)
@@ -48,7 +48,7 @@ class StandardLengthType(DiagCodedType):
48
48
 
49
49
  def convert_internal_to_bytes(self, internal_value: AtomicOdxType, encode_state: EncodeState,
50
50
  bit_position: int) -> bytes:
51
- return self._to_bytes(
51
+ return self._encode_internal_value(
52
52
  self.__apply_mask(internal_value),
53
53
  bit_position,
54
54
  self.bit_length,
@@ -59,7 +59,7 @@ class StandardLengthType(DiagCodedType):
59
59
  def convert_bytes_to_internal(self,
60
60
  decode_state: DecodeState,
61
61
  bit_position: int = 0) -> Tuple[AtomicOdxType, int]:
62
- internal_value, cursor_position = self._extract_internal(
62
+ internal_value, cursor_position = self._extract_internal_value(
63
63
  decode_state.coded_message,
64
64
  decode_state.cursor_position,
65
65
  bit_position,
@@ -34,7 +34,7 @@
34
34
  {%- macro printPhysicalType(physical_type) %}
35
35
  {%- if physical_type.display_radix is not none %}
36
36
  <PHYSICAL-TYPE BASE-DATA-TYPE="{{physical_type.base_data_type.value}}" DISPLAY-RADIX="{{physical_type.display_radix.name}}" />
37
- {%- elif physical_type.precision is not none %}
37
+ {%- elif physical_type.precision is not none %}
38
38
  <PHYSICAL-TYPE BASE-DATA-TYPE="{{physical_type.base_data_type.value}}">
39
39
  <PRECISION>{{physical_type.precision}}</PRECISION>
40
40
  </PHYSICAL-TYPE>
@@ -44,11 +44,52 @@
44
44
  {%- endmacro -%}
45
45
 
46
46
  {%- macro printLimitValue(lv) -%}
47
- {%- if hasattr(lv, 'hex') %}
47
+ {%- if hasattr(lv, 'hex') -%}
48
48
  {#- bytes or bytarray limit #}
49
49
  {{lv.hex()}}
50
- {%- else %}
50
+ {%- else -%}
51
51
  {{lv}}
52
+ {%- endif -%}
53
+ {%- endmacro -%}
54
+
55
+ {%- macro printScaleConstr(sc) %}
56
+ <SCALE-CONSTR VALIDITY="{{sc.validity.value}}">
57
+ {%- if sc.short_label and sc.short_label.strip() %}
58
+ <SHORT-LABEL>{{sc.short_label|e}}</SHORT-LABEL>
59
+ {%- endif %}
60
+ {%- if sc.description and sc.description.strip() %}
61
+ <DESC>
62
+ {{sc.description}}
63
+ </DESC>
64
+ {%- endif %}
65
+ <LOWER-LIMIT>{{printLimitValue(sc.lower_limit.value)}}</LOWER-LIMIT>
66
+ <UPPER-LIMIT>{{printLimitValue(sc.upper_limit.value)}}</UPPER-LIMIT>
67
+ </SCALE-CONSTR>
68
+ {%- endmacro -%}
69
+
70
+ {%- macro printInternalConstr(ic, is_physical) %}
71
+ {%- if is_physical %}
72
+ <PHYS-CONSTR>
73
+ {%- else %}
74
+ <INTERNAL-CONSTR>
75
+ {%- endif %}
76
+ {%- if ic.lower_limit %}
77
+ <LOWER-LIMIT>{{printLimitValue(ic.lower_limit.value)}}</LOWER-LIMIT>
78
+ {%- endif %}
79
+ {%- if ic.upper_limit %}
80
+ <UPPER-LIMIT>{{printLimitValue(ic.upper_limit.value)}}</UPPER-LIMIT>
81
+ {%- endif %}
82
+ {%- if ic.scale_constrs %}
83
+ <SCALE-CONSTRS>
84
+ {%- for sc in ic.scale_constrs %}
85
+ {{- printScaleConstr(sc)|indent(4)}}
86
+ {%- endfor %}
87
+ </SCALE-CONSTRS>
88
+ {%- endif %}
89
+ {%- if is_physical %}
90
+ </PHYS-CONSTR>
91
+ {%- else %}
92
+ </INTERNAL-CONSTR>
52
93
  {%- endif %}
53
94
  {%- endmacro -%}
54
95
 
@@ -69,10 +110,10 @@
69
110
  </DESC>
70
111
  {%- endif %}
71
112
  {%- if cs.lower_limit is not none %}
72
- <LOWER-LIMIT>{{printLimitValue(cs.lower_limit.value)}}</LOWER-LIMIT>
113
+ <LOWER-LIMIT>{{printLimitValue(cs.lower_limit.value)}}</LOWER-LIMIT>
73
114
  {%- endif %}
74
115
  {%- if cs.upper_limit is not none %}
75
- <UPPER-LIMIT>{{printLimitValue(cs.upper_limit.value)}}</UPPER-LIMIT>
116
+ <UPPER-LIMIT>{{printLimitValue(cs.upper_limit.value)}}</UPPER-LIMIT>
76
117
  {%- endif %}
77
118
  {%- if cs.compu_inverse_value is not none %}
78
119
  <COMPU-INVERSE-VALUE>
@@ -191,9 +232,15 @@
191
232
  {{- printCompuMethod(dop.compu_method)|indent(1) }}
192
233
  {{- printDiagCodedType(dop.diag_coded_type)|indent(1) }}
193
234
  {{- printPhysicalType(dop.physical_type)|indent(1) }}
235
+ {%- if dop.internal_constr %}
236
+ {{- printInternalConstr(dop.internal_constr, False)|indent(1) }}
237
+ {%- endif %}
194
238
  {%- if dop.unit_ref %}
195
239
  <UNIT-REF ID-REF="{{ dop.unit_ref.ref_id }}" />
196
240
  {%- endif %}
241
+ {%- if dop.physical_constr %}
242
+ {{- printInternalConstr(dop.internal_constr, True)|indent(1) }}
243
+ {%- endif %}
197
244
  </DATA-OBJECT-PROP>
198
245
  {%- endmacro %}
199
246
 
odxtools/version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '6.4.2'
16
- __version_tuple__ = version_tuple = (6, 4, 2)
15
+ __version__ = version = '6.5.0'
16
+ __version_tuple__ = version_tuple = (6, 5, 0)