From a8445df3a4acd226abefc636db2776138b44265b Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:18:57 +0100 Subject: [PATCH 1/7] Database: add `__repr__()` this allows to easily dump the contents of the whole database objects. Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/database.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/odxtools/database.py b/odxtools/database.py index 05e5d7fc..22d30ff8 100644 --- a/odxtools/database.py +++ b/odxtools/database.py @@ -167,3 +167,11 @@ def comparam_subsets(self) -> NamedItemList[ComparamSubset]: @property def comparam_specs(self) -> NamedItemList[ComparamSpec]: return self._comparam_specs + + def __repr__(self) -> str: + return f"Database(model_version={self.model_version}, " \ + f"protocols={[x.short_name for x in self.protocols]}, " \ + f"ecus={[x.short_name for x in self.ecus]}, " \ + f"diag_layer_containers={repr(self.diag_layer_containers)}, " \ + f"comparam_subsets={repr(self.comparam_subsets)}, " \ + f"comparam_specs={repr(self.comparam_specs)})" From e4fc231f7157f6f959dcb80727be476f8efb7381 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Thu, 11 Jan 2024 15:07:14 +0100 Subject: [PATCH 2/7] fix reading and writing of complex comparams it turns out that the sub-parameter definitions are not interspersed with the for their default values, but that after all sub-params are outlined, there is a single "COMPLEX-PHYSICAL-DEFAULT-VALUE" tag which defines the default for all of them. This makes a little more sense than my original interpretation of the spec, but I still have questions: - why is the list of subparameters not contained in a "" tag like almost everything else in ODX? - what is the point of specifying a default value for the complex physical parameter when the constituent parameters can define their own defaults? which values get priority? Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/complexcomparam.py | 31 ++++++++++--------- .../templates/macros/printComparam.xml.jinja2 | 6 ++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/odxtools/complexcomparam.py b/odxtools/complexcomparam.py index d4d1db81..f8d6764f 100644 --- a/odxtools/complexcomparam.py +++ b/odxtools/complexcomparam.py @@ -50,32 +50,35 @@ def from_et(et_element: ElementTree.Element, # ODX specification, this is a *major* pain in the butt! subparams: NamedItemList[BaseComparam] = NamedItemList() elems = list(et_element) + + # go to the first COMPARAM or COMPLEX-COMPARAM sub-element i = 0 + while i < len(elems): + if elems[i].tag in ("COMPARAM", "COMPLEX-COMPARAM"): + break + i += 1 + + # extract the sub-parameters while i < len(elems): if elems[i].tag not in ("COMPARAM", "COMPLEX-COMPARAM"): - i += 1 - continue + break subparam = create_any_comparam_from_et(elems[i], doc_frags) - # the next element in the list *may* hold the physical - # default value for the sub-parameter. if it is not the - # correct tag, skip it! Note that the ODX specification - # *only* allows to specify COMPLEX-PHYSICAL-DEFAULT-VALUE - # tags here, even if the sub-parameter was a simple - # parameter. This is probably a bug in the ODX - # specification... - if i + 1 < len(elems) and elems[i + 1].tag == "COMPLEX-PHYSICAL-DEFAULT-VALUE": - subparam.physical_default_value = create_complex_value_from_et(elems[i + 1]) - i += 1 - subparams.append(subparam) i += 1 + # extract the complex physical default value. (what's the + # purpose of this? the sub-parameters can define their own + # default values if a default is desired...) + complex_physical_default_value: Optional[ComplexValue] = None + if (cpdv_elem := et_element.find("COMPLEX-PHYSICAL-DEFAULT-VALUE")) is not None: + complex_physical_default_value = create_complex_value_from_et(cpdv_elem) + allow_multiple_values_raw = odxstr_to_bool(et_element.get("ALLOW-MULTIPLE-VALUES")) return ComplexComparam( subparams=subparams, - physical_default_value=[], + physical_default_value=complex_physical_default_value, allow_multiple_values_raw=allow_multiple_values_raw, **kwargs) diff --git a/odxtools/templates/macros/printComparam.xml.jinja2 b/odxtools/templates/macros/printComparam.xml.jinja2 index b801fcd9..ca3efcd5 100644 --- a/odxtools/templates/macros/printComparam.xml.jinja2 +++ b/odxtools/templates/macros/printComparam.xml.jinja2 @@ -60,9 +60,9 @@ {{ peid.printElementIdSubtags(cp)|indent(1) }} {%- for sub_cp in cp.subparams %} {{- printAnyComparam(sub_cp) | indent(1, first=True) }} - {%- if hasattr(sub_cp, 'subparams') and sub_cp.physical_default_value is not none %} - {{ printComplexValue(sub_cp.physical_default_value, "COMPLEX-PHYSICAL-DEFAULT-VALUE") | indent(1) }} - {%- endif %} {%- endfor %} + {%- if cp.physical_default_value is not none %} + {{ printComplexValue(cp.physical_default_value, "COMPLEX-PHYSICAL-DEFAULT-VALUE") | indent(1) }} + {%- endif %} {%- endmacro %} From f0625a5a3ae698eda345f5523fd4211af1284e96 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:22:04 +0100 Subject: [PATCH 3/7] fix writing of SCALE-CONSTR the SCALE-LABEL subtag can only be omitted if the corresponding attribute is `None`. Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/templates/macros/printDOP.xml.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odxtools/templates/macros/printDOP.xml.jinja2 b/odxtools/templates/macros/printDOP.xml.jinja2 index bad940c7..eced5568 100644 --- a/odxtools/templates/macros/printDOP.xml.jinja2 +++ b/odxtools/templates/macros/printDOP.xml.jinja2 @@ -54,7 +54,7 @@ {%- macro printScaleConstr(sc) %} - {%- if sc.short_label and sc.short_label.strip() %} + {%- if sc.short_label is not none %} {{sc.short_label|e}} {%- endif %} {%- if sc.description and sc.description.strip() %} From b55efc63439ce9f243487a4c53fa92047974876c Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:26:04 +0100 Subject: [PATCH 4/7] fix writing of DIAG-COMM and its derivatives Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- .../templates/macros/printDiagComm.xml.jinja2 | 16 ++--- .../templates/macros/printService.xml.jinja2 | 60 +++++++++++-------- .../macros/printSingleEcuJob.xml.jinja2 | 54 ++++++++--------- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/odxtools/templates/macros/printDiagComm.xml.jinja2 b/odxtools/templates/macros/printDiagComm.xml.jinja2 index e6aa187e..980e43c4 100644 --- a/odxtools/templates/macros/printDiagComm.xml.jinja2 +++ b/odxtools/templates/macros/printDiagComm.xml.jinja2 @@ -8,17 +8,17 @@ {%- import('macros/printAudience.xml.jinja2') as paud %} {%- import('macros/printSpecialData.xml.jinja2') as psd %} -{%- macro printDiagCommOpenTag(dc, dcTagName) -%} -<{{dcTagName}} ID="{{dc.odx_id.local_id}}" - {{-make_xml_attrib("SEMANTIC", dc.semantic)}} - {{-make_xml_attrib("DIAGNOSTIC-CLASS", dc.diagnostic_class and dc.diagnostic_class.value)}} - {{-make_bool_xml_attrib("IS-MANDATORY", dc.is_mandatory_raw)}} - {{-make_bool_xml_attrib("IS-EXECUTABLE", dc.is_executable_raw)}} - {{-make_bool_xml_attrib("IS-FINAL", dc.is_final_raw)}}> +{%- macro printDiagCommAttribs(dc) -%} +ID="{{dc.odx_id.local_id}}" +{{-make_xml_attrib("SEMANTIC", dc.semantic)}} +{{-make_xml_attrib("DIAGNOSTIC-CLASS", dc.diagnostic_class and dc.diagnostic_class.value)}} +{{-make_bool_xml_attrib("IS-MANDATORY", dc.is_mandatory_raw)}} +{{-make_bool_xml_attrib("IS-EXECUTABLE", dc.is_executable_raw)}} +{{-make_bool_xml_attrib("IS-FINAL", dc.is_final_raw)}} {%- endmacro -%} -{%- macro printDiagCommElems(dc) -%} +{%- macro printDiagCommSubtags(dc) -%} {{ peid.printElementIdSubtags(dc)|indent(1) }} {%- if dc.admin_data %} {{- pad.printAdminData(dc.admin_data)|indent(1, first=True) }} diff --git a/odxtools/templates/macros/printService.xml.jinja2 b/odxtools/templates/macros/printService.xml.jinja2 index 13e88526..9aa2aa0c 100644 --- a/odxtools/templates/macros/printService.xml.jinja2 +++ b/odxtools/templates/macros/printService.xml.jinja2 @@ -6,31 +6,39 @@ {%- import('macros/printDiagComm.xml.jinja2') as pdc %} {%- macro printService(service) -%} -{{pdc.printDiagCommOpenTag(service, "DIAG-SERVICE") }} -{{pdc.printDiagCommElems(service) | indent(1, first=True) }} -{%- if service.comparam_refs %} - -{%- for ref in service.comparam_refs %} - -{%- endfor %} - -{%- endif%} -{%- if service.request_ref %} - -{%- endif %} -{%- if service.pos_response_refs %} - -{%- for ref in service.pos_response_refs %} - -{%- endfor %} - -{%- endif%} -{%- if service.neg_response_refs %} - -{%- for ref in service.neg_response_refs %} - -{%- endfor %} - -{%- endif%} + + {%- endif %}> + {{pdc.printDiagCommSubtags(service) | indent(1, first=True) }} + {%- if service.comparam_refs %} + + {%- for ref in service.comparam_refs %} + + {%- endfor %} + + {%- endif%} + {%- if service.request_ref %} + + {%- endif %} + {%- if service.pos_response_refs %} + + {%- for ref in service.pos_response_refs %} + + {%- endfor %} + + {%- endif%} + {%- if service.neg_response_refs %} + + {%- for ref in service.neg_response_refs %} + + {%- endfor %} + + {%- endif%} {%- endmacro -%} diff --git a/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 b/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 index 0671909b..a9e6a22a 100644 --- a/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 +++ b/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 @@ -7,34 +7,34 @@ {%- import('macros/printDiagComm.xml.jinja2') as pdc %} {%- macro printSingleEcuJob(job) -%} -{{pdc.printDiagCommOpenTag(job, "SINGLE-ECU-JOB") }} -{{pdc.printDiagCommElems(job) | indent(1, first=True) }} + + {{pdc.printDiagCommSubtags(job) | indent(2, first=True) }} -{%- for prog in job.prog_codes %} - {{ printProgCode(prog)|indent(2) }} -{%- endfor %} - -{%- if job.input_params %} - -{%- for param in job.input_params %} - {{ printInputParam(param)|indent(2) }} -{%- endfor %} - -{%- endif %} -{%- if job.output_params %} - -{%- for param in job.output_params %} - {{ printOutputParam(param)|indent(2) }} -{%- endfor %} - -{%- endif %} -{%- if job.neg_output_params %} - -{%- for param in job.neg_output_params %} - {{ printNegOutputParam(param)|indent(2) }} -{%- endfor %} - -{%- endif %} + {%- for prog in job.prog_codes %} + {{ printProgCode(prog)|indent(4) }} + {%- endfor %} + + {%- if job.input_params %} + + {%- for param in job.input_params %} + {{ printInputParam(param)|indent(4) }} + {%- endfor %} + + {%- endif %} + {%- if job.output_params %} + + {%- for param in job.output_params %} + {{ printOutputParam(param)|indent(4) }} + {%- endfor %} + + {%- endif %} + {%- if job.neg_output_params %} + + {%- for param in job.neg_output_params %} + {{ printNegOutputParam(param)|indent(4) }} + {%- endfor %} + + {%- endif %} {%- endmacro -%} From fb6252a6f8e9dfe734bed1f2693c13705bfb012f Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:29:48 +0100 Subject: [PATCH 5/7] write the ECU variant patterns Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- .../macros/printEcuVariantPattern.xml.jinja2 | 27 +++++++++++++++++++ .../templates/macros/printVariant.xml.jinja2 | 10 +++++++ 2 files changed, 37 insertions(+) create mode 100644 odxtools/templates/macros/printEcuVariantPattern.xml.jinja2 diff --git a/odxtools/templates/macros/printEcuVariantPattern.xml.jinja2 b/odxtools/templates/macros/printEcuVariantPattern.xml.jinja2 new file mode 100644 index 00000000..393838ca --- /dev/null +++ b/odxtools/templates/macros/printEcuVariantPattern.xml.jinja2 @@ -0,0 +1,27 @@ +{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*- + # + # SPDX-License-Identifier: MIT +-#} + +{%- import('macros/printElementId.xml.jinja2') as peid %} +{%- import('macros/printState.xml.jinja2') as ps %} +{%- import('macros/printStateTransition.xml.jinja2') as pst %} + +{%- macro printMatchingParameter(mp) -%} + + {{mp.expected_value}} + + {#- TODO: OUT-PARAM-IF-SNPATHREF #} + + +{%- endmacro -%} + +{%- macro printEcuVariantPattern(vp) -%} + + + {%- for mp in vp.matching_parameters %} + {{ printMatchingParameter(mp) | indent(2) }} + {%- endfor %} + + +{%- endmacro -%} diff --git a/odxtools/templates/macros/printVariant.xml.jinja2 b/odxtools/templates/macros/printVariant.xml.jinja2 index 92772392..6bdac9aa 100644 --- a/odxtools/templates/macros/printVariant.xml.jinja2 +++ b/odxtools/templates/macros/printVariant.xml.jinja2 @@ -23,6 +23,7 @@ {%- import('macros/printStateChart.xml.jinja2') as psc %} {%- import('macros/printAudience.xml.jinja2') as paud %} {%- import('macros/printSpecialData.xml.jinja2') as psd %} +{%- import('macros/printEcuVariantPattern.xml.jinja2') as pvpat %} {%- macro printVariant(dl) -%} {%- set dlr = dl.diag_layer_raw %} @@ -181,6 +182,15 @@ {%- endfor %} {%- endif %} +{%- if dlr.variant_type.value == "ECU-VARIANT" %} + {%- if dlr.ecu_variant_patterns %} + + {%- for vp in dlr.ecu_variant_patterns -%} + {{ pvpat.printEcuVariantPattern(vp)|indent(2) }} + {%- endfor -%} + + {%- endif %} +{%- endif %} {%- if dlr.variant_type.value == "PROTOCOL" %} {%- if dlr.prot_stack_snref is not none %} From dcb096c6f9bb72e46e2157cefe87741ddc86bed1 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:32:12 +0100 Subject: [PATCH 6/7] fix writing of end-of-PDU fields the {MAX,MIN}-NUMBER-OF-ITEMS subtags were missing. Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/templates/macros/printEndOfPdu.xml.jinja2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/odxtools/templates/macros/printEndOfPdu.xml.jinja2 b/odxtools/templates/macros/printEndOfPdu.xml.jinja2 index 83ac1bc9..2f1cef45 100644 --- a/odxtools/templates/macros/printEndOfPdu.xml.jinja2 +++ b/odxtools/templates/macros/printEndOfPdu.xml.jinja2 @@ -9,5 +9,11 @@ {{ peid.printElementIdSubtags(eopdu)|indent(1) }} + {%- if eopdu.max_number_of_items is not none %} + {{eopdu.max_number_of_items}} + {%- endif %} + {%- if eopdu.min_number_of_items is not none %} + {{eopdu.min_number_of_items}} + {%- endif %} {%- endmacro -%} From e30a6e8302a497b6f22cd1232582cb92cbdd39fc Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 12 Jan 2024 15:34:19 +0100 Subject: [PATCH 7/7] printEnvData macro: determine if ALL-VALUE ought to be used by looking at `.dtc_values` for some reason, this is more stable. Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/templates/macros/printEnvData.xml.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odxtools/templates/macros/printEnvData.xml.jinja2 b/odxtools/templates/macros/printEnvData.xml.jinja2 index 2a7f9e6e..fd0ac9c8 100644 --- a/odxtools/templates/macros/printEnvData.xml.jinja2 +++ b/odxtools/templates/macros/printEnvData.xml.jinja2 @@ -9,7 +9,7 @@ {%- macro printEnvData(env_data) %} {{ pbs.printBasicStructureSubtags(env_data)|indent(1) }} - {%- if env_data.all_value %} + {%- if not env_data.dtc_values %} {%- else %}