Index: scripts/MsgUtils/msgutils/templates/MsgDefs_cpp.jinja =================================================================== diff -u -r088513e6ea7bad08b4fb7862127c726eabad18fd -r402926738e7394ee2d3dc7add2e6d755f06a289d --- scripts/MsgUtils/msgutils/templates/MsgDefs_cpp.jinja (.../MsgDefs_cpp.jinja) (revision 088513e6ea7bad08b4fb7862127c726eabad18fd) +++ scripts/MsgUtils/msgutils/templates/MsgDefs_cpp.jinja (.../MsgDefs_cpp.jinja) (revision 402926738e7394ee2d3dc7add2e6d755f06a289d) @@ -1,5 +1,4 @@ {%- if msg_defs_header | length -%} -#include #include "{{ msg_defs_header }}" {%- endif %} {%- if cpp_namespace is defined and cpp_namespace is not none %} @@ -8,25 +7,9 @@ { {%- endif %} {%- for (msg_id_value, msg) in msg_cpp.data.items() %} -{%- if proto is defined %} // {{ msg['msg_id'] }} ({{ msg['msg_id_hex_string'] }}) // payload: {{ msg_cpp.field_list(msg_id_value) | join(", ") }} -void {{ msg['msg_name'] }}Payload::fromProtobuf([[maybe_unused]] const messages::{{ msg['msg_name'] }} &src) -{ -{%- for field in msg['payload'] %} -{%- if field['type'] != "union" %} - // {{ field['type'] ~ "-" ~ field['name'] }} - {{ field['name'] }}.value = src.{{ field['name'].lower() }}(); -{%- else %} - // TODO: {{ field['type'] ~ "-" ~ field['name'] }} -{%- endif %} -{%- endfor %} -} -{%- endif %} - -// {{ 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 %} @@ -56,27 +39,9 @@ return true; {%- endif %} } -{%- if proto is defined %} // {{ msg['msg_id'] }} ({{ msg['msg_id_hex_string'] }}) // payload: {{ msg_cpp.field_list(msg_id_value) | join(", ") }} -messages::{{ msg['msg_name'] }} {{ msg['msg_name'] }}Payload::toProtobuf() const -{ - messages::{{ msg['msg_name'] }} protoMsg; -{%- for field in msg['payload'] %} -{%- if field['type'] != "union" %} - // {{ field['type'] ~ "-" ~ field['name'] }} - protoMsg.set_{{ field['name'].lower() }}({{ field['name'] }}.value); -{%- else %} - // TODO: {{ field['type'] ~ "-" ~ field['name'] }} -{%- endif %} -{%- endfor %} - return protoMsg; -} -{%- 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 %} @@ -102,47 +67,6 @@ qDebug().noquote() << QString("{{ msg['msg_name'] }}Payload: %1").arg(paramList.count() ? paramList.join(", ") : ""); } {%- endfor %} -{%- if proto is defined %} - -QByteArray canMessageToProtobufByteArray(const QDateTime ×tamp, const QString &deviceSerialNum, const Can::Message &msg) -{ - const auto updateHeader = [&](messages::Header *header) { - if (header) { - const auto msecs = timestamp.toMSecsSinceEpoch(); - header->set_deviceserialnum(deviceSerialNum.toStdString()); - auto proto_timestamp = header->mutable_timestamp(); - if (proto_timestamp) { - proto_timestamp->set_seconds(msecs / 1000); - proto_timestamp->set_nanos((msecs % 1000) * 1000000); - } - header->set_msgid(msg.msgId); - header->set_sequence(msg.sequence); - } - }; - - switch (msg.msgId) { -{%- for (msg_id_value, msg) in msg_cpp.data.items() %} - case {{ msg['msg_id'] }}: { - {{ msg['msg_name'] }}Payload payload; - if (payload.fromQByteArray(msg.data) == false) { - qDebug().noquote() << "ERROR: could not convert CAN message with MsgId={{ msg['msg_name'] }} to struct"; - } - payload.dump(); - auto proto = payload.toProtobuf(); - updateHeader(proto.mutable_header()); - std::string out; - (void)proto.SerializeToString(&out); - return QByteArray(out.data(), static_cast(out.size())); - break; - } -{%- endfor %} - default: - qDebug().noquote() << QString("WARNING: MsgId=0x%1 not handled").arg(msg.msgId, 4, 16, QChar('0')); - break; - } - return QByteArray(); -} -{%- endif %} {%- if cpp_namespace is defined and cpp_namespace is not none %} } // namespace {{ cpp_namespace }}