Skip to content

Commit

Permalink
Merge pull request mercedes-benz#231 from andlaus/DiagComm
Browse files Browse the repository at this point in the history
add DiagComm as a base class for all diagnostic communication objects
  • Loading branch information
andlaus authored Nov 2, 2023
2 parents dad9c2d + 1d1b201 commit 13d8fde
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 391 deletions.
99 changes: 95 additions & 4 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=None,
pre_condition_state_refs=[],
state_transition_refs=[],
Expand All @@ -1597,6 +1608,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=None,
pre_condition_state_refs=[],
state_transition_refs=[],
Expand All @@ -1620,6 +1642,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=Audience(
enabled_audience_refs=[
OdxLinkRef.from_id(somersault_additional_audiences["attentive_admirer"].odx_id),
Expand Down Expand Up @@ -1652,6 +1685,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=None,
functional_class_refs=[],
pre_condition_state_refs=[],
Expand All @@ -1673,6 +1717,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description="<p>Do a forward flip.</p>",
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=Audience(
enabled_audience_refs=[
OdxLinkRef.from_id(somersault_additional_audiences["attentive_admirer"].odx_id)
Expand Down Expand Up @@ -1713,6 +1768,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=Audience(
enabled_audience_refs=[
OdxLinkRef.from_id(somersault_additional_audiences["attentive_admirer"].odx_id)
Expand Down Expand Up @@ -1747,6 +1813,17 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=Audience(
disabled_audience_refs=[
OdxLinkRef.from_id(somersault_additional_audiences["attentive_admirer"].odx_id)
Expand Down Expand Up @@ -1776,7 +1853,6 @@ class SomersaultSID(IntEnum):
somersault_single_ecu_jobs = {
"compulsory_program":
SingleEcuJob(
oid=None,
audience=None,
odx_id=OdxLinkId("somersault.service.compulsory_program", doc_frags),
short_name="compulsory_program",
Expand All @@ -1785,6 +1861,10 @@ class SomersaultSID(IntEnum):
admin_data=None,
semantic=None,
functional_class_refs=[],
protocol_snrefs=[],
related_diag_comm_refs=[],
pre_condition_state_refs=[],
state_transition_refs=[],
diagnostic_class=None,
prog_codes=[
ProgCode(
Expand All @@ -1796,9 +1876,9 @@ class SomersaultSID(IntEnum):
library_refs=[],
),
],
input_params=[],
output_params=[],
neg_output_params=[],
input_params=NamedItemList(),
output_params=NamedItemList(),
neg_output_params=NamedItemList(),
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
Expand Down Expand Up @@ -2152,6 +2232,12 @@ class SomersaultSID(IntEnum):
long_name=None,
description=None,
admin_data=None,
protocol_snrefs=[],
related_diag_comm_refs=[],
diagnostic_class=None,
is_mandatory_raw=None,
is_executable_raw=None,
is_final_raw=None,
semantic=None,
functional_class_refs=[],
pre_condition_state_refs=[],
Expand All @@ -2164,6 +2250,11 @@ class SomersaultSID(IntEnum):
neg_response_refs=[
OdxLinkRef.from_id(somersault_assiduous_negative_responses["fell_over"].odx_id),
],
comparam_refs=NamedItemList[CommunicationParameterRef](),
is_cyclic_raw=None,
is_multiple_raw=None,
addressing_raw=None,
transmission_mode_raw=None,
audience=Audience(
enabled_audience_refs=[
OdxLinkRef.from_id(somersault_additional_audiences["attentive_admirer"].odx_id)
Expand Down
11 changes: 7 additions & 4 deletions odxtools/cli/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def print_summary(
decode: bool = False,
) -> None:
ecu_names = ecu_variants if ecu_variants else [ecu.short_name for ecu in odxdb.ecus]
services: Dict[DiagService, List[str]] = {}
service_db: Dict[str, DiagService] = {}
service_ecus: Dict[str, List[str]] = {}
for ecu_name in ecu_names:
ecu = odxdb.ecus[ecu_name]
if not ecu:
Expand All @@ -39,12 +40,14 @@ def print_summary(
if data:
found_services = ecu._find_services_for_uds(data)
for found_service in found_services:
ecu_names = services.get(found_service, [])
ecu_names = service_ecus.get(found_service.short_name, [])
ecu_names.append(ecu_name)
services[found_service] = ecu_names
service_ecus[found_service.short_name] = ecu_names
service_db[found_service.short_name] = found_service

print(f"Binary data: {data.hex(' ')}")
for service, ecu_names in services.items():
for service_name, ecu_names in service_ecus.items():
service = service_db[service_name]
if isinstance(service, DiagService):
print(
f"Decoded by service '{service.short_name}' (decoding ECUs: {', '.join(ecu_names)})"
Expand Down
11 changes: 7 additions & 4 deletions odxtools/cli/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def print_summary(odxdb: Database,
allow_unknown_bit_lengths: bool = False,
print_params: bool = False) -> None:
ecu_names = ecu_variants if ecu_variants else [ecu.short_name for ecu in odxdb.ecus]
services: Dict[DiagService, List[str]] = {}
service_db: Dict[str, DiagService] = {}
service_ecus: Dict[str, List[str]] = {}
for ecu_name in ecu_names:
ecu = odxdb.ecus[ecu_name]
if not ecu:
Expand All @@ -39,11 +40,13 @@ def print_summary(odxdb: Database,
for service_name_search in service_names:
for service in ecu.services:
if service_name_search.lower() in service.short_name.lower():
ecu_names = services.get(service, [])
ecu_names = service_ecus.get(service.short_name, [])
ecu_names.append(ecu_name)
services[service] = ecu_names
service_ecus[service.short_name] = ecu_names
service_db[service.short_name] = service

for service, ecu_names in services.items():
for service_name, ecu_names in service_ecus.items():
service = service_db[service_name]
display_names = ", ".join(ecu_names)
filler = str.ljust("", len(display_names), "=")
print(f"\n{filler}")
Expand Down
10 changes: 5 additions & 5 deletions odxtools/cli/list.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# SPDX-License-Identifier: MIT
import argparse
from typing import Callable, List, Optional, Union
from typing import Callable, List, Optional

from ..database import Database
from ..diagcomm import DiagComm
from ..diaglayer import DiagLayer
from ..diagservice import DiagService
from ..singleecujob import SingleEcuJob
Expand All @@ -25,7 +26,7 @@ def print_summary(
print_audiences: bool = False,
allow_unknown_bit_lengths: bool = False,
variants: Optional[str] = None,
service_filter: Callable[[Union[DiagService, SingleEcuJob]], bool] = lambda x: True,
service_filter: Callable[[DiagComm], bool] = lambda x: True,
) -> None:

diag_layer_names = variants if variants else [dl.short_name for dl in odxdb.diag_layers]
Expand All @@ -37,8 +38,7 @@ def print_summary(
continue

assert isinstance(dl, DiagLayer)
all_services: List[Union[DiagService, SingleEcuJob]] = sorted(
dl.services, key=lambda x: x.short_name)
all_services: List[DiagComm] = sorted(dl.services, key=lambda x: x.short_name)

data_object_properties = dl.diag_data_dictionary_spec.data_object_props
com_params = dl.communication_parameters
Expand Down Expand Up @@ -182,7 +182,7 @@ def add_subparser(subparsers: "argparse._SubParsersAction") -> None:
def run(args: argparse.Namespace) -> None:
odxdb = _parser_utils.load_file(args)

def service_filter(s: Union[DiagService, SingleEcuJob]) -> bool:
def service_filter(s: DiagComm) -> bool:
if args.services and len(args.services) > 0:
return s.short_name in args.services
return True
Expand Down
Loading

0 comments on commit 13d8fde

Please sign in to comment.