read ini-file and determine device controller to install

This commit is contained in:
Gerhard Hoffmann 2025-03-07 12:06:03 +01:00
parent c304d1a78b
commit e7d8365c62

View File

@ -10,10 +10,12 @@
#include <QDir>
#include <QDebug>
#include <QThread>
#include <QRegularExpression>
#include "message_handler.h"
#include "commandline_parser.h"
#include "utils.h"
#include "utils_internal.h"
#include "update.h"
#include "System.h"
@ -53,14 +55,20 @@ int main(int argc, char **argv) {
openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("ATBDownloadDCFirmware");
QCoreApplication::setOrganizationName("ATB Automatentechnik Baumann GmBH");
QCoreApplication::setApplicationName("ATBUpdateDC");
QCoreApplication::setApplicationVersion(APP_VERSION);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(LOG_NOTICE);
}
//return 0;
/*
CommandLineParser parser;
parser.process(a);
parser.readSettings();
@ -125,6 +133,30 @@ int main(int argc, char **argv) {
QString const &customerRepo
= QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
*/
QString const &psaDcDir = internal::customerRepoDcDir();
QString const &psaRepoRootDir = internal::customerRepoRoot();
QString const &psaRepoDir = internal::customerRepoDir();
QString const &branchName = internal::branchName();
bool debug = false;
bool noaction = true;
QString workingDir;
QString libca;
std::unique_ptr<QSettings> settings = internal::readSettings();
if (settings) {
settings->beginGroup("COMMON");
debug = settings->value("debug", false).toBool();
settings->endGroup();
settings->beginGroup("RUNTIME");
noaction = settings->value("noaction", true).toBool();
workingDir = settings->value("workingdir", "/tmp").toBool();
libca = settings->value("libca", "/usr/lib/libCAslave.so").toString();
settings->endGroup();
}
// etc/dc: located under mount-path
std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
@ -135,47 +167,32 @@ int main(int argc, char **argv) {
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;
if (debug) {
qInfo() << "using customer repository" << psaRepoDir;
}
std::unique_ptr<QString> c = internal::dcCandidateToInstall();
if (c) {
fi.setFile(*c);
if (fi.exists() == false) {
qCritical() << "dc2c.bin candidate" << *c << "does not exist. STOP.";
return -1;
}
qInfo() << "dc2c.bin canditate" << fi.absoluteFilePath();
}
}
qInfo() << "downloading dc-firmware .." << fi.absoluteFilePath();
qInfo() << "dc-firmware size (bytes) ." << fi.size();
if (readDCVersion) {
qInfo() << "dc-version ..............." << Update::dcVersion(fi.absoluteFilePath());
if (debug) {
qInfo() << "downloading dc-firmware" << fi.absoluteFilePath();
qInfo() << "dc-firmware size (bytes)" << fi.size();
qInfo() << "dc-version" << Update::dcVersion(fi.absoluteFilePath());
}
QThread::currentThread()->setObjectName("main thread");
// qInfo() << "Main thread" << QThread::currentThreadId();
Update update(customerRepo,
QString::number(customerNr),
branchName,
plugInDir,
plugInName,
workingDir,
psaDcDir);
update.doUpdate(fi.absoluteFilePath());
// MainWindow mw;
// mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
// mw.showFullScreen();
// qCritical() << "SHOW";
// mw.show();
Update u(fi.absoluteFilePath(), libca, debug, noaction);
u.run();
qInfo() << "<DC-UPDATE-FINISH>";
return 0;
// return a.exec();
}