Skip to content

Commit

Permalink
Merge pull request #253 from andlaus/writing_fixes
Browse files Browse the repository at this point in the history
Writing fixes
  • Loading branch information
andlaus authored Jan 18, 2024
2 parents e3d1bfd + e30a6e8 commit 7a41b12
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 80 deletions.
31 changes: 17 additions & 14 deletions odxtools/complexcomparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions odxtools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})"
6 changes: 3 additions & 3 deletions odxtools/templates/macros/printComparam.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
</COMPLEX-COMPARAM>
{%- endmacro %}
2 changes: 1 addition & 1 deletion odxtools/templates/macros/printDOP.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

{%- macro printScaleConstr(sc) %}
<SCALE-CONSTR VALIDITY="{{sc.validity.value}}">
{%- if sc.short_label and sc.short_label.strip() %}
{%- if sc.short_label is not none %}
<SHORT-LABEL>{{sc.short_label|e}}</SHORT-LABEL>
{%- endif %}
{%- if sc.description and sc.description.strip() %}
Expand Down
16 changes: 8 additions & 8 deletions odxtools/templates/macros/printDiagComm.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
Expand Down
27 changes: 27 additions & 0 deletions odxtools/templates/macros/printEcuVariantPattern.xml.jinja2
Original file line number Diff line number Diff line change
@@ -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) -%}
<MATCHING-PARAMETER>
<EXPECTED-VALUE>{{mp.expected_value}}</EXPECTED-VALUE>
<DIAG-COMM-SNREF SHORT-NAME="{{mp.diag_comm_snref}}" />
{#- TODO: OUT-PARAM-IF-SNPATHREF #}
<OUT-PARAM-IF-SNREF SHORT-NAME="{{mp.out_param_if}}" />
</MATCHING-PARAMETER>
{%- endmacro -%}

{%- macro printEcuVariantPattern(vp) -%}
<ECU-VARIANT-PATTERN>
<MATCHING-PARAMETERS>
{%- for mp in vp.matching_parameters %}
{{ printMatchingParameter(mp) | indent(2) }}
{%- endfor %}
</MATCHING-PARAMETERS>
</ECU-VARIANT-PATTERN>
{%- endmacro -%}
6 changes: 6 additions & 0 deletions odxtools/templates/macros/printEndOfPdu.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
<END-OF-PDU-FIELD ID="{{eopdu.odx_id.local_id}}">
{{ peid.printElementIdSubtags(eopdu)|indent(1) }}
<BASIC-STRUCTURE-REF ID-REF="{{eopdu.structure_ref.ref_id}}" />
{%- if eopdu.max_number_of_items is not none %}
<MAX-NUMBER-OF-ITEMS>{{eopdu.max_number_of_items}}</MAX-NUMBER-OF-ITEMS>
{%- endif %}
{%- if eopdu.min_number_of_items is not none %}
<MIN-NUMBER-OF-ITEMS>{{eopdu.min_number_of_items}}</MIN-NUMBER-OF-ITEMS>
{%- endif %}
</END-OF-PDU-FIELD>
{%- endmacro -%}
2 changes: 1 addition & 1 deletion odxtools/templates/macros/printEnvData.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%- macro printEnvData(env_data) %}
<ENV-DATA {{ pbs.printBasicStructureAttribs(env_data) }}>
{{ pbs.printBasicStructureSubtags(env_data)|indent(1) }}
{%- if env_data.all_value %}
{%- if not env_data.dtc_values %}
<ALL-VALUE/>
{%- else %}
<DTC-VALUES>
Expand Down
60 changes: 34 additions & 26 deletions odxtools/templates/macros/printService.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<COMPARAM-REFS>
{%- for ref in service.comparam_refs %}
<COMPARAM-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</COMPARAM-REFS>
{%- endif%}
{%- if service.request_ref %}
<REQUEST-REF ID-REF="{{service.request_ref.ref_id}}"/>
{%- endif %}
{%- if service.pos_response_refs %}
<POS-RESPONSE-REFS>
{%- for ref in service.pos_response_refs %}
<POS-RESPONSE-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</POS-RESPONSE-REFS>
{%- endif%}
{%- if service.neg_response_refs %}
<NEG-RESPONSE-REFS>
{%- for ref in service.neg_response_refs %}
<NEG-RESPONSE-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</NEG-RESPONSE-REFS>
{%- endif%}
<DIAG-SERVICE {{pdc.printDiagCommAttribs(service) | indent(1) }}
{{-make_bool_xml_attrib("IS-CYCLIC", service.is_cyclic_raw)}}
{{-make_bool_xml_attrib("IS-MULTIPLE", service.is_multiple_raw)}}
{%- if service.addressing_raw is not none %}
{{-make_xml_attrib("ADDRESSING", service.addressing_raw.value)}}
{%- endif %}
{%- if service.transmission_mode_raw is not none %}
{{-make_xml_attrib("TRANSMISSION-MODE", service.transmission_mode_raw.value)}}>
{%- endif %}>
{{pdc.printDiagCommSubtags(service) | indent(1, first=True) }}
{%- if service.comparam_refs %}
<COMPARAM-REFS>
{%- for ref in service.comparam_refs %}
<COMPARAM-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</COMPARAM-REFS>
{%- endif%}
{%- if service.request_ref %}
<REQUEST-REF ID-REF="{{service.request_ref.ref_id}}"/>
{%- endif %}
{%- if service.pos_response_refs %}
<POS-RESPONSE-REFS>
{%- for ref in service.pos_response_refs %}
<POS-RESPONSE-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</POS-RESPONSE-REFS>
{%- endif%}
{%- if service.neg_response_refs %}
<NEG-RESPONSE-REFS>
{%- for ref in service.neg_response_refs %}
<NEG-RESPONSE-REF ID-REF="{{ref.ref_id}}" />
{%- endfor %}
</NEG-RESPONSE-REFS>
{%- endif%}
</DIAG-SERVICE>
{%- endmacro -%}
54 changes: 27 additions & 27 deletions odxtools/templates/macros/printSingleEcuJob.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
<SINGLE-ECU-JOB {{pdc.printDiagCommAttribs(job)|indent(1) }}>
{{pdc.printDiagCommSubtags(job) | indent(2, first=True) }}
<PROG-CODES>
{%- for prog in job.prog_codes %}
{{ printProgCode(prog)|indent(2) }}
{%- endfor %}
</PROG-CODES>
{%- if job.input_params %}
<INPUT-PARAMS>
{%- for param in job.input_params %}
{{ printInputParam(param)|indent(2) }}
{%- endfor %}
</INPUT-PARAMS>
{%- endif %}
{%- if job.output_params %}
<OUTPUT-PARAMS>
{%- for param in job.output_params %}
{{ printOutputParam(param)|indent(2) }}
{%- endfor %}
</OUTPUT-PARAMS>
{%- endif %}
{%- if job.neg_output_params %}
<NEG-OUTPUT-PARAMS>
{%- for param in job.neg_output_params %}
{{ printNegOutputParam(param)|indent(2) }}
{%- endfor %}
</NEG-OUTPUT-PARAMS>
{%- endif %}
{%- for prog in job.prog_codes %}
{{ printProgCode(prog)|indent(4) }}
{%- endfor %}
</PROG-CODES>
{%- if job.input_params %}
<INPUT-PARAMS>
{%- for param in job.input_params %}
{{ printInputParam(param)|indent(4) }}
{%- endfor %}
</INPUT-PARAMS>
{%- endif %}
{%- if job.output_params %}
<OUTPUT-PARAMS>
{%- for param in job.output_params %}
{{ printOutputParam(param)|indent(4) }}
{%- endfor %}
</OUTPUT-PARAMS>
{%- endif %}
{%- if job.neg_output_params %}
<NEG-OUTPUT-PARAMS>
{%- for param in job.neg_output_params %}
{{ printNegOutputParam(param)|indent(4) }}
{%- endfor %}
</NEG-OUTPUT-PARAMS>
{%- endif %}
</SINGLE-ECU-JOB>
{%- endmacro -%}

Expand Down
10 changes: 10 additions & 0 deletions odxtools/templates/macros/printVariant.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -181,6 +182,15 @@
{%- endfor %}
</COMPARAM-REFS>
{%- endif %}
{%- if dlr.variant_type.value == "ECU-VARIANT" %}
{%- if dlr.ecu_variant_patterns %}
<ECU-VARIANT-PATTERNS>
{%- for vp in dlr.ecu_variant_patterns -%}
{{ pvpat.printEcuVariantPattern(vp)|indent(2) }}
{%- endfor -%}
</ECU-VARIANT-PATTERNS>
{%- endif %}
{%- endif %}
{%- if dlr.variant_type.value == "PROTOCOL" %}
<COMPARAM-SPEC-REF ID-REF="{{dlr.comparam_spec_ref.ref_id}}" DOCREF="{{dlr.comparam_spec_ref.ref_docs[0].doc_name}}" DOCTYPE="COMPARAM-SPEC"/>
{%- if dlr.prot_stack_snref is not none %}
Expand Down

0 comments on commit 7a41b12

Please sign in to comment.