2024-05-14 16:38:47 +02:00
|
|
|
|
2024-02-29 11:36:24 +01:00
|
|
|
#include <QtGlobal>
|
2024-05-05 17:24:28 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QApplication>
|
2024-05-14 16:38:47 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDir>
|
2024-05-05 17:24:28 +02:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QThread>
|
|
|
|
|
2024-05-14 16:38:47 +02:00
|
|
|
#include "message_handler.h"
|
|
|
|
#include "commandline_parser.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "update.h"
|
2024-05-05 17:24:28 +02:00
|
|
|
#include "mainwindow.h"
|
2024-05-14 16:38:47 +02:00
|
|
|
#include "System.h"
|
|
|
|
|
|
|
|
#include <DeviceController/interfaces.h>
|
2024-05-05 17:24:28 +02:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PTU5
|
|
|
|
#define SERIAL_PORT "ttymxc2"
|
|
|
|
#else
|
|
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
|
|
#endif
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-05-14 16:38:47 +02:00
|
|
|
int read1stLineOfFile(QString fileName) {
|
|
|
|
QFile f(fileName);
|
|
|
|
if (f.exists()) {
|
|
|
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
QTextStream in(&f);
|
|
|
|
in.setCodec("UTF-8");
|
|
|
|
while(!in.atEnd()) {
|
|
|
|
return in.readLine().toInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-02-29 11:36:24 +01:00
|
|
|
int main(int argc, char **argv) {
|
2024-05-05 17:24:28 +02:00
|
|
|
QByteArray const value = qgetenv("LC_ALL");
|
|
|
|
if (value != "C") {
|
|
|
|
qputenv("LC_ALL", "C");
|
|
|
|
}
|
|
|
|
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
|
|
|
|
2024-12-20 13:01:34 +01:00
|
|
|
openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
|
2024-05-05 17:24:28 +02:00
|
|
|
|
|
|
|
QApplication a(argc, argv);
|
2024-06-05 10:10:21 +02:00
|
|
|
QApplication::setApplicationName("ATBDownloadDCFirmware");
|
2024-05-05 17:24:28 +02:00
|
|
|
QApplication::setApplicationVersion(APP_VERSION);
|
|
|
|
|
|
|
|
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
|
|
|
atbInstallMessageHandler(atbDebugOutput);
|
|
|
|
setDebugLevel(LOG_NOTICE);
|
|
|
|
}
|
|
|
|
|
2024-05-14 16:38:47 +02:00
|
|
|
CommandLineParser parser;
|
|
|
|
parser.process(a);
|
|
|
|
parser.readSettings();
|
|
|
|
|
|
|
|
QString repositoryUrl = parser.repositoryUrl();
|
|
|
|
QString plugInDir = parser.plugInDir();
|
|
|
|
QString plugInName = parser.plugInName();
|
|
|
|
QString workingDir = parser.workingDir();
|
|
|
|
QString psaConfigDir = parser.psaConfigDir();
|
|
|
|
QString psaTariffDir = parser.psaTariffDir();
|
2024-12-20 13:01:34 +01:00
|
|
|
QString psaDcDir = parser.dcDir();
|
2024-05-14 16:38:47 +02:00
|
|
|
QString iniFileName = parser.iniFileName();
|
|
|
|
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();
|
2024-11-27 15:54:42 +01:00
|
|
|
bool const readDCVersion = parser.readDCVersion();
|
2024-05-14 16:38:47 +02:00
|
|
|
|
|
|
|
QString const rtPath = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
|
|
int const machineNr = read1stLineOfFile("/mnt/system_data/machine_nr");
|
|
|
|
int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
|
|
|
|
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
|
|
|
QString const branchName = (zoneNr != 0)
|
|
|
|
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
|
|
|
|
|
|
|
qInfo() << "pwd ......................" << rtPath;
|
|
|
|
qInfo() << "repositoryUrl ............" << repositoryUrl;
|
|
|
|
qInfo() << "plugInDir ................" << plugInDir;
|
|
|
|
qInfo() << "plugInName ..............." << plugInName;
|
|
|
|
qInfo() << "workingDir ..............." << workingDir;
|
|
|
|
qInfo() << "psaConfigDir ............." << psaConfigDir;
|
|
|
|
qInfo() << "psaTariffDir ............." << psaTariffDir;
|
|
|
|
qInfo() << "dryRun ..................." << dryRun;
|
|
|
|
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
|
|
|
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
|
|
|
|
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
|
|
|
|
qInfo() << "showYoctoVersion ........." << showYoctoVersion;
|
|
|
|
qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
|
|
|
|
qInfo() << "showExtendedVersion ......" << showExtendedVersion;
|
|
|
|
qInfo() << "iniFileName .............." << iniFileName;
|
|
|
|
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
|
|
|
qInfo() << "machineNr ................" << machineNr;
|
|
|
|
qInfo() << "customerNr ..............." << customerNr;
|
|
|
|
qInfo() << "zoneNr ..................." << zoneNr;
|
2024-11-27 15:54:42 +01:00
|
|
|
qInfo() << "readDCVersion ............" << readDCVersion;
|
2024-12-20 13:01:34 +01:00
|
|
|
qInfo() << "dcDir ...................." << psaDcDir;
|
2024-11-27 15:54:42 +01:00
|
|
|
|
2024-12-20 13:01:34 +01:00
|
|
|
if (!QDir(plugInDir).exists()) {
|
|
|
|
qCritical() << plugInDir
|
|
|
|
<< "does not exists, but has to contain dc-library";
|
|
|
|
exit(-1);
|
2024-11-28 12:53:44 +01:00
|
|
|
}
|
2024-05-14 16:38:47 +02:00
|
|
|
|
|
|
|
if (showExtendedVersion) {
|
|
|
|
printf(APP_EXTENDED_VERSION"\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-12-20 13:01:34 +01:00
|
|
|
QString const &customerRepo
|
|
|
|
= QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
|
|
|
|
|
|
|
|
// etc/dc: located under mount-path
|
|
|
|
std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
|
|
|
|
QFileInfo fi;
|
|
|
|
if (mountPath.has_value()) {
|
|
|
|
fi.setFile(mountPath.value(), System::getDCFileOnUsbStick(mountPath.value()));
|
|
|
|
} else
|
|
|
|
if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) {
|
|
|
|
fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value()));
|
|
|
|
} else {
|
|
|
|
qInfo() << "using customer repository" << customerRepo;
|
|
|
|
|
|
|
|
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/dc"));
|
|
|
|
if (dir.exists()) {
|
|
|
|
fi.setFile(dir, dir.absoluteFilePath("dc2c.bin"));
|
|
|
|
} else {
|
|
|
|
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2024-11-28 12:53:44 +01:00
|
|
|
|
2024-12-20 13:01:34 +01:00
|
|
|
qInfo() << "downloading dc-firmware .." << fi.absoluteFilePath();
|
|
|
|
qInfo() << "dc-firmware size (bytes) ." << fi.size();
|
|
|
|
if (readDCVersion) {
|
|
|
|
qInfo() << "dc-version ..............." << Update::dcVersion(fi.absoluteFilePath());
|
|
|
|
}
|
2024-05-14 16:38:47 +02:00
|
|
|
|
2024-05-05 17:24:28 +02:00
|
|
|
QThread::currentThread()->setObjectName("main thread");
|
2024-12-20 13:01:34 +01:00
|
|
|
// qInfo() << "Main thread" << QThread::currentThreadId();
|
|
|
|
|
|
|
|
Update update(customerRepo,
|
|
|
|
QString::number(customerNr),
|
|
|
|
branchName,
|
|
|
|
plugInDir,
|
|
|
|
plugInName,
|
|
|
|
workingDir,
|
|
|
|
psaDcDir);
|
|
|
|
|
|
|
|
update.doUpdate(fi.absoluteFilePath());
|
2024-05-05 17:24:28 +02:00
|
|
|
|
2024-11-28 12:53:44 +01:00
|
|
|
// MainWindow mw;
|
2024-05-05 17:24:28 +02:00
|
|
|
|
2024-11-28 12:53:44 +01:00
|
|
|
// mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
2024-06-05 10:10:21 +02:00
|
|
|
// mw.showFullScreen();
|
2024-05-05 17:24:28 +02:00
|
|
|
|
2024-06-05 10:10:21 +02:00
|
|
|
// qCritical() << "SHOW";
|
2024-05-05 17:24:28 +02:00
|
|
|
|
2024-06-05 10:10:21 +02:00
|
|
|
// mw.show();
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-12-20 13:01:34 +01:00
|
|
|
qInfo() << "<DC-UPDATE-FINISH>";
|
|
|
|
|
2024-06-05 10:10:21 +02:00
|
|
|
return 0;
|
|
|
|
// return a.exec();
|
2024-02-29 11:36:24 +01:00
|
|
|
}
|