diff --git a/commander/main.cpp b/commander/main.cpp index b6165ddc..a7639973 100644 --- a/commander/main.cpp +++ b/commander/main.cpp @@ -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"; @@ -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"; @@ -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"; @@ -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"; diff --git a/commander/optmanager.cpp b/commander/optmanager.cpp index 71583b8b..975b3000 100644 --- a/commander/optmanager.cpp +++ b/commander/optmanager.cpp @@ -37,6 +37,7 @@ OptManager::OptManager() convert = false; filter = false; convertionmode = e_ASCI; + delimiter = ','; } /*OptManager* OptManager::getInstance() @@ -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 \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"; @@ -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")) @@ -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;} diff --git a/commander/optmanager.h b/commander/optmanager.h index 95fc9d6a..3bb321f3 100644 --- a/commander/optmanager.h +++ b/commander/optmanager.h @@ -54,6 +54,7 @@ class OptManager QStringList getFilterFiles(); QString getConvertSourceFile(); QString getConvertDestFile(); + char getDelimiter(); const QStringList &getPcapFiles() const; const QStringList &getMf4Files() const; @@ -71,6 +72,7 @@ class OptManager QStringList filterFiles; QString convertSourceFile; QString convertDestFile; + char delimiter; }; #endif // OPTMANAGER_H diff --git a/qdlt/qdltexporter.cpp b/qdlt/qdltexporter.cpp index f572b805..26547ad1 100644 --- a/qdlt/qdltexporter.cpp +++ b/qdlt/qdltexporter.cpp @@ -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; @@ -21,6 +21,7 @@ QDltExporter::QDltExporter(int _automaticTimeSettings,qlonglong _utcOffset,int _ automaticTimeSettings=_automaticTimeSettings; utcOffset=_utcOffset; dst=_dst; + delimiter=_delimiter; } QString QDltExporter::escapeCSVValue(QString arg) @@ -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)) @@ -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"; diff --git a/qdlt/qdltexporter.h b/qdlt/qdltexporter.h index 086f9a49..aa54119e 100644 --- a/qdlt/qdltexporter.h +++ b/qdlt/qdltexporter.h @@ -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 @@ -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 diff --git a/qdlt/qdltoptmanager.cpp b/qdlt/qdltoptmanager.cpp index c38af184..8a2d9f8f 100644 --- a/qdlt/qdltoptmanager.cpp +++ b/qdlt/qdltoptmanager.cpp @@ -36,6 +36,7 @@ QDltOptManager::QDltOptManager() terminate=false; convertionmode = e_ASCI; commandline_mode = false; + delimiter=','; } QDltOptManager* QDltOptManager::getInstance() @@ -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 \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"; @@ -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; @@ -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;} @@ -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;} diff --git a/qdlt/qdltoptmanager.h b/qdlt/qdltoptmanager.h index c736773a..6cdda7e1 100644 --- a/qdlt/qdltoptmanager.h +++ b/qdlt/qdltoptmanager.h @@ -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(); @@ -98,6 +97,7 @@ class QDLT_EXPORT QDltOptManager QStringList postPluginCommands; // command after loading log file QString workingDirectory; + char delimiter; }; #endif //QDLTOPTMANAGER_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc48fb2b..f00ab1c7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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); @@ -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"; @@ -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"; @@ -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"; @@ -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"; @@ -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))); @@ -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))); @@ -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; @@ -5736,7 +5736,8 @@ void MainWindow::on_action_menuHelp_Command_Line_triggered() QString(" -e |command|param1|..|param\n\t\t\tExecute a command plugin with 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 \tThe used delimiter for CSV export (Default: ,)\n") ); }