#pragma once #include #include #include #include #include #include #include #include "CanMessage.h" #include "types.h" {%- if proto is defined %} #include "{{ device_name }}MsgDefs.pb.h" {%- endif %} {%- if cpp_namespace is defined and cpp_namespace is not none %} namespace {{ cpp_namespace }} { {%- endif %} enum MsgId : quint16 { {%- for (msg_id_value, msg) in msg_cpp.data.items() %} {{ msg['msg_id'] }} = {{ msg['msg_id_hex_string'] }}, {%- endfor %} }; enum ParamType { {%- for type in msg_cpp.paramTypes %} {{ type }}, {%- endfor %} }; // typedef union { // Types::U08 uint8Value; // Types::U16 uint16Value; // Types::U32 uint32Value; // Types::S08 int8Value; // Types::S16 int16Value; // Types::S32 int32Value; // Types::F32 floatValue; // } ParamUnion; union ParamUnion { uint8_t uint8Value; uint16_t uint16Value; uint32_t uint32Value; int8_t int8Value; int16_t int16Value; int32_t int32Value; float floatValue; uint8_t bytes[std::max(sizeof(float), sizeof(uint32_t))]; }; {%- if msg_cpp.data.items() | length %} const QMap payloadSize = { {%- for (msg_id_value, msg) in msg_cpp.data.items() %} { {{ msg['msg_id'] }}, {{ msg['cpp_struct']['payload_size'] }} }, {%- endfor %} }; {%- endif %} {%- 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(", ") }} struct {{ msg['msg_name'] }}Payload { {%- for field in msg['cpp_struct']['payload'] %} {{ field['cpp_type'] }} {{ field['name'] }}; {%- endfor %} {%- if msg['cpp_struct']['payload'] | length %} {% endif %} {%- if proto is defined %} {%- if cpp_namespace is defined and cpp_namespace is not none %} void fromProtobuf(const {{ cpp_namespace }}::messages::{{ msg['msg_name'] }} &src); {%- else %} void fromProtobuf(const messages::{{ msg['msg_name'] }} &src); {%- endif %} {%- endif %} bool fromQByteArray(const QByteArray &src); {%- if proto is defined %} {%- if cpp_namespace is defined and cpp_namespace is not none %} {{ cpp_namespace }}::messages::{{ msg['msg_name'] }} toProtobuf() const; {%- else %} messages::{{ msg['msg_name'] }} toProtobuf() const; {%- endif %} {%- endif %} void toQByteArray(QByteArray &dst) const; void dump() const; }; {%- endfor %} {%- if cpp_namespace is defined and cpp_namespace is not none %} QByteArray canMessageToProtobufByteArray(const QDateTime ×tamp, const QString &deviceSerialNumber, const Can::Message &msg); } // namespace {{ cpp_namespace }} {%- endif %}