diff --git a/BuildDltViewer.pro b/BuildDltViewer.pro index 5e8cb770..8c25fad4 100644 --- a/BuildDltViewer.pro +++ b/BuildDltViewer.pro @@ -1,7 +1,7 @@ # TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += qdlt src plugin +SUBDIRS += qdlt src plugin commander CONFIG += c++11 ICON = Project.icns diff --git a/CMakeLists.txt b/CMakeLists.txt index d826265a..00cfc9f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ endif() add_subdirectory(qdlt) add_subdirectory(src) add_subdirectory(plugin) +add_subdirectory(commander) message(STATUS "\n\t** DLT Viewer Build Summary **") message(STATUS "\tCMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") diff --git a/build_sdk_windows_qt5_MSVC.bat b/build_sdk_windows_qt5_MSVC.bat index 5cc523a6..b326229d 100644 --- a/build_sdk_windows_qt5_MSVC.bat +++ b/build_sdk_windows_qt5_MSVC.bat @@ -175,6 +175,9 @@ if "%QTNO%"=="6" ( copy %BUILD_DIR%\dlt-viewer.exe %DLT_VIEWER_SDK_DIR% if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER +copy %BUILD_DIR%\dlt-commander.exe %DLT_VIEWER_SDK_DIR% +if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER + copy %BUILD_DIR%\qdlt.dll %DLT_VIEWER_SDK_DIR% if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER diff --git a/commander/CMakeLists.txt b/commander/CMakeLists.txt new file mode 100644 index 00000000..3124416a --- /dev/null +++ b/commander/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (C) 2016, Jack S. Smith +# +# This file is part of COVESA DLT-Commander project. +# +# This Source Code Form is subject to the terms of the +# Mozilla Public License (MPL), v. 2.0. +# If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# For further information see http://www.covesa.global/. +# +# List of changes: +# 01.Oct.2016, Jack Smith , Original Author + +add_executable(dlt-commander + main.cpp + optmanager.cpp) + +target_link_libraries(dlt-commander + qdlt + ${QT_PREFIX}::Core + ${QT_PREFIX}::Network + ${QT_PREFIX}::SerialPort) + +if(CMAKE_COMPILER_IS_GNUCXX) + # https://stackoverflow.com/questions/45329372/ubuntu-recognizes-executable-as-shared-library-and-wont-run-it-by-clicking + # https://forum.juce.com/t/cmake-executable-build-shows-up-as-shared-library-on-linux-mint/45503/6 + target_link_options(dlt-commander PRIVATE "-no-pie") +endif() + +set_target_properties(dlt-commander PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + INSTALL_RPATH "$ORIGIN/../lib;$<$:${DLT_QT_LIB_DIR}>") + + install(TARGETS dlt-commander + DESTINATION "${DLT_EXECUTABLE_INSTALLATION_PATH}" + # Underscore for NSIS compatibility https://gitlab.kitware.com/cmake/cmake/-/issues/19982 + COMPONENT dlt_cmd) + +if(WIN32) + set(DLT_ADDITIONAL_FILES_INSTALLATION_PATH "${DLT_EXECUTABLE_INSTALLATION_PATH}") +else() + set(DLT_ADDITIONAL_FILES_INSTALLATION_PATH ".") +endif() + +include(cmake/${CMAKE_SYSTEM_NAME}.cmake OPTIONAL) diff --git a/commander/cmake/Darwin.cmake b/commander/cmake/Darwin.cmake new file mode 100644 index 00000000..f4fb583d --- /dev/null +++ b/commander/cmake/Darwin.cmake @@ -0,0 +1 @@ +# set properties for the bundle Info.plist file diff --git a/commander/cmake/Linux.cmake b/commander/cmake/Linux.cmake new file mode 100644 index 00000000..ed4df2d2 --- /dev/null +++ b/commander/cmake/Linux.cmake @@ -0,0 +1,8 @@ +# install(DIRECTORY +# resources/icon/ +# COMPONENT dlt_viewer +# DESTINATION "${DLT_RESOURCE_INSTALLATION_PATH}/icons" +# PATTERN resources/icon/*.rc EXCLUDE) + +# https://docs.appimage.org/reference/appdir.html#root-icon + diff --git a/commander/cmake/Windows.cmake b/commander/cmake/Windows.cmake new file mode 100644 index 00000000..80b5c2c2 --- /dev/null +++ b/commander/cmake/Windows.cmake @@ -0,0 +1,12 @@ +set(QT_LIBS + ${QT_PREFIX}::Core + ${QT_PREFIX}::Network + ${QT_PREFIX}::SerialPort) + +foreach(QT_LIB IN ITEMS ${QT_LIBS}) + get_target_property(LIBRARY_PATH ${QT_LIB} LOCATION) + install(FILES + "${LIBRARY_PATH}" + DESTINATION "${DLT_EXECUTABLE_INSTALLATION_PATH}" + COMPONENT qt_libraries) +endforeach() \ No newline at end of file diff --git a/commander/commander.pro b/commander/commander.pro new file mode 100644 index 00000000..f50d84b3 --- /dev/null +++ b/commander/commander.pro @@ -0,0 +1,37 @@ +QT = core + +CONFIG += c++17 cmdline + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Executable name +TARGET = dlt-commander + +# Local includes +INCLUDEPATH = . ../qdlt + +# Unix executable install path +target.path = $$PREFIX/usr/bin +INSTALLS += target + +# Library definitions for debug and release builds +CONFIG(debug, debug|release) { + DESTDIR = ../debug + QMAKE_LIBDIR += ../debug + LIBS += -lqdltd +} else { + DESTDIR = ../release + QMAKE_LIBDIR += ../release + QMAKE_RPATHDIR += ../build/release + LIBS += -lqdlt +} + +SOURCES += \ + main.cpp \ + optmanager.cpp + +HEADERS += \ + export_rules.h \ + optmanager.h diff --git a/commander/main.cpp b/commander/main.cpp new file mode 100644 index 00000000..b6165ddc --- /dev/null +++ b/commander/main.cpp @@ -0,0 +1,166 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +/* + * Examples: + * + * -v + * c:/_test/input1.mf4 c:/_test/output.dlt + * c:/_test/input1.pcap output.dlt + * c:/_test/input1.mf4 c:/_test/input2.mf4 c:/_test/output.dlt + * c:/_test/input1.pcap c:/_test/input2.pcap c:/_test/output.dlt + * -c c:/_test/output.txt c:/_test/input.txt + * -csv -c c:/_test/output.csv c:/_test/input.dlt + * -csv -c c:/_test/output.csv c:/_test/filter.dlf c:/_test/input.dlt + * -d -c c:/_test/output.dlt c:/_test/filter.dlf c:/_test/input.dlt + * -csv -c c:/_test/output.csv c:/_test/input1.mf4 c:/_test/input2.mf4 c:/_test/filter.dlf c:/_test/output.dlt + * + */ + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + QDltFile dltFile; + QDltFilterList filterList; + OptManager opt; + QFile outputfile; + + // Parse commandline parameters + QStringList arguments = a.arguments(); + opt.parse(&arguments); + + // Perform some checks + if(opt.getLogFiles().size()<1) + { + qDebug() << "ERROR: No DLT file used. At least one DLT file must be provided."; + return -1; + } + if(opt.getMf4Files().size()>0 || opt.getPcapFiles().size()>0) + { + if(opt.getLogFiles().size()>1) + { + qDebug() << "ERROR: When importing from MF4 or PCAP files only one DLT file is allowed."; + return -1; + } + else + { + // open outputfile + outputfile.setFileName(opt.getLogFiles()[0]); + outputfile.open(QIODevice::WriteOnly|QIODevice::Truncate); + outputfile.close(); + } + } + + // Import + if(!outputfile.fileName().isEmpty()) + { + // load MF4 files + QStringList mf4Files = opt.getMf4Files(); + if(mf4Files.size()>0) + qDebug() << "### Load MF4 files"; + for ( const auto& i : mf4Files ) + { + qDebug() << "Import MF4 File:" << i; + QDltImporter importer; + importer.dltIpcFromMF4(outputfile,i,0,false); + } + // load PCAP files + QStringList pcapFiles = opt.getPcapFiles(); + if(pcapFiles.size()>0) + qDebug() << "### Load PCAP files"; + for ( const auto& i : pcapFiles ) + { + qDebug() << "Import PCAP File:" << i; + QDltImporter importer; + importer.dltIpcFromPCAP(outputfile,i,0,false); + } + } + + // Export + if(!opt.getConvertDestFile().isEmpty()) + { + // Load dlt files + qDebug() << "### Load DLT files"; + QStringList logFiles = opt.getLogFiles(); + for ( const auto& i : logFiles ) + { + qDebug() << "Load DLT File:" << i; + if(!dltFile.open(i)) + qDebug() << "ERROR: Failed loading file:" << i; + outputfile.setFileName(i); + } + + // Load filter + qDebug() << "### Load filters"; + QStringList filterFiles = opt.getFilterFiles(); + for ( const auto& i : filterFiles ) + { + qDebug() << "Load DLT Filter:" << i; + if(!filterList.LoadFilter(i,true)) + qDebug() << "ERROR: Failed loading filter:" << i; + dltFile.setFilterList(filterList); + dltFile.enableFilter(true); + } + + // Create index + qDebug() << "### Create index"; + dltFile.createIndex(); + qDebug() << "Number of messages:" << dltFile.size(); + + // Create filter index + qDebug() << "### Create filter index"; + dltFile.setFilterList(filterList); + dltFile.createIndexFilter(); + qDebug() << "Number of messages matching filter:" << dltFile.sizeFilter(); + + if(opt.get_convertionmode()==e_DLT) + { + QFile output(opt.getConvertDestFile()); + qDebug() << "### Convert to DLT"; + QDltExporter exporter(0,0,0); + qDebug() << "Commandline DLT convert to " << opt.getConvertDestFile(); + exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatDlt,QDltExporter::SelectionFiltered); + qDebug() << "DLT export to DLT file format done"; + } + if(opt.get_convertionmode()==e_ASCI) + { + QFile output(opt.getConvertDestFile()); + qDebug() << "### Convert to ASCII"; + QDltExporter exporter(0,0,0); + qDebug() << "Commandline ASCII convert to " << opt.getConvertDestFile(); + exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatAscii,QDltExporter::SelectionFiltered); + qDebug() << "DLT export ASCII done"; + } + if(opt.get_convertionmode()==e_CSV) + { + QFile output(opt.getConvertDestFile()); + qDebug() << "### Convert to CSV"; + QDltExporter exporter(0,0,0); + qDebug() << "Commandline ASCII convert to " << opt.getConvertDestFile(); + exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatCsv,QDltExporter::SelectionFiltered); + qDebug() << "DLT export CSV done"; + } + if(opt.get_convertionmode()==e_UTF8) + { + QFile output(opt.getConvertDestFile()); + qDebug() << "### Convert to UTF8"; + QDltExporter exporter(0,0,0); + qDebug() << "Commandline UTF8 convert to " << opt.getConvertDestFile(); + exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatUTF8,QDltExporter::SelectionFiltered); + qDebug() << "DLT export UTF8 done"; + } + } + + // Terminate + qDebug() << "### Terminate DLT Commander"; + + //return a.exec(); + return 0; +} diff --git a/commander/optmanager.cpp b/commander/optmanager.cpp new file mode 100644 index 00000000..71583b8b --- /dev/null +++ b/commander/optmanager.cpp @@ -0,0 +1,192 @@ +/** + * @licence app begin@ + * Copyright (C) 2011-2012 BMW AG + * + * This file is part of COVESA Project Dlt Viewer. + * + * Contributions are licensed to the COVESA Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \file optmanager.cpp + * For further information see http://www.covesa.global/. + * @licence end@ + */ + +#if (WIN32) +#include +#endif + +#include "optmanager.h" +#include "../src/version.h" +#include +#include +#include + +// Global static pointer used to ensure a single instance of the class. +//OptManager* OptManager::instance; + +OptManager::OptManager() +{ + project = false; + log = false; + convert = false; + filter = false; + convertionmode = e_ASCI; +} + +/*OptManager* OptManager::getInstance() +{ + if (!instance) + instance = new OptManager; + + return instance; +}*/ + +OptManager::OptManager(OptManager const&) +{ + +} + +const QStringList &OptManager::getMf4Files() const +{ + return mf4Files; +} + +const QStringList &OptManager::getPcapFiles() const +{ + return pcapFiles; +} + +void OptManager::printVersion(QString appname) +{ + qDebug() << "Start" << appname << "\nBuild time" << __DATE__ << __TIME__; + qDebug() << "Version" << PACKAGE_VERSION << PACKAGE_VERSION_STATE; +} + +void OptManager::printUsage() +{ + QString executable; +#if (WIN32) + qDebug()<<"\nUsage:\n\n dlt-commander.exe [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; + executable = " dlt-commander.exe"; +#else + qDebug()<<"\nUsage:\n\n dlt-commander [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; + executable = " dlt-commander"; +#endif + + qDebug()<<"\nOptions:\n"; + qDebug()<<" [logfile]\tLoading one or more logfiles on startup (must end with .dlt)"; + qDebug()<<" [filterfile]\tLoading filterfile on startup (must end with .dlf)"; + qDebug()<<" [pcapfile]\tImporting DLT/IPC from pcap file on startup (must end with .pcap)"; + qDebug()<<" [mf4file]\tImporting DLT/IPC from mf4 file on startup (must end with .mf4)"; + qDebug()<<" -h \t Print usage"; + qDebug()<<" -v or --version\tOnly show version and buildtime information"; + qDebug()<<" -c textfile\tConvert logfile file to textfile (logfile must end with .dlt)"; + qDebug()<<" -u\tConversion will be done in UTF8 instead of ASCII"; + qDebug()<<" -csv\tConversion will be done in CSV format"; + qDebug()<<" -d\tConversion will NOT be done, save in dlt file format again instead"; + qDebug()<<"\nExamples:\n"; + qDebug().noquote() << executable << "-c .\\trace.txt c:\\trace\\trace.dlt"; + qDebug().noquote() << executable << "-c -u .\\trace.txt c:\\trace\\trace.dlt"; + qDebug().noquote() << executable << "-d -c .\\trace.dlt c:\\trace\\trace.dlt"; + qDebug().noquote() << executable << "-csv -c .\\trace.csv c:\\trace\\trace.dlt"; + qDebug().noquote() << executable << "-d -c .\\filteredtrace.dlt c:\\filter\\filter.dlf c:\\trace\\trace.dlt"; + qDebug().noquote() << executable << "trace_1.dlt trace_2.dlt"; + qDebug().noquote() << executable << "input.pcap output.dlt"; + qDebug().noquote() << executable << "-c output.txt input.pcap"; + qDebug().noquote() << executable << "-c output.txt input1.mf4 input2.mf4\n"; +} + +void OptManager::parse(QStringList *opt) +{ + QString str; + + qDebug() << "### Starting DLT Commander"; + + printVersion(opt->at(0)); + + qDebug() << "### Parsing Options"; + + // 0==Binary 1==First Argument + for (int i = 0; i < opt->size(); ++i) + { + str = opt->at(i); + + if(str.compare("-h") == 0 || str.compare("--help") == 0) + { + printUsage(); + exit(0); + } + else if(str.compare("-v") == 0 || str.compare("--version") == 0) + { + printVersion(opt->at(0)); + exit(0); + } + else if(str.compare("-c")==0) + { + QString c1 = opt->value(i+1); + + convertDestFile = QString("%1").arg(c1); + // check here already if the selected file exists + + qDebug() << "Convert filename:" << convertDestFile; + + i += 1; + } + else if(str.compare("-u")==0) + { + convertionmode = e_UTF8; + } + else if(str.compare("-csv")==0) + { + convertionmode = e_CSV; + } + else if(str.compare("-d")==0) + { + convertionmode = e_DLT; + } + else if(opt->at(i).endsWith(".dlt") || opt->at(i).endsWith(".DLT")) + { + const QString logFile = QString("%1").arg(opt->at(i)); + logFiles += logFile; + qDebug()<< "DLT filename:" << logFile; + } + else if(opt->at(i).endsWith(".dlf") || opt->at(i).endsWith(".DLF")) + { + filterFiles += QString("%1").arg(opt->at(i)); + qDebug()<< "Filter filename:" << QString("%1").arg(opt->at(i)); + } + else if(opt->at(i).endsWith(".pcap") || opt->at(i).endsWith(".PCAP")) + { + const QString pcapFile = QString("%1").arg(opt->at(i)); + pcapFiles += pcapFile; + qDebug()<< "Pcap filename:" << pcapFile; + } + else if(opt->at(i).endsWith(".mf4") || opt->at(i).endsWith(".MF4")) + { + const QString mf4File = QString("%1").arg(opt->at(i)); + mf4Files += mf4File; + qDebug()<< "MF4 filename:" << mf4File; + } + + } // end of for loop +} + +bool OptManager::isLogFile(){return log;} +bool OptManager::isFilterFile(){return filter;} +bool OptManager::isConvert(){return convert;} + +e_convertionmode OptManager::get_convertionmode() +{ + return convertionmode; +} + +QStringList OptManager::getLogFiles(){return logFiles;} +QStringList OptManager::getFilterFiles(){return filterFiles;} +QString OptManager::getConvertSourceFile(){return convertSourceFile;} +QString OptManager::getConvertDestFile(){return convertDestFile;} diff --git a/commander/optmanager.h b/commander/optmanager.h new file mode 100644 index 00000000..95fc9d6a --- /dev/null +++ b/commander/optmanager.h @@ -0,0 +1,76 @@ +/** + * @licence app begin@ + * Copyright (C) 2011-2012 BMW AG + * + * This file is part of COVESA Project Dlt Viewer. + * + * Contributions are licensed to the COVESA Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \file optmanager.h + * For further information see http://www.covesa.global/. + * @licence end@ + */ + +#ifndef OPTMANAGER_H +#define OPTMANAGER_H + +#include + +enum e_convertionmode +{ + e_ASCI = 0, + e_UTF8 = 1, + e_DLT = 2, + e_CSV = 3, +}; + + + +class OptManager +{ +public: + OptManager(); + OptManager(OptManager const&); + + //static OptManager* getInstance(); + void printUsage(); + void printVersion(QString appname); + void parse(QStringList *opt); + + bool isLogFile(); + bool isFilterFile(); + bool isConvert(); + bool isConvertUTF8(); + + e_convertionmode get_convertionmode(); + + QStringList getLogFiles(); + QStringList getFilterFiles(); + QString getConvertSourceFile(); + QString getConvertDestFile(); + + const QStringList &getPcapFiles() const; + const QStringList &getMf4Files() const; + +private: + bool project; + bool log; + bool filter; + bool convert; + e_convertionmode convertionmode; + + QStringList logFiles; + QStringList pcapFiles; + QStringList mf4Files; + QStringList filterFiles; + QString convertSourceFile; + QString convertDestFile; +}; + +#endif // OPTMANAGER_H diff --git a/focal/debian/control b/focal/debian/control index 64ee972f..30aecc8b 100644 --- a/focal/debian/control +++ b/focal/debian/control @@ -30,5 +30,4 @@ Description: COVESA DLT Viewer Development files and decode logs and traces from an infotainment ECU. The Open Source Project is hosted by the COVESA organisation. More information can be found on the homepage of the project: - https://github.com/COVESA/dlt-viewer - + https://github.com/COVESA/dlt-viewer diff --git a/focal/debian/covesa-dlt-viewer.install b/focal/debian/covesa-dlt-viewer.install index fc5599a0..afdb315c 100644 --- a/focal/debian/covesa-dlt-viewer.install +++ b/focal/debian/covesa-dlt-viewer.install @@ -1,4 +1,5 @@ usr/bin/dlt-viewer +usr/bin/dlt-commander usr/lib/*/libqdlt.so.* usr/share/applications/org.genivi.DLTViewer.desktop usr/share/pixmaps/org.genivi.DLTViewer.ico diff --git a/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp b/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp index 37cb6272..14291b90 100644 --- a/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp +++ b/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp @@ -109,11 +109,14 @@ bool DltTestRobotPlugin::controlMsg(int , QDltMsg &) } bool DltTestRobotPlugin::stateChanged(int index, QDltConnection::QDltConnectionState connectionState,QString hostname){ + Q_UNUSED(index) + Q_UNUSED(connectionState) + Q_UNUSED(hostname) #if QT_5_SUPPORTED_VERSION - qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << Qt::endl; + //qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << Qt::endl; #else - qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << endl; + //qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << endl; #endif return true; } diff --git a/plugin/dummycontrolplugin/dummycontrolplugin.cpp b/plugin/dummycontrolplugin/dummycontrolplugin.cpp index 8d138ab6..0f958e4b 100644 --- a/plugin/dummycontrolplugin/dummycontrolplugin.cpp +++ b/plugin/dummycontrolplugin/dummycontrolplugin.cpp @@ -108,11 +108,14 @@ void DummyControlPlugin::updateCounters(int ,int ) } bool DummyControlPlugin::stateChanged(int index, QDltConnection::QDltConnectionState connectionState,QString hostname){ + Q_UNUSED(index) + Q_UNUSED(connectionState) + Q_UNUSED(hostname) #if QT_5_SUPPORTED_VERSION - qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << Qt::endl; + //qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << Qt::endl; #else - qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << endl; + //qDebug() << ecuList->at(index) << "ConnectionState:" << connectionState << "Hostname:" << hostname << endl; #endif return true; } diff --git a/qdlt/CMakeLists.txt b/qdlt/CMakeLists.txt index 735aa700..288b673b 100644 --- a/qdlt/CMakeLists.txt +++ b/qdlt/CMakeLists.txt @@ -36,7 +36,10 @@ add_library(qdlt SHARED qdltplugin.cpp qdltsegmentedmsg.cpp qdltoptmanager.cpp - qdltsettingsmanager.cpp) + qdltsettingsmanager.cpp + qdltexporter.cpp + qdltimporter.cpp + fieldnames.cpp) target_compile_definitions(qdlt PRIVATE BYTE_ORDER=LITTLE_ENDIAN diff --git a/src/fieldnames.cpp b/qdlt/fieldnames.cpp similarity index 100% rename from src/fieldnames.cpp rename to qdlt/fieldnames.cpp diff --git a/src/fieldnames.h b/qdlt/fieldnames.h similarity index 94% rename from src/fieldnames.h rename to qdlt/fieldnames.h index 48708edc..447d2434 100644 --- a/src/fieldnames.h +++ b/qdlt/fieldnames.h @@ -1,11 +1,12 @@ #ifndef FIELDNAMES_H #define FIELDNAMES_H +#include "export_rules.h" #include "qdltsettingsmanager.h" #include #include -class FieldNames : public QObject +class QDLT_EXPORT FieldNames : public QObject { Q_OBJECT public: diff --git a/qdlt/qdlt.pro b/qdlt/qdlt.pro index 84870469..b1980c34 100644 --- a/qdlt/qdlt.pro +++ b/qdlt/qdlt.pro @@ -62,6 +62,9 @@ SOURCES += \ qdltoptmanager.cpp \ qdltsegmentedmsg.cpp \ qdltsettingsmanager.cpp \ + qdltexporter.cpp \ + fieldnames.cpp \ + qdltimporter.cpp \ HEADERS += qdlt.h \ export_rules.h \ @@ -90,6 +93,9 @@ HEADERS += qdlt.h \ qdltoptmanager.h \ qdltsegmentedmsg.h \ qdltsettingsmanager.h \ + qdltexporter.h \ + fieldnames.h \ + qdltimporter.h \ unix:VERSION = 1.0.0 diff --git a/src/dltexporter.cpp b/qdlt/qdltexporter.cpp similarity index 64% rename from src/dltexporter.cpp rename to qdlt/qdltexporter.cpp index 621d156a..f572b805 100644 --- a/src/dltexporter.cpp +++ b/qdlt/qdltexporter.cpp @@ -1,15 +1,12 @@ #include -#include -#include -#include -#include #include +#include -#include "dltexporter.h" +#include "qdltexporter.h" #include "fieldnames.h" #include "qdltoptmanager.h" -DltExporter::DltExporter(Project *_project,QObject *parent) : +QDltExporter::QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,QObject *parent) : QObject(parent) { size = 0; @@ -21,17 +18,19 @@ DltExporter::DltExporter(Project *_project,QObject *parent) : exportSelection = SelectionAll; starting_index=0; stoping_index=0; - project = _project; + automaticTimeSettings=_automaticTimeSettings; + utcOffset=_utcOffset; + dst=_dst; } -QString DltExporter::escapeCSVValue(QString arg) +QString QDltExporter::escapeCSVValue(QString arg) { QString retval = arg.replace(QChar('\"'), QString("\"\"")); retval = QString("\"%1\"").arg(retval); return retval; } -bool DltExporter::writeCSVHeader(QFile *file) +bool QDltExporter::writeCSVHeader(QFile *file) { QString header("\"%1\",\"%2\",\"%3\",\"%4\",\"%5\",\"%6\",\"%7\",\"%8\",\"%9\",\"%10\",\"%11\",\"%12\",\"%13\"\n"); header = header.arg(FieldNames::getName(FieldNames::Index)) @@ -50,13 +49,13 @@ bool DltExporter::writeCSVHeader(QFile *file) return file->write(header.toLatin1().constData()) < 0 ? false : true; } -void DltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg) +void QDltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg) { QString text(""); text += escapeCSVValue(QString("%1").arg(index)).append(","); - if( project->settings->automaticTimeSettings == 0 ) - text += escapeCSVValue(QString("%1.%2").arg(msg.getGmTimeWithOffsetString(project->settings->utcOffset,project->settings->dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(","); + if( automaticTimeSettings == 0 ) + text += escapeCSVValue(QString("%1.%2").arg(msg.getGmTimeWithOffsetString(utcOffset,dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(","); else text += escapeCSVValue(QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(","); text += escapeCSVValue(QString("%1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0'))).append(","); @@ -75,10 +74,10 @@ void DltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg) to->write(text.toLatin1().constData()); } -bool DltExporter::start() +bool QDltExporter::start() { /* Sort the selection list and create Row list */ - if(exportSelection == DltExporter::SelectionSelected && selection != NULL) + if(exportSelection == QDltExporter::SelectionSelected && selection != NULL) { std::sort(selection->begin(), selection->end()); selectedRows.clear(); @@ -91,9 +90,9 @@ bool DltExporter::start() } /* open the export file */ - if(exportFormat == DltExporter::FormatAscii || - exportFormat == DltExporter::FormatUTF8 || - exportFormat == DltExporter::FormatCsv) + if(exportFormat == QDltExporter::FormatAscii || + exportFormat == QDltExporter::FormatUTF8 || + exportFormat == QDltExporter::FormatCsv) { if(!to->open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -102,12 +101,12 @@ bool DltExporter::start() qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); } else - QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), - QString("Cannot open the export file %1").arg(to->fileName())); + ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + // QString("Cannot open the export file %1").arg(to->fileName())); return false; } } - else if((exportFormat == DltExporter::FormatDlt)||(exportFormat == DltExporter::FormatDltDecoded)) + else if((exportFormat == QDltExporter::FormatDlt)||(exportFormat == QDltExporter::FormatDltDecoded)) { if(!to->open(QIODevice::WriteOnly)) { @@ -116,14 +115,14 @@ bool DltExporter::start() qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); } else - QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), - QString("Cannot open the export file %1").arg(to->fileName())); + ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + // QString("Cannot open the export file %1").arg(to->fileName())); return false; } } /* write CSV header if CSV export */ - if(exportFormat == DltExporter::FormatCsv) + if(exportFormat == QDltExporter::FormatCsv) { /* Write the first line of CSV file */ if(!writeCSVHeader(to)) @@ -133,23 +132,23 @@ bool DltExporter::start() qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); } else - QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), - QString("Cannot open the export file %1").arg(to->fileName())); + ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + // QString("Cannot open the export file %1").arg(to->fileName())); return false; } } /* calculate size */ - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) size = from->size(); - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) size = from->sizeFilter(); - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) size = selectedRows.size(); else return false; - if(exportFormat == DltExporter::FormatClipboardJiraTableHead) + if(exportFormat == QDltExporter::FormatClipboardJiraTableHead) { clipboardString = "||" "Index" "||" "Time" "||" "Timestamp" @@ -163,26 +162,23 @@ bool DltExporter::start() return true; } -bool DltExporter::finish() +bool QDltExporter::finish() { - if(exportFormat == DltExporter::FormatAscii || - exportFormat == DltExporter::FormatUTF8 || - exportFormat == DltExporter::FormatCsv || - exportFormat == DltExporter::FormatDlt || - exportFormat == DltExporter::FormatDltDecoded) + if(exportFormat == QDltExporter::FormatAscii || + exportFormat == QDltExporter::FormatUTF8 || + exportFormat == QDltExporter::FormatCsv || + exportFormat == QDltExporter::FormatDlt || + exportFormat == QDltExporter::FormatDltDecoded) { /* close output file */ to->close(); } - else if (exportFormat == DltExporter::FormatClipboard || - exportFormat == DltExporter::FormatClipboardPayloadOnly || - exportFormat == DltExporter::FormatClipboardJiraTable || - exportFormat == DltExporter::FormatClipboardJiraTableHead) + else if (exportFormat == QDltExporter::FormatClipboard || + exportFormat == QDltExporter::FormatClipboardPayloadOnly || + exportFormat == QDltExporter::FormatClipboardJiraTable || + exportFormat == QDltExporter::FormatClipboardJiraTableHead) { - /* export to clipboard */ - QClipboard *clipboard = QApplication::clipboard(); - /*remove '\n' from the string*/ if (clipboardString.endsWith('\n')) { @@ -190,17 +186,17 @@ bool DltExporter::finish() } /* remove null characters */ clipboardString.remove(QChar::Null); - clipboard->setText(clipboardString,QClipboard::Clipboard); + emit clipboard(clipboardString); } return true; } -bool DltExporter::getMsg(unsigned long int num,QDltMsg &msg,QByteArray &buf) +bool QDltExporter::getMsg(unsigned long int num,QDltMsg &msg,QByteArray &buf) { bool result; buf.clear(); - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) { buf = from->getMsg(num); if( true == buf.isEmpty()) @@ -211,7 +207,7 @@ bool DltExporter::getMsg(unsigned long int num,QDltMsg &msg,QByteArray &buf) result = msg.setMsg(buf); msg.setIndex(num); } - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) { buf = from->getMsgFilter(num); if( true == buf.isEmpty()) @@ -222,7 +218,7 @@ bool DltExporter::getMsg(unsigned long int num,QDltMsg &msg,QByteArray &buf) result = msg.setMsg(buf); msg.setIndex(from->getMsgFilterPos(num)); } - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) { buf = from->getMsgFilter(selectedRows[num]); if( true == buf.isEmpty()) @@ -242,32 +238,32 @@ bool DltExporter::getMsg(unsigned long int num,QDltMsg &msg,QByteArray &buf) return result; } -bool DltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &buf) +bool QDltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &buf) { - if((exportFormat == DltExporter::FormatDlt)||(exportFormat == DltExporter::FormatDltDecoded)) + if((exportFormat == QDltExporter::FormatDlt)||(exportFormat == QDltExporter::FormatDltDecoded)) { to->write(buf); } - else if(exportFormat == DltExporter::FormatAscii || - exportFormat == DltExporter::FormatUTF8 || - exportFormat == DltExporter::FormatClipboard || - exportFormat == DltExporter::FormatClipboardPayloadOnly) + else if(exportFormat == QDltExporter::FormatAscii || + exportFormat == QDltExporter::FormatUTF8 || + exportFormat == QDltExporter::FormatClipboard || + exportFormat == QDltExporter::FormatClipboardPayloadOnly) { QString text; /* get message ASCII text */ - if(exportFormat != DltExporter::FormatClipboardPayloadOnly) + if(exportFormat != QDltExporter::FormatClipboardPayloadOnly) { - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) text += QString("%1 ").arg(num); - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) text += QString("%1 ").arg(from->getMsgFilterPos(num)); - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) text += QString("%1 ").arg(from->getMsgFilterPos(selectedRows[num])); else return false; - if( project->settings->automaticTimeSettings == 0 ) - text += QString("%1.%2").arg(msg.getGmTimeWithOffsetString(project->settings->utcOffset,project->settings->dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); + if( automaticTimeSettings == 0 ) + text += QString("%1.%2").arg(msg.getGmTimeWithOffsetString(utcOffset,dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); else text += QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); text += QString(" %1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0')); @@ -287,46 +283,46 @@ bool DltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &buf text += "\n"; try { - if(exportFormat == DltExporter::FormatAscii) + if(exportFormat == QDltExporter::FormatAscii) /* write to file */ to->write(text.toLatin1().constData()); - else if (exportFormat == DltExporter::FormatUTF8) + else if (exportFormat == QDltExporter::FormatUTF8) to->write(text.toUtf8().constData()); - else if(exportFormat == DltExporter::FormatClipboard || - exportFormat == DltExporter::FormatClipboardPayloadOnly) + else if(exportFormat == QDltExporter::FormatClipboard || + exportFormat == QDltExporter::FormatClipboardPayloadOnly) clipboardString += text; } catch (...) { } } - else if(exportFormat == DltExporter::FormatCsv) + else if(exportFormat == QDltExporter::FormatCsv) { - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) writeCSVLine(num, to, msg); - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) writeCSVLine(from->getMsgFilterPos(num), to, msg); - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) writeCSVLine(from->getMsgFilterPos(selectedRows[num]), to, msg); else return false; } - else if ((exportFormat == DltExporter::FormatClipboardJiraTable) || - (exportFormat == DltExporter::FormatClipboardJiraTableHead) ) + else if ((exportFormat == QDltExporter::FormatClipboardJiraTable) || + (exportFormat == QDltExporter::FormatClipboardJiraTableHead) ) { QString text = "|"; - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) text += QString("%1").arg(num); - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) text += QString("%1").arg(from->getMsgFilterPos(num)); - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) text += QString("%1").arg(from->getMsgFilterPos(selectedRows[num])); else return false; - if( project->settings->automaticTimeSettings == 0 ) - text += "|" + QString("%1.%2").arg(msg.getGmTimeWithOffsetString(project->settings->utcOffset,project->settings->dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); + if( automaticTimeSettings == 0 ) + text += "|" + QString("%1.%2").arg(msg.getGmTimeWithOffsetString(utcOffset,dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); else text += "|" + QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); text += "|" + QString("%1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0')) + @@ -341,15 +337,15 @@ bool DltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &buf } -void DltExporter::exportMessageRange(unsigned long start, unsigned long stop) +void QDltExporter::exportMessageRange(unsigned long start, unsigned long stop) { this->starting_index=start; this->stoping_index=stop; } -void DltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *pluginManager, - DltExporter::DltExportFormat exportFormat, - DltExporter::DltExportSelection exportSelection, QModelIndexList *selection) +void QDltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *pluginManager, + QDltExporter::DltExportFormat exportFormat, + QDltExporter::DltExportSelection exportSelection, QModelIndexList *selection) { QDltMsg msg; QByteArray buf; @@ -395,37 +391,21 @@ void DltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *p /* init fileprogress */ - QProgressDialog fileprogress("Export ...", "Cancel", 0, stoping, qobject_cast(parent())); - if (silentMode == true) - { - fileprogress.setWindowTitle("DLT Viewer"); - fileprogress.setWindowModality(Qt::WindowModal); - fileprogress.show(); - } + int progressCounter = 1; + emit progress("Exp",1,0); for(;starting=progressCounter) { - percent=(( starting * 100.0 ) /stoping ); - if (silentMode == true) - { - fileprogress.setValue(starting); - } - if( 0 == (starting%1000000)) - { - qszPercent = QString("Exported: %1 %").arg(percent, 0, 'f',2); - qDebug().noquote() << qszPercent; - } + progressCounter += 1; + emit progress("MF4:",2,percent); // every 1% + if((percent>0) && ((percent%10)==0)) + qDebug() << "Exported:" << percent << "%"; // every 10% } - if (fileprogress.wasCanceled() == true) - { - qDebug().noquote() << "Export canceled !"; - return; - } + // TODO: Handle cancel operation // get message if(false == getMsg(starting,msg,buf)) @@ -437,10 +417,11 @@ void DltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *p // return; } // decode message if needed - if(exportFormat != DltExporter::FormatDlt) + if(exportFormat != QDltExporter::FormatDlt) { - pluginManager->decodeMsg(msg,silentMode); - if (exportFormat == DltExporter::FormatDltDecoded) + if(pluginManager) + pluginManager->decodeMsg(msg,silentMode); + if (exportFormat == QDltExporter::FormatDltDecoded) { msg.setNumberOfArguments(msg.sizeArguments()); msg.getMsg(buf,true); @@ -460,11 +441,7 @@ void DltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *p exportCounter++; } // for loop - if (silentMode == true) - { - fileprogress.close(); - } - + emit progress("",3,100); if (!finish()) { @@ -477,7 +454,7 @@ void DltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *p //qDebug() << "DLT Export finish() failed"; if (silentMode == true ) // reversed login in this case ! { - QMessageBox::warning(NULL,"Export Errors!",QString("Exported successful: %1 / %2\n\nReadErrors:%3\nWriteErrors:%4\nStart/Finish errors:%5").arg(exportCounter).arg(size).arg(readErrors).arg(exportErrors).arg(startFinishError)); + ;//QMessageBox::warning(NULL,"Export Errors!",QString("Exported successful: %1 / %2\n\nReadErrors:%3\nWriteErrors:%4\nStart/Finish errors:%5").arg(exportCounter).arg(size).arg(readErrors).arg(exportErrors).arg(startFinishError)); } return; } diff --git a/src/dltexporter.h b/qdlt/qdltexporter.h similarity index 75% rename from src/dltexporter.h rename to qdlt/qdltexporter.h index c5d6d72a..086f9a49 100644 --- a/src/dltexporter.h +++ b/qdlt/qdltexporter.h @@ -1,17 +1,16 @@ -#ifndef DLTEXPORTER_H -#define DLTEXPORTER_H +#ifndef QDLTEXPORTER_H +#define QDLTEXPORTER_H #include #include #include -#include +#include "export_rules.h" #include "qdltfile.h" #include "qdltmsg.h" #include "qdltpluginmanager.h" -#include "project.h" -class DltExporter : public QObject +class QDLT_EXPORT QDltExporter : public QObject { Q_OBJECT @@ -54,7 +53,7 @@ class DltExporter : public QObject /* Default QT constructor. * Please pass a window as a parameter to parent dialogs correctly. */ - explicit DltExporter(Project *_project,QObject *parent = 0); + explicit QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,QObject *parent = 0); /* Export some messages from QDltFile to a CSV file. * \param from QDltFile to pull messages from @@ -65,13 +64,16 @@ class DltExporter : public QObject * \param selection Limit export to these messages. Leave to NULL to export everything, */ void exportMessages(QDltFile *from, QFile *to, QDltPluginManager *pluginManager, - DltExporter::DltExportFormat exportFormat, - DltExporter::DltExportSelection exportSelection, QModelIndexList *selection = 0); + QDltExporter::DltExportFormat exportFormat, + QDltExporter::DltExportSelection exportSelection, QModelIndexList *selection = 0); void exportMessageRange(unsigned long start, unsigned long stop); signals: + void clipboard(QString text); + void progress(QString name,int status, int progress); + public slots: private: @@ -84,9 +86,11 @@ public slots: QDltPluginManager *pluginManager; QModelIndexList *selection; QList selectedRows; - DltExporter::DltExportFormat exportFormat; - DltExporter::DltExportSelection exportSelection; - Project *project; + QDltExporter::DltExportFormat exportFormat; + QDltExporter::DltExportSelection exportSelection; + int automaticTimeSettings; // project and local setting + qlonglong utcOffset; // project and local setting + int dst; // project and local setting }; -#endif // DLTEXPORTER_H +#endif // QDLTEXPORTER_H diff --git a/src/dltimporter.cpp b/qdlt/qdltimporter.cpp similarity index 94% rename from src/dltimporter.cpp rename to qdlt/qdltimporter.cpp index 92151258..11247a9e 100644 --- a/src/dltimporter.cpp +++ b/qdlt/qdltimporter.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include #include @@ -24,20 +22,25 @@ extern "C" { #include /* for gettimeofday() */ #endif -#include "dltimporter.h" +#include "qdltmsg.h" +#include "qdltimporter.h" -DltImporter::DltImporter() +QDltImporter::QDltImporter(QObject *parent) : + QObject(parent) { } -DltImporter::~DltImporter() +QDltImporter::~QDltImporter() { } -void DltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *parent,bool silent) +void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *parent,bool silent) { + Q_UNUSED(silent) + Q_UNUSED(parent) + counterRecords = 0; counterRecordsDLT = 0; counterRecordsIPC = 0; @@ -49,21 +52,12 @@ void DltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *par if(!inputfile.open(QFile::ReadOnly)) return; - QProgressDialog progress("Import DLT/IPC from PCAP...", "Abort Import", 0, inputfile.size()/1000, parent); - QLabel label(&progress); - if(!silent) - { - progress.setWindowTitle("Import DLT/IPC from PCAP"); - progress.setWindowModality(Qt::WindowModal); - progress.setLabel(&label); - } - quint64 progressCounter = 0; + int progressCounter = 1; + emit progress("PCAP",1,0); pcap_hdr_t globalHeader; pcaprec_hdr_t recordHeader; - QDltMsg qmsg; - qDebug() << "Import DLT/IPC from PCAP file:" << fileName; if(inputfile.read((char*)&globalHeader,sizeof(pcap_hdr_t))!=sizeof(pcap_hdr_t)) @@ -74,18 +68,16 @@ void DltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *par } while(inputfile.read((char*)&recordHeader,sizeof(pcaprec_hdr_t))==sizeof(pcaprec_hdr_t)) { - progressCounter++; - if(!silent && progressCounter%1000==0) + int percent = inputfile.pos()*100/inputfile.size(); + if(percent>=progressCounter) { - progress.setValue(inputfile.pos()/1000); - label.setText(QString("Imported DLT %1 IPC %2").arg(counterDLTMessages).arg(counterIPCMessages)); + progressCounter += 1; + emit progress("PCAP:",2,percent); // every 1% + if((percent>0) && ((percent%10)==0)) + qDebug() << "Import PCAP:" << percent << "%"; // every 10% } - if (progress.wasCanceled()) - { - qDebug() << "fromPCAP:" << "Import Stopped"; - break; - } + // TODO: Handle cancel request QByteArray record = inputfile.read(recordHeader.incl_len); if(record.length() != recordHeader.incl_len) @@ -121,6 +113,8 @@ void DltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *par } inputfile.close(); + emit progress("",3,100); + qDebug() << "fromPCAP: Counter Records:" << counterRecords; qDebug() << "fromPCAP: Counter Records DLT:" << counterRecordsDLT; qDebug() << "fromPCAP: Counter DLT Mesages:" << counterDLTMessages; @@ -131,8 +125,11 @@ void DltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *par } -void DltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *parent,bool silent) +void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *parent,bool silent) { + Q_UNUSED(silent) + Q_UNUSED(parent) + counterRecords = 0; counterRecordsDLT = 0; counterRecordsIPC = 0; @@ -149,15 +146,8 @@ void DltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *pare return; } - QProgressDialog progress("Import DLT/IPC from MF4...", "Abort Import", 0, inputfile.size()/1000, parent); - QLabel label(&progress); - if(!silent) - { - progress.setWindowTitle("Import DLT/IPC from MF4"); - progress.setWindowModality(Qt::WindowModal); - progress.setLabel(&label); - } - quint64 progressCounter = 0; + int progressCounter = 1; + emit progress("MF4",1,0); qDebug() << "Import DLT/IPC from MF4 file:" << fileName; @@ -301,18 +291,16 @@ void DltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *pare QByteArray recordData; while(posDt<(mdfHeader.length-sizeof(mdf_hdr_t))) { - progressCounter++; - if(!silent && progressCounter%1000==0) + int percent = inputfile.pos()*100/inputfile.size(); + if(percent>=progressCounter) { - progress.setValue(inputfile.pos()/1000); - label.setText(QString("Imported DLT %1 IPC %2").arg(counterDLTMessages).arg(counterIPCMessages)); + progressCounter += 1; + emit progress("MF4:",2,percent); // every 1% + if((percent>0) && ((percent%10)==0)) + qDebug() << "Import MF4:" << percent << "%"; // every 10% } - if (progress.wasCanceled()) - { - qDebug() << "fromMF4:" << "Import Stopped"; - break; - } + // TODO: Handle cancel operation //qDebug() << "posDt =" << posDt; inputfile.seek(pos+sizeof(mdf_hdr_t)+posDt); @@ -659,6 +647,8 @@ void DltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *pare inputfile.close(); + emit progress("",3,100); + qDebug() << "fromMF4: counterRecords:" << counterRecords; qDebug() << "fromMF4: counterRecordsDLT:" << counterRecordsDLT; qDebug() << "fromMF4: counterDLTMessages:" << counterDLTMessages; @@ -668,7 +658,7 @@ void DltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *pare qDebug() << "fromMF4: Import finished"; } -bool DltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) +bool QDltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) { if(etherType==0x9100 || etherType==0x88a8) { @@ -806,7 +796,7 @@ bool DltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int return true; } -bool DltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArray &record,quint32 sec,quint32 usec) +bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArray &record,quint32 sec,quint32 usec) { bool startOfSegment = plpRaw->probeFlags & 0x2; if(startOfSegment) @@ -901,7 +891,7 @@ bool DltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArr return true; } -bool DltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 sec,quint32 usec) +bool QDltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 sec,quint32 usec) { counterRecordsDLT++; // Now read the DLT Messages @@ -941,7 +931,7 @@ bool DltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 } -bool DltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) +bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) { if(etherType==0x9100 || etherType==0x88a8) { @@ -1081,7 +1071,7 @@ bool DltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int return true; } -void DltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,EcuItem* ecuitem,quint32 sec,quint32 usec) +void QDltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec,quint32 usec) { DltStorageHeader str; @@ -1113,8 +1103,7 @@ void DltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHead str.microseconds = (int32_t)tv.tv_usec; /* value is long */ #endif } - if (ecuitem) - dlt_set_id(str.ecu, ecuitem->id.toLatin1()); + dlt_set_id(str.ecu, ecuId.toLatin1()); /* check if message is matching the filter */ if(!outputfile.open(QIODevice::WriteOnly|QIODevice::Append)) @@ -1123,12 +1112,12 @@ void DltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHead } // write data into file - if(!ecuitem || !ecuitem->getWriteDLTv2StorageHeader()) + //if(!ecuitem || !ecuitem->getWriteDLTv2StorageHeader()) { // write version 1 storage header outputfile.write((char*)&str,sizeof(DltStorageHeader)); } - else + /*else { // write version 2 storage header outputfile.write((char*)"DLT",3); @@ -1142,7 +1131,7 @@ void DltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHead length = ecuitem->id.length(); outputfile.write((char*)&length,1); outputfile.write(ecuitem->id.toLatin1(),ecuitem->id.length()); - } + }*/ outputfile.write(bufferHeader); outputfile.write(bufferPayload,bufferPayloadSize); outputfile.flush(); diff --git a/src/dltimporter.h b/qdlt/qdltimporter.h similarity index 92% rename from src/dltimporter.h rename to qdlt/qdltimporter.h index 8e43f68c..b6fff3cc 100644 --- a/src/dltimporter.h +++ b/qdlt/qdltimporter.h @@ -1,12 +1,11 @@ -#ifndef DLTIMPORTER_H -#define DLTIMPORTER_H +#ifndef QDLTIMPORTER_H +#define QDLTIMPORTER_H #include -#include "qdltfile.h" -#include "qdltmsg.h" +#include "export_rules.h" +#include "qfile.h" #include "dlt_common.h" -#include "project.h" typedef struct pcap_hdr_s { quint32 magic_number; /* magic number */ @@ -147,13 +146,14 @@ typedef struct mdf_hdr { quint64 link_count; /* number of links in link section */ } PACKED mdf_hdr_t; -class DltImporter +class QDLT_EXPORT QDltImporter : public QObject { + Q_OBJECT public: - explicit DltImporter(); - ~DltImporter(); + explicit QDltImporter(QObject *parent=0); + ~QDltImporter(); void dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *parent,bool silent); void dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *parent,bool silent); @@ -165,7 +165,7 @@ class DltImporter bool ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec = 0,quint32 usec = 0); bool ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArray &record,quint32 sec = 0,quint32 usec = 0); - void writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,EcuItem* ecuitem = 0,quint32 sec = 0,quint32 usec = 0); + void writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec = 0,quint32 usec = 0); mdf_idblock_t mdfIdblock; mdf_hdblocklinks_t hdBlockLinks; @@ -183,6 +183,10 @@ class DltImporter QMap channelGroupLength; QMap channelGroupName; +signals: + + void progress(QString name,int status, int progress); + }; -#endif // DLTIMPORTER_H +#endif // QDLTIMPORTER_H diff --git a/qdlt/qdltoptmanager.cpp b/qdlt/qdltoptmanager.cpp index fbf2bc98..c38af184 100644 --- a/qdlt/qdltoptmanager.cpp +++ b/qdlt/qdltoptmanager.cpp @@ -107,9 +107,9 @@ void QDltOptManager::printUsage() qDebug()<<" -w workingdirectory\tSet the working directory"; qDebug()<<"\nExamples:"; qDebug()<<" dlt-viewer.exe -t -c output.txt input.dlt"; - qDebug()<<" dlt-viewer.exe -t -s -u -c output.dlt input.txt"; + qDebug()<<" dlt-viewer.exe -t -s -u -c output.txt input.dlt"; qDebug()<<" dlt-viewer.exe -t -s -d -c output.dlt input.dlt"; - qDebug()<<" dlt-viewer.exe -t -s -p decoded.dlp -dd -c output.dlt input.dlt "; + qDebug()<<" dlt-viewer.exe -t -s decoded.dlp -dd -c output.dlt input.dlt "; qDebug()<<" dlt-viewer.exe -t -s -csv -c output.csv input.dlt"; qDebug()<<" dlt-viewer.exe -t -s -d filter.dlf -c output.dlt input.dlt"; qDebug()<<" dlt-viewer.exe -p export.dlp -e \"Filetransfer Plugin|export|ftransferdir\" input.dlt"; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5c0496f..6877e1cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,9 +36,6 @@ add_executable(dlt-viewer dltfileutils.cpp dltfileindexer.cpp dlttableview.cpp - dltexporter.cpp - dltimporter.cpp - fieldnames.cpp dltuiutils.cpp workingdirectory.cpp jumptodialog.cpp diff --git a/src/exporterdialog.cpp b/src/exporterdialog.cpp index c3b6e7da..ead8c5d1 100644 --- a/src/exporterdialog.cpp +++ b/src/exporterdialog.cpp @@ -14,54 +14,54 @@ ExporterDialog::~ExporterDialog() delete ui; } -void ExporterDialog::setFormat(DltExporter::DltExportFormat exportFormat) +void ExporterDialog::setFormat(QDltExporter::DltExportFormat exportFormat) { - if(exportFormat == DltExporter::FormatDlt) + if(exportFormat == QDltExporter::FormatDlt) ui->radioButtonDlt->setChecked(true); - else if(exportFormat == DltExporter::FormatAscii) + else if(exportFormat == QDltExporter::FormatAscii) ui->radioButtonAscii->setChecked(true); - else if (exportFormat == DltExporter::FormatUTF8) + else if (exportFormat == QDltExporter::FormatUTF8) ui->radioButtonUTF8->setChecked(true); - else if(exportFormat == DltExporter::FormatCsv) + else if(exportFormat == QDltExporter::FormatCsv) ui->radioButtonCsv->setChecked(true); - else if(exportFormat == DltExporter::FormatDltDecoded) + else if(exportFormat == QDltExporter::FormatDltDecoded) ui->radioButtonDltDecoded->setChecked(true); } -DltExporter::DltExportFormat ExporterDialog::getFormat() +QDltExporter::DltExportFormat ExporterDialog::getFormat() { if(ui->radioButtonDlt->isChecked()) - return DltExporter::FormatDlt; + return QDltExporter::FormatDlt; if(ui->radioButtonAscii->isChecked()) - return DltExporter::FormatAscii; + return QDltExporter::FormatAscii; if(ui->radioButtonUTF8->isChecked()) - return DltExporter::FormatUTF8; + return QDltExporter::FormatUTF8; if(ui->radioButtonCsv->isChecked()) - return DltExporter::FormatCsv; + return QDltExporter::FormatCsv; if(ui->radioButtonDltDecoded->isChecked()) - return DltExporter::FormatDltDecoded; - return DltExporter::FormatDlt; + return QDltExporter::FormatDltDecoded; + return QDltExporter::FormatDlt; } -void ExporterDialog::setSelection(DltExporter::DltExportSelection exportSelection) +void ExporterDialog::setSelection(QDltExporter::DltExportSelection exportSelection) { - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) ui->radioButtonAll->setChecked(true); - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) ui->radioButtonFiltered->setChecked(true); - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) ui->radioButtonSelection->setChecked(true); } -DltExporter::DltExportSelection ExporterDialog::getSelection() +QDltExporter::DltExportSelection ExporterDialog::getSelection() { if(ui->radioButtonAll->isChecked()) - return DltExporter::SelectionAll; + return QDltExporter::SelectionAll; if(ui->radioButtonFiltered->isChecked()) - return DltExporter::SelectionFiltered; + return QDltExporter::SelectionFiltered; if(ui->radioButtonSelection->isChecked()) - return DltExporter::SelectionSelected; - return DltExporter::SelectionAll; + return QDltExporter::SelectionSelected; + return QDltExporter::SelectionAll; } void ExporterDialog::getRange(unsigned long *start, unsigned long *stop) diff --git a/src/exporterdialog.h b/src/exporterdialog.h index dcb7dc79..16f5e422 100644 --- a/src/exporterdialog.h +++ b/src/exporterdialog.h @@ -3,7 +3,7 @@ #include -#include "dltexporter.h" +#include "qdltexporter.h" namespace Ui { class ExporterDialog; @@ -17,11 +17,11 @@ class ExporterDialog : public QDialog explicit ExporterDialog(QWidget *parent = 0); ~ExporterDialog(); - void setFormat(DltExporter::DltExportFormat exportFormat); - DltExporter::DltExportFormat getFormat(); + void setFormat(QDltExporter::DltExportFormat exportFormat); + QDltExporter::DltExportFormat getFormat(); - void setSelection(DltExporter::DltExportSelection exportSelection); - DltExporter::DltExportSelection getSelection(); + void setSelection(QDltExporter::DltExportSelection exportSelection); + QDltExporter::DltExportSelection getSelection(); void getRange(unsigned long *start, unsigned long *stop); void setRange(unsigned long start, unsigned long stop); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 90f0583a..a261c34d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -81,8 +81,8 @@ extern "C" { #include "version.h" #include "dltfileutils.h" #include "dltuiutils.h" -#include "dltexporter.h" -#include "dltimporter.h" +#include "qdltexporter.h" +#include "qdltimporter.h" #include "jumptodialog.h" #include "fieldnames.h" #include "tablemodel.h" @@ -816,7 +816,7 @@ void MainWindow::initFileHandling() if(!QDltOptManager::getInstance()->getPcapFiles().isEmpty()) { qDebug() << "### Import PCAP files"; - DltImporter importer; + QDltImporter importer; for ( const auto& filename : QDltOptManager::getInstance()->getPcapFiles() ) importer.dltIpcFromPCAP(outputfile,filename,this,QDltOptManager::getInstance()->issilentMode()); if(QDltOptManager::getInstance()->isCommandlineMode()) @@ -831,7 +831,7 @@ void MainWindow::initFileHandling() if(!QDltOptManager::getInstance()->getMf4Files().isEmpty()) { qDebug() << "### Import MF4 files"; - DltImporter importer; + QDltImporter importer; for ( const auto& filename : QDltOptManager::getInstance()->getMf4Files() ) importer.dltIpcFromMF4(outputfile,filename,this,QDltOptManager::getInstance()->issilentMode()); if(QDltOptManager::getInstance()->isCommandlineMode()) @@ -851,10 +851,10 @@ void MainWindow::commandLineConvertToDLT() qDebug() << "### Convert to DLT"; /* start exporter */ - DltExporter exporter(&project); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); qDebug() << "Commandline DLT convert to " << dltFile.fileName(); - //exporter.exportMessages(&qfile,&asciiFile,&pluginManager,DltExporter::FormatAscii,DltExporter::SelectionFiltered); - exporter.exportMessages(&qfile,&dltFile,&pluginManager,DltExporter::FormatDlt,DltExporter::SelectionFiltered); + //exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatAsciiQ,QDltExporter::SelectionFiltered); + exporter.exportMessages(&qfile,&dltFile,&pluginManager,QDltExporter::FormatDlt,QDltExporter::SelectionFiltered); qDebug() << "DLT export to DLT file format done"; } @@ -866,9 +866,9 @@ void MainWindow::commandLineConvertToASCII() qDebug() << "### Convert to ASCII"; /* start exporter */ - DltExporter exporter(&project); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); qDebug() << "Commandline ASCII convert to " << asciiFile.fileName(); - exporter.exportMessages(&qfile,&asciiFile,&pluginManager,DltExporter::FormatAscii,DltExporter::SelectionFiltered); + exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatAscii,QDltExporter::SelectionFiltered); qDebug() << "DLT export ASCII done"; } @@ -879,9 +879,9 @@ void MainWindow::commandLineConvertToCSV() qDebug() << "### Convert to CSV"; /* start exporter */ - DltExporter exporter(&project); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); qDebug() << "Commandline ASCII convert to " << asciiFile.fileName(); - exporter.exportMessages(&qfile,&asciiFile,&pluginManager,DltExporter::FormatCsv,DltExporter::SelectionFiltered); + exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatCsv,QDltExporter::SelectionFiltered); qDebug() << "DLT export CSV done"; } @@ -893,9 +893,9 @@ void MainWindow::commandLineConvertToUTF8() /* start exporter */ qDebug() << "### Convert to UTF8"; - DltExporter exporter(&project); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); qDebug() << "Commandline UTF8 convert to " << asciiFile.fileName(); - exporter.exportMessages(&qfile,&asciiFile,&pluginManager,DltExporter::FormatUTF8,DltExporter::SelectionFiltered); + exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatUTF8,QDltExporter::SelectionFiltered); qDebug() << "DLT export UTF8 done"; } @@ -906,9 +906,9 @@ void MainWindow::commandLineConvertToDLTDecoded() qDebug() << "### Convert to DLT Decoded"; /* start exporter */ - DltExporter exporter(&project); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); qDebug() << "Commandline decoding to dlt formated file" << dltFile.fileName(); - exporter.exportMessages(&qfile,&dltFile,&pluginManager,DltExporter::FormatDltDecoded,DltExporter::SelectionFiltered); + exporter.exportMessages(&qfile,&dltFile,&pluginManager,QDltExporter::FormatDltDecoded,QDltExporter::SelectionFiltered); qDebug() << "DLT export DLT decoded done"; } @@ -1101,7 +1101,7 @@ void MainWindow::on_action_menuFile_Open_triggered() /* change DLT file working directory */ workingDirectory.setDltDirectory(QFileInfo(fileNames[0]).absolutePath()); - DltImporter importer; + QDltImporter importer; QStringList dltFileNames,pcapFileNames,mf4FileNames; for ( const auto& i : fileNames ) @@ -1123,7 +1123,9 @@ void MainWindow::on_action_menuFile_Open_triggered() on_action_menuFile_Clear_triggered(); for ( const auto& i : pcapFileNames ) { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); } reloadLogFile(); } @@ -1132,7 +1134,9 @@ void MainWindow::on_action_menuFile_Open_triggered() on_action_menuFile_Clear_triggered(); for ( const auto& i : mf4FileNames ) { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); } reloadLogFile(); } @@ -1476,16 +1480,24 @@ void MainWindow::on_actionAppend_triggered() /* change DLT file working directory */ workingDirectory.setDltDirectory(QFileInfo(fileNames[0]).absolutePath()); - DltImporter importer; + QDltImporter importer; for ( const auto& i : fileNames ) { if(i.endsWith(".dlt",Qt::CaseInsensitive)) appendDltFile(i); else if(i.endsWith(".pcap",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } else if(i.endsWith(".mf4",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } } reloadLogFile(); @@ -1525,7 +1537,7 @@ void MainWindow::unmark_all_lines() } -void MainWindow::exportSelection(bool ascii = true,bool file = false,DltExporter::DltExportFormat format = DltExporter::FormatClipboard) +void MainWindow::exportSelection(bool ascii = true,bool file = false,QDltExporter::DltExportFormat format = QDltExporter::FormatClipboard) { Q_UNUSED(ascii); Q_UNUSED(file); @@ -1533,11 +1545,13 @@ void MainWindow::exportSelection(bool ascii = true,bool file = false,DltExporter QModelIndexList list = ui->tableView->selectionModel()->selection().indexes(); - DltExporter exporter(&project); - exporter.exportMessages(&qfile,0,&pluginManager,format,DltExporter::SelectionSelected,&list); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); + connect(&exporter,SIGNAL(clipboard(QString)),this,SLOT(clipboard(QString))); + exporter.exportMessages(&qfile,0,&pluginManager,format,QDltExporter::SelectionSelected,&list); + disconnect(&exporter,SIGNAL(clipboard(QString)),this,SLOT(clipboard(QString))); } -void MainWindow::exportSelection_searchTable(DltExporter::DltExportFormat format = DltExporter::FormatClipboard) +void MainWindow::exportSelection_searchTable(QDltExporter::DltExportFormat format = QDltExporter::FormatClipboard) { const QModelIndexList list = ui->tableView_SearchIndex->selectionModel()->selectedRows(); @@ -1567,8 +1581,10 @@ void MainWindow::exportSelection_searchTable(DltExporter::DltExportFormat format QModelIndexList finallist = ui->tableView->selectionModel()->selection().indexes(); - DltExporter exporter(&project); - exporter.exportMessages(&qfile,0,&pluginManager,format,DltExporter::SelectionSelected,&finallist); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst); + connect(&exporter,SIGNAL(clipboard(QString)),this,SLOT(clipboard(QString))); + exporter.exportMessages(&qfile,0,&pluginManager,format,QDltExporter::SelectionSelected,&finallist); + disconnect(&exporter,SIGNAL(clipboard(QString)),this,SLOT(clipboard(QString))); } void MainWindow::on_actionExport_triggered() @@ -1580,12 +1596,12 @@ void MainWindow::on_actionExport_triggered() if(exporterDialog.result() != QDialog::Accepted) return; - DltExporter::DltExportFormat exportFormat = exporterDialog.getFormat(); - DltExporter::DltExportSelection exportSelection = exporterDialog.getSelection(); + QDltExporter::DltExportFormat exportFormat = exporterDialog.getFormat(); + QDltExporter::DltExportSelection exportSelection = exporterDialog.getSelection(); QModelIndexList list = ui->tableView->selectionModel()->selection().indexes(); /* check plausibility */ - if(exportSelection == DltExporter::SelectionAll) + if(exportSelection == QDltExporter::SelectionAll) { qDebug() << "DLT Export of all" << qfile.size() << "messages"; if(qfile.size() <= 0) @@ -1595,7 +1611,7 @@ void MainWindow::on_actionExport_triggered() return; } } - else if(exportSelection == DltExporter::SelectionFiltered) + else if(exportSelection == QDltExporter::SelectionFiltered) { qDebug() << "DLT Export of filterd" << qfile.sizeFilter() << "messages"; if(qfile.sizeFilter() <= 0) @@ -1605,7 +1621,7 @@ void MainWindow::on_actionExport_triggered() return; } } - else if(exportSelection == DltExporter::SelectionSelected) + else if(exportSelection == QDltExporter::SelectionSelected) { qDebug() << "DLT Export of selected" << list.count() << "messages"; if(list.count() <= 0) @@ -1620,28 +1636,28 @@ void MainWindow::on_actionExport_triggered() QFileDialog dialog(this); QStringList filters; - if((exportFormat == DltExporter::FormatDlt)||(exportFormat == DltExporter::FormatDltDecoded)) + if((exportFormat == QDltExporter::FormatDlt)||(exportFormat == QDltExporter::FormatDltDecoded)) { filters << "DLT Files (*.dlt)" <<"All files (*.*)"; dialog.setDefaultSuffix("dlt"); dialog.setWindowTitle("Export to DLT file"); qDebug() << "DLT Export to Dlt"; } - else if(exportFormat == DltExporter::FormatAscii) + else if(exportFormat == QDltExporter::FormatAscii) { filters << "Ascii Files (*.txt)" <<"All files (*.*)"; dialog.setDefaultSuffix("txt"); dialog.setWindowTitle("Export to Ascii file"); qDebug() << "DLT Export to Ascii"; } - else if(exportFormat == DltExporter::FormatUTF8) + else if(exportFormat == QDltExporter::FormatUTF8) { filters << "UTF8 Text Files (*.txt)" <<"All files (*.*)"; dialog.setDefaultSuffix("txt"); dialog.setWindowTitle("Export to UTF8 file"); qDebug() << "DLT Export to UTF8"; } - else if(exportFormat == DltExporter::FormatCsv) + else if(exportFormat == QDltExporter::FormatCsv) { filters << "CSV Files (*.csv)" <<"All files (*.*)"; dialog.setDefaultSuffix("csv"); @@ -1665,13 +1681,14 @@ void MainWindow::on_actionExport_triggered() /* change last export directory */ workingDirectory.setExportDirectory(QFileInfo(fileName).absolutePath()); - DltExporter exporter(&project,this); + QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,this); QFile outfile(fileName); unsigned long int startix, stopix; exporterDialog.getRange(&startix,&stopix); - if(exportSelection == DltExporter::SelectionSelected) // marked messages + connect(&exporter,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + if(exportSelection == QDltExporter::SelectionSelected) // marked messages { //qDebug() << "Selection" << __LINE__; exporter.exportMessages(&qfile, &outfile, &pluginManager,exportFormat,exportSelection,&list); @@ -1682,8 +1699,7 @@ void MainWindow::on_actionExport_triggered() exporter.exportMessageRange(startix,stopix); exporter.exportMessages(&qfile, &outfile, &pluginManager,exportFormat,exportSelection); } - - + disconnect(&exporter,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); } void MainWindow::on_action_menuFile_SaveAs_triggered() @@ -1922,6 +1938,36 @@ void MainWindow::reloadLogFileProgressText(QString text) statusProgressBar->setFormat(QString("%1 %p%").arg(text)); } +void MainWindow::progress(QString text,int status,int progress) +{ + switch(status) + { + case 1: + statusProgressBar->setRange(0,100); + statusProgressBar->setValue(0); + statusProgressBar->setFormat(QString("%1 %p%").arg(text)); + break; + case 2: + statusProgressBar->setValue(progress); + statusProgressBar->setFormat(QString("%1 %p%").arg(text)); + //qDebug().noquote() << "Progress" << text << progress << "%"; + //statusProgressBar->update(); + //statusProgressBar->repaint(); + //QApplication::processEvents(); + break; + case 3: + statusProgressBar->setValue(100); + statusProgressBar->setFormat(QString("%1 %p%").arg(text)); + break; + } +} + +void MainWindow::clipboard(QString text) +{ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(text); +} + void MainWindow::reloadLogFileVersionString(QString ecuId, QString version) { // version message found in loading file, only called when loading a logfile ! @@ -7234,8 +7280,10 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) on_action_menuFile_Clear_triggered(); for ( const auto& i : pcapFileNames ) { - DltImporter importer; + QDltImporter importer; + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); } reloadLogFile(); } @@ -7244,8 +7292,10 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) on_action_menuFile_Clear_triggered(); for ( const auto& i : mf4FileNames ) { - DltImporter importer; + QDltImporter importer; + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); } reloadLogFile(); } @@ -7254,7 +7304,6 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) bool first = true; for ( const auto& i : dlfFileNames ) { - DltImporter importer; if(first) { openDlfFile(i,true); @@ -7278,7 +7327,7 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) connect(action, &QAction::triggered, this, [this, indexes](){ QStringList pathsList; auto selectedIndexes = indexes; - DltImporter importer; + QDltImporter importer; for (auto &index : selectedIndexes) { if (0 == index.column()) @@ -7287,9 +7336,17 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) if(i.endsWith(".dlt",Qt::CaseInsensitive)) appendDltFile(i); else if(i.endsWith(".pcap",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } else if(i.endsWith(".mf4",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } else if(i.endsWith(".dlf",Qt::CaseInsensitive)) openDlfFile(i,false); } @@ -7345,14 +7402,22 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) QStringList files; QDirIterator it_sh(path, QStringList() << "*.pcap" << "*.mf4", QDir::Files, QDirIterator::Subdirectories); - DltImporter importer; + QDltImporter importer; while (it_sh.hasNext()) { QString i = it_sh.next(); if (i.endsWith(".pcap",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } else if (i.endsWith(".mf4",Qt::CaseInsensitive)) + { + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,i,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); + } } reloadLogFile(); @@ -7440,22 +7505,22 @@ void MainWindow::on_tableView_SearchIndex_customContextMenuRequested(QPoint pos) void MainWindow::onActionMenuConfigSearchTableCopyToClipboardTriggered() { - exportSelection_searchTable(DltExporter::FormatClipboard); + exportSelection_searchTable(QDltExporter::FormatClipboard); } void MainWindow::onActionMenuConfigSearchTableCopyPayloadToClipboardTriggered() { - exportSelection_searchTable(DltExporter::FormatClipboardPayloadOnly); + exportSelection_searchTable(QDltExporter::FormatClipboardPayloadOnly); } void MainWindow::onActionMenuConfigSearchTableCopyJiraToClipboardTriggered() { - exportSelection_searchTable(DltExporter::FormatClipboardJiraTable); + exportSelection_searchTable(QDltExporter::FormatClipboardJiraTable); } void MainWindow::onActionMenuConfigSearchTableCopyJiraHeadToClipboardTriggered() { - exportSelection_searchTable(DltExporter::FormatClipboardJiraTableHead); + exportSelection_searchTable(QDltExporter::FormatClipboardJiraTableHead); } void MainWindow::keyPressEvent ( QKeyEvent * event ) @@ -7555,15 +7620,19 @@ void MainWindow::dropEvent(QDropEvent *event) else if(filename.endsWith(".pcap", Qt::CaseInsensitive)) { /* Filter file dropped */ - DltImporter importer; + QDltImporter importer; + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,filename,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); reloadLogFile(); } else if(filename.endsWith(".mf4", Qt::CaseInsensitive)) { /* Filter file dropped */ - DltImporter importer; + QDltImporter importer; + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,filename,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); reloadLogFile(); } else @@ -7732,17 +7801,17 @@ void MainWindow::on_action_menuConfig_Copy_to_clipboard_triggered() void MainWindow::onActionAenuConfigCopyPayloadToClipboardTriggered() { - exportSelection(true,false,DltExporter::FormatClipboardPayloadOnly); + exportSelection(true,false,QDltExporter::FormatClipboardPayloadOnly); } void MainWindow::onActionMenuConfigCopyJiraToClipboardTriggered() { - exportSelection(true,false,DltExporter::FormatClipboardJiraTable); + exportSelection(true,false,QDltExporter::FormatClipboardJiraTable); } void MainWindow::onActionMenuConfigCopyJiraHeadToClipboardTriggered() { - exportSelection(true,false,DltExporter::FormatClipboardJiraTableHead); + exportSelection(true,false,QDltExporter::FormatClipboardJiraTableHead); } void MainWindow::on_action_menuFilter_Append_Filters_triggered() @@ -8381,7 +8450,7 @@ void MainWindow::on_exploreView_activated(const QModelIndex &index) auto result = std::find_if(ext.begin(), ext.end(), [&path](const QString &el){return path.toLower().endsWith(el);}); - DltImporter importer; + QDltImporter importer; switch(result - ext.begin()) { case 0: /* this represents index in "ext" list */ @@ -8395,11 +8464,15 @@ void MainWindow::on_exploreView_activated(const QModelIndex &index) openDlpFile(path); break; case 3: + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromPCAP(outputfile,path,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); reloadLogFile(); break; case 4: + connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); importer.dltIpcFromMF4(outputfile,path,this,false); + disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); reloadLogFile(); break; default: diff --git a/src/mainwindow.h b/src/mainwindow.h index 07315264..aaf969a0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -257,8 +257,8 @@ class MainWindow : public QMainWindow void reloadLogFileDefaultFilter(); - void exportSelection(bool ascii,bool file,DltExporter::DltExportFormat format); - void exportSelection_searchTable(DltExporter::DltExportFormat format); + void exportSelection(bool ascii,bool file,QDltExporter::DltExportFormat format); + void exportSelection_searchTable(QDltExporter::DltExportFormat format); void ControlServiceRequest(EcuItem* ecuitem, int service_id ); void SendInjection(EcuItem* ecuitem); @@ -391,6 +391,8 @@ private slots: void reloadLogFileProgressMax(int num); void reloadLogFileProgress(int num); void reloadLogFileProgressText(QString text); + void progress(QString,int status,int progress); + void clipboard(QString); void reloadLogFileVersionString(QString ecuId, QString version); void reloadLogFileFinishIndex(); void reloadLogFileFinishFilter(); diff --git a/src/src.pro b/src/src.pro index 01d704c7..ea113ce1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -120,7 +120,6 @@ TEMPLATE = app # Compile these sources SOURCES += main.cpp \ - dltimporter.cpp \ mainwindow.cpp \ project.cpp \ ecudialog.cpp \ @@ -138,8 +137,6 @@ SOURCES += main.cpp \ dltfileutils.cpp \ dltfileindexer.cpp \ dlttableview.cpp \ - dltexporter.cpp \ - fieldnames.cpp \ dltuiutils.cpp \ workingdirectory.cpp \ jumptodialog.cpp\ @@ -154,7 +151,6 @@ SOURCES += main.cpp \ # Show these headers in the project HEADERS += mainwindow.h \ - dltimporter.h \ project.h \ ecudialog.h \ applicationdialog.h \ @@ -172,8 +168,6 @@ HEADERS += mainwindow.h \ dltfileutils.h \ dltfileindexer.h \ dlttableview.h \ - dltexporter.h \ - fieldnames.h \ workingdirectory.h \ dltuiutils.h \ jumptodialog.h \ diff --git a/src/version.h b/src/version.h index eddda073..f3e70037 100644 --- a/src/version.h +++ b/src/version.h @@ -23,12 +23,12 @@ /* changing minor & major when layout of settings file config.ini changes */ /* this kind of change is tracked in the settings dialogr */ /* for other bugfixes and not major feature enhancement just use patch level */ -#define PACKAGE_VERSION_STATE "stable" +#define PACKAGE_VERSION_STATE "unstable" #define PACKAGE_MAJOR_VERSION 2 -#define PACKAGE_MINOR_VERSION 26 +#define PACKAGE_MINOR_VERSION 27 #define PACKAGE_PATCH_LEVEL 0 -#define PACKAGE_VERSION "2.26.0" -#define PACKAGE_REVISION "stable" +#define PACKAGE_VERSION "2.27.0" +#define PACKAGE_REVISION "unstable" #define PACKAGE_DESCRIPTION "DLT Viewer" #define DLT_SUPPORT_MAIL_ADDRESS "" #define DLT_SUPPORT_NAME "COVESA"