Skip to content

Commit

Permalink
remove the "CANdela workaround" hacks
Browse files Browse the repository at this point in the history
The reason for these were that CANdela uses different communication
parameter specifications than the ones specified by the `odx-cs` files
that are shipped with the ODX standard. This resulted in a different
ordering for some of the complex communication parameters (albeit with
all required fields being present). Fortunately, with mercedes-benz#92 merged, this
became unnecessary.

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Alexander Walz <alexander.walz@mbition.io>
  • Loading branch information
andlaus committed Nov 17, 2022
1 parent 540f2a8 commit 5ed214a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 49 deletions.
2 changes: 0 additions & 2 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,6 @@ def extract_constant_bytes(params):
],
)],
communication_parameters=somersault_communication_parameters,
enable_candela_workarounds=False,
)

##################
Expand All @@ -1163,7 +1162,6 @@ def extract_constant_bytes(params):
# this variant does everything which the base variant does
)],
communication_parameters=somersault_communication_parameters,
enable_candela_workarounds=False,
)

# the assiduous ECU also does headstands...
Expand Down
10 changes: 1 addition & 9 deletions odxtools/cli/_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@ def add_pdx_argument(parser):
"pdx_file", metavar="PDX_FILE", help="path to the .pdx file")
#parser.add_argument("pdx_files", metavar="PDX_FILES", nargs="+", help="PDX descriptions of all ECUs which shall be analyzed")

# do not enable the CANdela workarounds. Note that we disable then
# by default because CANdela is by far the most common tool to
# work with ODX.
# Note that the short option "-c" is reserved for the "--channel" of the snoop command.
parser.add_argument("--conformant", default=False, action='store_const', const=True,
required=False, help="The input file fully confirms to the standard, i.e., disable work-arounds for bugs of the CANdela tool")


def load_file(args):
db_file_name = args.pdx_file
odxdb = None
if db_file_name is not None:
odxdb = _load_file(db_file_name,
enable_candela_workarounds=not args.conformant)
odxdb = _load_file(db_file_name)
return odxdb
6 changes: 2 additions & 4 deletions odxtools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class Database:

def __init__(self,
pdx_zip: Optional[ZipFile] = None,
odx_d_file_name: Optional[str] = None,
enable_candela_workarounds: bool = True):
odx_d_file_name: Optional[str] = None):

if pdx_zip is None and odx_d_file_name is None:
# create an empty database object
Expand Down Expand Up @@ -62,8 +61,7 @@ def __init__(self,
dlc = root.find("DIAG-LAYER-CONTAINER")
if dlc is not None:
dlcs.append(read_diag_layer_container_from_odx(
dlc,
enable_candela_workarounds=enable_candela_workarounds
dlc
))
# In ODX 2.0 there was only COMPARAM-SPEC
# In ODX 2.2 content of COMPARAM-SPEC was renamed to COMPARAM-SUBSET
Expand Down
35 changes: 12 additions & 23 deletions odxtools/diaglayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional, Any, Dict, Iterable, List, Union
from copy import copy
import warnings
from xml.etree import ElementTree

from .utils import short_name_as_id
from .exceptions import DecodeError, OdxWarning
Expand Down Expand Up @@ -107,7 +108,6 @@ def __init__(self,
diag_data_dictionary_spec: Optional[DiagDataDictionarySpec] = None,
communication_parameters:
Iterable[CommunicationParameterRef] = [],
enable_candela_workarounds=True,
odxlinks=None,
additional_audiences=[],
functional_classes=[],
Expand Down Expand Up @@ -164,9 +164,6 @@ def __init__(self,
if odxlinks is not None:
self.finalize_init(odxlinks)

# specify whether enable work arounds for bugs of CANdela studio
self._enable_candela_workarounds = enable_candela_workarounds

@property
def services(self) -> NamedItemList[Union[DiagService, SingleEcuJob]]:
"""All services that this diagnostic layer offers including inherited services."""
Expand Down Expand Up @@ -465,7 +462,7 @@ def get_receive_id(self) -> Optional[int]:
value = com_param.value
if not isinstance(value, dict):
return None

return value.get('CP_CanPhysReqId', None)

def get_send_id(self) -> Optional[int]:
Expand Down Expand Up @@ -530,8 +527,7 @@ def __repr__(self) -> str:
diag_comm_refs={self._diag_comm_refs},
parent_refs={self.parent_refs},
diag_data_dictionary_spec={self.local_diag_data_dictionary_spec},
communication_parameters={self._local_communication_parameters},
enable_candela_workarounds={self._enable_candela_workarounds})"""
communication_parameters={self._local_communication_parameters})"""

def __str__(self) -> str:
return f"DiagLayer('{self.short_name}', type='{self.variant_type}')"
Expand All @@ -557,14 +553,14 @@ def read_parent_ref_from_odx(et_element, doc_frags: List[OdxDocFragment]) \
)


def read_diag_layer_from_odx(et_element,
doc_frags: List[OdxDocFragment],
enable_candela_workarounds=True) \
def read_diag_layer_from_odx(et_element: ElementTree.Element,
doc_frags: List[OdxDocFragment]) \
-> DiagLayer:

variant_type = et_element.tag

short_name = et_element.findtext("SHORT-NAME")
assert short_name is not None
long_name = et_element.findtext("LONG-NAME")
description = read_description_from_odx(et_element.find("DESC"))

Expand Down Expand Up @@ -664,13 +660,11 @@ def read_diag_layer_from_odx(et_element,
functional_classes=functional_classes,
states=states,
state_transitions=state_transitions,
enable_candela_workarounds=enable_candela_workarounds,
import_refs=import_refs,
)

return dl


class DiagLayerContainer:
def __init__(self,
odx_id: OdxLinkId,
Expand Down Expand Up @@ -736,7 +730,7 @@ def __str__(self) -> str:
return f"DiagLayerContainer('{self.short_name}')"


def read_diag_layer_container_from_odx(et_element, enable_candela_workarounds=True):
def read_diag_layer_container_from_odx(et_element):
short_name = et_element.findtext("SHORT-NAME")
assert short_name is not None
long_name = et_element.findtext("LONG-NAME")
Expand All @@ -751,24 +745,19 @@ def read_diag_layer_container_from_odx(et_element, enable_candela_workarounds=Tr
admin_data = read_admin_data_from_odx(et_element.find("ADMIN-DATA"), doc_frags)
company_datas = read_company_datas_from_odx(et_element.find("COMPANY-DATAS"), doc_frags)
ecu_shared_datas = [read_diag_layer_from_odx(dl_element,
doc_frags,
enable_candela_workarounds=enable_candela_workarounds)
doc_frags)
for dl_element in et_element.iterfind("ECU-SHARED-DATAS/ECU-SHARED-DATA")]
protocols = [read_diag_layer_from_odx(dl_element,
doc_frags,
enable_candela_workarounds=enable_candela_workarounds)
doc_frags)
for dl_element in et_element.iterfind("PROTOCOLS/PROTOCOL")]
functional_groups = [read_diag_layer_from_odx(dl_element,
doc_frags,
enable_candela_workarounds=enable_candela_workarounds)
doc_frags)
for dl_element in et_element.iterfind("FUNCTIONAL-GROUPS/FUNCTIONAL-GROUP")]
base_variants = [read_diag_layer_from_odx(dl_element,
doc_frags,
enable_candela_workarounds=enable_candela_workarounds)
doc_frags)
for dl_element in et_element.iterfind("BASE-VARIANTS/BASE-VARIANT")]
ecu_variants = [read_diag_layer_from_odx(dl_element,
doc_frags,
enable_candela_workarounds=enable_candela_workarounds)
doc_frags)
for dl_element in et_element.iterfind("ECU-VARIANTS/ECU-VARIANT")]

