UpdatePTUDevCtrl/main.cpp

63 lines
1.4 KiB
C++
Raw Normal View History

2023-04-05 14:43:27 +02:00
#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
2023-04-13 11:22:32 +02:00
#include <QFileInfo>
2023-04-05 14:43:27 +02:00
#include "message_handler.h"
2023-05-19 15:33:40 +02:00
#include "interfaces.h"
#include "DCPlugin/include/hwapi.h"
2023-04-05 14:43:27 +02:00
#include <unistd.h>
#include <thread>
#include <memory>
2023-04-14 09:06:45 +02:00
#include <QSharedMemory>
2023-05-19 15:33:40 +02:00
#include <QRunnable>
#include <QThreadPool>
2023-05-22 16:04:50 +02:00
#include "update.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
2023-05-19 15:33:40 +02:00
class Work : public QRunnable {
2023-05-22 16:04:50 +02:00
QString m_update_ctrl_file;
2023-05-19 15:33:40 +02:00
public:
2023-05-22 16:04:50 +02:00
explicit Work(QString update_ctrl_file)
: m_update_ctrl_file(update_ctrl_file) {}
2023-05-19 15:33:40 +02:00
void run() {
2023-05-22 16:04:50 +02:00
Update m_update(m_update_ctrl_file);
m_update.doUpdate();
2023-04-05 14:43:27 +02:00
}
2023-05-19 15:33:40 +02:00
};
2023-04-05 14:43:27 +02:00
// argv[1]: file to send to dc
int main(int argc, char *argv[]) {
2023-04-05 14:43:27 +02:00
QApplication a(argc, argv);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
//setDebugLevel(QtMsgType::QtDebugMsg);
}
2023-05-19 15:33:40 +02:00
QString update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
if (argc == 2) {
update_ctrl_file = argv[1];
2023-04-13 11:22:32 +02:00
}
2023-05-22 16:04:50 +02:00
qInfo() << "Using" << update_ctrl_file << "as update logfile";
2023-04-13 11:22:32 +02:00
2023-05-19 15:33:40 +02:00
Work work(update_ctrl_file);
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(&work);
2023-05-22 16:04:50 +02:00
if (!threadPool->waitForDone()) {
return -1;
}
return 0;
2023-04-05 14:43:27 +02:00
}