2018-06-19 19:58:52 +00:00
|
|
|
#include <QApplication>
|
2021-02-02 09:05:59 +00:00
|
|
|
#include <iostream>
|
2021-02-07 20:07:26 +00:00
|
|
|
#include "wfmain.h"
|
2021-02-23 21:21:22 +00:00
|
|
|
#include "logcategories.h"
|
2018-06-19 19:58:52 +00:00
|
|
|
|
2021-02-02 09:05:59 +00:00
|
|
|
// Copytight 2017-2021 Elliott H. Liggett
|
2018-06-19 19:58:52 +00:00
|
|
|
|
2021-02-07 20:07:26 +00:00
|
|
|
// Smart pointer to log file
|
|
|
|
QScopedPointer<QFile> m_logFile;
|
|
|
|
QMutex logMutex;
|
|
|
|
|
|
|
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
2018-06-19 19:58:52 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
2018-06-22 23:31:52 +00:00
|
|
|
//a.setStyle( "Fusion" );
|
|
|
|
|
2020-01-05 01:12:35 +00:00
|
|
|
a.setOrganizationName("eliggett");
|
2018-11-24 08:10:05 +00:00
|
|
|
a.setOrganizationDomain("nodomain");
|
2020-01-05 01:12:35 +00:00
|
|
|
a.setApplicationName("wfview");
|
2018-11-24 08:10:05 +00:00
|
|
|
|
2021-02-02 09:05:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
QString serialPortCL;
|
|
|
|
QString hostCL;
|
|
|
|
QString civCL;
|
2021-02-07 20:07:26 +00:00
|
|
|
QString logFilename= QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0] + "/wfview.log";
|
2021-02-02 09:05:59 +00:00
|
|
|
|
|
|
|
QString currentArg;
|
|
|
|
|
2021-02-11 19:47:29 +00:00
|
|
|
|
2021-02-11 08:57:14 +00:00
|
|
|
const QString helpText = QString("\nUsage: -p --port /dev/port, -h --host remotehostname, -c --civ 0xAddr, -l --logfile filename.log\n"); // TODO...
|
2021-02-02 09:05:59 +00:00
|
|
|
|
|
|
|
for(int c=1; c<argc; c++)
|
|
|
|
{
|
|
|
|
//qDebug() << "Argc: " << c << " argument: " << argv[c];
|
|
|
|
currentArg = QString(argv[c]);
|
|
|
|
|
|
|
|
if((currentArg == "-p") || currentArg == "--port")
|
|
|
|
{
|
|
|
|
if(argc > c)
|
|
|
|
{
|
|
|
|
serialPortCL = argv[c+1];
|
|
|
|
c+=1;
|
|
|
|
}
|
|
|
|
} else if ((currentArg == "-h") || (currentArg == "--host"))
|
|
|
|
{
|
|
|
|
if(argc > c)
|
|
|
|
{
|
|
|
|
hostCL = argv[c+1];
|
|
|
|
c+=1;
|
|
|
|
}
|
2021-02-07 20:07:26 +00:00
|
|
|
}
|
|
|
|
else if ((currentArg == "-c") || (currentArg == "--civ"))
|
2021-02-02 09:05:59 +00:00
|
|
|
{
|
2021-02-07 20:07:26 +00:00
|
|
|
if (argc > c)
|
2021-02-02 09:05:59 +00:00
|
|
|
{
|
2021-02-07 20:07:26 +00:00
|
|
|
civCL = argv[c + 1];
|
|
|
|
c += 1;
|
|
|
|
}
|
|
|
|
}
|
2021-02-08 09:20:06 +00:00
|
|
|
else if ((currentArg == "-l") || (currentArg == "--logfile"))
|
2021-02-07 20:07:26 +00:00
|
|
|
{
|
|
|
|
if (argc > c)
|
|
|
|
{
|
|
|
|
logFilename = argv[c + 1];
|
|
|
|
c += 1;
|
2021-02-02 09:05:59 +00:00
|
|
|
}
|
|
|
|
} else if ((currentArg == "--help"))
|
|
|
|
{
|
|
|
|
std::cout << helpText.toStdString();
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
std::cout << "Unrecognized option: " << currentArg.toStdString();
|
|
|
|
std::cout << helpText.toStdString();
|
2021-02-11 19:47:29 +00:00
|
|
|
|
2021-02-11 08:57:14 +00:00
|
|
|
return -1;
|
2021-02-02 09:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-07 20:07:26 +00:00
|
|
|
// Set the logging file before doing anything else.
|
|
|
|
m_logFile.reset(new QFile(logFilename));
|
|
|
|
// Open the file logging
|
|
|
|
m_logFile.data()->open(QFile::Append | QFile::Text);
|
|
|
|
// Set handler
|
|
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
|
2021-02-23 21:21:22 +00:00
|
|
|
qInfo(logSystem()) << "Starting wfview";
|
2021-02-07 20:07:26 +00:00
|
|
|
|
2021-02-02 09:05:59 +00:00
|
|
|
|
|
|
|
#ifdef QT_DEBUG
|
2021-02-23 21:21:22 +00:00
|
|
|
qInfo(logSystem()) << "SerialPortCL as set by parser: " << serialPortCL;
|
|
|
|
qInfo(logSystem()) << "remote host as set by parser: " << hostCL;
|
|
|
|
qInfo(logSystem()) << "CIV as set by parser: " << civCL;
|
2021-02-02 09:05:59 +00:00
|
|
|
#endif
|
2018-11-25 06:21:36 +00:00
|
|
|
a.setWheelScrollLines(1); // one line per wheel click
|
2021-02-02 09:05:59 +00:00
|
|
|
wfmain w( serialPortCL, hostCL);
|
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
w.show();
|
|
|
|
|
2021-02-02 09:05:59 +00:00
|
|
|
|
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
return a.exec();
|
2021-02-07 20:07:26 +00:00
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
}
|
2021-02-07 20:07:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
|
|
|
{
|
|
|
|
// Open stream file writes
|
|
|
|
QMutexLocker locker(&logMutex);
|
|
|
|
QTextStream out(m_logFile.data());
|
|
|
|
|
|
|
|
// Write the date of recording
|
|
|
|
out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz ");
|
|
|
|
// By type determine to what level belongs message
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case QtInfoMsg: out << "INF "; break;
|
|
|
|
case QtDebugMsg: out << "DBG "; break;
|
|
|
|
case QtWarningMsg: out << "WRN "; break;
|
|
|
|
case QtCriticalMsg: out << "CRT "; break;
|
|
|
|
case QtFatalMsg: out << "FTL "; break;
|
|
|
|
}
|
|
|
|
// Write to the output category of the message and the message itself
|
|
|
|
out << context.category << ": " << msg << "\n";
|
|
|
|
out.flush(); // Clear the buffered data
|
2021-02-08 09:20:06 +00:00
|
|
|
}
|