read ini-file and determine device controller to install
This commit is contained in:
		@@ -10,10 +10,12 @@
 | 
				
			|||||||
#include <QDir>
 | 
					#include <QDir>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QThread>
 | 
					#include <QThread>
 | 
				
			||||||
 | 
					#include <QRegularExpression>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "message_handler.h"
 | 
					#include "message_handler.h"
 | 
				
			||||||
#include "commandline_parser.h"
 | 
					#include "commandline_parser.h"
 | 
				
			||||||
#include "utils.h"
 | 
					#include "utils.h"
 | 
				
			||||||
 | 
					#include "utils_internal.h"
 | 
				
			||||||
#include "update.h"
 | 
					#include "update.h"
 | 
				
			||||||
#include "System.h"
 | 
					#include "System.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,14 +55,20 @@ int main(int argc, char **argv) {
 | 
				
			|||||||
    openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
 | 
					    openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QCoreApplication a(argc, argv);
 | 
					    QCoreApplication a(argc, argv);
 | 
				
			||||||
    QCoreApplication::setApplicationName("ATBDownloadDCFirmware");
 | 
					    QCoreApplication::setOrganizationName("ATB Automatentechnik Baumann GmBH");
 | 
				
			||||||
 | 
					    QCoreApplication::setApplicationName("ATBUpdateDC");
 | 
				
			||||||
    QCoreApplication::setApplicationVersion(APP_VERSION);
 | 
					    QCoreApplication::setApplicationVersion(APP_VERSION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
 | 
					    if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
 | 
				
			||||||
        atbInstallMessageHandler(atbDebugOutput);
 | 
					        atbInstallMessageHandler(atbDebugOutput);
 | 
				
			||||||
        setDebugLevel(LOG_NOTICE);
 | 
					        setDebugLevel(LOG_NOTICE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
    CommandLineParser parser;
 | 
					    CommandLineParser parser;
 | 
				
			||||||
    parser.process(a);
 | 
					    parser.process(a);
 | 
				
			||||||
    parser.readSettings();
 | 
					    parser.readSettings();
 | 
				
			||||||
@@ -125,6 +133,30 @@ int main(int argc, char **argv) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    QString const &customerRepo
 | 
					    QString const &customerRepo
 | 
				
			||||||
        = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
 | 
					        = 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
 | 
					    // etc/dc: located under mount-path
 | 
				
			||||||
    std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
 | 
					    std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
 | 
				
			||||||
@@ -135,47 +167,32 @@ int main(int argc, char **argv) {
 | 
				
			|||||||
    if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) {
 | 
					    if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) {
 | 
				
			||||||
        fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value()));
 | 
					        fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value()));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        qInfo() << "using customer repository" << customerRepo;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/dc"));
 | 
					        if (debug) {
 | 
				
			||||||
        if (dir.exists()) {
 | 
					            qInfo() << "using customer repository" << psaRepoDir;
 | 
				
			||||||
            fi.setFile(dir, dir.absoluteFilePath("dc2c.bin"));
 | 
					        }
 | 
				
			||||||
        } else {
 | 
					
 | 
				
			||||||
            qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
 | 
					        std::unique_ptr<QString> c = internal::dcCandidateToInstall();
 | 
				
			||||||
            return -1;
 | 
					        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();
 | 
					    if (debug) {
 | 
				
			||||||
    qInfo() << "dc-firmware size (bytes) ." << fi.size();
 | 
					        qInfo() << "downloading dc-firmware" << fi.absoluteFilePath();
 | 
				
			||||||
    if (readDCVersion) {
 | 
					        qInfo() << "dc-firmware size (bytes)" << fi.size();
 | 
				
			||||||
        qInfo() << "dc-version ..............." << Update::dcVersion(fi.absoluteFilePath());
 | 
					        qInfo() << "dc-version" << Update::dcVersion(fi.absoluteFilePath());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QThread::currentThread()->setObjectName("main thread");
 | 
					    Update u(fi.absoluteFilePath(), libca, debug, noaction);
 | 
				
			||||||
    // qInfo() << "Main thread" << QThread::currentThreadId();
 | 
					    u.run();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    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();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qInfo() << "<DC-UPDATE-FINISH>";
 | 
					    qInfo() << "<DC-UPDATE-FINISH>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
    // return a.exec();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user