Skip to content

Commit

Permalink
DLT Commander Tool (#500)
Browse files Browse the repository at this point in the history
* Move Export, Import and Fieldname classes to qdlt.
* Current limitation that progress bar is not updated.
* First DLT Commander tool.
* Command line only tool for environments without Qt GUI.
* Prepare 2.27.0 unstable release
* Finish first commander version.

Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
  • Loading branch information
alexmucde committed Jul 16, 2024
1 parent 8a8305c commit 10f9da6
Show file tree
Hide file tree
Showing 31 changed files with 891 additions and 293 deletions.
2 changes: 1 addition & 1 deletion BuildDltViewer.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += qdlt src plugin
SUBDIRS += qdlt src plugin commander
CONFIG += c++11

ICON = Project.icns
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
3 changes: 3 additions & 0 deletions build_sdk_windows_qt5_MSVC.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 46 additions & 0 deletions commander/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <jack.smith@elektrobit.com>, 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;$<$<BOOL:${DLT_USE_QT_RPATH}>:${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)
1 change: 1 addition & 0 deletions commander/cmake/Darwin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# set properties for the bundle Info.plist file
8 changes: 8 additions & 0 deletions commander/cmake/Linux.cmake
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions commander/cmake/Windows.cmake
Original file line number Diff line number Diff line change
@@ -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()
37 changes: 37 additions & 0 deletions commander/commander.pro
Original file line number Diff line number Diff line change
@@ -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
166 changes: 166 additions & 0 deletions commander/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#include <QCoreApplication>
#include <QDebug>
#include <QFile>

#include <qdltfile.h>
#include <qdltfilter.h>
#include <qdltimporter.h>
#include <qdltexporter.h>
#include <optmanager.h>

/*
* 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;
}
Loading

0 comments on commit 10f9da6

Please sign in to comment.