155 lines
4.5 KiB
C++
155 lines
4.5 KiB
C++
#include <QCoreApplication>
|
|
#include <QApplication>
|
|
#include <QDebug>
|
|
#include <QTimer>
|
|
#include <QFileInfo>
|
|
|
|
#ifdef __linux__
|
|
#include <stdlib.h> // system()
|
|
#endif
|
|
|
|
#include "message_handler.h"
|
|
#include "plugins/interfaces.h"
|
|
#include "commandline_parser.h"
|
|
|
|
#include <unistd.h>
|
|
#include <memory>
|
|
#include <QSharedMemory>
|
|
#include <QRunnable>
|
|
#include <QThreadPool>
|
|
#include <QDir>
|
|
#include <QProcess>
|
|
#include <QCommandLineParser>
|
|
#include <QStandardPaths>
|
|
#include <QMainWindow>
|
|
#include <QSettings>
|
|
|
|
#include "update.h"
|
|
#include "git/git_client.h"
|
|
#include "ismas/ismas_client.h"
|
|
#include "worker_thread.h"
|
|
#include "worker.h"
|
|
#include "mainwindow.h"
|
|
#include "utils.h"
|
|
|
|
#include <QThread>
|
|
#include <QtWidgets>
|
|
#include <QScopedPointer>
|
|
|
|
#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX)
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#endif
|
|
|
|
#ifdef PTU5
|
|
#define SERIAL_PORT "ttymxc2"
|
|
#else
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
#endif
|
|
|
|
// argv[1]: file to send to dc
|
|
int main(int argc, char *argv[]) {
|
|
QByteArray const value = qgetenv("LC_ALL");
|
|
if (value != "C") {
|
|
qputenv("LC_ALL", "C");
|
|
}
|
|
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
|
|
|
openlog("ATB-UPDATE", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
|
|
|
QApplication a(argc, argv);
|
|
QApplication::setApplicationName("ATBUpdateTool");
|
|
QApplication::setApplicationVersion(APP_VERSION);
|
|
|
|
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
|
atbInstallMessageHandler(atbDebugOutput);
|
|
setDebugLevel(LOG_NOTICE);
|
|
}
|
|
|
|
CommandLineParser parser;
|
|
parser.process(a);
|
|
parser.readSettings();
|
|
|
|
QString repositoryUrl = parser.repositoryUrl();
|
|
QString plugInDir = parser.plugInDir();
|
|
QString plugInName = parser.plugInName();
|
|
QString workingDir = parser.workingDir();
|
|
bool const dryRun = parser.dryRun();
|
|
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
|
|
bool const showYoctoVersion = parser.yoctoVersion();
|
|
bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
|
|
bool const showExtendedVersion = parser.extendedVersion();
|
|
bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
|
|
bool const alwaysDownloadDC = parser.alwaysDownloadDC();
|
|
|
|
QString const rtPath = QCoreApplication::applicationDirPath();
|
|
|
|
qInfo() << "pwd ......................" << rtPath;
|
|
qInfo() << "repositoryUrl ............" << repositoryUrl;
|
|
qInfo() << "plugInDir ................" << plugInDir;
|
|
qInfo() << "plugInName ..............." << plugInName;
|
|
qInfo() << "workingDir ..............." << workingDir;
|
|
qInfo() << "dryRun ..................." << dryRun;
|
|
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
|
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
|
|
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
|
|
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
|
|
|
if (showExtendedVersion) {
|
|
printf(APP_EXTENDED_VERSION"\n");
|
|
return 0;
|
|
}
|
|
if (showYoctoVersion) {
|
|
printf("%s\n", Worker::getATBUpdateToolYoctoVersion().toStdString().c_str());
|
|
return 0;
|
|
}
|
|
if (showYoctoInstallStatus) {
|
|
printf("%s\n", Worker::getATBUpdateToolYoctoInstallationStatus().toStdString().c_str());
|
|
return 0;
|
|
}
|
|
|
|
int machineNr = Utils::read1stLineOfFile("/etc/machine_nr");
|
|
int customerNr = Utils::read1stLineOfFile("/etc/cust_nr");
|
|
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
|
|
QString const branchName = (zoneNr != 0)
|
|
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
|
|
|
QThread::currentThread()->setObjectName("main thread");
|
|
qInfo() << "Main thread" << QThread::currentThreadId();
|
|
|
|
|
|
if (!QDir(plugInDir).exists()) {
|
|
qCritical() << plugInDir
|
|
<< "does not exists, but has to contain dc-library";
|
|
exit(-1);
|
|
}
|
|
|
|
// before loading the library, delete all possible shared memory segments
|
|
#if defined Q_OS_LINUX || defined Q_OS_UNIX
|
|
// system("rm -rf /tmp/qipc*");
|
|
#else
|
|
#error "Only tested under UNIX/LINUX"
|
|
#endif
|
|
|
|
Worker worker(customerNr,
|
|
machineNr,
|
|
zoneNr,
|
|
repositoryUrl,
|
|
branchName,
|
|
plugInDir,
|
|
plugInName,
|
|
workingDir,
|
|
noUpdatePsaHardware,
|
|
alwaysDownloadConfig,
|
|
alwaysDownloadDC,
|
|
dryRun);
|
|
|
|
MainWindow mw(&worker);
|
|
worker.setMainWindow(&mw);
|
|
|
|
mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
|
mw.showFullScreen();
|
|
|
|
return a.exec();
|
|
}
|