diff --git a/plugin/dltdbusplugin/dltdbusplugin.cpp b/plugin/dltdbusplugin/dltdbusplugin.cpp index bbf78b3d..f9072550 100644 --- a/plugin/dltdbusplugin/dltdbusplugin.cpp +++ b/plugin/dltdbusplugin/dltdbusplugin.cpp @@ -305,7 +305,7 @@ void DltDBusPlugin::selectedIdxMsg(int /*index*/, QDltMsg &msg) text += QString("Destination%1").arg(dbusMsg.getDestination()); text += QString("Sender%1").arg(dbusMsg.getSender()); QByteArray signature = dbusMsg.getSignature(); - text += QString("Signature%1").arg(msg.toAsciiTable(signature,false,false,true,256,256,false)); + text += QString("Signature%1").arg(QDlt::toAsciiTable(signature,false,false,true,256,256,false)); text += QString("UnixFds%1").arg(dbusMsg.getUnixFds()); text += QString(""); @@ -315,7 +315,7 @@ void DltDBusPlugin::selectedIdxMsg(int /*index*/, QDltMsg &msg) /* DBus message payload Hex*/ QByteArray payload = dbusMsg.getPayload(); text = QString("

Size: %1

").arg(payload.size()); - text += msg.toAsciiTable(payload,true,true,false); + text += QDlt::toAsciiTable(payload,true,true,false); form->setTextBrowserPayloadHex(text); /* decode DBus payload */ diff --git a/plugin/dltviewerplugin/dltviewerplugin.cpp b/plugin/dltviewerplugin/dltviewerplugin.cpp index ac3e193a..4e90d27a 100644 --- a/plugin/dltviewerplugin/dltviewerplugin.cpp +++ b/plugin/dltviewerplugin/dltviewerplugin.cpp @@ -288,13 +288,13 @@ void DltViewerPlugin::selectedIdxMsg(int index, QDltMsg &msg) { QByteArray bytes_payload = msg.getPayload(); /* Show Ascii output */ - form->setTextBrowserAscii(msg.toAsciiTable(bytes_header,false,false,true,8,64)+msg.toAsciiTable(bytes_payload,false,false,true,8,64)); + form->setTextBrowserAscii(QDlt::toAsciiTable(bytes_header,false,false,true,8,64)+QDlt::toAsciiTable(bytes_payload,false,false,true,8,64)); /* Show Binary output */ - form->setTextBrowserBinary(msg.toAsciiTable(bytes_header,true,true,false)+msg.toAsciiTable(bytes_payload,true,true,false)); + form->setTextBrowserBinary(QDlt::toAsciiTable(bytes_header,true,true,false)+QDlt::toAsciiTable(bytes_payload,true,true,false)); /* Show Mixed output */ - form->setTextBrowserMixed(msg.toAsciiTable(bytes_header,true,true,true)+msg.toAsciiTable(bytes_payload,true,true,true)); + form->setTextBrowserMixed(QDlt::toAsciiTable(bytes_header,true,true,true)+QDlt::toAsciiTable(bytes_payload,true,true,true)); } diff --git a/plugin/nonverboseplugin/nonverboseplugin.cpp b/plugin/nonverboseplugin/nonverboseplugin.cpp index 01eb179e..c30eaa21 100644 --- a/plugin/nonverboseplugin/nonverboseplugin.cpp +++ b/plugin/nonverboseplugin/nonverboseplugin.cpp @@ -636,7 +636,7 @@ bool NonverbosePlugin::decodeMsg(QDltMsg &msg, int triggeredByUser) { if((unsigned int)payload.size()<(offset+sizeof(unsigned short))) break; - if(argument.getEndianness() == QDltMsg::DltEndiannessLittleEndian) + if(argument.getEndianness() == QDlt::DltEndiannessLittleEndian) length = *((unsigned short*) (payload.constData()+offset)); else length = DLT_SWAP_16(*((unsigned short*) (payload.constData()+offset))); diff --git a/qdlt/CMakeLists.txt b/qdlt/CMakeLists.txt index 2c0ac5e3..de850cfa 100644 --- a/qdlt/CMakeLists.txt +++ b/qdlt/CMakeLists.txt @@ -42,7 +42,10 @@ add_library(qdlt SHARED fieldnames.cpp dltmessagematcher.cpp dltmessagematcher.h - qdltlrucache.hpp) + qdltlrucache.hpp + export_c_rules.h + export_rules.h +) target_compile_definitions(qdlt PRIVATE BYTE_ORDER=LITTLE_ENDIAN diff --git a/qdlt/dlt_common.h b/qdlt/dlt_common.h index e853fa3d..2e009f12 100644 --- a/qdlt/dlt_common.h +++ b/qdlt/dlt_common.h @@ -64,7 +64,7 @@ #ifndef DLT_COMMON_H #define DLT_COMMON_H -#include "export_rules.h" +#include "export_c_rules.h" /** \defgroup commonapi DLT Common API diff --git a/qdlt/dlt_user.h b/qdlt/dlt_user.h index 194602d2..77de6954 100644 --- a/qdlt/dlt_user.h +++ b/qdlt/dlt_user.h @@ -350,7 +350,7 @@ int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type * This function has to be called first, before using any DLT user lib functions. * @return negative value if there was an error */ -int dlt_init(); +int dlt_init(void); /** * Initialise the user lib writing only to file. diff --git a/qdlt/export_c_rules.h b/qdlt/export_c_rules.h new file mode 100644 index 00000000..e1b3e29b --- /dev/null +++ b/qdlt/export_c_rules.h @@ -0,0 +1,21 @@ +#ifndef EXPORT_C_RULES_H +#define EXPORT_C_RULES_H + +/// \file export_c_rules.h +/// \brief Export rules for C code to control symbols visibility + +#if defined(QDLT_LIBRARY) +# if defined(_WIN32) || defined(_WIN64) +# define QDLT_C_EXPORT __declspec(dllexport) +# else +# define QDLT_C_EXPORT __attribute__((visibility("default"))) +# endif +#else +# if defined(_WIN32) || defined(_WIN64) +# define QDLT_C_EXPORT __declspec(dllimport) +# else +# define QDLT_C_EXPORT +# endif +#endif + +#endif // EXPORT_C_RULES_H diff --git a/qdlt/export_rules.h b/qdlt/export_rules.h index 588b173c..a4df9746 100644 --- a/qdlt/export_rules.h +++ b/qdlt/export_rules.h @@ -1,20 +1,17 @@ #ifndef EXPORT_RULES_H #define EXPORT_RULES_H +/// \file export_rules.h +/// \brief Export rules for C++ code to control symbols visibility +/// \details This file is used to control the visibility of symbols in the shared library. See +/// https://doc.qt.io/qt-5/sharedlibrary.html#using-symbols-from-shared-libraries for details + +#include + #if defined(QDLT_LIBRARY) # define QDLT_EXPORT Q_DECL_EXPORT -# if defined(_WIN32) || defined(_WIN64) -# define QDLT_C_EXPORT __declspec(dllexport) -# else -# define QDLT_C_EXPORT __attribute__((visibility("default"))) -# endif #else # define QDLT_EXPORT Q_DECL_IMPORT -# if defined(_WIN32) || defined(_WIN64) -# define QDLT_C_EXPORT __declspec(dllimport) -# else -# define QDLT_C_EXPORT -# endif #endif #endif // EXPORT_RULES_H diff --git a/qdlt/qdlt.pro b/qdlt/qdlt.pro index 978c5d6f..244b2a90 100644 --- a/qdlt/qdlt.pro +++ b/qdlt/qdlt.pro @@ -71,6 +71,7 @@ SOURCES += \ HEADERS += qdlt.h \ export_rules.h \ + export_c_rules.h \ dlt_common.h \ dlt_user.h \ qdltipconnection.h \ diff --git a/qdlt/qdltargument.cpp b/qdlt/qdltargument.cpp index 893db5f5..8c6dc70a 100644 --- a/qdlt/qdltargument.cpp +++ b/qdlt/qdltargument.cpp @@ -19,8 +19,6 @@ * @licence end@ */ -#include - #include "qdltargument.h" extern "C" @@ -28,17 +26,17 @@ extern "C" #include "dlt_common.h" } +namespace { +constexpr const char * const qDltTypeInfo[] = {"String", "Bool", "SignedInteger", "UnsignedInteger", + "Float", "RawData", "TraceInfo", "Utf8String"}; +} + QDltArgument::QDltArgument() { // clear content of argument clear(); } -QDltArgument::~QDltArgument() -{ - -} - int QDltArgument::getOffsetPayload() const { return offsetPayload; @@ -72,12 +70,12 @@ QDltArgument::DltTypeInfoDef QDltArgument::getTypeInfo() const QString QDltArgument::getTypeInfoString() const { if(typeInfo<0) - return QString(""); + return ""; - return QString(qDltTypeInfo[typeInfo]); + return qDltTypeInfo[typeInfo]; } -bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset,DltEndiannessDef _endianess) +bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset, QDlt::DltEndiannessDef _endianess) { unsigned short length=0,length2=0,length3=0; @@ -93,7 +91,7 @@ bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset,DltEndia /* get type info */ if((unsigned int)payload.size()<(offset+sizeof(unsigned int))) return false; - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) dltType = *((unsigned int*) (payload.constData()+offset)); else dltType = DLT_SWAP_32((*((unsigned int*) (payload.constData()+offset)))); @@ -145,7 +143,7 @@ bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset,DltEndia { if((unsigned int)payload.size()<(offset+sizeof(unsigned short))) return false; - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) length = *((unsigned short*) (payload.constData()+offset)); else length = DLT_SWAP_16((*((unsigned short*) (payload.constData()+offset)))); @@ -158,7 +156,7 @@ bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset,DltEndia { if((unsigned int)payload.size()<(offset+sizeof(unsigned short))) return false; - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) length2 = *((unsigned short*) (payload.constData()+offset)); else length2 = DLT_SWAP_16((*((unsigned short*) (payload.constData()+offset)))); @@ -167,7 +165,7 @@ bool QDltArgument::setArgument(QByteArray &payload,unsigned int &offset,DltEndia { if((unsigned int)payload.size()<(offset+sizeof(unsigned short))) return false; - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) length3 = *((unsigned short*) (payload.constData()+offset)); else length3 = DLT_SWAP_16((*((unsigned short*) (payload.constData()+offset)))); @@ -374,7 +372,7 @@ void QDltArgument::clear() data.clear(); name.clear(); unit.clear(); - endianness = QDltArgument::DltEndiannessUnknown; + endianness = QDlt::DltEndiannessUnknown; dltType = 0; } @@ -384,7 +382,7 @@ QString QDltArgument::toString(bool binary) const text.reserve(1024); if(binary) { - return toAscii(data); + return QDlt::toAscii(data); } switch(getTypeInfo()) { @@ -418,19 +416,19 @@ QString QDltArgument::toString(bool binary) const text += QString("%1").arg((short)(*(char*)(data.constData()))); break; case 2: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((short)(*(short*)(data.constData()))); else text += QString("%1").arg((short)DLT_SWAP_16((short)(*(short*)(data.constData())))); break; case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((int)(*(int*)(data.constData()))); else text += QString("%1").arg((int)DLT_SWAP_32((int)(*(int*)(data.constData())))); break; case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((long long)(*(long long*)(data.constData()))); else text += QString("%1").arg((long long)DLT_SWAP_64((long long)(*(long long*)(data.constData())))); @@ -444,20 +442,20 @@ QString QDltArgument::toString(bool binary) const if ((dltType & DLT_TYPE_INFO_SCOD)==DLT_SCOD_BIN) { if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_8BIT) - text += toAscii(data,2,1); // show binary + text += QDlt::toAscii(data,2,1); // show binary else if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_16BIT) - text += toAscii(data,2,2); // show binary + text += QDlt::toAscii(data,2,2); // show binary } else if ((dltType & DLT_TYPE_INFO_SCOD)==DLT_SCOD_HEX) { if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_8BIT) - text += toAscii(data,0,1); // show 8 bit hex + text += QDlt::toAscii(data,0,1); // show 8 bit hex else if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_16BIT) - text += toAscii(data,0,2); // show 16 bit hex + text += QDlt::toAscii(data,0,2); // show 16 bit hex else if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_32BIT) - text += toAscii(data,0,4); // show 32 bit hex + text += QDlt::toAscii(data,0,4); // show 32 bit hex else if((dltType & DLT_TYPE_INFO_TYLE)==DLT_TYLE_64BIT) - text += toAscii(data,0,8); // show 64 bit hex + text += QDlt::toAscii(data,0,8); // show 64 bit hex } else { @@ -467,19 +465,19 @@ QString QDltArgument::toString(bool binary) const text += QString("%1").arg((unsigned short)(*(unsigned char*)(data.constData()))); break; case 2: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((unsigned short)(*(unsigned short*)(data.constData()))); else text += QString("%1").arg((unsigned short)DLT_SWAP_16((unsigned short)(*(unsigned short*)(data.constData())))); break; case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((unsigned int)(*(unsigned int*)(data.constData()))); else text += QString("%1").arg((unsigned int)DLT_SWAP_32((unsigned int)(*(unsigned int*)(data.constData())))); break; case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((unsigned long long)(*(unsigned long long*)(data.constData()))); else text += QString("%1").arg((unsigned long long)DLT_SWAP_64((unsigned long long)(*(unsigned long long*)(data.constData())))); @@ -493,7 +491,7 @@ QString QDltArgument::toString(bool binary) const switch(data.size()) { case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((double)(*(float*)(data.constData())), 0, 'f', 8); else { @@ -503,7 +501,7 @@ QString QDltArgument::toString(bool binary) const } break; case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1").arg((double)(*(double*)(data.constData())), 0, 'f', 8); else { const auto tmp = DLT_SWAP_64((unsigned long long)(*(unsigned long long*)(data.constData()))); @@ -516,7 +514,7 @@ QString QDltArgument::toString(bool binary) const } break; case DltTypeInfoRawd: - text += toAscii(data,0); // show raw format (no leading 0x) + text += QDlt::toAscii(data,0); // show raw format (no leading 0x) break; case DltTypeInfoTrai: text += QString("?"); @@ -554,17 +552,17 @@ QVariant QDltArgument::getValue() const case 1: return QVariant((short)(*(char*)(data.constData()))); case 2: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((short)(*(short*)(data.constData()))); else return QVariant(DLT_SWAP_16((short)(*(short*)(data.constData())))); case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((int)(*(int*)(data.constData()))); else return QVariant(DLT_SWAP_32((int)(*(int*)(data.constData())))); case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((long long)(*(long long*)(data.constData()))); else return QVariant(DLT_SWAP_64((long long)(*(long long*)(data.constData())))); @@ -578,17 +576,17 @@ QVariant QDltArgument::getValue() const case 1: return QVariant((unsigned short)(*(unsigned char*)(data.constData()))); case 2: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((unsigned short)(*(unsigned short*)(data.constData()))); else return QVariant(DLT_SWAP_16((unsigned short)(*(unsigned short*)(data.constData())))); case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((unsigned int)(*(unsigned int*)(data.constData()))); else return QVariant(DLT_SWAP_32((unsigned int)(*(unsigned int*)(data.constData())))); case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((unsigned long long)(*(unsigned long long*)(data.constData()))); else return QVariant(DLT_SWAP_64((unsigned long long)(*(unsigned long long*)(data.constData())))); @@ -601,7 +599,7 @@ QVariant QDltArgument::getValue() const switch(data.size()) { case 4: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((double)(*(float*)(data.constData()))); else { @@ -611,7 +609,7 @@ QVariant QDltArgument::getValue() const return QVariant((double)(*((float*)buf))); } case 8: - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) return QVariant((double)(*(double*)(data.constData()))); else { const auto tmp = DLT_SWAP_64((unsigned long long)(*(unsigned long long*)(data.constData()))); @@ -638,7 +636,7 @@ bool QDltArgument::setValue(QVariant value, bool verboseMode) { Q_UNUSED(verboseMode); - endianness = QDltArgument::DltEndiannessLittleEndian; + endianness = QDlt::DltEndiannessLittleEndian; switch(value.type()) { diff --git a/qdlt/qdltargument.h b/qdlt/qdltargument.h index 49e52b6e..04c53ea1 100644 --- a/qdlt/qdltargument.h +++ b/qdlt/qdltargument.h @@ -22,13 +22,8 @@ #ifndef QDLT_ARGUMENT_H #define QDLT_ARGUMENT_H -#include #include -#include -#include -#include #include -#include #include "qdltbase.h" #include "export_rules.h" @@ -38,7 +33,7 @@ This class contains one argument of a DLT message. A QDltMessage contains several Arguments. */ -class QDLT_EXPORT QDltArgument : public QDlt +class QDLT_EXPORT QDltArgument { public: @@ -48,11 +43,6 @@ class QDLT_EXPORT QDltArgument : public QDlt */ QDltArgument(); - //! Destructor. - /*! - */ - ~QDltArgument(); - //! The type definition of a DLT message argument. typedef enum { DltTypeInfoUnknown = -2, DltTypeInfoStrg = 0,DltTypeInfoBool,DltTypeInfoSInt,DltTypeInfoUInt, DltTypeInfoFloa, DltTypeInfoRawd, DltTypeInfoTrai, DltTypeInfoUtf8 } DltTypeInfoDef; @@ -99,14 +89,14 @@ class QDLT_EXPORT QDltArgument : public QDlt \sa DltEndiannessDef \return The endianness of the DLT message. */ - DltEndiannessDef getEndianness() const { return endianness; } + QDlt::DltEndiannessDef getEndianness() const { return endianness; } //! Set the endianness of the Argument. /*! \sa DltEndiannessDef \param _endianess The endianness of the argument. */ - void setEndianness(DltEndiannessDef _endianess) { endianness = (QDlt::DltEndiannessDef)_endianess; } + void setEndianness(QDlt::DltEndiannessDef _endianess) { endianness = _endianess; } //! Get the byte data of the parameter. /*! @@ -163,7 +153,7 @@ class QDLT_EXPORT QDltArgument : public QDlt \param _endianess The new endianness of the argument \return The name of the unit of the variable. */ - bool setArgument(QByteArray &payload,unsigned int &offset,DltEndiannessDef _endianess); + bool setArgument(QByteArray &payload,unsigned int &offset, QDlt::DltEndiannessDef _endianess); //! Get argument as byte array and appends it to data. /*! @@ -192,7 +182,7 @@ class QDLT_EXPORT QDltArgument : public QDlt private: //! The endianness of the argument. - DltEndiannessDef endianness; + QDlt::DltEndiannessDef endianness; //! This type of the argument linked in the DLT message header unsigned int dltType; @@ -217,7 +207,6 @@ class QDLT_EXPORT QDltArgument : public QDlt This is an optional parameter. */ QString unit; - }; diff --git a/qdlt/qdltbase.cpp b/qdlt/qdltbase.cpp index 7bfe1259..d8216c16 100644 --- a/qdlt/qdltbase.cpp +++ b/qdlt/qdltbase.cpp @@ -19,63 +19,11 @@ * @licence end@ */ -#include - #include "qdltbase.h" -extern "C" -{ -#include "dlt_common.h" -} - -const char *qDltMessageType[] = {"log","app_trace","nw_trace","control","","","",""}; -const char *qDltLogInfo[] = {"","fatal","error","warn","info","debug","verbose","","","","","","","","",""}; -const char *qDltTraceType[] = {"","variable","func_in","func_out","state","vfb","","","","","","","","","",""}; -const char *qDltNwTraceType[] = {"","ipc","can","flexray","most","vfb","","","","","","","","","",""}; -const char *qDltControlType[] = {"","request","response","time","","","","","","","","","","","",""}; -const char *qDltMode[] = {"non-verbose","verbose"}; -const char *qDltEndianness[] = {"little-endian","big-endian"}; -const char *qDltTypeInfo[] = {"String","Bool","SignedInteger","UnsignedInteger","Float","RawData","TraceInfo","Utf8String"}; -const char *qDltCtrlServiceId[] = {"","set_log_level","set_trace_status","get_log_info","get_default_log_level","store_config","reset_to_factory_default", - "set_com_interface_status","set_com_interface_max_bandwidth","set_verbose_mode","set_message_filtering","set_timing_packets", - "get_local_time","use_ecu_id","use_session_id","use_timestamp","use_extended_header","set_default_log_level","set_default_trace_status", - "get_software_version","message_buffer_overflow"}; -const char *qDltCtrlReturnType [] = {"ok","not_supported","error","3","4","5","6","7","no_matching_context_id"}; - -QDlt::QDlt() -{ - -} - -QDlt::~QDlt() -{ - -} - -bool QDlt::swap(QByteArray &bytes,int size, int offset) -{ - char tmp; - - if( (offset < 0) || (offset >= bytes.size()) ) - return false; - - if(size == -1) - size = bytes.size()-offset; - - if((size+offset) > bytes.size()) - return false; - - for(int num = 0;num<(size/2);num++) - { - tmp = bytes[offset+num]; - bytes[offset+num] = bytes[offset+size-1-num]; - bytes[offset+size-1-num] = tmp; - } - - return true; -} +#include -QString QDlt::toAsciiTable(const QByteArray &bytes, bool withLineNumber, bool withBinary, bool withAscii, int blocksize, int linesize, bool toHtml) const +QString QDlt::toAsciiTable(const QByteArray &bytes, bool withLineNumber, bool withBinary, bool withAscii, int blocksize, int linesize, bool toHtml) { QString text; text.reserve(1024+bytes.size()); @@ -156,9 +104,8 @@ QString QDlt::toAsciiTable(const QByteArray &bytes, bool withLineNumber, bool wi return text; } -QString QDlt::toAscii(const QByteArray &bytes, int type,int size_bytes) const +QString QDlt::toAscii(const QByteArray &bytes, int type,int size_bytes) { - static const char hexmap[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; if (type==1) { // ascii @@ -231,6 +178,7 @@ QString QDlt::toAscii(const QByteArray &bytes, int type,int size_bytes) const char* strData = &str[0]; const char* byteData = bytes.data(); + static const char hexmap[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; for(int num=0;num> 4 ]; diff --git a/qdlt/qdltbase.h b/qdlt/qdltbase.h index 8544bedc..56db5836 100644 --- a/qdlt/qdltbase.h +++ b/qdlt/qdltbase.h @@ -22,37 +22,11 @@ #ifndef QDLT_BASE_H #define QDLT_BASE_H -#include #include -#include -#include -#include -#include #include "export_rules.h" -extern "C" { - QDLT_C_EXPORT extern const char *qDltMessageType[]; - QDLT_C_EXPORT extern const char *qDltLogInfo[]; - QDLT_C_EXPORT extern const char *qDltTraceType[]; - QDLT_C_EXPORT extern const char *qDltNwTraceType[]; - QDLT_C_EXPORT extern const char *qDltControlType[]; - QDLT_C_EXPORT extern const char *qDltMode[]; - QDLT_C_EXPORT extern const char *qDltEndianness[]; - QDLT_C_EXPORT extern const char *qDltTypeInfo[]; - QDLT_C_EXPORT extern const char *qDltCtrlServiceId[]; - QDLT_C_EXPORT extern const char *qDltCtrlReturnType[]; -} - -#define DLT_MAX_MESSAGE_LEN 1024*64 -#define DEFAULT_COLOR "#FFFFFF" - -struct sDltFile; -struct sDltMessage; - -class QSerialPort; -class QTcpSocket; -class QUdpSocket; +inline constexpr const auto DLT_MAX_MESSAGE_LEN = 1024*64; //! Base class for all DLT classes. /*! @@ -60,26 +34,7 @@ class QUdpSocket; */ class QDLT_EXPORT QDlt { - public: - //! Constructor. - /*! - */ - QDlt(); - - //! Destructor. - /*! - */ - ~QDlt(); - - //! Byte swap some bytes. - /*! - \param bytes The data to be swapped - \param size The number of bytes to be swapped, -1 if all bytes of teh byte array - \param offset Offset in the byte array where to begin to byte swap - */ - bool swap(QByteArray &bytes,int size = -1, int offset = 0); - //! Convert byte array to text or HTML output. /*! \param bytes The data to be converted @@ -91,7 +46,7 @@ class QDLT_EXPORT QDlt \param toHtml true output is don in HTML, false output in text only \return The string with ASCII or html output. */ - QString toAsciiTable(const QByteArray &bytes, bool withLineNumber, bool withBinary, bool withAscii, int blocksize = 8, int linesize = 16, bool toHtml = true) const; + static QString toAsciiTable(const QByteArray &bytes, bool withLineNumber, bool withBinary, bool withAscii, int blocksize = 8, int linesize = 16, bool toHtml = true); //! Convert byte array to text output. /*! @@ -100,17 +55,10 @@ class QDLT_EXPORT QDlt \param size_bytes grouping of bytes together (0xff for raw format) \return The string with ASCII output. */ - QString toAscii(const QByteArray &bytes, int type = false, int size_bytes = 0xff) const; + static QString toAscii(const QByteArray &bytes, int type = false, int size_bytes = 0xff); //! The endianness of the message. - typedef enum { DltEndiannessUnknown = -2, DltEndiannessLittleEndian = 0, DltEndiannessBigEndian = 1 } DltEndiannessDef; - -protected: - - -private: - - + enum DltEndiannessDef { DltEndiannessUnknown = -2, DltEndiannessLittleEndian = 0, DltEndiannessBigEndian = 1 }; }; diff --git a/qdlt/qdltconnection.cpp b/qdlt/qdltconnection.cpp index 7b89fcf5..727f301f 100644 --- a/qdlt/qdltconnection.cpp +++ b/qdlt/qdltconnection.cpp @@ -227,7 +227,7 @@ bool QDltConnection::parseAscii(QDltMsg &msg) // add one argument as String QDltArgument arg; arg.setTypeInfo(QDltArgument::DltTypeInfoStrg); - arg.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg.setEndianness(QDlt::DltEndiannessLittleEndian); arg.setOffsetPayload(0); arg.setData(QByteArray(cbuf,num)+QByteArray("",1)); msg.addArgument(arg); diff --git a/qdlt/qdltimporter.cpp b/qdlt/qdltimporter.cpp index 770190b6..1f209672 100644 --- a/qdlt/qdltimporter.cpp +++ b/qdlt/qdltimporter.cpp @@ -2,15 +2,8 @@ #include #include -/** - * From QDlt. - * Must be a "C" include to interpret the imports correctly - * for MSVC compilers. - **/ -#include "dlt_common.h" extern "C" { - - #include "dlt_user.h" + #include "dlt_common.h" } #if defined(_MSC_VER) @@ -195,7 +188,6 @@ void QDltImporter::dltIpcFromMF4(QString fileName) mdf_hdr_t mdfHeader,mdfDgHeader,mdfCgHeader,mdfCnHeader,mdfTxHeader; mdf_dgblocklinks_t mdfDgBlockLinks; memset((char*)&mdfHeader,0,sizeof(mdf_hdr_t)); - quint64 pos=0,hd_pos=0,dt_pos=0; if(inputfile.read((char*)&mdfHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { @@ -204,11 +196,8 @@ void QDltImporter::dltIpcFromMF4(QString fileName) qDebug() << "fromMF4:" << "Size Error: Cannot read mdf header"; return; } - if(!hd_pos && mdfHeader.id[0]=='#' && mdfHeader.id[1]=='#' && mdfHeader.id[2]=='H' && mdfHeader.id[3]=='D') + if(mdfHeader.id[0]=='#' && mdfHeader.id[1]=='#' && mdfHeader.id[2]=='H' && mdfHeader.id[3]=='D') { - pos = inputfile.pos() - sizeof(mdf_hdr_t); - //qDebug() << "HD:"; - hd_pos=pos; if(inputfile.read((char*)&hdBlockLinks,sizeof(mdf_hdblocklinks_t))!=sizeof(mdf_hdblocklinks_t)) { inputfile.close(); @@ -388,9 +377,7 @@ void QDltImporter::dltIpcFromMF4(QString fileName) } if(mdfHeader.id[0]=='#' && mdfHeader.id[1]=='#' && mdfHeader.id[2]=='D' && mdfHeader.id[3]=='T') { - pos = inputfile.pos() - sizeof(mdf_hdr_t); - //qDebug() << "DT:"; - dt_pos=pos; + const auto pos = inputfile.pos() - sizeof(mdf_hdr_t); quint64 posDt=0; quint16 recordId; quint32 lengthVLSD; @@ -513,17 +500,15 @@ void QDltImporter::dltIpcFromMF4(QString fileName) } if(!recordData.isEmpty()) { - int pos = 0; quint64 time = hdBlockLinks.start_time_ns+ethFrame.timeStamp+(hdBlockLinks.hd_tz_offset_min+hdBlockLinks.hd_dst_offset_min)*60*1000000000; - if(!dltFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!dltFromEthernetFrame(recordData,0,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } - pos = 0; - if(!ipcFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!ipcFromEthernetFrame(recordData,0,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); outputfile->close(); @@ -896,7 +881,7 @@ bool QDltImporter::ipcFromEthernetFrame(QByteArray &record,int pos,quint16 ether // add PLP Header Data QDltArgument arg1; arg1.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg1.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg1.setEndianness(QDlt::DltEndiannessLittleEndian); arg1.setOffsetPayload(0); arg1.setData(record.mid(pos-sizeof(plp_header_data_t),sizeof(plp_header_data_t))); msg.addArgument(arg1); @@ -904,7 +889,7 @@ bool QDltImporter::ipcFromEthernetFrame(QByteArray &record,int pos,quint16 ether // add IPC Header QDltArgument arg2; arg2.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg2.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg2.setEndianness(QDlt::DltEndiannessLittleEndian); arg2.setOffsetPayload(0); if(endOfSegment) { @@ -919,7 +904,7 @@ bool QDltImporter::ipcFromEthernetFrame(QByteArray &record,int pos,quint16 ether // add IPC Data QDltArgument arg3; arg3.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg3.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg3.setEndianness(QDlt::DltEndiannessLittleEndian); arg3.setOffsetPayload(0); if(endOfSegment) { @@ -988,7 +973,7 @@ bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw,QByteArray &record,quint32 // add PLP Header Data QDltArgument arg1; arg1.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg1.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg1.setEndianness(QDlt::DltEndiannessLittleEndian); arg1.setOffsetPayload(0); plp_header_data_t plpHeaderData; plpHeaderData.busSpecId=0; @@ -1002,7 +987,7 @@ bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw,QByteArray &record,quint32 // add IPC Header QDltArgument arg2; arg2.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg2.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg2.setEndianness(QDlt::DltEndiannessLittleEndian); arg2.setOffsetPayload(0); if(endOfSegment) { @@ -1017,7 +1002,7 @@ bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw,QByteArray &record,quint32 // add IPC Data QDltArgument arg3; arg3.setTypeInfo(QDltArgument::DltTypeInfoRawd); - arg3.setEndianness(QDltArgument::DltEndiannessLittleEndian); + arg3.setEndianness(QDlt::DltEndiannessLittleEndian); arg3.setOffsetPayload(0); if(endOfSegment) { diff --git a/qdlt/qdltmsg.cpp b/qdlt/qdltmsg.cpp index c49957a6..f9eed48a 100644 --- a/qdlt/qdltmsg.cpp +++ b/qdlt/qdltmsg.cpp @@ -19,9 +19,6 @@ * @licence end@ */ -#include -#include - #include "qdltmsg.h" extern "C" @@ -29,14 +26,27 @@ extern "C" #include "dlt_common.h" } -QDltMsg::QDltMsg() -{ - clear(); +#include +#include + +namespace { + constexpr const char * const qDltMessageType[] = {"log","app_trace","nw_trace","control","","","",""}; + constexpr const char * const qDltLogInfo[] = {"","fatal","error","warn","info","debug","verbose","","","","","","","","",""}; + constexpr const char * const qDltTraceType[] = {"","variable","func_in","func_out","state","vfb","","","","","","","","","",""}; + constexpr const char * const qDltNwTraceType[] = {"","ipc","can","flexray","most","vfb","","","","","","","","","",""}; + constexpr const char * const qDltControlType[] = {"","request","response","time","","","","","","","","","","","",""}; + constexpr const char * const qDltMode[] = {"non-verbose","verbose"}; + constexpr const char * const qDltEndianness[] = {"little-endian","big-endian"}; + constexpr const char * const qDltCtrlServiceId[] = {"","set_log_level","set_trace_status","get_log_info","get_default_log_level","store_config","reset_to_factory_default", + "set_com_interface_status","set_com_interface_max_bandwidth","set_verbose_mode","set_message_filtering","set_timing_packets", + "get_local_time","use_ecu_id","use_session_id","use_timestamp","use_extended_header","set_default_log_level","set_default_trace_status", + "get_software_version","message_buffer_overflow"}; + constexpr const char * const qDltCtrlReturnType [] = {"ok","not_supported","error","3","4","5","6","7","no_matching_context_id"}; } -QDltMsg::~QDltMsg() +QDltMsg::QDltMsg() { - + clear(); } QString QDltMsg::getStringFromId(const char *text) @@ -54,7 +64,7 @@ QString QDltMsg::getStringFromId(const char *text) QString QDltMsg::getTypeString() const { - return QString((type>=0 && type<=7)?qDltMessageType[type]:""); + return (type >= 0 && type <= 7) ? qDltMessageType[type] : ""; } QString QDltMsg::getSubtypeString() const @@ -277,7 +287,7 @@ quint32 QDltMsg::checkMsgSize(const char *data,quint32 size,bool supportDLTv2) withTags = htyp2 & 0x0200; withSourceFileNameLineNumber = htyp2 & 0x0100; /* TODO: Endianess of payload not defined in DLTv2, undefined, set to LittleEndian by default */ - endianness = DltEndiannessLittleEndian; + endianness = QDlt::DltEndiannessLittleEndian; /* get Message Counter */ messageCounter = *((quint8*) (data + 4 + sizeStorageHeader)); @@ -486,10 +496,10 @@ bool QDltMsg::setMsg(const QByteArray& buf, bool withStorageHeader,bool supportD /* extract endianness */ if(DLT_IS_HTYP_MSBF(standardheader->htyp)) { - endianness = DltEndiannessBigEndian; + endianness = QDlt::DltEndiannessBigEndian; } else { - endianness = DltEndiannessLittleEndian; + endianness = QDlt::DltEndiannessLittleEndian; } /* extract time */ @@ -528,7 +538,7 @@ bool QDltMsg::setMsg(const QByteArray& buf, bool withStorageHeader,bool supportD /* set messageid if non verbose */ if((mode == DltModeNonVerbose) && payload.size()>=4) { /* message id is always in big endian format */ - if(endianness == DltEndiannessLittleEndian) { + if(endianness == QDlt::DltEndiannessLittleEndian) { messageId = (*((unsigned int*) payload.constData())); } else { @@ -538,7 +548,7 @@ bool QDltMsg::setMsg(const QByteArray& buf, bool withStorageHeader,bool supportD /* set service id if message of type control */ if((type == DltTypeControl) && payload.size()>=4) { - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) ctrlServiceId = *((unsigned int*) payload.constData()); else ctrlServiceId = DLT_SWAP_32(*((unsigned int*) payload.constData())); @@ -612,7 +622,7 @@ bool QDltMsg::setMsg(const QByteArray& buf, bool withStorageHeader,bool supportD withTags = htyp2 & 0x0200; withSourceFileNameLineNumber = htyp2 & 0x0100; /* TODO: Endianess of payload not defined in DLTv2, undefined, set to LittleEndian by default */ - endianness = DltEndiannessLittleEndian; + endianness = QDlt::DltEndiannessLittleEndian; /* get Message Counter : always*/ messageCounter = *((quint8*) (buf.constData() + 4 + sizeStorageHeader)); @@ -861,7 +871,7 @@ bool QDltMsg::setMsg(const QByteArray& buf, bool withStorageHeader,bool supportD /* set service id if message of type control */ if((type == DltTypeControl) && payload.size()>=4) { - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) ctrlServiceId = *((unsigned int*) payload.constData()); else ctrlServiceId = DLT_SWAP_32(*((unsigned int*) payload.constData())); @@ -946,7 +956,7 @@ bool QDltMsg::getMsg(QByteArray &buf,bool withStorageHeader) { /* write standardheader */ standardheader.htyp = 0x01 << 5; /* intialise with version number 0x1 */ - if(endianness == DltEndiannessBigEndian) { + if(endianness == QDlt::DltEndiannessBigEndian) { standardheader.htyp |= DLT_HTYP_MSBF; } if(mode == DltModeVerbose) { @@ -1002,7 +1012,7 @@ void QDltMsg::clear() type = DltTypeUnknown; subtype = DltLogUnknown; mode = DltModeUnknown; - endianness = DltEndiannessUnknown; + endianness = QDlt::DltEndiannessUnknown; time = 0; microseconds = 0; timestamp = 0; @@ -1121,9 +1131,9 @@ QString QDltMsg::toStringPayload() const data = payload.mid(4,(payload.size()>260)?256:(payload.size()-4)); if(!data.isEmpty()) { - text += toAsciiTable(data,false,false,true,1024,1024,false); + text += QDlt::toAsciiTable(data,false,false,true,1024,1024,false); text += "|"; - text += toAscii(data, false); + text += QDlt::toAscii(data, false); } return text; } @@ -1142,7 +1152,7 @@ QString QDltMsg::toStringPayload() const { // Skip the ServiceID, Status and Lenght bytes and start from the String containing the ECU Software Version data = payload.mid(9,(payload.size()>265)?256:(payload.size()-9)); - text += toAscii(data,true); + text += QDlt::toAscii(data,true); } else if(getCtrlServiceId() == DLT_SERVICE_ID_CONNECTION_INFO) { @@ -1166,7 +1176,7 @@ QString QDltMsg::toStringPayload() const else { data = payload.mid(5,(payload.size()>261)?256:(payload.size()-5)); - text += toAscii(data); + text += QDlt::toAscii(data); } } else if(getCtrlServiceId() == DLT_SERVICE_ID_TIMEZONE) @@ -1176,7 +1186,7 @@ QString QDltMsg::toStringPayload() const DltServiceTimezone *service; service = (DltServiceTimezone*) payload.constData(); - if(endianness == DltEndiannessLittleEndian) + if(endianness == QDlt::DltEndiannessLittleEndian) text += QString("%1 s").arg(service->timezone); else text += QString("%1 s").arg(DLT_SWAP_32(service->timezone)); @@ -1185,13 +1195,13 @@ QString QDltMsg::toStringPayload() const else { data = payload.mid(5,(payload.size()>261)?256:(payload.size()-5)); - text += toAscii(data); + text += QDlt::toAscii(data); } } else { data = payload.mid(5,(payload.size()>261)?256:(payload.size()-5)); - text += toAscii(data); + text += QDlt::toAscii(data); } return text; @@ -1200,7 +1210,7 @@ QString QDltMsg::toStringPayload() const if( getType()==QDltMsg::DltTypeControl) { text += QString("[%1] ").arg(getCtrlServiceIdString()); data = payload.mid(4,(payload.size()>260)?256:(payload.size()-4)); - text += toAscii(data); + text += QDlt::toAscii(data); return text; } @@ -1505,7 +1515,7 @@ void QDltMsg::genMsg() // write standardheader standardheader.htyp = 0x01 << 5; /* intialise with version number 0x1 */ - if(endianness == DltEndiannessBigEndian) { + if(endianness == QDlt::DltEndiannessBigEndian) { standardheader.htyp |= DLT_HTYP_MSBF; } if(mode == DltModeVerbose) { diff --git a/qdlt/qdltmsg.h b/qdlt/qdltmsg.h index becb392d..b89b0150 100644 --- a/qdlt/qdltmsg.h +++ b/qdlt/qdltmsg.h @@ -22,12 +22,7 @@ #ifndef QDLT_MSG_H #define QDLT_MSG_H -#include #include -#include -#include -#include -#include #include "export_rules.h" #include "qdltbase.h" @@ -38,7 +33,7 @@ This class provide access to a single DLT message from a DLT log file. This class is currently not thread safe. */ -class QDLT_EXPORT QDltMsg : public QDlt +class QDLT_EXPORT QDltMsg { public: //! Constructor. @@ -47,11 +42,6 @@ class QDLT_EXPORT QDltMsg : public QDlt */ QDltMsg(); - //! Destructor. - /*! - */ - ~QDltMsg(); - //! The type of the DLT message. typedef enum { DltTypeUnknown = -2, DltTypeLog = 0,DltTypeAppTrace,DltTypeNwTrace,DltTypeControl } DltTypeDef; @@ -228,14 +218,14 @@ class QDLT_EXPORT QDltMsg : public QDlt \sa DltEndiannessDef \return The endianness of the DLT message. */ - DltEndiannessDef getEndianness() const { return endianness; } + QDlt::DltEndiannessDef getEndianness() const { return endianness; } //! Set the endianness of the DLT message. /*! \sa DltEndiannessDef \param _endianness The endianness of the DLT message. */ - void setEndianness(DltEndiannessDef _endianness) { endianness = _endianness; } + void setEndianness(QDlt::DltEndiannessDef _endianness) { endianness = _endianness; } //! Get the text of the endianness of the DLT message. /*! @@ -546,8 +536,6 @@ class QDLT_EXPORT QDltMsg : public QDlt int getIndex() const; void setIndex(int newIndex); -protected: - private: //! The header parameter ECU Id. @@ -569,7 +557,7 @@ class QDLT_EXPORT QDltMsg : public QDlt DltModeDef mode; //! The endianness of the payload of the message. - DltEndiannessDef endianness; + QDlt::DltEndiannessDef endianness; //! The time, seconds part, of the message generated by the logger. time_t time; diff --git a/qdlt/qdltsegmentedmsg.cpp b/qdlt/qdltsegmentedmsg.cpp index afe9d725..3d6aae43 100644 --- a/qdlt/qdltsegmentedmsg.cpp +++ b/qdlt/qdltsegmentedmsg.cpp @@ -19,11 +19,8 @@ * @licence end@ */ -#include - #include "qdltsegmentedmsg.h" - QDltSegmentedMsg::QDltSegmentedMsg() { diff --git a/src/dltfileindexer.cpp b/src/dltfileindexer.cpp index 9013eb97..f214730c 100644 --- a/src/dltfileindexer.cpp +++ b/src/dltfileindexer.cpp @@ -15,7 +15,6 @@ extern "C" { #include "dlt_common.h" - #include "dlt_user.h" } DltFileIndexerKey::DltFileIndexerKey(time_t time, unsigned int microseconds, int index) diff --git a/src/dltfileindexerthread.cpp b/src/dltfileindexerthread.cpp index c8ef7219..b4b5529c 100644 --- a/src/dltfileindexerthread.cpp +++ b/src/dltfileindexerthread.cpp @@ -66,7 +66,7 @@ void DltFileIndexerThread::processMessage(QSharedPointer &msg, int inde { QByteArray payload = msg->getPayload(); QByteArray data = payload.mid(9, (payload.size() > 262) ? 256 : (payload.size() - 9)); - QString version = msg->toAscii(data,true); + QString version = QDlt::toAscii(data,true); version = version.trimmed(); // remove all white spaces at beginning and end indexer->versionString(msg->getEcuid(),version); } @@ -83,7 +83,7 @@ void DltFileIndexerThread::processMessage(QSharedPointer &msg, int inde DltServiceTimezone *service; service = (DltServiceTimezone*) payload.constData(); - if(msg->getEndianness() == QDltMsg::DltEndiannessLittleEndian) + if(msg->getEndianness() == QDlt::DltEndiannessLittleEndian) indexer->timezone(service->timezone, service->isdst); else indexer->timezone(DLT_SWAP_32(service->timezone), service->isdst); @@ -163,7 +163,7 @@ void DltFileIndexerThread::processMessage(QSharedPointer &msg, int inde ptr = payload.constData(); length = payload.size(); DLT_MSG_READ_VALUE(service_id_tmp,ptr, length, uint32_t); - service_id=DLT_ENDIAN_GET_32(((msg->getEndianness() == QDltMsg::DltEndiannessBigEndian) ? DLT_HTYP_MSBF:0), service_id_tmp); + service_id=DLT_ENDIAN_GET_32(((msg->getEndianness() == QDlt::DltEndiannessBigEndian) ? DLT_HTYP_MSBF:0), service_id_tmp); if(service_id == DLT_SERVICE_ID_GET_LOG_INFO) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3c14a865..5f2a5ec6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -56,9 +56,7 @@ * Must be a "C" include to interpret the imports correctly * for MSVC compilers. **/ -#include "dlt_common.h" extern "C" { - #include "dlt_user.h" } @@ -200,8 +198,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->actionProject->setChecked(ui->dockWidgetContents->isVisible()); ui->actionSearch_Results->setChecked(ui->dockWidgetSearchIndex->isVisible()); - newCompleter = new QCompleter(&m_CompleterModel,this); - /* what for do we need the next 2 lines ? */ draw_timer.setSingleShot (true); connect(&draw_timer, SIGNAL(timeout()), this, SLOT(draw_timeout())); @@ -278,7 +274,6 @@ MainWindow::~MainWindow() delete dltIndexer; delete m_shortcut_searchnext; delete m_shortcut_searchprev; - delete newCompleter; delete sortProxyModel; } @@ -2384,21 +2379,15 @@ void MainWindow::on_action_menuFile_Quit_triggered() void MainWindow::on_actionFindNext() { - //qDebug() << "on_actionFindNext" << __LINE__; - if(!searchInput->input()->text().isEmpty() && !list.contains(searchInput->input()->text())) - { - list.append(searchInput->input()->text()); - } - QString title = "Search Results"; + searchInput->updateHistory(); + QString title = "Search Results"; if ( 0 < m_searchtableModel->get_SearchResultListSize()) { - title = QString("Search Results: %L1").arg(m_searchtableModel->get_SearchResultListSize()); + title += QStringLiteral(": %L1").arg(m_searchtableModel->get_SearchResultListSize()); } ui->dockWidgetSearchIndex->setWindowTitle(title); ui->dockWidgetSearchIndex->show(); - m_CompleterModel.setStringList(list); - searchInput->input()->setCompleter(newCompleter); } void MainWindow::on_action_menuProject_New_triggered() @@ -4476,7 +4465,7 @@ void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QD /* control message was received */ uint32_t service_id_tmp=0; DLT_MSG_READ_VALUE(service_id_tmp,ptr,length,uint32_t); - uint32_t service_id=DLT_ENDIAN_GET_32( ((msg.getEndianness()==QDltMsg::DltEndiannessBigEndian)?DLT_HTYP_MSBF:0), service_id_tmp); + uint32_t service_id=DLT_ENDIAN_GET_32( ((msg.getEndianness()==QDlt::DltEndiannessBigEndian)?DLT_HTYP_MSBF:0), service_id_tmp); switch (service_id) { @@ -4488,6 +4477,7 @@ void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QD versionString(msg); autoloadPluginsVersionEcus.append(msg.getEcuid()); } + break; } case DLT_SERVICE_ID_GET_LOG_INFO: { @@ -4507,7 +4497,7 @@ void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QD { uint16_t count_app_ids=0,count_app_ids_tmp=0; DLT_MSG_READ_VALUE(count_app_ids_tmp,ptr,length,uint16_t); - count_app_ids=DLT_ENDIAN_GET_16(((msg.getEndianness()==QDltMsg::DltEndiannessBigEndian)?DLT_HTYP_MSBF:0), count_app_ids_tmp); + count_app_ids=DLT_ENDIAN_GET_16(((msg.getEndianness()==QDlt::DltEndiannessBigEndian)?DLT_HTYP_MSBF:0), count_app_ids_tmp); for (int32_t num=0;numtimezone, service->isdst); else controlMessage_Timezone(DLT_SWAP_32(service->timezone), service->isdst); @@ -6340,7 +6330,7 @@ void MainWindow::versionString(const QDltMsg &msg) QByteArray payload = msg.getPayload(); QByteArray data = payload.mid(9,(payload.size()>262)?256:(payload.size()-9)); - target_version_string = msg.toAscii(data,true); + target_version_string = QDlt::toAscii(data,true); target_version_string = target_version_string.trimmed(); // remove all white spaces at beginning and end //qDebug() << "Versionstring"<< target_version_string << __LINE__ ; @@ -7871,8 +7861,6 @@ void MainWindow::on_actionJump_To_triggered() } jump_to_line(dlg.getIndex()); - - } @@ -8235,18 +8223,10 @@ void MainWindow::on_actionDefault_Filter_Reload_triggered() /* load the default filter list */ defaultFilter.load(dir.absolutePath()); - QStringList completerList; - - /* default filter list update combobox */ - QDltFilterList *filterList; - foreach(filterList,defaultFilter.defaultFilterList){ + // default filter list update combobox + for (const auto *filterList : defaultFilter.defaultFilterList) { ui->comboBoxFilterSelection->addItem(filterList->getFilename()); - completerList << filterList->getFilename(); } - //QCompleter *completer = new QCompleter(completerList, this); - //completer->setFilterMode(Qt::MatchContains); - //completer->setCaseSensitivity(Qt::CaseInsensitive); - //ui->comboBoxFilterSelection->setCompleter(completer); } void MainWindow::on_actionDefault_Filter_Create_Index_triggered() diff --git a/src/mainwindow.h b/src/mainwindow.h index 4abd3cd2..fd560c98 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include "tablemodel.h" #include "settingsdialog.h" @@ -43,14 +41,6 @@ #include "ui_mainwindow.h" #include "searchform.h" - -/** - * When ecu items buffer size exceeds this while using - * serial connection, it will be considered corrupted. - **/ - -#define DLT_BUFFER_CORRUPT_TRESHOLD 4* 1024 - /** * @brief Namespace to contain the toolbar positions. * You should always remember to update these enums if you @@ -116,7 +106,6 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; - QCompleter *newCompleter; /* Timer for connecting to ECUs */ QTimer timer; @@ -374,8 +363,6 @@ class MainWindow : public QMainWindow /* default filters */ void resetDefaultFilter(); - QStringListModel m_CompleterModel; - /* Get path from explorerView model index */ QString getPathFromExplorerViewIndexModel(const QModelIndex &proxyIndex); @@ -626,7 +613,6 @@ public slots: QDltDefaultFilter defaultFilter; QStringList openFileNames; - QStringList list; /* store startLoggingDateTime when logging first data */ QDateTime startLoggingDateTime; diff --git a/src/searchform.cpp b/src/searchform.cpp index 25d33024..584d8464 100644 --- a/src/searchform.cpp +++ b/src/searchform.cpp @@ -2,6 +2,7 @@ #include "ui_searchform.h" #include +#include SearchForm::SearchForm(QWidget *parent) : QWidget(parent) @@ -12,6 +13,9 @@ SearchForm::SearchForm(QWidget *parent) ui->comboBox->setLineEdit(new QLineEdit); ui->comboBox->setInsertPolicy(QComboBox::InsertAtTop); + m_completer = new QCompleter(&m_historyModel, this); + input()->setCompleter(m_completer); + connect (ui->abortButton, &QPushButton::clicked, this, &SearchForm::abortSearch); } @@ -46,3 +50,11 @@ void SearchForm::resetProgress() { setProgress(0); } + +void SearchForm::updateHistory() { + if (auto list = m_historyModel.stringList(); + !input()->text().isEmpty() && !list.contains(input()->text())) { + list.append(input()->text()); + m_historyModel.setStringList(std::move(list)); + } +} diff --git a/src/searchform.h b/src/searchform.h index 117a8a17..00e0871a 100644 --- a/src/searchform.h +++ b/src/searchform.h @@ -2,12 +2,14 @@ #define SEARCHFORM_H #include +#include namespace Ui { class SearchForm; } class QLineEdit; +class QCompleter; class SearchForm : public QWidget { @@ -27,12 +29,16 @@ class SearchForm : public QWidget void setState(State state); void setProgress(int val); void resetProgress(); + void updateHistory(); signals: void abortSearch(); private: Ui::SearchForm *ui; + + QCompleter *m_completer{nullptr}; + QStringListModel m_historyModel; }; #endif // SEARCHFORM_H