Skip to content

Commit

Permalink
New command line option delimiter for CSV export. (COVESA#515)
Browse files Browse the repository at this point in the history
Set dlt-commander export timezone to default.

Signed-off-by: Alexander Wenzel <[email protected]>
  • Loading branch information
alexmucde authored Aug 6, 2024
1 parent a3ad76c commit 86c8da1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 48 deletions.
8 changes: 4 additions & 4 deletions commander/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int main(int argc, char *argv[])
{
QFile output(opt.getConvertDestFile());
qDebug() << "### Convert to DLT";
QDltExporter exporter(0,0,0);
QDltExporter exporter(1,0,0,opt.getDelimiter());
qDebug() << "Commandline DLT convert to " << opt.getConvertDestFile();
exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatDlt,QDltExporter::SelectionFiltered);
qDebug() << "DLT export to DLT file format done";
Expand All @@ -133,7 +133,7 @@ int main(int argc, char *argv[])
{
QFile output(opt.getConvertDestFile());
qDebug() << "### Convert to ASCII";
QDltExporter exporter(0,0,0);
QDltExporter exporter(1,0,0,opt.getDelimiter());
qDebug() << "Commandline ASCII convert to " << opt.getConvertDestFile();
exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatAscii,QDltExporter::SelectionFiltered);
qDebug() << "DLT export ASCII done";
Expand All @@ -142,7 +142,7 @@ int main(int argc, char *argv[])
{
QFile output(opt.getConvertDestFile());
qDebug() << "### Convert to CSV";
QDltExporter exporter(0,0,0);
QDltExporter exporter(1,0,0,opt.getDelimiter());
qDebug() << "Commandline ASCII convert to " << opt.getConvertDestFile();
exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatCsv,QDltExporter::SelectionFiltered);
qDebug() << "DLT export CSV done";
Expand All @@ -151,7 +151,7 @@ int main(int argc, char *argv[])
{
QFile output(opt.getConvertDestFile());
qDebug() << "### Convert to UTF8";
QDltExporter exporter(0,0,0);
QDltExporter exporter(1,0,0,opt.getDelimiter());
qDebug() << "Commandline UTF8 convert to " << opt.getConvertDestFile();
exporter.exportMessages(&dltFile,&output,0,QDltExporter::FormatUTF8,QDltExporter::SelectionFiltered);
qDebug() << "DLT export UTF8 done";
Expand Down
26 changes: 20 additions & 6 deletions commander/optmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ OptManager::OptManager()
convert = false;
filter = false;
convertionmode = e_ASCI;
delimiter = ',';
}

/*OptManager* OptManager::getInstance()
Expand Down Expand Up @@ -90,6 +91,7 @@ void OptManager::printUsage()
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()<<" -delimiter <character>\tThe used delimiter for CSV export (Default: ,).";
qDebug()<<"\nExamples:\n";
qDebug().noquote() << executable << "-c .\\trace.txt c:\\trace\\trace.dlt";
qDebug().noquote() << executable << "-c -u .\\trace.txt c:\\trace\\trace.dlt";
Expand Down Expand Up @@ -138,16 +140,32 @@ void OptManager::parse(QStringList *opt)

i += 1;
}
else if(str.compare("-delimiter")==0)
{
QString c1 = opt->value(i+1);

delimiter = QString("%1").arg(c1).front().toLatin1();

qDebug() << "Delimiter:" << delimiter;

i += 1;
}
else if(str.compare("-u")==0)
{
qDebug() << "Convert to UTF8";

convertionmode = e_UTF8;
}
else if(str.compare("-csv")==0)
{
qDebug() << "Convert to CSV";

convertionmode = e_CSV;
}
else if(str.compare("-d")==0)
{
qDebug() << "Convert to DLT";

convertionmode = e_DLT;
}
else if(opt->at(i).endsWith(".dlt") || opt->at(i).endsWith(".DLT"))
Expand Down Expand Up @@ -180,13 +198,9 @@ void OptManager::parse(QStringList *opt)
bool OptManager::isLogFile(){return log;}
bool OptManager::isFilterFile(){return filter;}
bool OptManager::isConvert(){return convert;}

e_convertionmode OptManager::get_convertionmode()
{
return convertionmode;
}

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;}
char OptManager::getDelimiter(){return delimiter;}
2 changes: 2 additions & 0 deletions commander/optmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class OptManager
QStringList getFilterFiles();
QString getConvertSourceFile();
QString getConvertDestFile();
char getDelimiter();

const QStringList &getPcapFiles() const;
const QStringList &getMf4Files() const;
Expand All @@ -71,6 +72,7 @@ class OptManager
QStringList filterFiles;
QString convertSourceFile;
QString convertDestFile;
char delimiter;
};

#endif // OPTMANAGER_H
31 changes: 16 additions & 15 deletions qdlt/qdltexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "fieldnames.h"
#include "qdltoptmanager.h"

QDltExporter::QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,QObject *parent) :
QDltExporter::QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,char _delimiter,QObject *parent) :
QObject(parent)
{
size = 0;
Expand All @@ -21,6 +21,7 @@ QDltExporter::QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _
automaticTimeSettings=_automaticTimeSettings;
utcOffset=_utcOffset;
dst=_dst;
delimiter=_delimiter;
}

QString QDltExporter::escapeCSVValue(QString arg)
Expand All @@ -32,7 +33,7 @@ QString QDltExporter::escapeCSVValue(QString arg)

bool QDltExporter::writeCSVHeader(QFile *file)
{
QString header("\"%1\",\"%2\",\"%3\",\"%4\",\"%5\",\"%6\",\"%7\",\"%8\",\"%9\",\"%10\",\"%11\",\"%12\",\"%13\"\n");
QString header = QString("\"%1\"")+delimiter+QString("\"%2\"")+delimiter+QString("\"%3\"")+delimiter+QString("\"%4\"")+delimiter+QString("\"%5\"")+delimiter+QString("\"%6\"")+delimiter+QString("\"%7\"")+delimiter+QString("\"%8\"")+delimiter+QString("\"%9\"")+delimiter+QString("\"%10\"")+delimiter+QString("\"%11\"")+delimiter+QString("\"%12\"")+delimiter+QString("\"%13\"\n");
header = header.arg(FieldNames::getName(FieldNames::Index))
.arg(FieldNames::getName(FieldNames::Time))
.arg(FieldNames::getName(FieldNames::TimeStamp))
Expand All @@ -53,21 +54,21 @@ void QDltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg)
{
QString text("");

text += escapeCSVValue(QString("%1").arg(index)).append(",");
text += escapeCSVValue(QString("%1").arg(index)).append(delimiter);
if( automaticTimeSettings == 0 )
text += escapeCSVValue(QString("%1.%2").arg(msg.getGmTimeWithOffsetString(utcOffset,dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(",");
text += escapeCSVValue(QString("%1.%2").arg(msg.getGmTimeWithOffsetString(utcOffset,dst)).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(delimiter);
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(",");
text += escapeCSVValue(QString("%1").arg(msg.getMessageCounter())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getEcuid().simplified())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getApid().simplified())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getCtid().simplified())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getSessionid())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getTypeString())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getSubtypeString())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getModeString())).append(",");
text += escapeCSVValue(QString("%1").arg(msg.getNumberOfArguments())).append(",");
text += escapeCSVValue(QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'))).append(delimiter);
text += escapeCSVValue(QString("%1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0'))).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getMessageCounter())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getEcuid().simplified())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getApid().simplified())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getCtid().simplified())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getSessionid())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getTypeString())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getSubtypeString())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getModeString())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getNumberOfArguments())).append(delimiter);
text += escapeCSVValue(msg.toStringPayload().simplified().remove(QChar::Null));
text += "\n";

Expand Down
3 changes: 2 additions & 1 deletion qdlt/qdltexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class QDLT_EXPORT QDltExporter : public QObject
/* Default QT constructor.
* Please pass a window as a parameter to parent dialogs correctly.
*/
explicit QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,QObject *parent = 0);
explicit QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _dst,char _delimiter,QObject *parent = 0);