return DiagLayerContainer(odx_id,
Expand Down
6 changes: 3 additions & 3 deletions odxtools/load_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from .load_pdx_file import load_pdx_file
from .load_odx_d_file import load_odx_d_file

def load_file(file_name: str, enable_candela_workarounds: bool = True):
def load_file(file_name: str):
if file_name.lower().endswith(".pdx"):
return load_pdx_file(file_name, enable_candela_workarounds=enable_candela_workarounds)
return load_pdx_file(file_name)
elif file_name.lower().endswith(".odx-d"):
return load_odx_d_file(file_name, enable_candela_workarounds=enable_candela_workarounds)
return load_odx_d_file(file_name)
else:
raise RuntimeError(f"Could not guess the file format of file '{file_name}'!")
5 changes: 2 additions & 3 deletions odxtools/load_odx_d_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from .database import Database
from .globals import logger

def load_odx_d_file(odx_d_file_name: str, enable_candela_workarounds: bool = True):
container = Database(odx_d_file_name=odx_d_file_name,
enable_candela_workarounds=enable_candela_workarounds)
def load_odx_d_file(odx_d_file_name: str):
container = Database(odx_d_file_name=odx_d_file_name)
logger.info(f"--- --- --- Done with parsing --- --- ---")
return container
4 changes: 2 additions & 2 deletions odxtools/load_pdx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .database import Database
from .globals import logger

def load_pdx_file(pdx_file: str, enable_candela_workarounds: bool = True):
def load_pdx_file(pdx_file: str):
u = ZipFile(pdx_file)
container = Database(pdx_zip=u, enable_candela_workarounds=enable_candela_workarounds)
container = Database(pdx_zip=u)
logger.info(f"--- --- --- Done with parsing --- --- ---")
return container
3 changes: 1 addition & 2 deletions tests/test_odxtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from odxtools.load_pdx_file import load_pdx_file
from odxtools.odxlink import OdxLinkRef, OdxDocFragment

odxdb = load_pdx_file("./examples/somersault.pdx",
enable_candela_workarounds=False)
odxdb = load_pdx_file("./examples/somersault.pdx")

# use the diag layer container's document fragments as the default for
# resolving references
Expand Down
2 changes: 1 addition & 1 deletion tests/test_somersault.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
except ImportError:
from io import StringIO

odxdb = load_pdx_file("./examples/somersault.pdx", enable_candela_workarounds=False)
odxdb = load_pdx_file("./examples/somersault.pdx")

class TestDatabase(unittest.TestCase):

Expand Down

0 comments on commit 5ed214a

Please sign in to comment.