{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*-
 #
 # SPDX-License-Identifier: MIT
-#}

{%- import('macros/printDiagComm.xml.jinja2') as pdc %}
{%- import('macros/printComparamRef.xml.jinja2') as pcom %}

{%- macro printPosResponseSuppressible(prs) -%}
<POS-RESPONSE-SUPPRESSABLE>
  {%- set num_nibbles = (prs.bit_mask.bit_length() + 7) // 8 * 2 %}
  <BIT-MASK>{{ ("%%0%dX" | format(num_nibbles | int)) | format(prs.bit_mask | int) }}</BIT-MASK>
  {%- if prs.coded_const_snref is not none %}
  <CODED-CONST-SNREF SHORT-NAME="{{ prs.coded_const_snref }}" />
  {%- endif %}
  {%- if prs.coded_const_snpathref is not none %}
  <CODED-CONST-SNPATHREF SHORT-PATH-NAME="{{ prs.coded_const_snpathref }}" />
  {%- endif %}
  {%- if prs.value_snref is not none %}
  <VALUE-SNREF SHORT-NAME="{{ prs.value_snref }}" />
  {%- endif %}
  {%- if prs.value_snpathref is not none %}
  <VALUE-SNPATHREF SHORT-PATH-NAME="{{ prs.value_snpathref }}" />
  {%- endif %}
  {%- if prs.phys_const_snref is not none %}
  <PHYS-CONST-SNREF SHORT-NAME="{{ prs.phys_const_snref }}" />
  {%- endif %}
  {%- if prs.phys_const_snpathref is not none %}
  <PHYS-CONST-SNPATHREF SHORT-PATH-NAME="{{ prs.phys_const_snpathref }}" />
  {%- endif %}
  {%- if prs.table_key_snref is not none %}
  <TABLE-KEY-SNREF SHORT-NAME="{{ prs.table_key_snref }}" />
  {%- endif %}
  {%- if prs.table_key_snpathref is not none %}
  <TABLE-KEY-SNPATHREF SHORT-PATH-NAME="{{ prs.table_key_snpathref }}" />
  {%- endif %}
</POS-RESPONSE-SUPPRESSABLE>
{%- endmacro -%}

{%- macro printService(service) -%}
<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 cpref in service.comparam_refs %}
    {{ pcom.printComparamRef(cpref)|indent(4) }}
    {%- 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 -%}