/* Export some messages from QDltFile to a CSV file.
* \param from QDltFile to pull messages from
Expand Down Expand Up @@ -91,6 +91,7 @@ public slots:
int automaticTimeSettings; // project and local setting
qlonglong utcOffset; // project and local setting
int dst; // project and local setting
char delimiter;
};

#endif // QDLTEXPORTER_H
26 changes: 15 additions & 11 deletions qdlt/qdltoptmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ QDltOptManager::QDltOptManager()
terminate=false;
convertionmode = e_ASCI;
commandline_mode = false;
delimiter=',';
}

QDltOptManager* QDltOptManager::getInstance()
Expand Down Expand Up @@ -105,6 +106,7 @@ void QDltOptManager::printUsage()
qDebug()<<" -t or --terminate\tTerminate DLT Viewer after command line execution.";
qDebug()<<" -v or --version\tOnly show version and buildtime information";
qDebug()<<" -w workingdirectory\tSet the working directory";
qDebug()<<" -delimiter <character>\tThe used delimiter for CSV export (Default: ,).";
qDebug()<<"\nExamples:";
qDebug()<<" dlt-viewer.exe -t -c output.txt input.dlt";
qDebug()<<" dlt-viewer.exe -t -s -u -c output.txt input.dlt";
Expand Down Expand Up @@ -190,6 +192,16 @@ void QDltOptManager::parse(QStringList *opt)

i += 1;
}
else if(str.compare("-delimiter")==0)
{
QString c1 = opt->value(i+1);

delimiter = QString("%1").arg(c1).front().toLatin1();

qDebug() << "Delimiter:" << delimiter;

i += 1;
}
else if(str.compare("-u")==0)
{
convertionmode = e_UTF8;
Expand Down Expand Up @@ -286,17 +298,8 @@ bool QDltOptManager::isProjectFile(){ return project;}
bool QDltOptManager::isTerminate(){return terminate;}
bool QDltOptManager::issilentMode(){return silent_mode;}
bool QDltOptManager::isCommandlineMode(){return commandline_mode;}

e_convertionmode QDltOptManager::get_convertionmode()
{
return convertionmode;
}

e_inputmode QDltOptManager::get_inputmode()
{
return inputmode;
}

e_convertionmode QDltOptManager::get_convertionmode(){return convertionmode;}
e_inputmode QDltOptManager::get_inputmode(){return inputmode;}
QString QDltOptManager::getProjectFile(){return projectFile;}
QStringList QDltOptManager::getLogFiles(){return logFiles;}
QStringList QDltOptManager::getFilterFiles(){return filterFiles;}
Expand All @@ -305,3 +308,4 @@ QString QDltOptManager::getPluginName(){return pluginName;}
QString QDltOptManager::getCommandName(){return commandName;}
QStringList QDltOptManager::getCommandParams(){return commandParams;}
QString QDltOptManager::getWorkingDirectory() const { return workingDirectory; }
char QDltOptManager::getDelimiter(){return delimiter;}
4 changes: 2 additions & 2 deletions qdlt/qdltoptmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ class QDLT_EXPORT QDltOptManager
QString getWorkingDirectory() const;
const QStringList &getPrePluginCommands() const;
const QStringList &getPostPluginCommands() const;

const QStringList &getPcapFiles() const;

const QStringList &getMf4Files() const;
char getDelimiter();

private:
QDltOptManager();
Expand Down Expand Up @@ -98,6 +97,7 @@ class QDLT_EXPORT QDltOptManager
QStringList postPluginCommands; // command after loading log file

QString workingDirectory;
char delimiter;
};

#endif //QDLTOPTMANAGER_H
19 changes: 10 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void MainWindow::commandLineConvertToDLT()
qDebug() << "### Convert to DLT";

/* start exporter */
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
qDebug() << "Commandline DLT convert to " << dltFile.fileName();
//exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatAsciiQ,QDltExporter::SelectionFiltered);
exporter.exportMessages(&qfile,&dltFile,&pluginManager,QDltExporter::FormatDlt,QDltExporter::SelectionFiltered);
Expand All @@ -874,7 +874,7 @@ void MainWindow::commandLineConvertToASCII()
qDebug() << "### Convert to ASCII";

