diff --git a/ATBUpdateTool.pro b/ATBUpdateTool.pro index 39236f9..7643eb6 100644 --- a/ATBUpdateTool.pro +++ b/ATBUpdateTool.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS = DownloadDCFirmware DownloadDCJsonFiles UpdatePTUDevCtrl +SUBDIRS = DownloadDCFirmware DownloadDCJsonFiles SyncTariffs UpdatePTUDevCtrl diff --git a/DownloadDCFirmware/update.cpp b/DownloadDCFirmware/update.cpp index dafbc1b..2e7af00 100644 --- a/DownloadDCFirmware/update.cpp +++ b/DownloadDCFirmware/update.cpp @@ -209,7 +209,7 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const { QString s = nextTimePoint(); s += " sending block "; - s += QString("%1/%2 ...done ").arg(bNum).arg(m_totalBlocks); + s += QString("%1/%2 ...done ").arg(bNum).arg(m_totalBlocks); s += QString::number(ceil(((bNum * 100.0) / (double)m_totalBlocks))); qInfo() << s.toUtf8().constData(); diff --git a/DownloadDCJsonFiles/main.cpp b/DownloadDCJsonFiles/main.cpp index aa861e3..21e32f9 100644 --- a/DownloadDCJsonFiles/main.cpp +++ b/DownloadDCJsonFiles/main.cpp @@ -79,6 +79,7 @@ int main(int argc, char **argv) { bool const showExtendedVersion = parser.extendedVersion(); bool const alwaysDownloadConfig = parser.alwaysDownloadConfig(); bool const alwaysDownloadDC = parser.alwaysDownloadDC(); + Update::setPPid(parser.ppid()); QString const rtPath = QCoreApplication::applicationDirPath(); @@ -88,29 +89,32 @@ int main(int argc, char **argv) { 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; + if (Update::ppid() == -1) { + 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; + qInfo() << "parent pid ..............." << Update::ppid(); - if (showExtendedVersion) { - printf(APP_EXTENDED_VERSION"\n"); - return 0; + if (showExtendedVersion) { + printf(APP_EXTENDED_VERSION"\n"); + return 0; + } } QString const &customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr)); @@ -121,7 +125,10 @@ int main(int argc, char **argv) { if (mountPath.has_value()) { filesToUpdate = System::getJsonFilesOnUsbStick(mountPath.value()); } else { - qCritical() << "Using customer repository" << customerRepo; + + if (Update::ppid() == -1) { + qCritical() << "Using customer repository" << customerRepo; + } QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config")); if (dir.exists()) { @@ -146,13 +153,16 @@ int main(int argc, char **argv) { plugInName, workingDir); - update.doUpdate(filesToUpdate, mountPath.has_value()); - update.checkJsonVersions(); + update.doUpdate(); + // update.doUpdate(filesToUpdate, mountPath.has_value()); + // update.checkJsonVersions(); //update.checkJsonVersions(filesToUpdate); if (mountPath.has_value()) { System::umountUSBStick(); } + qInfo() << ""; + return 0; } diff --git a/DownloadDCJsonFiles/update.cpp b/DownloadDCJsonFiles/update.cpp index cf82f30..586233a 100644 --- a/DownloadDCJsonFiles/update.cpp +++ b/DownloadDCJsonFiles/update.cpp @@ -21,10 +21,13 @@ #include #include #include +#include #define UPDATE_OPKG (1) #define UPDATE_DC (0) +qint64 Update::c_ppid = -1; + static const QMap baudrateMap = { {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, {"57600" , 4}, {"115200" , 5} @@ -104,7 +107,7 @@ Update::Update(QString customerRepository, char const *serialInterface, char const *baudrate) : QObject(parent) - , m_hw(loadDCPlugin(QDir(plugInDir), pluginName)) + // , m_hw(loadDCPlugin(QDir(plugInDir), pluginName)) , m_serialInterface(serialInterface) , m_baudrate(baudrate) , m_customerRepository(customerRepository) @@ -115,27 +118,65 @@ Update::Update(QString customerRepository, , m_dryRun(dryRun) , m_sys_areDCdataValid(false) { - if (!m_hw) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???"; - } else { - int tries = 20; - while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) { - // must deliver 'true', only then are all data from hwapi valid - if (--tries < 0) { - qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED"; - break; - } - m_hw->dc_autoRequest(true); - QThread::msleep(500); - } + m_start = QDateTime::currentDateTime(); - qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_sys_areDCDataValid ..." - << m_sys_areDCdataValid; + if (Update::ppid() == -1) { + if (!m_hw) { + qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???"; + } else { + int tries = 20; + while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) { + // must deliver 'true', only then are all data from hwapi valid + if (--tries < 0) { + qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED"; + break; + } + m_hw->dc_autoRequest(true); + QThread::msleep(500); + } + + qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_sys_areDCDataValid ..." + << m_sys_areDCdataValid; + } } } Update::~Update() { - unloadDCPlugin(); + // unloadDCPlugin(); +} + +bool Update::doUpdate() { + + int numberOfFiles = 3; + + QString s = nextTimePoint(); + s += " sending "; + s += QString("%1 ...done ").arg("DC2C_cash.json"); + s += QString::number(ceil(((1 * 100.0) / (double)numberOfFiles))); + + qInfo() << s.toUtf8().constData(); + + QThread::msleep(2000); + + s = nextTimePoint(); + s += " sending "; + s += QString("%1 ...done ").arg("DC2C_device.json"); + s += QString::number(ceil(((2 * 100.0) / (double)numberOfFiles))); + + qInfo() << s.toUtf8().constData(); + + QThread::msleep(2000); + + s = nextTimePoint(); + s += " sending "; + s += QString("%1 ...done ").arg("DC2C_print01.json"); + s += QString::number(ceil(((3 * 100.0) / (double)numberOfFiles))); + + qInfo() << s.toUtf8().constData(); + + QThread::msleep(2000); + + return true; } bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) { diff --git a/DownloadDCJsonFiles/update.h b/DownloadDCJsonFiles/update.h index daa3037..bbd071c 100644 --- a/DownloadDCJsonFiles/update.h +++ b/DownloadDCJsonFiles/update.h @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -36,6 +37,14 @@ class Update : public QObject { static QPluginLoader pluginLoader; + QDateTime m_start; + QString nextTimePoint() const { + float const secs = m_start.msecsTo(QDateTime::currentDateTime()) / 1000.0; + return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0')); + } + + static qint64 c_ppid; + public: enum class DownloadResult {OK, ERROR, TIMEOUT, NOP}; enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6}; @@ -44,6 +53,8 @@ public: static bool unloadDCPlugin(); static QStringList split(QString line, QChar sep = ','); + static qint64 ppid() { return c_ppid; } + static void setPPid(qint64 ppid) { c_ppid = ppid; } explicit Update(QString customerRepository, QString customerNrStr, @@ -59,6 +70,7 @@ public: virtual ~Update() override; bool doUpdate(QStringList const &jsonFilesToDownload, bool usbStickDetected = false); + bool doUpdate(); bool updatePrinterTemplate(int templateIdx, QString fname) const; bool updateConfig(QString jsFileToSendToDC); diff --git a/SyncTariffs/SyncTariffs.pro b/SyncTariffs/SyncTariffs.pro new file mode 100644 index 0000000..9484e9e --- /dev/null +++ b/SyncTariffs/SyncTariffs.pro @@ -0,0 +1,77 @@ +QT += core + +TARGET = ATBDownloadDCFirmware + +VERSION="1.0.0" +win32 { + BUILD_DATE=$$system("date /t") + BUILD_TIME=$$system("time /t") +} else { + BUILD_DATE=$$system("date +%d-%m-%y") + BUILD_TIME=$$system("date +%H:%M:%S") +} + +GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1") + +EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}" + + +INCLUDEPATH += \ + plugins \ + $${INCLUDEINTERFACES} \ + $${_PRO_FILE_PWD_}/../UpdatePTUDevCtrl \ + $${_PRO_FILE_PWD_}/../common/include + +CONFIG += c++17 + +DEFINES+=APP_VERSION=\\\"$$VERSION\\\" +DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\" +DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\" +DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" + +# keep comments, as /* fall through */ +QMAKE_CXXFLAGS += -C +QMAKE_CXXFLAGS += -g +QMAKE_CXXFLAGS += -Wno-deprecated-copy -O + +contains( CONFIG, PTU5 ) { + CONFIG += link_pkgconfig + QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7 + # QMAKE_CXXFLAGS += -Wno-deprecated-copy + PTU5BASEPATH = /opt/devel/ptu5 + + INCLUDEPATH += $$PTU5BASEPATH/qt/libs/devicecontroller/include + LIBS += -L$$PTU5BASEPATH/qt/libs/devicecontroller/library + + ARCH = PTU5 + DEFINES+=PTU5 +} +contains( CONFIG, PTU5_YOCTO ) { + QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7 + # QMAKE_CXXFLAGS += -Wno-deprecated-copy + PTU5BASEPATH = /opt/devel/ptu5 + ARCH = PTU5 + DEFINES+=PTU5 +} +contains( CONFIG, DesktopLinux ) { + # QMAKE_CC = ccache $$QMAKE_CC + # QMAKE_CXX = ccache $$QMAKE_CXX + QMAKE_CXXFLAGS += -std=c++17 + # QMAKE_CXXFLAGS += -Wno-deprecated-copy + linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments } + ARCH = DesktopLinux + DEFINES+=DesktopLinux +} + +SOURCES += \ + main.cpp + +# HEADERS += \ + +########################################################################################## +# for running program on target through QtCreator +contains( CONFIG, PTU5 ) { + qnx: target.path = /tmp/$${TARGET}/bin + else: unix:!android: target.path = /opt/app/tools/atbupdate/ + !isEmpty(target.path): INSTALLS += target +} diff --git a/SyncTariffs/main.cpp b/SyncTariffs/main.cpp new file mode 100644 index 0000000..627d253 --- /dev/null +++ b/SyncTariffs/main.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + return 0; +} diff --git a/UpdatePTUDevCtrl/commandline_parser.cpp b/UpdatePTUDevCtrl/commandline_parser.cpp index 67613d7..2e797f5 100644 --- a/UpdatePTUDevCtrl/commandline_parser.cpp +++ b/UpdatePTUDevCtrl/commandline_parser.cpp @@ -95,7 +95,13 @@ CommandLineParser::CommandLineParser() QCommandLineOption( QStringList() << "D" << "read-dc-version", QCoreApplication::translate("main", "Show version of device controller."), - QCoreApplication::translate("main", "Show version of device controller."))) { + QCoreApplication::translate("main", "Show version of device controller."))) + , m_setPPid( + QCommandLineOption( + QStringList() << "P" << "set-ppid", + QCoreApplication::translate("main", "Set pid of parent process."), + QCoreApplication::translate("main", "Set pid of parent process."))) { + configure(); } @@ -154,6 +160,9 @@ void CommandLineParser::configure() { m_readDCVersionOption.setDefaultValue("false"); m_parser.addOption(m_readDCVersionOption); + + m_setPPid.setDefaultValue("-1"); + m_parser.addOption(m_setPPid); } void CommandLineParser::readSettings() { @@ -286,6 +295,19 @@ QString CommandLineParser::workingDir() { return m_workingDir; } +qint64 CommandLineParser::ppid() { + m_ppid = -1; + if (m_parser.isSet(m_setPPid)) { + QString p = m_parser.value(m_setPPid); + bool ok; + qint64 q = p.toLongLong(&ok); + if (ok) { + m_ppid = q; + } + } + return m_ppid; +} + bool CommandLineParser::dryRun() { if (m_parser.isSet(m_dryRunOption)) { m_dryRun = m_parser.value(m_dryRunOption); diff --git a/UpdatePTUDevCtrl/commandline_parser.h b/UpdatePTUDevCtrl/commandline_parser.h index 082680d..e1996d8 100644 --- a/UpdatePTUDevCtrl/commandline_parser.h +++ b/UpdatePTUDevCtrl/commandline_parser.h @@ -23,6 +23,7 @@ class CommandLineParser : public QCommandLineParser { QString m_alwaysDownloadDC; QString m_readDCVersion{"false"}; QString m_dcDir{"etc/dc/"}; + qint64 m_ppid; QCommandLineOption m_repositoryUrlOption; QCommandLineOption m_iniFileDirectoryOption; @@ -41,6 +42,7 @@ class CommandLineParser : public QCommandLineParser { QCommandLineOption m_yoctoInstallStatusOption; QCommandLineOption m_dcDirectoryOption; QCommandLineOption m_readDCVersionOption; + QCommandLineOption m_setPPid; QCommandLineParser m_parser; @@ -63,6 +65,7 @@ public: QString psaConfigDir(); QString psaTariffDir(); bool dryRun(); + qint64 ppid(); bool noUpdatePsaHardware(); bool yoctoVersion(); bool yoctoInstallStatus(); diff --git a/UpdatePTUDevCtrl/main.cpp b/UpdatePTUDevCtrl/main.cpp index c8f4770..1f7592b 100644 --- a/UpdatePTUDevCtrl/main.cpp +++ b/UpdatePTUDevCtrl/main.cpp @@ -87,10 +87,12 @@ int main(int argc, char *argv[]) { if (v.isEmpty()) { QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig"); if (QFileInfo(sshKeyFile).exists()) { - gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig"; - if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) { - qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting..."; - return -1; + if (qgetenv("GIT_SSH_COMMAND").isNull()) { + gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig"; + if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) { + qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting..."; + return -1; + } } } else { qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting..."; @@ -201,7 +203,7 @@ int main(int argc, char *argv[]) { mw.showFullScreen(); // test - worker.dcUpdate(); + worker.jsUpdate(); // worker.summary(); return a.exec(); diff --git a/UpdatePTUDevCtrl/mainwindow.cpp b/UpdatePTUDevCtrl/mainwindow.cpp index 1584bc3..a83b75a 100644 --- a/UpdatePTUDevCtrl/mainwindow.cpp +++ b/UpdatePTUDevCtrl/mainwindow.cpp @@ -83,6 +83,9 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent) connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString))); connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit())); connect(m_worker, SIGNAL(showDcDownload(QString)),this,SLOT(onShowDcDownload(QString))); + connect(m_worker, SIGNAL(showJsonDownload(QString)),this,SLOT(onShowJsonDownload(QString))); + connect(m_worker, SIGNAL(showTariffUpdate(QString)),this,SLOT(onShowTariffUpdate(QString))); + connect(m_worker, SIGNAL(showISMASChecks(QString)),this,SLOT(onShowISMASChecks(QString))); connect(m_worker, SIGNAL(setDcDownloadProgress(int)),this,SLOT(onSetDcDownloadProgress(int))); connect(m_worker, SIGNAL(enableExit()),this,SLOT(onEnableExit())); connect(m_worker, SIGNAL(stopStartTimer()),this,SLOT(onStopStartTimer())); @@ -105,6 +108,7 @@ void MainWindow::onShowSummary(QString text) { ui->updateLabel->setText(s); ui->updateLabel->hide(); ui->stepLabel->hide(); + ui->updateProgress->hide(); s += text; ui->updateStatus->setText(s); @@ -114,10 +118,80 @@ void MainWindow::onSetDcDownloadProgress(int v) { ui->updateProgress->setValue(v); } +void MainWindow::onShowTariffUpdate(QString) { + ui->exit->setEnabled(false); + + QString s = ui->stepLabel->text(); + + QString tmp("Install tariff files "); + int len = m_showLineLength - tmp.length(); + while (--len > 0) { + tmp += " "; + } + + s += QString("%1 [OK ]
").arg(tmp); + + ui->stepLabel->setText(s); +} + +void MainWindow::onShowISMASChecks(QString) { + QString s = ui->stepLabel->text(); + + QString tmp("Check ISMAS connectivity "); + int len = m_showLineLength - tmp.length(); + while (--len > 0) { + tmp += " "; + } + + s += QString("%1 [OK ]
").arg(tmp); + + tmp = "Check update activation "; + len = m_showLineLength - tmp.length(); + + while (--len > 0) { + tmp += " "; + } + + s += QString("%1 [OK ]
").arg(tmp); + ui->stepLabel->setText(s); +} + +void MainWindow::onShowJsonDownload(QString) { + ui->exit->setEnabled(false); + + QString s = ui->stepLabel->text(); + + QString tmp("Send json files to dc-hardware "); + int len = m_showLineLength - tmp.length(); + while (--len > 0) { + tmp += " "; + } + + s += QString("%1 [OK ]
").arg(tmp); + + ui->stepLabel->setText(s); +} + void MainWindow::onShowDcDownload(QString version) { m_targetDcVersion = version; ui->exit->setEnabled(false); - ui->stepLabel->setText(QString("Device controller update. Target version: %1").arg(version).leftJustified(m_width-3)); + + // test + onShowISMASChecks(""); + onShowTariffUpdate(""); + onShowJsonDownload(""); + + QString s = ui->stepLabel->text(); + + QString tmp("Send dc-firmware to dc-hardware "); + int len = m_showLineLength - tmp.length(); + while (--len > 0) { + tmp += " "; + } + + s += QString("%1 [OK ] (%2)").arg(tmp).arg(version); + + ui->stepLabel->setText(s); } MainWindow::~MainWindow() { diff --git a/UpdatePTUDevCtrl/mainwindow.h b/UpdatePTUDevCtrl/mainwindow.h index cd11f74..c17e361 100644 --- a/UpdatePTUDevCtrl/mainwindow.h +++ b/UpdatePTUDevCtrl/mainwindow.h @@ -52,6 +52,9 @@ public slots: void onEnableExit(); void onDisableExit(); void onShowDcDownload(QString); + void onShowJsonDownload(QString); + void onShowTariffUpdate(QString); + void onShowISMASChecks(QString); void onSetDcDownloadProgress(int); void onShowSummary(QString); #if EMERGENCY_LEAVE_BL==1 @@ -68,6 +71,9 @@ private slots: void onQuit(); private: + + int const m_showLineLength = 37; + void scrollDownTextEdit(); void onShowMessage(QString, QString); diff --git a/UpdatePTUDevCtrl/process/command.cpp b/UpdatePTUDevCtrl/process/command.cpp index b0b8747..608b11b 100644 --- a/UpdatePTUDevCtrl/process/command.cpp +++ b/UpdatePTUDevCtrl/process/command.cpp @@ -37,6 +37,7 @@ void Command::readyReadStandardOutput() { QProcess *p = (QProcess *)sender(); if (p) { QString s = p->readAllStandardOutput(); + if (m_worker) { int i = -1; if ((i = s.indexOf("")) != -1) { @@ -49,9 +50,9 @@ void Command::readyReadStandardOutput() { } emit m_worker->showDcDownload(s); } else - if ((i = s.indexOf("")) != -1) { + if ((i = s.indexOf("")) != -1) { bool ok; - int v = s.mid(i+10).trimmed().toInt(&ok); + int v = s.mid(i+13).trimmed().toInt(&ok); if (ok) { emit m_worker->setDcDownloadProgress(v); emit m_worker->insertText(s.mid(0,i) + "\n"); @@ -67,6 +68,14 @@ void Command::readyReadStandardOutput() { if ((i = s.indexOf("")) != -1) { m_worker->summary(); //qApp->exit(-1); + } else + if ((i = s.indexOf("")) != -1) { + bool ok; + int v = s.mid(i+13).trimmed().toInt(&ok); + if (ok) { + emit m_worker->setDcDownloadProgress(v); + emit m_worker->insertText(s.mid(0,i) + "\n"); + } } else { emit m_worker->insertText(s); } @@ -93,6 +102,11 @@ void Command::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) { } disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput())); disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError())); + disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus))); + + if (m_command.contains("ATBDownloadDCJsonFiles")) { + m_worker->dcUpdate(); + } } bool Command::start(QString workingDirectory, QStringList args) { @@ -104,12 +118,16 @@ bool Command::start(QString workingDirectory, QStringList args) { if (m_p != nullptr) { delete m_p; } + + qCritical() << "COMMAND" << m_command << workingDirectory << args; + m_p = new QProcess(this); m_p->setWorkingDirectory(workingDirectory); m_p->setProcessChannelMode(QProcess::MergedChannels); connect(m_p, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); connect(m_p, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError())); + connect(m_p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus))); if (!args.isEmpty()) { m_p->start(m_command, args); diff --git a/UpdatePTUDevCtrl/utils.cpp b/UpdatePTUDevCtrl/utils.cpp index 7b7ec65..7b529a3 100644 --- a/UpdatePTUDevCtrl/utils.cpp +++ b/UpdatePTUDevCtrl/utils.cpp @@ -18,9 +18,99 @@ #include #include #include +#include +#include #include +QVector> Utils::installedJsonFiles(QDir const &customerDir) { + QVector> vec; + QStringList fileList; + + QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_config")); + while (it.hasNext()) { + QFileInfo const fi(it.next()); + if (fi.fileName().startsWith("DC2C") && fi.fileName().endsWith(".json")) { + fileList << fi.absoluteFilePath(); + } + } + + fileList.sort(); + + QString const ¤t = QDir::current().absolutePath(); + + if (!QDir::setCurrent(customerDir.absolutePath())) { + qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set" + << "working directory to" << customerDir.absolutePath(); + } else { + + for (int i = 0; i < fileList.size(); ++i) { + + QProcess p; + QStringList params; + params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i]; + + p.start("bash", params); + p.waitForFinished(); + QString r = p.readAllStandardOutput().left(8); + + vec.push_back(QPair(QFileInfo(fileList[i]).fileName(), r)); + } + + if (!QDir::setCurrent(current)) { + qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set" + << "working directory to" << current; + } + } + + return vec; +} + +QVector> Utils::installedTariffFiles(QDir const &customerDir) { + QVector> vec; + QStringList fileList; + + QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_tariff")); + while (it.hasNext()) { + QFileInfo const fi(it.next()); + if (fi.fileName().startsWith("tariff") && fi.fileName().endsWith(".json")) { + fileList << fi.absoluteFilePath(); + } + } + + fileList.sort(); + + QString const ¤t = QDir::current().absolutePath(); + + if (!QDir::setCurrent(customerDir.absolutePath())) { + qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set" + << "working directory to" << customerDir.absolutePath(); + } else { + + for (int i = 0; i < fileList.size(); ++i) { + + QProcess p; + QStringList params; + params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i]; + + qCritical() << current << "git log -n 1 --pretty=format:%H -- " << fileList[i]; + + p.start("bash", params); + p.waitForFinished(); + QString r = p.readAllStandardOutput().left(8); + + vec.push_back(QPair(QFileInfo(fileList[i]).fileName(), r)); + } + + if (!QDir::setCurrent(current)) { + qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set" + << "working directory to" << current; + } + } + + return vec; +} + QVector> Utils::installedPackages() { QVector> vec; if (QFile::exists("/usr/bin/ptuPackageVersions")) { @@ -165,7 +255,7 @@ QString Utils::getTariffInfo(QString fileName) { } -QString Utils::zoneName(quint8 i) { +QString Utils::zoneName(quint8 /* i */) { //static constexpr char const *zName[] = { // "", // "purple", diff --git a/UpdatePTUDevCtrl/utils.h b/UpdatePTUDevCtrl/utils.h index a5c93c1..9300f10 100644 --- a/UpdatePTUDevCtrl/utils.h +++ b/UpdatePTUDevCtrl/utils.h @@ -36,6 +36,8 @@ namespace Utils { bool isATBQTRunning(); QVector> installedPackages(); + QVector> installedJsonFiles(QDir const &customerDir); + QVector> installedTariffFiles(QDir const &customerDir); } #endif // UTILS_H_INCLUDED diff --git a/UpdatePTUDevCtrl/worker.cpp b/UpdatePTUDevCtrl/worker.cpp index 20bbe42..862272f 100644 --- a/UpdatePTUDevCtrl/worker.cpp +++ b/UpdatePTUDevCtrl/worker.cpp @@ -178,12 +178,15 @@ Worker::Worker(int customerNr, , m_updateProcessRunning(true) , m_mainWindow(nullptr) /* contains plugin */ , m_dcDownloadFirmware(new Command("/opt/app/tools/atbupdate/ATBDownloadDCFirmware --read-dc-version true")) + , m_dcDownloadJsonFiles(new Command( + QString("/opt/app/tools/atbupdate/ATBDownloadDCJsonFiles --set-ppid %1").arg(QCoreApplication::applicationPid()))) //, m_withoutIsmasDirectPort(true) /* useful for testing */ { , m_withoutIsmasDirectPort(false) /* useful for testing */ { m_start = QDateTime::currentDateTime(); m_dcDownloadFirmware->setWorker(this); + m_dcDownloadJsonFiles->setWorker(this); // TODO: turn object into singleton instance = this; @@ -1511,6 +1514,10 @@ PSAInstalled Worker::getPSAInstalled() { return psaInstalled; } +bool Worker::jsUpdate() { + return m_dcDownloadJsonFiles->start("/opt/app/tools/atbupdate"); +} + bool Worker::dcUpdate() { return m_dcDownloadFirmware->start("/opt/app/tools/atbupdate"); } @@ -1520,6 +1527,9 @@ void Worker::summary() { QString summary, first, second, line, tmp; QVector> vec = Utils::installedPackages(); + vec.append(Utils::installedTariffFiles(m_customerRepository)); + vec.append(Utils::installedJsonFiles(m_customerRepository)); + int max_first = 0, max_second = 0; for (int i = 0; i < vec.size(); ++i) { max_first = std::max(max_first, vec[i].first.length()); @@ -1584,4 +1594,5 @@ void Worker::summary() { } emit showSummary(summary); + emit enableExit(); } diff --git a/UpdatePTUDevCtrl/worker.h b/UpdatePTUDevCtrl/worker.h index 8c54d69..4b6358f 100644 --- a/UpdatePTUDevCtrl/worker.h +++ b/UpdatePTUDevCtrl/worker.h @@ -191,6 +191,7 @@ class Worker : public QThread{ MainWindow *m_mainWindow; Command *m_dcDownloadFirmware; + Command *m_dcDownloadJsonFiles; bool m_withoutIsmasDirectPort; QString m_apismVersion; @@ -460,6 +461,7 @@ public: Update *update() { return m_update; } Update const *update() const { return m_update; } + bool jsUpdate(); bool dcUpdate(); void summary(); QDateTime start() { return m_start; } @@ -478,6 +480,9 @@ signals: void enableExit(); void disableExit(); void showDcDownload(QString); + void showJsonDownload(QString); + void showTariffUpdate(QString); + void showISMASChecks(QString); void showSummary(QString); void setDcDownloadProgress(int);