Skip to content

Commit

Permalink
Merge pull request #248 from mercedes-benz/hotfix/odx_2.0
Browse files Browse the repository at this point in the history
Fix ODX 2.0 compatibility
  • Loading branch information
andlaus authored Dec 8, 2023
2 parents f9777bc + 9132677 commit c295a76
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions odxtools/basecomparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) ->

# Required in ODX 2.2, missing in ODX 2.0
cpusage_str = et_element.attrib.get("CPUSAGE")
cpusage = None
if cpusage_str is not None:
try:
cpusage = Usage(cpusage_str)
Expand Down
11 changes: 4 additions & 7 deletions odxtools/database.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# SPDX-License-Identifier: MIT
from itertools import chain
from pathlib import Path
from typing import List, Optional, Tuple
from typing import List, Optional
from xml.etree import ElementTree
from zipfile import ZipFile
from packaging.version import Version

from .comparamspec import ComparamSpec
from .comparamsubset import ComparamSubset
Expand All @@ -14,10 +15,6 @@
from .odxlink import OdxLinkDatabase


def version(v: str) -> Tuple[int, ...]:
return tuple(map(int, (v.split("."))))


class Database:
"""This class internalizes the diagnostic database for various ECUs
described by a collection of ODX files which are usually collated
Expand Down Expand Up @@ -62,7 +59,7 @@ def __init__(self,
comparam_specs: List[ComparamSpec] = []
for root in documents:
# ODX spec version
model_version = version(root.attrib.get("MODEL-VERSION", "2.0"))
model_version = Version(root.attrib.get("MODEL-VERSION", "2.0"))
if self.model_version is not None and self.model_version != model_version:
odxraise(f"Different ODX versions used in the same file (ODX {model_version} "
f"and ODX {self.model_version}")
Expand All @@ -81,7 +78,7 @@ def __init__(self,

cp_spec = root.find("COMPARAM-SPEC")
if cp_spec is not None:
if model_version == "2.0":
if model_version < Version("2.2"):
comparam_subsets.append(ComparamSubset.from_et(cp_spec, []))
else: # odx >= 2.2
comparam_specs.append(ComparamSpec.from_et(cp_spec, []))
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies = [
"python-can >= 4.2",
"markdownify >= 0.11",
"deprecation >= 2.1",
"packaging",
]
dynamic = ["version"]

Expand Down

0 comments on commit c295a76

Please sign in to comment.