Skip to content

Commit

Permalink
Log files, project file and filter file can now be loaded in commandl…
Browse files Browse the repository at this point in the history
…ine without option. (#413)

Remove old commands -l, -p, -f.
Multiple plugin commands at once now possible.
New option -b to execute plugin commands before loading log file.
Update command line documentation.

Signed-off-by: Alexander Wenzel <[email protected]>
  • Loading branch information
alexmucde authored Jan 25, 2024
1 parent 1a762cf commit 064328b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 127 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ The Diagnostic Log and Trace Viewer is an application that can send and receive

### Command line usage;

+ Windows: `dlt-viewer.exe [OPTIONS]`
+ Linux: `dlt-viewer [OPTIONS]`
+ MacOS: `open -a $DLT_BUILD_DIR/bin/DLT\ Viewer.app --args [OPTIONS]`
+ Windows: `dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile]`
+ Linux: `dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile]`
+ MacOS: `open -a $DLT_BUILD_DIR/bin/DLT\ Viewer.app --args [OPTIONS] [logfile] [projectfile] [filterfile]`

Options:
+ [logfile] Loading one or more logfiles on startup (must end with .dlt)
+ [projectfile] Loading project file on startup (must end with .dlp)
+ [filterfile] Loading filterfile on startup (must end with .dlf)
+ `-h` Print usage
+ `-p projectfile` Loading project file on startup (must end with .dlp)
+ `-l logfile` Loading logfile on startup (must end with .dlt)
+ `-f filterfile` Loading filterfile on startup (must end with .dlf)
+ `-s or --silent` Enable silent mode without warning message boxes
+ `-v or --version` Only show version and buildtime information
+ `-c logfile textfile` Convert logfile file to textfile (logfile must end with .dlt)
+ `-u` Conversion will be done in UTF8 instead of ASCII";
+ `-csv` Conversion will be done in CSV format";
+ `-d` Conversion will NOT be done, save in dlt file format again instead"
+ `-dd` Conversion will NOT be done, save as decoded messages in dlt format"
+ `-e "name of plugin|command in plugin|param1|..|param<n>"` Execute a plugin command with <n> parameters
+ `-u` Conversion will be done in UTF8 instead of ASCII;
+ `-csv` Conversion will be done in CSV format;
+ `-d` Conversion will NOT be done, save in dlt file format again instead
+ `-dd` Conversion will NOT be done, save as decoded messages in dlt format
+ `-b "name of plugin|command in plugin|param1|..|param<n>"` Execute a plugin command with <n> parameters before loading log file
+ `-e "name of plugin|command in plugin|param1|..|param<n>"` Execute a plugin command with <n> parameters after loading log file
+ `-w workingdirectory` Set the working directory

## API Documentation

Expand Down
147 changes: 47 additions & 100 deletions qdlt/qdltoptmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ QDltOptManager::QDltOptManager(QDltOptManager const&)

}

const QStringList &QDltOptManager::getPostPluginCommands() const
{
return postPluginCommands;
}

const QStringList &QDltOptManager::getPrePluginCommands() const
{
return prePluginCommands;
}

