UpdatePTUDevCtrl/main.cpp

79 lines
2.0 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"
#include "plugins/interfaces.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-26 13:02:45 +02:00
#include <QDir>
2023-05-19 15:33:40 +02:00
2023-05-22 16:04:50 +02:00
#include "update.h"
#include "worker_thread.h"
#include "worker.h"
#include <thread>
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
static void doWork(QString update_ctrl_file, QString workingDir) {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
//Update update(update_ctrl_file, workingDir);
//update.doUpdate();
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
QCoreApplication::quit();
}
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-26 13:02:45 +02:00
QByteArray const value = qgetenv("XDG_RUNTIME_DIR");
if (value.size() == 0) {
qputenv("XDG_RUNTIME_DIR", "/run/user/0");
2023-04-13 11:22:32 +02:00
}
QString rtPath = QCoreApplication::applicationDirPath();
QString plugInDir(rtPath +(rtPath.endsWith("/") ? "" : "/") + "plugins");
if (!QDir(plugInDir).exists()) {
qCritical() << plugInDir
<< "does not exists, but has to contain dc-library";
exit(-1);
}
qInfo() << "pwd" << "=" << rtPath;
qInfo() << "plugInDir" << "=" << plugInDir;
hwinf *hw = Update::loadDCPlugin(QDir(plugInDir), "libCAmaster.so");
2023-05-26 13:02:45 +02:00
QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
QString const workingDir = (argc == 2) ? argv[1] : ".";
Update update(hw, update_ctrl_file, workingDir);
2023-05-26 13:02:45 +02:00
2023-05-22 16:04:50 +02:00
return 0;
std::thread t(doWork, update_ctrl_file, workingDir);
int ret = a.exec();
t.join();
return ret;
2023-04-05 14:43:27 +02:00
}