/* start exporter */
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
qDebug() << "Commandline ASCII convert to " << asciiFile.fileName();
exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatAscii,QDltExporter::SelectionFiltered);
qDebug() << "DLT export ASCII done";
Expand All @@ -887,7 +887,7 @@ void MainWindow::commandLineConvertToCSV()
qDebug() << "### Convert to CSV";

/* start exporter */
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
qDebug() << "Commandline ASCII convert to " << asciiFile.fileName();
exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatCsv,QDltExporter::SelectionFiltered);
qDebug() << "DLT export CSV done";
Expand All @@ -901,7 +901,7 @@ void MainWindow::commandLineConvertToUTF8()
/* start exporter */
qDebug() << "### Convert to UTF8";

QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
qDebug() << "Commandline UTF8 convert to " << asciiFile.fileName();
exporter.exportMessages(&qfile,&asciiFile,&pluginManager,QDltExporter::FormatUTF8,QDltExporter::SelectionFiltered);
qDebug() << "DLT export UTF8 done";
Expand All @@ -914,7 +914,7 @@ void MainWindow::commandLineConvertToDLTDecoded()
qDebug() << "### Convert to DLT Decoded";

/* start exporter */
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
qDebug() << "Commandline decoding to dlt formated file" << dltFile.fileName();
exporter.exportMessages(&qfile,&dltFile,&pluginManager,QDltExporter::FormatDltDecoded,QDltExporter::SelectionFiltered);
qDebug() << "DLT export DLT decoded done";
Expand Down Expand Up @@ -1553,7 +1553,7 @@ void MainWindow::exportSelection(bool ascii = true,bool file = false,QDltExporte
QModelIndexList list = ui->tableView->selectionModel()->selection().indexes();


QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
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)));
Expand Down Expand Up @@ -1589,7 +1589,7 @@ void MainWindow::exportSelection_searchTable(QDltExporter::DltExportFormat forma

QModelIndexList finallist = ui->tableView->selectionModel()->selection().indexes();

QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter());
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)));
Expand Down Expand Up @@ -1689,7 +1689,7 @@ void MainWindow::on_actionExport_triggered()

/* change last export directory */
workingDirectory.setExportDirectory(QFileInfo(fileName).absolutePath());
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,this);
QDltExporter exporter(project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter(),this);
QFile outfile(fileName);

unsigned long int startix, stopix;
Expand Down Expand Up @@ -5736,7 +5736,8 @@ void MainWindow::on_action_menuHelp_Command_Line_triggered()
QString(" -e <pluginname>|command|param1|..|param<n>\n\t\t\tExecute a command plugin with <n> parameters after loading log file\n")+
QString(" -t\t\t\tTerminate DLT Viewer after command line execution\n")+
QString(" -v\t\t\tShow version and buildtime information\n")+
QString(" -w workingdirectory\tSet the working directory\n")
QString(" -w workingdirectory\tSet the working directory\n")+
QString(" -delimiter <character>\tThe used delimiter for CSV export (Default: ,)\n")
);
}

Expand Down

0 comments on commit 86c8da1

Please sign in to comment.