void QDltOptManager::printVersion(QString appname)
{
qDebug() << "Start" << appname << "\nBuild time" << __DATE__ << __TIME__;
Expand All @@ -65,24 +75,26 @@ void QDltOptManager::printVersion(QString appname)
void QDltOptManager::printUsage()
{
#if (WIN32)
qDebug()<<"Usage: dlt-viewer.exe [OPTIONS]";
qDebug()<<"Usage: dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile]";
#else
qDebug()<<"Usage: dlt-viewer [OPTIONS]";
qDebug()<<"Usage: dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile]";
#endif

qDebug()<<"Options:";
qDebug()<<" -h Print usage";
qDebug()<<" -p projectfile \t Loading project file on startup (must end with .dlp)";
qDebug()<<" -l logfile \t Loading logfile on startup (must end with .dlt)";
qDebug()<<" -f filterfile \t Loading filterfile on startup (must end with .dlf)";
qDebug()<<" -s or --silent \t Enable silent mode without warning message boxes.";
qDebug()<<" -v or --version \t Only show version and buildtime information";
qDebug()<<" -c logfile textfile \t Convert logfile file to textfile (logfile must end with .dlt)";
qDebug()<<" -u Conversion will be done in UTF8 instead of ASCII";
qDebug()<<" -csv Conversion will be done in CSV format";
qDebug()<<" -d Conversion will NOT be done, save in dlt file format again instead";
qDebug()<<" -dd Conversion will NOT be done, save as decoded messages in dlt format";
qDebug()<<" -e \"plugin|command|param1|..|param<n>\" \tExecute a plugin command with <n> parameters.\n";
qDebug()<<" [logfile]\tLoading one or more logfiles on startup (must end with .dlt)";
qDebug()<<" [projectfile]\tLoading project file on startup (must end with .dlp)";
qDebug()<<" [filterfile]\tLoading filterfile on startup (must end with .dlf)";
qDebug()<<" -h \t Print usage";
qDebug()<<" -s or --silent\tEnable silent mode without warning message boxes.";
qDebug()<<" -v or --version\tOnly show version and buildtime information";
qDebug()<<" -c logfile 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()<<" -dd\tConversion will NOT be done, save as decoded messages in dlt format";
qDebug()<<" -b \"plugin|command|param1|..|param<n>\"\tExecute a plugin command with <n> parameters before loading log file.";
qDebug()<<" -e \"plugin|command|param1|..|param<n>\"\tExecute a plugin command with <n> parameters after loading log file.";
qDebug()<<" -w workingdirectory\tSet the working directory";
qDebug()<<"Examples:";
#if (WIN32)
qDebug()<<" dlt-viewer.exe -c c:\\trace\\trace.dlt .\\trace.txt";
Expand Down Expand Up @@ -167,91 +179,6 @@ void QDltOptManager::parse(QStringList *opt)
printVersion(opt->at(0));
exit(0);
}
else if(str.compare("-p")==0)
{
QString p1 = opt->value(i+1);

if(p1!=nullptr && (p1.endsWith(".dlp") || p1.endsWith(".DLP")))
{
projectFile = QString("%1").arg(opt->at(i+1));
QFile Fout(projectFile);
if(!Fout.exists())
{
qDebug()<< "\n Error: " << projectFile << " not found !\n";
exit(-1);
}
qDebug()<< "Projectfile is " << projectFile;
project = true;
}
else
{
qDebug()<<"\nError occured during processing of command line option \"-p\"";
qDebug()<<"e.g. file extension has to be \".dlp\"\n";
printUsage();
exit(-1);
}
i += 1;
}
else if(str.compare("-l")==0)
{
if (convert == true)
{
qDebug() << "\nError: Can't use -l and -c at once\n";
printUsage();
exit(-1);
}

QString l1 = opt->value(i+1);

if(l1!=nullptr && (l1.endsWith(".dlt")||l1.endsWith(".DLT")))
{
const QString logFile = QString("%1").arg(l1);
logFiles += logFile;
QFile Fout(logFile);
if(false == Fout.exists())
{
qDebug()<< "\nGiven file " << logFile << " not found !\nCreate empty file instead ...";
}
else
{
qDebug()<< "\nLogfile is " << logFile;
}
log = true;
}
else
{
qDebug()<<"\nError occured during processing of command line option \"-l\"";
qDebug()<<"e.g. file extension has to be \".dlt\"\n";
printUsage();
exit(-1);
}
i += 1;
}
else if(str.compare("-f")==0)
{
QString f1 = opt->value(i+1);

if(f1!=nullptr && (f1.endsWith(".dlf")||f1.endsWith(".DLF")))
{
filterFile = QString("%1").arg(f1);
QFile Fout(filterFile);
if(!Fout.exists())
{
qDebug()<< "\nError: " << filterFile << " not found !\n";
exit(-1);
}
filter = true;
qDebug()<< "Filterfile is " << filterFile;
}
else
{
qDebug()<<"\nError occured during processing of command line option \"-f\"";
qDebug()<<"e.g. file extension has to be \".dlf\"\n";
printUsage();
exit(-1);
}
i += 1;
}
else if(str.compare("-c")==0)
{
if (log == true)
Expand Down Expand Up @@ -308,6 +235,7 @@ void QDltOptManager::parse(QStringList *opt)
else if(str.compare("-e")==0)
{
QString c = opt->value(i+1);
postPluginCommands += c;
QStringList args = c.split("|");
commandline_mode = true;
if(c != nullptr && args.size() > 1)
Expand All @@ -318,7 +246,6 @@ void QDltOptManager::parse(QStringList *opt)
args.removeAt(0);
commandParams = args;
plugin = true;

}
else
{
Expand All @@ -328,6 +255,13 @@ void QDltOptManager::parse(QStringList *opt)
}
++i;
}
else if(str.compare("-b")==0)
{
QString c = opt->value(i+1);
prePluginCommands += c;
commandline_mode = true;
++i;
}
else if (str.compare("-w") == 0)
{
workingDirectory = opt->value(i+1);
Expand Down Expand Up @@ -360,6 +294,19 @@ void QDltOptManager::parse(QStringList *opt)
project = true;
qDebug()<< "Loading projectfile " << projectFile;
}
else if(opt->at(i).endsWith(".dlf") || opt->at(i).endsWith(".DLF"))
{
if (filter == true)
{
qDebug() << "\nError: Can't load multiple filter files once\n";
printUsage();
exit(-1);
}

filterFile = QString("%1").arg(opt->at(i));
filter = true;
qDebug()<< "Loading filterfile " << filterFile;
}

} // end of for loop
printVersion(opt->at(0));
Expand Down
6 changes: 6 additions & 0 deletions qdlt/qdltoptmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class QDLT_EXPORT QDltOptManager
QString getCommandName();
QStringList getCommandParams();
QString getWorkingDirectory() const;
const QStringList &getPrePluginCommands() const;
const QStringList &getPostPluginCommands() const;

