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/database.py b/odxtools/database.py index 896293c4..5b93c199 100644 --- a/odxtools/database.py +++ b/odxtools/database.py @@ -164,3 +164,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)})" 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 %} 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() %} 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/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/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 -%} 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 %} 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 -%} 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 %}