Skip to content

Commit

Permalink
Merge pull request #207 from andlaus/write_dynamic_length_fields
Browse files Browse the repository at this point in the history
write dynamic length fields
  • Loading branch information
andlaus authored Sep 20, 2023
2 parents 954fba9 + c39d1e1 commit 6f91d99
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 175 deletions.
12 changes: 3 additions & 9 deletions odxtools/templates/macros/printAudience.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printAdditionalAudience(audience) -%}
<ADDITIONAL-AUDIENCE ID="{{audience.odx_id.local_id}}">
<SHORT-NAME>{{audience.short_name}}</SHORT-NAME>
{%- if audience.long_name %}
<LONG-NAME>{{audience.long_name}}</LONG-NAME>
{%- endif %}
{%- if audience.description is string and audience.description.strip() %}
<DESC>
{{audience.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(audience)|indent(1) }}
</ADDITIONAL-AUDIENCE>
{%- endmacro -%}

Expand Down
31 changes: 4 additions & 27 deletions odxtools/templates/macros/printCompanyData.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

{%- macro printCompanyData(company_data) -%}
<COMPANY-DATA ID="{{company_data.odx_id.local_id}}">
<SHORT-NAME>{{company_data.short_name|e}}</SHORT-NAME>
{%- if company_data.long_name is not none %}
<LONG-NAME>{{company_data.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if company_data.description is not none %}
<DESC>
{{company_data.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(company_data)|indent(1) }}
{%- if company_data.roles is not none %}
<ROLES>
{%- for role in company_data.roles %}
Expand All @@ -27,15 +20,7 @@
<TEAM-MEMBERS>
{%- for team_member in company_data.team_members %}
<TEAM-MEMBER ID="{{team_member.odx_id.local_id}}">
<SHORT-NAME>{{team_member.short_name|e}}</SHORT-NAME>
{%- if company_data.long_name is not none %}
<LONG-NAME>{{team_member.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if company_data.description is not none %}
<DESC>
{{team_member.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(team_member)|indent(3) }}
{%- if team_member.roles is not none %}
<ROLES>
{%- for role in team_member.roles %}
Expand Down Expand Up @@ -75,15 +60,7 @@
<RELATED-DOC>
{%- if rd.xdoc is not none %}
<XDOC>
<SHORT-NAME>{{rd.xdoc.short_name|e}}</SHORT-NAME>
{%- if rd.xdoc.long_name is not none %}
<LONG-NAME>{{rd.xdoc.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if rd.xdoc.description is not none %}
<DESC>
{{rd.xdoc.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(rd.xdoc)|indent(5) }}
{%- if rd.xdoc.number is not none %}
<NUMBER>{{rd.xdoc.number|e}}</NUMBER>
{%- endif %}
Expand Down
22 changes: 4 additions & 18 deletions odxtools/templates/macros/printComparam.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printComplexValue(cv) %}
<COMPLEX-VALUE>
{%- for val in cv %}
Expand Down Expand Up @@ -41,15 +43,7 @@
CPTYPE="{{cp.cptype.value}}"
{{make_xml_attrib("DISPLAY-LEVEL", cp.display_level)}}
CPUSAGE="{{cp.cpusage.value}}">
<SHORT-NAME>{{cp.short_name}}</SHORT-NAME>
{%- if cp.long_name and cp.long_name.strip() %}
<LONG-NAME>{{cp.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if cp.description and cp.description.strip() %}
<DESC>
{{cp.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(cp)|indent(1) }}
<PHYSICAL-DEFAULT-VALUE>{{cp.physical_default_value}}</PHYSICAL-DEFAULT-VALUE>
<DATA-OBJECT-PROP-REF ID-REF="{{cp.dop_ref.ref_id}}" />
</COMPARAM>
Expand All @@ -63,15 +57,7 @@
CPUSAGE="{{cp.cpusage.value}}"
{{make_bool_xml_attrib("ALLOW-MULTIPLE-VALUES", cp.allow_multiple_values_raw)}}
{#- #}>
<SHORT-NAME>{{cp.short_name}}</SHORT-NAME>
{%- if cp.long_name and cp.long_name.strip() %}
<LONG-NAME>{{cp.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if cp.description and cp.description.strip() %}
<DESC>
{{cp.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(cp)|indent(1) }}
{%- for sub_cp in cp.comparams %}
{{- printGenericComparam(sub_cp) | indent(1, first=True) }}
{%- endfor %}
Expand Down
12 changes: 3 additions & 9 deletions odxtools/templates/macros/printDOP.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printAdminData.xml.jinja2') as pad %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

Expand Down Expand Up @@ -164,13 +165,7 @@

{%- macro printDOP(dop, tag_name) %}
<{{tag_name}} ID="{{dop.odx_id.local_id}}">
<SHORT-NAME>{{dop.short_name}}</SHORT-NAME>
{%- if dop.long_name %}
<LONG-NAME>{{dop.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if dop.description %}
<DESC>{{dop.description}}</DESC>
{%- endif %}
{{ peid.printElementID(dop)|indent(1) }}
{%- if dop.admin_data %}
{{- pad.printAdminData(dop.admin_data)|indent(2, first=True) }}
{%- endif %}
Expand All @@ -192,8 +187,7 @@

{%- macro printDTCDOP(dop) %}
<DTC-DOP ID="{{dop.odx_id.local_id}}">
<SHORT-NAME>{{dop.short_name}}</SHORT-NAME>
<LONG-NAME>{{dop.long_name|e}}</LONG-NAME>
{{ peid.printElementID(dop)|indent(1) }}
{{- psd.printSpecialDataGroups(dop.sdgs)|indent(1, first=True) }}
{{- printDiagCodedType(dop.diag_coded_type)|indent(1, first=True) }}
{{- printPhysicalType(dop.physical_type)|indent(1, first=True) }}
Expand Down
22 changes: 22 additions & 0 deletions odxtools/templates/macros/printDynamicLengthField.xml.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*-
#
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printDynamicLengthField(dlf) -%}
<DYNAMIC-LENGTH-FIELD ID="{{dlf.odx_id.local_id}}">
{{ peid.printElementID(dlf)|indent(1) }}
<BASIC-STRUCTURE-REF ID-REF="{{dlf.structure_ref.ref_id}}" />
<OFFSET>{{dlf.offset}}</OFFSET>
<DETERMINE-NUMBER-OF-ITEMS>
{%- set dni = dlf.determine_number_of_items %}
<BYTE-POSITION>{{dni.byte_position}}</BYTE-POSITION>
{%- if dni.bit_position is not none %}
<BIT-POSITION>{{dni.bit_position}}</BIT-POSITION>
{%- endif %}
<DATA-OBJECT-PROP-REF ID-REF="{{dni.dop_ref.ref_id}}" />
</DETERMINE-NUMBER-OF-ITEMS>
</DYNAMIC-LENGTH-FIELD>
{%- endmacro -%}
12 changes: 6 additions & 6 deletions odxtools/templates/macros/printElementID.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# SPDX-License-Identifier: MIT
-#}

{%- macro printElementID(element) -%}
<SHORT-NAME>{{ element.short_name }}</SHORT-NAME>
{%- if element.long_name is string and element.long_name.strip() %}
<LONG-NAME>{{ element.long_name|e }}</LONG-NAME>
{%- macro printElementID(obj) -%}
<SHORT-NAME>{{ obj.short_name }}</SHORT-NAME>
{%- if obj.long_name %}
<LONG-NAME>{{ obj.long_name|e }}</LONG-NAME>
{%- endif %}
{%- if element.description is string and element.description.strip() %}
<DESC>{{ element.description }}</DESC>
{%- if obj.description %}
<DESC>{{ obj.description }}</DESC>
{%- endif %}
{%- endmacro -%}
5 changes: 3 additions & 2 deletions odxtools/templates/macros/printEndOfPdu.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printEndOfPdu(eopdu) -%}
<END-OF-PDU-FIELD ID="{{eopdu.odx_id.local_id}}">
<SHORT-NAME>{{eopdu.short_name}}</SHORT-NAME>
<LONG-NAME>{{eopdu.long_name|e}}</LONG-NAME>
{{ peid.printElementID(eopdu)|indent(1) }}
<BASIC-STRUCTURE-REF ID-REF="{{eopdu.structure_ref.ref_id}}" />
</END-OF-PDU-FIELD>
{%- endmacro -%}
4 changes: 2 additions & 2 deletions odxtools/templates/macros/printEnvData.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printParam.xml.jinja2') as pparam %}

{%- macro printEnvData(env_data) %}
<ENV-DATA ID="{{env_data.odx_id.local_id}}">
<SHORT-NAME>{{env_data.short_name}}</SHORT-NAME>
<LONG-NAME>{{env_data.long_name}}</LONG-NAME>
{{ peid.printElementID(env_data)|indent(1) }}
<PARAMS>
{%- for param in env_data.parameters %}
{{pparam.printParam(param) | indent(6, first=True) }}
Expand Down
5 changes: 3 additions & 2 deletions odxtools/templates/macros/printEnvDataDesc.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printEnvDataDesc(env_data_desc) %}
<ENV-DATA-DESC ID="{{env_data_desc.odx_id.local_id}}">
<SHORT-NAME>{{env_data_desc.short_name}}</SHORT-NAME>
<LONG-NAME>{{env_data_desc.long_name}}</LONG-NAME>
{{ peid.printElementID(env_data_desc)|indent(1) }}
<PARAM-SNREF SHORT-NAME="{{env_data_desc.param_snref}}"/>
<ENV-DATA-REFS>
{%- for env_data_ref in env_data_desc.env_data_refs %}
Expand Down
12 changes: 3 additions & 9 deletions odxtools/templates/macros/printFunctionalClass.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printFunctionalClass(fc) -%}
<FUNCT-CLASS ID="{{fc.odx_id.local_id}}">
<SHORT-NAME>{{fc.short_name}}</SHORT-NAME>
{%- if fc.long_name is string and fc.long_name.strip() %}
<LONG-NAME>{{fc.long_name}}</LONG-NAME>
{%- endif %}
{%- if fc.description is string and fc.description.strip() %}
<DESC>
{{fc.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(fc)|indent(1) }}
</FUNCT-CLASS>
{%- endmacro -%}
11 changes: 5 additions & 6 deletions odxtools/templates/macros/printMux.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}

{%- macro printMux(mux) %}
<MUX ID="{{mux.odx_id.local_id}}">
<SHORT-NAME>{{mux.short_name}}</SHORT-NAME>
<LONG-NAME>{{mux.long_name|e}}</LONG-NAME>
{{ peid.printElementID(mux)|indent(1) }}
<BYTE-POSITION>{{mux.byte_position}}</BYTE-POSITION>
<SWITCH-KEY>
<BYTE-POSITION>{{mux.switch_key.byte_position}}</BYTE-POSITION>
Expand All @@ -17,8 +18,7 @@
</SWITCH-KEY>
{%- if mux.default_case is not none %}
<DEFAULT-CASE>
<SHORT-NAME>{{mux.default_case.short_name}}</SHORT-NAME>
<LONG-NAME>{{mux.default_case.long_name}}</LONG-NAME>
{{ peid.printElementID(mux.default_case)|indent(4) }}
{%- if mux.default_case.structure_ref is not none %}
<STRUCTURE-REF ID-REF="{{mux.default_case.structure_ref.ref_id}}"/>
{%- endif %}
Expand All @@ -31,8 +31,7 @@
<CASES>
{%- for case in mux.cases %}
<CASE>
<SHORT-NAME>{{case.short_name}}</SHORT-NAME>
<LONG-NAME>{{case.long_name}}</LONG-NAME>
{{ peid.printElementID(case)|indent(6) }}
{%- if case.structure_ref is not none %}
<STRUCTURE-REF ID-REF="{{case.structure_ref.ref_id}}"/>
{%- endif %}
Expand Down
9 changes: 2 additions & 7 deletions odxtools/templates/macros/printParam.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printDOP.xml.jinja2') as pdop %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

Expand All @@ -19,13 +20,7 @@
{%- else %}
<PARAM {{semattrib}} xsi:type="{{param.parameter_type}}">
{%- endif%}
<SHORT-NAME>{{param.short_name}}</SHORT-NAME>
{%- if param.long_name %}
<LONG-NAME>{{param.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if param.description %}
<DESC>{{param.description}}</DESC>
{%- endif %}
{{ peid.printElementID(param)|indent(1) }}
{{- psd.printSpecialDataGroups(param.sdgs)|indent(1, first=True) }}
{%- if param.byte_position is not none %}
<BYTE-POSITION>{{param.byte_position}}</BYTE-POSITION>
Expand Down
11 changes: 2 additions & 9 deletions odxtools/templates/macros/printRequest.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printDOP.xml.jinja2') as pdop %}
{%- import('macros/printParam.xml.jinja2') as pp %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

{%- macro printRequest(request) -%}
<REQUEST ID="{{request.odx_id.local_id}}">
<SHORT-NAME>{{request.short_name}}</SHORT-NAME>
{%- if request.long_name %}
<LONG-NAME>{{request.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if request.description and request.description.strip() %}
<DESC>
{{request.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(request)|indent(1) }}
{%- if request.parameters %}
<PARAMS>
{%- for param in request.parameters -%}
Expand Down
11 changes: 2 additions & 9 deletions odxtools/templates/macros/printResponse.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printParam.xml.jinja2') as pp %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

{%- macro printResponse(resp, tag_name="POS-RESPONSE") -%}
<{{tag_name}} ID="{{resp.odx_id.local_id}}">
<SHORT-NAME>{{resp.short_name}}</SHORT-NAME>
{%- if resp.long_name %}
<LONG-NAME>{{resp.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if resp.description and resp.description.strip() %}
<DESC>
{{resp.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(resp)|indent(1) }}
{%- if resp.parameters %}
<PARAMS>
{%- for param in resp.parameters -%}
Expand Down
11 changes: 2 additions & 9 deletions odxtools/templates/macros/printService.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementID.xml.jinja2') as peid %}
{%- import('macros/printAdminData.xml.jinja2') as pad %}
{%- import('macros/printAudience.xml.jinja2') as paud %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}
Expand All @@ -14,15 +15,7 @@
{%- set semattrib = " SEMANTIC=\"UNKNOWN\"" -%}
{%- endif -%}
<DIAG-SERVICE ID="{{service.odx_id.local_id}}" {{semattrib}}>
<SHORT-NAME>{{service.short_name}}</SHORT-NAME>
{%- if service.long_name and service.long_name.strip() %}
<LONG-NAME>{{service.long_name|e}}</LONG-NAME>
{%- endif %}
{%- if service.description and service.description.strip() %}
<DESC>
{{service.description}}
</DESC>
{%- endif %}
{{ peid.printElementID(service)|indent(1) }}
{%- if service.admin_data %}
{{- pad.printAdminData(service.admin_data)|indent(1, first=True) }}
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion odxtools/templates/macros/printSpecialData.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{%- macro printSdgCaption(sdg_caption) %}
<SDG-CAPTION ID="{{sdg_caption.odx_id.local_id}}">
{{ peid.printElementID(sdg_caption) | indent(1) }}
{{ peid.printElementID(sdg_caption)|indent(1) }}
</SDG-CAPTION>
{%- endmacro %}

Expand Down
Loading

0 comments on commit 6f91d99

Please sign in to comment.