{%- if msg_defs_header | length -%} #include "{{ msg_defs_header }}" {%- endif %} #include {%- if cpp_namespace is defined and cpp_namespace is not none %} namespace {{ cpp_namespace }} { {%- endif %} QString msgIdString(const MsgId msgId) { switch (msgId) { {%- for (msg_id_value, msg) in msg_cpp.data.items() %} case {{ msg['msg_id'] }}: return QStringLiteral("{{ msg['msg_id'] }}"); {%- endfor %} default: return QStringLiteral("0x%1").arg(static_cast(msgId), 4, 16, QChar('0')); } } {%- for (msg_id_value, msg) in msg_cpp.data.items() %} // {{ msg['msg_id'] }} ({{ msg['msg_id_hex_string'] }}) // payload: {{ msg_cpp.field_list(msg_id_value) | join(", ") }} bool {{ msg['msg_name'] }}Payload::fromQByteArray([[maybe_unused]] const QByteArray &src) { {%- if msg['payload'] | length %} int offset = 0; return ( {%- set fields = namespace(count = 0) %} {%- for field in msg['payload'] %} {%- if field['type'] == "union" %} // TODO: {{ field['type'] ~ "-" ~ field['name'] }} {%- if fields.count < msg['payload'] | length - 1 %} true && {%- else %} true {%- endif %} {%- else %} // {{ field['type'] ~ "-" ~ field['name'] }} {%- if fields.count < msg['payload'] | length - 1 %} Types::getValue<>(src, offset, {{ field['name'] }}, QT_STRINGIFY({{ field['name'] }})) && {%- else %} Types::getValue<>(src, offset, {{ field['name'] }}, QT_STRINGIFY({{ field['name'] }})) {%- endif %} {%- endif %} {%- set fields.count = fields.count + 1 %} {%- endfor %} ); {%- else %} return true; {%- endif %} } // {{ msg['msg_id'] }} ({{ msg['msg_id_hex_string'] }}) // payload: {{ msg_cpp.field_list(msg_id_value) | join(", ") }} void {{ msg['msg_name'] }}Payload::toQByteArray([[maybe_unused]] QByteArray &dst) const { {%- if msg['payload'] | length %} {%- for field in msg['payload'] %} {%- if field['type'] == "union" %} // TODO: {{ field['type'] ~ "-" ~ field['name'] }} {%- else %} // {{ field['type'] ~ "-" ~ field['name'] }} Types::setValue<>({{ field['name'] }}, dst); {%- endif %} {%- endfor %} {%- endif %} } void {{ msg['msg_name'] }}Payload::dump() const { QStringList paramList; {%- for field in msg['payload'] %} {%- if field['type'] != "union" %} paramList << QString("{{ field['name'] }}=%1").arg({{ field['name'] }}.value); {%- endif %} {%- endfor %} qDebug().noquote() << QString("{{ msg['msg_name'] }}Payload: %1").arg(paramList.count() ? paramList.join(", ") : ""); } {%- endfor %} {%- if cpp_namespace is defined and cpp_namespace is not none %} } // namespace {{ cpp_namespace }} {%- endif %}