private:
QDltOptManager();
Expand All @@ -86,6 +88,10 @@ class QDLT_EXPORT QDltOptManager
QString pluginName;
QString commandName;
QStringList commandParams;

QStringList prePluginCommands; // command before loading log file
QStringList postPluginCommands; // command after loading log file

QString workingDirectory;
};

Expand Down
64 changes: 48 additions & 16 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,46 @@ MainWindow::MainWindow(QWidget *parent) :

initSignalConnections();

/* Commands plugin before loading log file */
if(QDltOptManager::getInstance()->isPlugin())
{
QStringList commands = QDltOptManager::getInstance()->getPrePluginCommands();

for(int num = 0; num< commands.size();num++)
{
QStringList args = commands[num].split("|");
if(args.size() > 1)
{
QString pluginName = args.at(0);
QString commandName = args.at(1);
args.removeAt(0);
args.removeAt(0);
QStringList commandParams = args;
commandLineExecutePlugin(pluginName,commandName,commandParams);
}
}
}

initFileHandling();

/* Command plugin */
/* Commands plugin after loading log file */
if(QDltOptManager::getInstance()->isPlugin())
{
commandLineExecutePlugin(QDltOptManager::getInstance()->getPluginName(),
QDltOptManager::getInstance()->getCommandName(),
QDltOptManager::getInstance()->getCommandParams());
QStringList commands = QDltOptManager::getInstance()->getPostPluginCommands();

for(int num = 0; num< commands.size();num++)
{
QStringList args = commands[num].split("|");
if(args.size() > 1)
{
QString pluginName = args.at(0);
QString commandName = args.at(1);
args.removeAt(0);
args.removeAt(0);
QStringList commandParams = args;
commandLineExecutePlugin(pluginName,commandName,commandParams);
}
}
}

/* auto connect */
Expand Down Expand Up @@ -5869,26 +5901,26 @@ void MainWindow::on_action_menuHelp_Command_Line_triggered()

QMessageBox::information(0, QString("DLT Viewer - Command line usage\t\t\t\t\t"), // tabs used to expand mesage box !
#ifdef WIN32
QString("Usage: dlt-viewer.exe [OPTIONS]\n\n")+
QString("Usage: dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile]\n\n")+
QString("Options:\n")+
#else
QString("Usage: dlt-viewer [OPTIONS]\n\n")+
QString("Usage: dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile]\n\n")+
QString("Options:\n")+
#endif
QString(" -h \t\tPrint usage\n")+
QString(" -v \t\tShow version and buildtime information\n")+
QString("\n")+
QString(" -p <projectfile> \tLoading project (*.dlp) file on startup\n")+
QString(" -f <filterfile> \t\tLoading filterfile on startup (must end with \".dlf\")\n")+
QString(" -l <logfile> \t\tLoading (*.dlt) logfile on startup\n")+
QString(" -c <logfile> <textfile> \tConvert (*.dlt) logfile to ASCII textfile\n")+
QString(" [logfile]\t\t\tLoading one or more logfiles on startup (must end with .dlt)\n")+
QString(" [projectfile]\t\tLoading project file on startup (must end with .dlp)\n")+
QString(" [filterfile]\t\tLoading filterfile on startup (must end with .dlf)\n")+
QString(" -h\t\t\tPrint usage\n")+
QString(" -s \t\t\tEnable silent mode - no message boxes\n")+
QString(" -v\t\t\tShow version and buildtime information\n")+
QString(" -c <logfile> <textfile>\tConvert (*.dlt) logfile to ASCII textfile\n")+
QString(" -u \t\t\tExport logfile to UTF8 instead\n")+
QString(" -csv \t\t\tExport logfile to csv ( Excel ) instead\n")+
QString(" -d \t\t\tExport logfile to DLT format\n")+
QString(" -dd \t\t\tExport logfile to decoded DLT format\n")+
QString(" -s \t\t\tEnable silent mode - no message boxes\n")+
QString("\n")+
QString(" -e <pluginname>|command|param1|..|param<n> \n\t\t\tExecute a command plugin with <n> parameters")
QString(" -b <pluginname>|command|param1|..|param<n> \n\t\t\tExecute a command plugin with <n> parameters before loading log file\n")+
QString(" -e <pluginname>|command|param1|..|param<n> \n\t\t\tExecute a command plugin with <n> parameters after loading log file\n")+
QString(" -w workingdirectory\tSet the working directory\n")
);
}

Expand Down

0 comments on commit 064328b

Please sign in to comment.