ATBUpdateTool/main.cpp

69 lines
1.7 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 <QDir>
#include "update.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
class Work : public QRunnable {
QString m_update_ctrl_file;
QString m_workingDir;
public:
explicit Work(QString update_ctrl_file, QString workingDir)
: m_update_ctrl_file(update_ctrl_file)
, m_workingDir(workingDir) {
}
void run() {
Update m_update(m_update_ctrl_file, m_workingDir);
// if (m_update.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);
}
QByteArray const value = qgetenv("XDG_RUNTIME_DIR");
if (value.size() == 0) {
qputenv("XDG_RUNTIME_DIR", "/run/user/0");
}
QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
QString const workingDir = (argc == 2) ? argv[1] : ".";
Work work(update_ctrl_file, workingDir);
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(&work);
if (!threadPool->waitForDone()) {
return -1;
}
return 0;
}