UpdatePTUDevCtrl/main.cpp

58 lines
1.3 KiB
C++

#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <QFileInfo>
#include "message_handler.h"
#include "interfaces.h"
#include "DCPlugin/include/hwapi.h"
#include <unistd.h>
#include <thread>
#include <memory>
#include <QSharedMemory>
#include <QRunnable>
#include <QThreadPool>
#include "utils.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
class Work : public QRunnable {
Utils m_utils;
public:
explicit Work(QString update_ctrl_file) : m_utils(update_ctrl_file) {}
void run() {
m_utils.doUpdate();
}
};
// argv[1]: file to send to dc
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
//setDebugLevel(QtMsgType::QtDebugMsg);
}
QString update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
if (argc == 2) {
update_ctrl_file = argv[1];
}
qCritical() << "Using" << update_ctrl_file << "as update logfile";
Work work(update_ctrl_file);
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(&work);
return threadPool->waitForDone();
}