odxtools 10.1.0__py3-none-any.whl → 10.2.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.
- odxtools/addrdeffilter.py +33 -0
- odxtools/addrdefphyssegment.py +33 -0
- odxtools/checksum.py +67 -0
- odxtools/checksumresult.py +7 -0
- odxtools/cli/compare.py +143 -170
- odxtools/database.py +24 -4
- odxtools/datablock.py +153 -0
- odxtools/datafile.py +23 -0
- odxtools/dataformat.py +39 -0
- odxtools/dataformatselection.py +9 -0
- odxtools/description.py +2 -5
- odxtools/diagdatadictionaryspec.py +1 -3
- odxtools/direction.py +7 -0
- odxtools/ecumem.py +71 -0
- odxtools/ecumemconnector.py +136 -0
- odxtools/encryptcompressmethod.py +39 -0
- odxtools/encryptcompressmethodtype.py +13 -0
- odxtools/expectedident.py +40 -0
- odxtools/externflashdata.py +34 -0
- odxtools/filter.py +32 -0
- odxtools/flash.py +88 -0
- odxtools/flashclass.py +32 -0
- odxtools/flashdata.py +70 -0
- odxtools/fwchecksum.py +7 -0
- odxtools/fwsignature.py +7 -0
- odxtools/identdesc.py +54 -0
- odxtools/identvalue.py +32 -0
- odxtools/identvaluetype.py +14 -0
- odxtools/internflashdata.py +33 -0
- odxtools/loadfile.py +1 -1
- odxtools/mem.py +80 -0
- odxtools/modification.py +3 -2
- odxtools/negoffset.py +21 -0
- odxtools/ownident.py +38 -0
- odxtools/physicaltype.py +12 -10
- odxtools/physmem.py +52 -0
- odxtools/physsegment.py +42 -0
- odxtools/posoffset.py +21 -0
- odxtools/security.py +42 -0
- odxtools/securitymethod.py +7 -0
- odxtools/segment.py +63 -0
- odxtools/session.py +88 -0
- odxtools/sessiondesc.py +101 -0
- odxtools/sessionsubelemtype.py +14 -0
- odxtools/sizedeffilter.py +33 -0
- odxtools/sizedefphyssegment.py +33 -0
- odxtools/specialdata.py +2 -1
- odxtools/targetaddroffset.py +13 -0
- odxtools/templates/comparam-spec.odx-c.xml.jinja2 +1 -0
- odxtools/templates/comparam-subset.odx-cs.xml.jinja2 +1 -0
- odxtools/templates/diag_layer_container.odx-d.xml.jinja2 +2 -1
- odxtools/templates/flash.odx-f.xml.jinja2 +42 -0
- odxtools/templates/macros/printAdminData.xml.jinja2 +4 -4
- odxtools/templates/macros/printAudience.xml.jinja2 +3 -3
- odxtools/templates/macros/printChecksum.xml.jinja2 +36 -0
- odxtools/templates/macros/printComparam.xml.jinja2 +1 -1
- odxtools/templates/macros/printComparamRef.xml.jinja2 +1 -3
- odxtools/templates/macros/printCompuMethod.xml.jinja2 +1 -1
- odxtools/templates/macros/printDOP.xml.jinja2 +3 -3
- odxtools/templates/macros/printDatablock.xml.jinja2 +78 -0
- odxtools/templates/macros/printDiagComm.xml.jinja2 +2 -2
- odxtools/templates/macros/printDiagLayer.xml.jinja2 +2 -1
- odxtools/templates/macros/printDiagVariable.xml.jinja2 +4 -4
- odxtools/templates/macros/printDynDefinedSpec.xml.jinja2 +3 -3
- odxtools/templates/macros/printDynamicEndmarkerField.xml.jinja2 +2 -2
- odxtools/templates/macros/printDynamicLengthField.xml.jinja2 +2 -2
- odxtools/templates/macros/printEcuMem.xml.jinja2 +24 -0
- odxtools/templates/macros/printEcuMemConnector.xml.jinja2 +58 -0
- odxtools/templates/macros/printEndOfPdu.xml.jinja2 +1 -1
- odxtools/templates/macros/printEnvDataDesc.xml.jinja2 +1 -1
- odxtools/templates/macros/printExpectedIdent.xml.jinja2 +21 -0
- odxtools/templates/macros/printFlashdata.xml.jinja2 +43 -0
- odxtools/templates/macros/printIdentDesc.xml.jinja2 +17 -0
- odxtools/templates/macros/printMem.xml.jinja2 +35 -0
- odxtools/templates/macros/printMux.xml.jinja2 +3 -3
- odxtools/templates/macros/printOdxCategory.xml.jinja2 +4 -4
- odxtools/templates/macros/printOwnIdent.xml.jinja2 +17 -0
- odxtools/templates/macros/printParam.xml.jinja2 +4 -4
- odxtools/templates/macros/printParentRef.xml.jinja2 +1 -5
- odxtools/templates/macros/printPhysMem.xml.jinja2 +20 -0
- odxtools/templates/macros/printPhysSegment.xml.jinja2 +33 -0
- odxtools/templates/macros/printPreConditionStateRef.xml.jinja2 +1 -1
- odxtools/templates/macros/printProtStack.xml.jinja2 +1 -1
- odxtools/templates/macros/printProtocol.xml.jinja2 +1 -1
- odxtools/templates/macros/printSecurity.xml.jinja2 +37 -0
- odxtools/templates/macros/printSegment.xml.jinja2 +31 -0
- odxtools/templates/macros/printService.xml.jinja2 +3 -3
- odxtools/templates/macros/printSession.xml.jinja2 +45 -0
- odxtools/templates/macros/printSessionDesc.xml.jinja2 +40 -0
- odxtools/templates/macros/printSingleEcuJob.xml.jinja2 +3 -3
- odxtools/templates/macros/printSpecialData.xml.jinja2 +2 -2
- odxtools/templates/macros/printStateTransitionRef.xml.jinja2 +1 -1
- odxtools/templates/macros/printStaticField.xml.jinja2 +1 -1
- odxtools/templates/macros/printSubComponent.xml.jinja2 +3 -3
- odxtools/templates/macros/printTable.xml.jinja2 +6 -6
- odxtools/templates/macros/printUnitSpec.xml.jinja2 +2 -2
- odxtools/text.py +2 -6
- odxtools/utils.py +22 -1
- odxtools/validityfor.py +30 -0
- odxtools/version.py +2 -2
- odxtools/writepdxfile.py +70 -21
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/METADATA +1 -1
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/RECORD +107 -50
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/WHEEL +1 -1
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/entry_points.txt +0 -0
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/licenses/LICENSE +0 -0
- {odxtools-10.1.0.dist-info → odxtools-10.2.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .datafile import Datafile
|
7
|
+
from .exceptions import odxrequire
|
8
|
+
from .flashdata import Flashdata
|
9
|
+
from .odxdoccontext import OdxDocContext
|
10
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
11
|
+
from .snrefcontext import SnRefContext
|
12
|
+
from .utils import dataclass_fields_asdict
|
13
|
+
|
14
|
+
|
15
|
+
@dataclass(kw_only=True)
|
16
|
+
class ExternFlashdata(Flashdata):
|
17
|
+
datafile: Datafile
|
18
|
+
|
19
|
+
@staticmethod
|
20
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "ExternFlashdata":
|
21
|
+
kwargs = dataclass_fields_asdict(Flashdata.from_et(et_element, context))
|
22
|
+
|
23
|
+
datafile = Datafile.from_et(odxrequire(et_element.find("DATAFILE")), context)
|
24
|
+
|
25
|
+
return ExternFlashdata(datafile=datafile, **kwargs)
|
26
|
+
|
27
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
28
|
+
return super()._build_odxlinks()
|
29
|
+
|
30
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
31
|
+
super()._resolve_odxlinks(odxlinks)
|
32
|
+
|
33
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
34
|
+
super()._resolve_snrefs(context)
|
odxtools/filter.py
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .exceptions import odxrequire
|
7
|
+
from .odxdoccontext import OdxDocContext
|
8
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
9
|
+
from .snrefcontext import SnRefContext
|
10
|
+
from .utils import read_hex_binary
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass(kw_only=True)
|
14
|
+
class Filter:
|
15
|
+
filter_start: int
|
16
|
+
|
17
|
+
@staticmethod
|
18
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "Filter":
|
19
|
+
filter_start = odxrequire(read_hex_binary(et_element.find("FILTER-START")))
|
20
|
+
|
21
|
+
return Filter(filter_start=filter_start)
|
22
|
+
|
23
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
24
|
+
odxlinks: dict[OdxLinkId, Any] = {}
|
25
|
+
|
26
|
+
return odxlinks
|
27
|
+
|
28
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
29
|
+
pass
|
30
|
+
|
31
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
32
|
+
pass
|
odxtools/flash.py
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass, field
|
3
|
+
from typing import TYPE_CHECKING, Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .additionalaudience import AdditionalAudience
|
7
|
+
from .ecumem import EcuMem
|
8
|
+
from .ecumemconnector import EcuMemConnector
|
9
|
+
from .nameditemlist import NamedItemList
|
10
|
+
from .odxcategory import OdxCategory
|
11
|
+
from .odxdoccontext import OdxDocContext
|
12
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
13
|
+
from .snrefcontext import SnRefContext
|
14
|
+
from .utils import dataclass_fields_asdict
|
15
|
+
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from .database import Database
|
18
|
+
|
19
|
+
|
20
|
+
@dataclass(kw_only=True)
|
21
|
+
class Flash(OdxCategory):
|
22
|
+
ecu_mems: NamedItemList[EcuMem] = field(default_factory=NamedItemList)
|
23
|
+
ecu_mem_connectors: NamedItemList[EcuMemConnector] = field(default_factory=NamedItemList)
|
24
|
+
additional_audiences: NamedItemList[AdditionalAudience] = field(default_factory=NamedItemList)
|
25
|
+
|
26
|
+
@staticmethod
|
27
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "Flash":
|
28
|
+
|
29
|
+
base_obj = OdxCategory.from_et(et_element, context)
|
30
|
+
kwargs = dataclass_fields_asdict(base_obj)
|
31
|
+
|
32
|
+
ecu_mems = NamedItemList(
|
33
|
+
[EcuMem.from_et(el, context) for el in et_element.iterfind("ECU-MEMS/ECU-MEM")])
|
34
|
+
ecu_mem_connectors = NamedItemList([
|
35
|
+
EcuMemConnector.from_et(el, context)
|
36
|
+
for el in et_element.iterfind("ECU-MEM-CONNECTORS/ECU-MEM-CONNECTOR")
|
37
|
+
])
|
38
|
+
additional_audiences = NamedItemList([
|
39
|
+
AdditionalAudience.from_et(el, context)
|
40
|
+
for el in et_element.iterfind("ADDITIONAL-AUDIENCES/ADDITIONAL-AUDIENCE")
|
41
|
+
])
|
42
|
+
|
43
|
+
return Flash(
|
44
|
+
ecu_mems=ecu_mems,
|
45
|
+
ecu_mem_connectors=ecu_mem_connectors,
|
46
|
+
additional_audiences=additional_audiences,
|
47
|
+
**kwargs)
|
48
|
+
|
49
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
50
|
+
odxlinks = super()._build_odxlinks()
|
51
|
+
|
52
|
+
for ecu_mem in self.ecu_mems:
|
53
|
+
odxlinks.update(ecu_mem._build_odxlinks())
|
54
|
+
|
55
|
+
for ecu_mem_connector in self.ecu_mem_connectors:
|
56
|
+
odxlinks.update(ecu_mem_connector._build_odxlinks())
|
57
|
+
|
58
|
+
for additional_audiences in self.additional_audiences:
|
59
|
+
odxlinks.update(additional_audiences._build_odxlinks())
|
60
|
+
|
61
|
+
return odxlinks
|
62
|
+
|
63
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
64
|
+
super()._resolve_odxlinks(odxlinks)
|
65
|
+
|
66
|
+
for ecu_mem in self.ecu_mems:
|
67
|
+
ecu_mem._resolve_odxlinks(odxlinks)
|
68
|
+
|
69
|
+
for ecu_mem_connector in self.ecu_mem_connectors:
|
70
|
+
ecu_mem_connector._resolve_odxlinks(odxlinks)
|
71
|
+
|
72
|
+
for additional_audiences in self.additional_audiences:
|
73
|
+
additional_audiences._resolve_odxlinks(odxlinks)
|
74
|
+
|
75
|
+
def _finalize_init(self, database: "Database", odxlinks: OdxLinkDatabase) -> None:
|
76
|
+
super()._finalize_init(database, odxlinks)
|
77
|
+
|
78
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
79
|
+
super()._resolve_snrefs(context)
|
80
|
+
|
81
|
+
for ecu_mem in self.ecu_mems:
|
82
|
+
ecu_mem._resolve_snrefs(context)
|
83
|
+
|
84
|
+
for ecu_mem_connector in self.ecu_mem_connectors:
|
85
|
+
ecu_mem_connector._resolve_snrefs(context)
|
86
|
+
|
87
|
+
for additional_audiences in self.additional_audiences:
|
88
|
+
additional_audiences._resolve_snrefs(context)
|
odxtools/flashclass.py
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .element import IdentifiableElement
|
7
|
+
from .odxdoccontext import OdxDocContext
|
8
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
9
|
+
from .snrefcontext import SnRefContext
|
10
|
+
from .utils import dataclass_fields_asdict
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass(kw_only=True)
|
14
|
+
class FlashClass(IdentifiableElement):
|
15
|
+
"""
|
16
|
+
Corresponds to FLASH-CLASS.
|
17
|
+
"""
|
18
|
+
|
19
|
+
@staticmethod
|
20
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "FlashClass":
|
21
|
+
kwargs = dataclass_fields_asdict(IdentifiableElement.from_et(et_element, context))
|
22
|
+
|
23
|
+
return FlashClass(**kwargs)
|
24
|
+
|
25
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
26
|
+
return {self.odx_id: self}
|
27
|
+
|
28
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
29
|
+
pass
|
30
|
+
|
31
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
32
|
+
pass
|
odxtools/flashdata.py
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .dataformat import Dataformat
|
7
|
+
from .element import IdentifiableElement
|
8
|
+
from .encryptcompressmethod import EncryptCompressMethod
|
9
|
+
from .exceptions import odxrequire
|
10
|
+
from .odxdoccontext import OdxDocContext
|
11
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
12
|
+
from .snrefcontext import SnRefContext
|
13
|
+
from .utils import dataclass_fields_asdict
|
14
|
+
|
15
|
+
|
16
|
+
@dataclass(kw_only=True)
|
17
|
+
class Flashdata(IdentifiableElement):
|
18
|
+
size_length: int | None = None
|
19
|
+
address_length: int | None = None
|
20
|
+
dataformat: Dataformat
|
21
|
+
encrypt_compress_method: EncryptCompressMethod | None = None
|
22
|
+
|
23
|
+
@staticmethod
|
24
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "Flashdata":
|
25
|
+
|
26
|
+
kwargs = dataclass_fields_asdict(IdentifiableElement.from_et(et_element, context))
|
27
|
+
|
28
|
+
size_length = None
|
29
|
+
if (size_length_str := et_element.findtext("SIZE-LENGTH")) is not None:
|
30
|
+
size_length = int(size_length_str)
|
31
|
+
|
32
|
+
address_length = None
|
33
|
+
if (address_length_str := et_element.findtext("ADDRESS-LENGTH")) is not None:
|
34
|
+
address_length = int(address_length_str)
|
35
|
+
|
36
|
+
dataformat = Dataformat.from_et(odxrequire(et_element.find("DATAFORMAT")), context)
|
37
|
+
|
38
|
+
encrypt_compress_method = None
|
39
|
+
if (encrypt_compress_method_elem := et_element.find("ENCRYPT-COMPRESS-METHOD")) is not None:
|
40
|
+
encrypt_compress_method = EncryptCompressMethod.from_et(encrypt_compress_method_elem,
|
41
|
+
context)
|
42
|
+
|
43
|
+
return Flashdata(
|
44
|
+
size_length=size_length,
|
45
|
+
address_length=address_length,
|
46
|
+
dataformat=dataformat,
|
47
|
+
encrypt_compress_method=encrypt_compress_method,
|
48
|
+
**kwargs)
|
49
|
+
|
50
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
51
|
+
odxlinks = {self.odx_id: self}
|
52
|
+
|
53
|
+
if self.dataformat is not None:
|
54
|
+
odxlinks.update(self.dataformat._build_odxlinks())
|
55
|
+
if self.encrypt_compress_method is not None:
|
56
|
+
odxlinks.update(self.encrypt_compress_method._build_odxlinks())
|
57
|
+
|
58
|
+
return odxlinks
|
59
|
+
|
60
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
61
|
+
if self.dataformat is not None:
|
62
|
+
self.dataformat._resolve_odxlinks(odxlinks)
|
63
|
+
if self.encrypt_compress_method is not None:
|
64
|
+
self.encrypt_compress_method._resolve_odxlinks(odxlinks)
|
65
|
+
|
66
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
67
|
+
if self.dataformat is not None:
|
68
|
+
self.dataformat._resolve_snrefs(context)
|
69
|
+
if self.encrypt_compress_method is not None:
|
70
|
+
self.encrypt_compress_method._resolve_snrefs(context)
|
odxtools/fwchecksum.py
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from .validityfor import ValidityFor
|
3
|
+
|
4
|
+
# Note that the ODX specification specifies a separate tag for this,
|
5
|
+
# but this tag is identical to VALIDITY-FOR, so let's use a type alias
|
6
|
+
# to reduce the amount of copy-and-pasted code
|
7
|
+
FwChecksum = ValidityFor
|
odxtools/fwsignature.py
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from .validityfor import ValidityFor
|
3
|
+
|
4
|
+
# Note that the ODX specification specifies a separate tag for this,
|
5
|
+
# but this tag is identical to VALIDITY-FOR, so let's use a type alias
|
6
|
+
# to reduce the amount of copy-and-pasted code
|
7
|
+
FwSignature = ValidityFor
|
odxtools/identdesc.py
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .exceptions import odxrequire
|
7
|
+
from .odxdoccontext import OdxDocContext
|
8
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
9
|
+
from .snrefcontext import SnRefContext
|
10
|
+
|
11
|
+
|
12
|
+
@dataclass(kw_only=True)
|
13
|
+
class IdentDesc:
|
14
|
+
diag_comm_snref: str
|
15
|
+
ident_if_snref: str
|
16
|
+
|
17
|
+
# exactly one of the two attributes below must be defined
|
18
|
+
out_param_if_snref: str | None = None
|
19
|
+
out_param_if_snpathref: str | None = None
|
20
|
+
|
21
|
+
@staticmethod
|
22
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "IdentDesc":
|
23
|
+
diag_comm_snref = odxrequire(
|
24
|
+
odxrequire(et_element.find("DIAG-COMM-SNREF")).attrib.get("SHORT-NAME"))
|
25
|
+
ident_if_snref = odxrequire(
|
26
|
+
odxrequire(et_element.find("IDENT-IF-SNREF")).attrib.get("SHORT-NAME"))
|
27
|
+
out_param_if_snref = None
|
28
|
+
if (out_param_if_snref_elem := et_element.find("OUT-PARAM-IF-SNREF")) is not None:
|
29
|
+
out_param_if_snref = odxrequire(out_param_if_snref_elem.attrib.get("SHORT-NAME"))
|
30
|
+
|
31
|
+
out_param_if_snpathref = None
|
32
|
+
if (out_param_if_snpathref_elem := et_element.find("OUT-PARAM-IF-SNPATHREF")) is not None:
|
33
|
+
out_param_if_snpathref = odxrequire(
|
34
|
+
out_param_if_snpathref_elem.attrib.get("SHORT-NAME-PATH"))
|
35
|
+
|
36
|
+
return IdentDesc(
|
37
|
+
diag_comm_snref=diag_comm_snref,
|
38
|
+
ident_if_snref=ident_if_snref,
|
39
|
+
out_param_if_snref=out_param_if_snref,
|
40
|
+
out_param_if_snpathref=out_param_if_snpathref,
|
41
|
+
)
|
42
|
+
|
43
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
44
|
+
odxlinks: dict[OdxLinkId, Any] = {}
|
45
|
+
|
46
|
+
return odxlinks
|
47
|
+
|
48
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
49
|
+
pass
|
50
|
+
|
51
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
52
|
+
# TODO: resolve the short name references. for IdentDesc this
|
53
|
+
# is (probably) not possible ahead of time...
|
54
|
+
pass
|
odxtools/identvalue.py
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from xml.etree import ElementTree
|
4
|
+
|
5
|
+
from .exceptions import odxraise
|
6
|
+
from .identvaluetype import IdentValueType
|
7
|
+
from .odxdoccontext import OdxDocContext
|
8
|
+
|
9
|
+
|
10
|
+
@dataclass(kw_only=True)
|
11
|
+
class IdentValue:
|
12
|
+
"""
|
13
|
+
Corresponds to IDENT-VALUE.
|
14
|
+
"""
|
15
|
+
|
16
|
+
value: str
|
17
|
+
|
18
|
+
# note that the spec says this attribute is named "TYPE", but in
|
19
|
+
# python, "type" is a build-in function...
|
20
|
+
value_type: IdentValueType
|
21
|
+
|
22
|
+
@staticmethod
|
23
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "IdentValue":
|
24
|
+
value = et_element.text or ""
|
25
|
+
|
26
|
+
try:
|
27
|
+
value_type = IdentValueType(et_element.attrib["TYPE"])
|
28
|
+
except Exception as e:
|
29
|
+
odxraise(f"Cannot parse IDENT-VALUE-TYPE: {e}")
|
30
|
+
value_type = None
|
31
|
+
|
32
|
+
return IdentValue(value=value, value_type=value_type)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from enum import Enum
|
3
|
+
|
4
|
+
from .odxtypes import DataType
|
5
|
+
|
6
|
+
|
7
|
+
class IdentValueType(Enum):
|
8
|
+
A_UINT32 = "A_UINT32"
|
9
|
+
A_BYTEFIELD = "A_BYTEFIELD"
|
10
|
+
A_ASCIISTRING = "A_ASCIISTRING"
|
11
|
+
|
12
|
+
@property
|
13
|
+
def data_type(self) -> DataType:
|
14
|
+
return DataType(self.value)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .exceptions import odxrequire
|
7
|
+
from .flashdata import Flashdata
|
8
|
+
from .odxdoccontext import OdxDocContext
|
9
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
10
|
+
from .snrefcontext import SnRefContext
|
11
|
+
from .utils import dataclass_fields_asdict
|
12
|
+
|
13
|
+
|
14
|
+
@dataclass(kw_only=True)
|
15
|
+
class InternFlashdata(Flashdata):
|
16
|
+
data: str
|
17
|
+
|
18
|
+
@staticmethod
|
19
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "InternFlashdata":
|
20
|
+
kwargs = dataclass_fields_asdict(Flashdata.from_et(et_element, context))
|
21
|
+
|
22
|
+
data = odxrequire(et_element.findtext("DATA"))
|
23
|
+
|
24
|
+
return InternFlashdata(data=data, **kwargs)
|
25
|
+
|
26
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
27
|
+
return super()._build_odxlinks()
|
28
|
+
|
29
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
30
|
+
super()._resolve_odxlinks(odxlinks)
|
31
|
+
|
32
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
33
|
+
super()._resolve_snrefs(context)
|
odxtools/loadfile.py
CHANGED
@@ -23,7 +23,7 @@ def load_odx_d_file(odx_d_file_name: str | Path) -> Database:
|
|
23
23
|
def load_file(file_name: str | Path) -> Database:
|
24
24
|
if str(file_name).lower().endswith(".pdx"):
|
25
25
|
return load_pdx_file(str(file_name))
|
26
|
-
elif
|
26
|
+
elif Path(file_name).suffix.lower().startswith(".odx"):
|
27
27
|
return load_odx_d_file(str(file_name))
|
28
28
|
else:
|
29
29
|
raise RuntimeError(f"Could not guess the file format of file '{file_name}'!")
|
odxtools/mem.py
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .datablock import Datablock
|
7
|
+
from .exceptions import odxraise
|
8
|
+
from .externflashdata import ExternFlashdata
|
9
|
+
from .flashdata import Flashdata
|
10
|
+
from .globals import xsi
|
11
|
+
from .internflashdata import InternFlashdata
|
12
|
+
from .nameditemlist import NamedItemList
|
13
|
+
from .odxdoccontext import OdxDocContext
|
14
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
15
|
+
from .session import Session
|
16
|
+
from .snrefcontext import SnRefContext
|
17
|
+
|
18
|
+
|
19
|
+
@dataclass(kw_only=True)
|
20
|
+
class Mem:
|
21
|
+
sessions: NamedItemList[Session]
|
22
|
+
datablocks: NamedItemList[Datablock]
|
23
|
+
flashdatas: NamedItemList[Flashdata]
|
24
|
+
|
25
|
+
@staticmethod
|
26
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "Mem":
|
27
|
+
sessions = NamedItemList([
|
28
|
+
Session.from_et(sess_elem, context)
|
29
|
+
for sess_elem in et_element.iterfind("SESSIONS/SESSION")
|
30
|
+
])
|
31
|
+
|
32
|
+
datablocks = NamedItemList([
|
33
|
+
Datablock.from_et(db_elem, context)
|
34
|
+
for db_elem in et_element.iterfind("DATABLOCKS/DATABLOCK")
|
35
|
+
])
|
36
|
+
|
37
|
+
flashdatas: NamedItemList[Flashdata] = NamedItemList()
|
38
|
+
for flashdata_elem in et_element.iterfind("FLASHDATAS/FLASHDATA"):
|
39
|
+
flashdata_type = flashdata_elem.attrib.get(f"{xsi}type")
|
40
|
+
if flashdata_type == "INTERN-FLASHDATA":
|
41
|
+
flashdatas.append(InternFlashdata.from_et(flashdata_elem, context))
|
42
|
+
elif flashdata_type == "EXTERN-FLASHDATA":
|
43
|
+
flashdatas.append(ExternFlashdata.from_et(flashdata_elem, context))
|
44
|
+
else:
|
45
|
+
odxraise(f"Encountered unknown flashdata type {flashdata_type}")
|
46
|
+
flashdatas.append(Flashdata.from_et(flashdata_elem, context))
|
47
|
+
|
48
|
+
return Mem(
|
49
|
+
sessions=sessions,
|
50
|
+
datablocks=datablocks,
|
51
|
+
flashdatas=flashdatas,
|
52
|
+
)
|
53
|
+
|
54
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
55
|
+
odxlinks = {}
|
56
|
+
|
57
|
+
for session in self.sessions:
|
58
|
+
odxlinks.update(session._build_odxlinks())
|
59
|
+
for datablock in self.datablocks:
|
60
|
+
odxlinks.update(datablock._build_odxlinks())
|
61
|
+
for flashdata in self.flashdatas:
|
62
|
+
odxlinks.update(flashdata._build_odxlinks())
|
63
|
+
|
64
|
+
return odxlinks
|
65
|
+
|
66
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
67
|
+
for session in self.sessions:
|
68
|
+
session._resolve_odxlinks(odxlinks)
|
69
|
+
for datablock in self.datablocks:
|
70
|
+
datablock._resolve_odxlinks(odxlinks)
|
71
|
+
for flashdata in self.flashdatas:
|
72
|
+
flashdata._resolve_odxlinks(odxlinks)
|
73
|
+
|
74
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
75
|
+
for session in self.sessions:
|
76
|
+
session._resolve_snrefs(context)
|
77
|
+
for datablock in self.datablocks:
|
78
|
+
datablock._resolve_snrefs(context)
|
79
|
+
for flashdata in self.flashdatas:
|
80
|
+
flashdata._resolve_snrefs(context)
|
odxtools/modification.py
CHANGED
@@ -7,6 +7,7 @@ from .exceptions import odxrequire
|
|
7
7
|
from .odxdoccontext import OdxDocContext
|
8
8
|
from .odxlink import OdxLinkDatabase, OdxLinkId
|
9
9
|
from .snrefcontext import SnRefContext
|
10
|
+
from .utils import strip_indent
|
10
11
|
|
11
12
|
|
12
13
|
@dataclass(kw_only=True)
|
@@ -16,8 +17,8 @@ class Modification:
|
|
16
17
|
|
17
18
|
@staticmethod
|
18
19
|
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "Modification":
|
19
|
-
change = odxrequire(et_element.findtext("CHANGE"))
|
20
|
-
reason = et_element.findtext("REASON")
|
20
|
+
change = odxrequire(strip_indent(et_element.findtext("CHANGE")))
|
21
|
+
reason = strip_indent(et_element.findtext("REASON"))
|
21
22
|
|
22
23
|
return Modification(change=change, reason=reason)
|
23
24
|
|
odxtools/negoffset.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from xml.etree import ElementTree
|
4
|
+
|
5
|
+
from .exceptions import odxrequire
|
6
|
+
from .odxdoccontext import OdxDocContext
|
7
|
+
from .targetaddroffset import TargetAddrOffset
|
8
|
+
from .utils import dataclass_fields_asdict, read_hex_binary
|
9
|
+
|
10
|
+
|
11
|
+
@dataclass(kw_only=True)
|
12
|
+
class NegOffset(TargetAddrOffset):
|
13
|
+
negative_offset: int
|
14
|
+
|
15
|
+
@staticmethod
|
16
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "NegOffset":
|
17
|
+
kwargs = dataclass_fields_asdict(TargetAddrOffset.from_et(et_element, context))
|
18
|
+
|
19
|
+
negative_offset = odxrequire(read_hex_binary(et_element.find("NEGATIVE-OFFSET")))
|
20
|
+
|
21
|
+
return NegOffset(negative_offset=negative_offset, **kwargs)
|
odxtools/ownident.py
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Any
|
4
|
+
from xml.etree import ElementTree
|
5
|
+
|
6
|
+
from .element import IdentifiableElement
|
7
|
+
from .exceptions import odxrequire
|
8
|
+
from .identvalue import IdentValue
|
9
|
+
from .odxdoccontext import OdxDocContext
|
10
|
+
from .odxlink import OdxLinkDatabase, OdxLinkId
|
11
|
+
from .snrefcontext import SnRefContext
|
12
|
+
from .utils import dataclass_fields_asdict
|
13
|
+
|
14
|
+
|
15
|
+
@dataclass(kw_only=True)
|
16
|
+
class OwnIdent(IdentifiableElement):
|
17
|
+
"""
|
18
|
+
Corresponds to OWN-IDENT.
|
19
|
+
"""
|
20
|
+
|
21
|
+
ident_value: IdentValue
|
22
|
+
|
23
|
+
@staticmethod
|
24
|
+
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "OwnIdent":
|
25
|
+
kwargs = dataclass_fields_asdict(IdentifiableElement.from_et(et_element, context))
|
26
|
+
|
27
|
+
ident_value = IdentValue.from_et(odxrequire(et_element.find("IDENT-VALUE")), context)
|
28
|
+
|
29
|
+
return OwnIdent(ident_value=ident_value, **kwargs)
|
30
|
+
|
31
|
+
def _build_odxlinks(self) -> dict[OdxLinkId, Any]:
|
32
|
+
return {self.odx_id: self}
|
33
|
+
|
34
|
+
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
|
35
|
+
pass
|
36
|
+
|
37
|
+
def _resolve_snrefs(self, context: SnRefContext) -> None:
|
38
|
+
pass
|
odxtools/physicaltype.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
from dataclasses import dataclass
|
3
3
|
from xml.etree import ElementTree
|
4
4
|
|
5
|
-
from .exceptions import odxraise
|
5
|
+
from .exceptions import odxraise, odxrequire
|
6
6
|
from .odxdoccontext import OdxDocContext
|
7
7
|
from .odxtypes import DataType
|
8
8
|
from .radix import Radix
|
@@ -31,27 +31,29 @@ class PhysicalType:
|
|
31
31
|
PhysicalType(DataType.A_FLOAT64, precision=2)
|
32
32
|
"""
|
33
33
|
|
34
|
+
#: Number of digits after the decimal point to display to the user
|
35
|
+
#: The precision is only applicable if the base data type is
|
36
|
+
#: A_FLOAT32 or A_FLOAT64.
|
34
37
|
precision: int | None = None
|
35
|
-
"""Number of digits after the decimal point to display to the user
|
36
|
-
The precision is only applicable if the base data type is A_FLOAT32 or A_FLOAT64.
|
37
|
-
"""
|
38
38
|
|
39
39
|
base_data_type: DataType
|
40
40
|
|
41
|
+
#: The display radix defines how integers are displayed to the
|
42
|
+
#: user. The display radix is only applicable if the base data type
|
43
|
+
#: is A_UINT32.
|
41
44
|
display_radix: Radix | None = None
|
42
|
-
"""The display radix defines how integers are displayed to the user.
|
43
|
-
The display radix is only applicable if the base data type is A_UINT32.
|
44
|
-
"""
|
45
45
|
|
46
46
|
@staticmethod
|
47
47
|
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "PhysicalType":
|
48
48
|
precision_str = et_element.findtext("PRECISION")
|
49
49
|
precision = int(precision_str) if precision_str is not None else None
|
50
50
|
|
51
|
-
base_data_type_str = et_element.get("BASE-DATA-TYPE")
|
52
|
-
|
51
|
+
base_data_type_str = odxrequire(et_element.attrib.get("BASE-DATA-TYPE"))
|
52
|
+
try:
|
53
|
+
base_data_type = DataType(base_data_type_str)
|
54
|
+
except ValueError:
|
53
55
|
odxraise(f"Encountered unknown base data type '{base_data_type_str}'")
|
54
|
-
|
56
|
+
base_data_type = None
|
55
57
|
|
56
58
|
display_radix_str = et_element.get("DISPLAY-RADIX")
|
57
59
|
if display_radix_str is not None:
|