From 34cc077937a14871b945d36c04fb8bfa1a53235b Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 15 Sep 2025 13:12:57 +0200 Subject: [PATCH] move commandline_parser to ../common/ --- UpdatePTUDevCtrl/UpdatePTUDevCtrl.pro | 2 - UpdatePTUDevCtrl/commandline_parser.cpp | 360 ------ UpdatePTUDevCtrl/commandline_parser.h | 78 -- .../ismas/ismas_client.cpp.master | 1107 +++++++++++++++++ 4 files changed, 1107 insertions(+), 440 deletions(-) delete mode 100644 UpdatePTUDevCtrl/commandline_parser.cpp delete mode 100644 UpdatePTUDevCtrl/commandline_parser.h create mode 100644 UpdatePTUDevCtrl/ismas/ismas_client.cpp.master diff --git a/UpdatePTUDevCtrl/UpdatePTUDevCtrl.pro b/UpdatePTUDevCtrl/UpdatePTUDevCtrl.pro index 2f2cc7a..b8056ed 100644 --- a/UpdatePTUDevCtrl/UpdatePTUDevCtrl.pro +++ b/UpdatePTUDevCtrl/UpdatePTUDevCtrl.pro @@ -294,7 +294,6 @@ SOURCES += \ process/show_software_status_command.cpp \ message_handler.cpp \ worker.cpp \ - commandline_parser.cpp \ work_process_list.cpp \ $${_PRO_FILE_PWD_}/../common/src/utils_internal.cpp \ $${_PRO_FILE_PWD_}/../common/src/commandline_parser.cpp \ @@ -324,7 +323,6 @@ HEADERS += \ process/show_software_status_command.h \ message_handler.h \ worker.h \ - commandline_parser.h \ work_process_list.h \ $${_PRO_FILE_PWD_}/../common/include/utils_internal.h \ $${_PRO_FILE_PWD_}/../common/include/commandline_parser.h \ diff --git a/UpdatePTUDevCtrl/commandline_parser.cpp b/UpdatePTUDevCtrl/commandline_parser.cpp deleted file mode 100644 index 2e797f5..0000000 --- a/UpdatePTUDevCtrl/commandline_parser.cpp +++ /dev/null @@ -1,360 +0,0 @@ -#include "commandline_parser.h" - -#include -#include -#include -#include - -CommandLineParser::CommandLineParser() - : m_repositoryUrl("https://git.mimbach49.de/GerhardHoffmann") - , m_plugInDir("/usr/lib/") - , m_plugInName("libCAslave.so") - , m_workingDir("/opt/app/tools/atbupdate/") - , m_dryRun("false") - , m_noUpdatePsaHardware("false") - , m_showYoctoVersion("false") - , m_showYoctoInstallStatus("false") - , m_showExtendedVersion("false") - , m_iniFileName("ATBUpdateTool.ini") - , m_alwaysDownloadConfig("false") - , m_alwaysDownloadDC("false") - , m_repositoryUrlOption( - QCommandLineOption( - QStringList() << "repository-url" << "repository-url", - QCoreApplication::translate("main", "Where to find a customer repository."), - QCoreApplication::translate("main", "directory"))) - , m_iniFileDirectoryOption( - QCommandLineOption( - QStringList() << "ini-directory" << "ini-directory", - QCoreApplication::translate("main", "Where to find an ini-file."), - QCoreApplication::translate("main", "directory"))) - , m_iniFileNameOption( - QCommandLineOption( - QStringList() << "ini-filename" << "ini-filename", - QCoreApplication::translate("main", "Name of ini-file."), - QCoreApplication::translate("main", "file"))) - , m_pluginDirectoryOption( - QCommandLineOption( - QStringList() << "plugin-directory" << "plugin-directory", - QCoreApplication::translate("main", "Where to find dc-plugin."), - QCoreApplication::translate("main", "directory"))) - , m_pluginNameOption( - QCommandLineOption( - QStringList() << "plugin-name" << "plugin-name", - QCoreApplication::translate("main", "Name of dc-plugin."), - QCoreApplication::translate("main", "directory"))) - , m_noDownloadOption( - QCommandLineOption( - "no-psa-hardware-update", - QCoreApplication::translate("main", "Do not update the PSA firmware (json, device-controller)."))) - , m_alwaysDownloadConfigOption( - QCommandLineOption( - "always-download-config", - QCoreApplication::translate("main", "Always download the (json-)configs to DC)."))) - , m_alwaysDownloadDCOption( - QCommandLineOption( - "always-download-dc", - QCoreApplication::translate("main", "Always download the dc-bin-file to DC)."))) - , m_workingDirectoryOption( - QCommandLineOption( - QStringList() << "working-directory" << "working-directory", - QCoreApplication::translate("main", "working directory of update-script."), - QCoreApplication::translate("main", "directory"))) - , m_psaConfigDirectoryOption( - QCommandLineOption( - QStringList() << "psa-config-directory" << "psa-config-directory", - QCoreApplication::translate("main", "config directory of json-files sent to dc."), - QCoreApplication::translate("main", "directory"))) - , m_psaTariffDirectoryOption( - QCommandLineOption( - QStringList() << "psa-tariff-directory" << "psa-tariff-directory", - QCoreApplication::translate("main", "tariff directory of tariff-json-files."), - QCoreApplication::translate("main", "directory"))) - , m_dryRunOption( - QCommandLineOption( - QStringList() << "d" << "dry-run", - QCoreApplication::translate("main", "Start ATBUpdateTool in dry-run-mode. No actual actions."))) - , m_extendedVersionOption( - QCommandLineOption( - QStringList() << "V" << "extended-version", - QCoreApplication::translate("main", "Show extended version (including last git commit)."))) - , m_yoctoVersionOption( - QCommandLineOption( - QStringList() << "y" << "yocto-version", - QCoreApplication::translate("main", "Show yocto version of ATBUpdateTool."))) - , m_yoctoInstallStatusOption( - QCommandLineOption( - QStringList() << "Y" << "yocto-install", - QCoreApplication::translate("main", "Show yocto install status of ATBUpdateTool."))) - , m_dcDirectoryOption( - QCommandLineOption( - QStringList() << "dc-directory" << "dc-directory", - QCoreApplication::translate("main", "device controller directory."), - QCoreApplication::translate("main", "directory"))) - , m_readDCVersionOption( - QCommandLineOption( - QStringList() << "D" << "read-dc-version", - 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(); -} - -void CommandLineParser::configure() { - m_parser.setApplicationDescription("Download tool for downloading device controller firmware, printer json-files and executing opkg-commands."); - m_parser.addHelpOption(); - m_parser.addVersionOption(); - - m_repositoryUrlOption.setDefaultValue("https://git.mimbach49.de/GerhardHoffmann"); - m_parser.addOption(m_repositoryUrlOption); - - m_iniFileDirectoryOption.setDefaultValue(QCoreApplication::applicationDirPath()); - m_parser.addOption(m_iniFileDirectoryOption); - - m_iniFileNameOption.setDefaultValue("ATBUpdateTool.ini"); - m_parser.addOption(m_iniFileNameOption); - - m_pluginDirectoryOption.setDefaultValue("/usr/lib/"); - m_parser.addOption(m_pluginDirectoryOption); - - m_pluginNameOption.setDefaultValue("libCAslave.so"); - m_parser.addOption(m_pluginNameOption); - - m_alwaysDownloadConfigOption.setDefaultValue("false"); - m_parser.addOption(m_alwaysDownloadConfigOption); - - m_alwaysDownloadDCOption.setDefaultValue("false"); - m_parser.addOption(m_alwaysDownloadDCOption); - - m_noDownloadOption.setDefaultValue("false"); - m_parser.addOption(m_noDownloadOption); - - m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate/"); - m_parser.addOption(m_workingDirectoryOption); - - m_psaConfigDirectoryOption.setDefaultValue("etc/psa_config/"); - m_parser.addOption(m_psaConfigDirectoryOption); - - m_psaTariffDirectoryOption.setDefaultValue("etc/psa_tariff/"); - m_parser.addOption(m_psaTariffDirectoryOption); - - m_dryRunOption.setDefaultValue("false"); - m_parser.addOption(m_dryRunOption); - - m_extendedVersionOption.setDefaultValue("false"); - m_parser.addOption(m_extendedVersionOption); - - m_yoctoVersionOption.setDefaultValue("false"); - m_parser.addOption(m_yoctoVersionOption); - - m_yoctoInstallStatusOption.setDefaultValue("false"); - m_parser.addOption(m_yoctoInstallStatusOption); - - m_dcDirectoryOption.setDefaultValue("etc/dc/"); - m_parser.addOption(m_dcDirectoryOption); - - m_readDCVersionOption.setDefaultValue("false"); - m_parser.addOption(m_readDCVersionOption); - - m_setPPid.setDefaultValue("-1"); - m_parser.addOption(m_setPPid); -} - -void CommandLineParser::readSettings() { - QString const iniFileDir = m_parser.value(m_iniFileDirectoryOption); - QString const iniFileName = m_parser.value(m_iniFileNameOption); - m_iniFileName = QDir::cleanPath(iniFileDir + QDir::separator() + iniFileName); - - //qCritical() << __PRETTY_FUNCTION__ << " iniFileDir" << iniFileDir; - //qCritical() << __PRETTY_FUNCTION__ << "iniFileName" << m_iniFileName; - - if (!m_iniFileName.isEmpty()) { - if (QFile(m_iniFileName).exists()) { - QSettings settings(m_iniFileName, QSettings::IniFormat); - QStringList keys = settings.allKeys(); - for (QString const &key: keys) { - QVariant v = settings.value(key); - - //qCritical() << "(" << __func__ << ":" << __LINE__ << ")" - // << key << " -> " << v.toString(); - - if (key.contains("repository-url")) { - m_repositoryUrl = v.toString(); - } else - if (key.contains("plugin-directory")) { - m_plugInDir = v.toString(); - } else - if (key.contains("working-directory")) { - m_workingDir = v.toString(); - } else - if (key.contains("psa-config-directory")) { - m_psaConfigDir = v.toString(); - } else - if (key.contains("psa-tariff-directory")) { - m_psaTariffDir = v.toString(); - } else - if (key.contains("dry-run")) { - m_dryRun = (v.toBool() ? "true" : "false"); - } else - if (key.contains("extended-version")) { - m_showExtendedVersion = (v.toBool() ? "true" : "false"); - } else - if (key.contains("no-psa-hardware-update")) { - m_noUpdatePsaHardware = (v.toBool() ? "true" : "false"); - } else - if (key.contains("always-download-config")) { - m_alwaysDownloadConfig = (v.toBool() ? "true" : "false"); - } else - if (key.contains("always-download-dc")) { - m_alwaysDownloadDC = (v.toBool() ? "true" : "false"); - } else - if (key.contains("yocto-install")) { - m_showYoctoInstallStatus = (v.toBool() ? "true" : "false"); - } else - if (key.contains("yocto-version")) { - m_showYoctoVersion = (v.toBool() ? "true" : "false"); - } else - if (key.contains("plugin-name")) { - m_plugInName = v.toString(); - } else - if (key.contains("dc-directory")) { - m_dcDir = v.toString(); - } else - if (key.contains("read-dc-version")) { - m_readDCVersion = (v.toBool() ? "true" : "false"); - } else { - qCritical() << __PRETTY_FUNCTION__ - << key << " -> (UNKNOWN) " << v.toString(); - } - } - } else { - qCritical() << __PRETTY_FUNCTION__ << "iniFileName" << m_iniFileName - << "DOES NOT EXIST"; - } - } -} - -QString CommandLineParser::repositoryUrl() { - if (m_parser.isSet(m_repositoryUrlOption)) { - m_repositoryUrl = m_parser.value(m_repositoryUrlOption); - } - return m_repositoryUrl; -} - -QString CommandLineParser::plugInDir() { - if (m_parser.isSet(m_pluginDirectoryOption)) { - m_plugInDir = m_parser.value(m_pluginDirectoryOption); - } - return m_plugInDir; -} - -QString CommandLineParser::plugInName() { - if (m_parser.isSet(m_pluginNameOption)) { - m_plugInName = m_parser.value(m_pluginNameOption); - } - return m_plugInName; -} - -QString CommandLineParser::psaConfigDir() { - if (m_parser.isSet(m_psaConfigDirectoryOption)) { - m_psaConfigDir = m_parser.value(m_psaConfigDirectoryOption); - } - return m_psaConfigDir; -} - -QString CommandLineParser::psaTariffDir() { - if (m_parser.isSet(m_psaTariffDirectoryOption)) { - m_psaTariffDir = m_parser.value(m_psaTariffDirectoryOption); - } - return m_psaTariffDir; -} - -QString CommandLineParser::dcDir() { - if (m_parser.isSet(m_dcDirectoryOption)) { - m_dcDir = m_parser.value(m_dcDirectoryOption); - } - return m_dcDir; -} - -bool CommandLineParser::readDCVersion() { - if (m_parser.isSet(m_readDCVersionOption)) { - m_readDCVersion = m_parser.value(m_readDCVersionOption); - } - return m_readDCVersion == "false" ? false : true; -} - -QString CommandLineParser::workingDir() { - if (m_parser.isSet(m_workingDirectoryOption)) { - m_workingDir = m_parser.value(m_workingDirectoryOption); - } - 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); - } - return m_dryRun == "false" ? false : true; -} - -bool CommandLineParser::noUpdatePsaHardware() { - if (m_parser.isSet(m_noDownloadOption)) { - m_noUpdatePsaHardware = m_parser.value(m_noDownloadOption); - } - return m_noUpdatePsaHardware == "false" ? false : true; -} - -bool CommandLineParser::yoctoVersion() { - if (m_parser.isSet(m_yoctoVersionOption)) { - m_showYoctoVersion = m_parser.value(m_yoctoVersionOption); - } - return m_showYoctoVersion == "false" ? false : true; -} - -bool CommandLineParser::yoctoInstallStatus() { - if (m_parser.isSet(m_yoctoInstallStatusOption)) { - m_showYoctoInstallStatus = m_parser.value(m_yoctoInstallStatusOption); - } - return m_showYoctoInstallStatus == "false" ? false : true; -} - -bool CommandLineParser::extendedVersion() { - if (m_parser.isSet(m_extendedVersionOption)) { - m_showExtendedVersion = m_parser.value(m_extendedVersionOption); - } - return m_showExtendedVersion == "false" ? false : true; -} - -bool CommandLineParser::alwaysDownloadConfig() { - if (m_parser.isSet(m_alwaysDownloadConfigOption)) { - m_alwaysDownloadConfig = m_parser.value(m_alwaysDownloadConfigOption); - // qCritical() << "m_alwaysDownloadConfigOption IS SET" << m_alwaysDownloadConfig; - } - // qCritical() << "m_alwaysDownloadConfig" << m_alwaysDownloadConfig; - return m_alwaysDownloadConfig == "false" ? false : true; -} - -bool CommandLineParser::alwaysDownloadDC() { - if (m_parser.isSet(m_alwaysDownloadDCOption)) { - m_alwaysDownloadDC = m_parser.value(m_alwaysDownloadDCOption); - } - return m_alwaysDownloadDC == "false" ? false : true; -} diff --git a/UpdatePTUDevCtrl/commandline_parser.h b/UpdatePTUDevCtrl/commandline_parser.h deleted file mode 100644 index e1996d8..0000000 --- a/UpdatePTUDevCtrl/commandline_parser.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef COMMAND_LINE_PARSER_H_INCLUDED -#define COMMAND_LINE_PARSER_H_INCLUDED - -#include -#include -#include -#include - -class CommandLineParser : public QCommandLineParser { - QString m_repositoryUrl; - QString m_plugInDir; - QString m_plugInName; - QString m_workingDir; - QString m_psaConfigDir{"etc/psa_config"}; - QString m_psaTariffDir{"etc/psa_tariff"}; - QString m_dryRun; - QString m_noUpdatePsaHardware; - QString m_showYoctoVersion; - QString m_showYoctoInstallStatus; - QString m_showExtendedVersion; - QString m_iniFileName; - QString m_alwaysDownloadConfig; - QString m_alwaysDownloadDC; - QString m_readDCVersion{"false"}; - QString m_dcDir{"etc/dc/"}; - qint64 m_ppid; - - QCommandLineOption m_repositoryUrlOption; - QCommandLineOption m_iniFileDirectoryOption; - QCommandLineOption m_iniFileNameOption; - QCommandLineOption m_pluginDirectoryOption; - QCommandLineOption m_pluginNameOption; - QCommandLineOption m_noDownloadOption; - QCommandLineOption m_alwaysDownloadConfigOption; - QCommandLineOption m_alwaysDownloadDCOption; - QCommandLineOption m_workingDirectoryOption; - QCommandLineOption m_psaConfigDirectoryOption; - QCommandLineOption m_psaTariffDirectoryOption; - QCommandLineOption m_dryRunOption; - QCommandLineOption m_extendedVersionOption; - QCommandLineOption m_yoctoVersionOption; - QCommandLineOption m_yoctoInstallStatusOption; - QCommandLineOption m_dcDirectoryOption; - QCommandLineOption m_readDCVersionOption; - QCommandLineOption m_setPPid; - - QCommandLineParser m_parser; - - void configure(); - -public: - - explicit CommandLineParser(); - ~CommandLineParser() = default; - - QCommandLineParser &parser() { return m_parser; } - QCommandLineParser const &parser() const { return m_parser; } - void process(const QCoreApplication &app) { m_parser.process(app); } - QString const &iniFileName() const { return m_iniFileName; } - void readSettings(); - QString repositoryUrl(); - QString plugInDir(); - QString plugInName(); - QString workingDir(); - QString psaConfigDir(); - QString psaTariffDir(); - bool dryRun(); - qint64 ppid(); - bool noUpdatePsaHardware(); - bool yoctoVersion(); - bool yoctoInstallStatus(); - bool extendedVersion(); - bool alwaysDownloadConfig(); - bool alwaysDownloadDC(); - bool readDCVersion(); - QString dcDir(); -}; -#endif // COMMAND_LINE_PARSER_H_INCLUDED diff --git a/UpdatePTUDevCtrl/ismas/ismas_client.cpp.master b/UpdatePTUDevCtrl/ismas/ismas_client.cpp.master new file mode 100644 index 0000000..44c12fc --- /dev/null +++ b/UpdatePTUDevCtrl/ismas/ismas_client.cpp.master @@ -0,0 +1,1107 @@ +#include "ismas/ismas_client.h" +#include "utils.h" + +#include +#include + +#include +#include // inet_addr() +#include +#include +#include +#include +#include +#include +#include // bzero() +#include +#include // read(), write(), close() +#include + + +#include +#include +#include +#include + +#if 0 +######################## +# Spec vom 27.10.2023: +# U0010 -> %-Werte +# U0001 -> 100% +# U0003 -> "FAIL" +# U0002 -> "" (OK -> WAIT state reset) +# ISMAS -> "WAIT" +######################## +# +# $1: EVENT: U0001 update finished: 100% +# U0002 reset TRG +# U0003 error +# U0010 for update process +# $2: PERCENT : "only for ISMAS: 0-100%", +# $3: RESULTCODE : "only for ISMAS", +# 0: Success +# 1: no Update nessesary +# 2: Backup failed +# 3: Package error/ Wrong package +# 4: Install Error +# $4: STEP : "running step (only for us): update_psa...", +# $5: STEP_RESULT : "error and result text", +# $6: VERSION : "opkg and conf info; what will be updated" +# +#endif + +#include +#include + +void IsmasClient::printDebugMessage(int port, + QString const &clientIP, + int clientPort, + QString const &message) { +#if 0 + Q_UNUSED(port); + Q_UNUSED(clientIP); + Q_UNUSED(clientPort); + Q_UNUSED(message); +#else + qDebug().noquote() + << "\n" + << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" + << "hostname ........" << "127.0.0.1" << "\n" + << "port ............" << port << "\n" + << "local address ..." << clientIP << "\n" + << "local port ......" << clientPort << "\n" + << message; +#endif +} + +void IsmasClient::printInfoMessage(int port, + QString const &clientIP, + int clientPort, + QString const &message) { +#if 0 + Q_UNUSED(port); + Q_UNUSED(clientIP); + Q_UNUSED(clientPort); + Q_UNUSED(message); +#else + qInfo().noquote() + << "\n" + << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" + << "hostname ........" << "127.0.0.1" << "\n" + << "port ............" << port << "\n" + << "local address ..." << clientIP << "\n" + << "local port ......" << clientPort << "\n" + << message; +#endif +} + +void IsmasClient::printErrorMessage(int port, + QString const &clientIP, + int clientPort, + QString const &message) { + qCritical().noquote() + << "\n" + << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" + << "hostname ........" << "127.0.0.1" << "\n" + << "port ............" << port << "\n" + << "local address ..." << clientIP << "\n" + << "local port ......" << clientPort << "\n" + << message; +} + +std::optional +IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { + + qInfo() << "REQUEST" << request; + + int sockfd; + int r; + errno = 0; + // socket create and verification + if ((sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) { + qCritical().noquote() + << "\n" + << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" + << "SOCKET CREATION FAILED (" << strerror(errno) << ")"; + return std::nullopt; + } + + struct sockaddr_in servAddr; + bzero(&servAddr, sizeof(servAddr)); + // assign IP, PORT + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); + + servAddr.sin_port = htons(port); + // connect the client socket to server socket + if ((r = ::connect(sockfd, (struct sockaddr *)(&servAddr), sizeof(servAddr))) != 0) { + qCritical().noquote() + << "\n" + << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" + << "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")"; + ::close(sockfd); + return std::nullopt; + } + + struct sockaddr_in clientAddr; + bzero(&clientAddr, sizeof(clientAddr)); + socklen_t sockLen = sizeof(clientAddr); + + char clientIP[16]; + bzero(&clientIP, sizeof(clientIP)); + getsockname(sockfd, (struct sockaddr *)(&clientAddr), &sockLen); + inet_ntop(AF_INET, &clientAddr.sin_addr, clientIP, sizeof(clientIP)); + unsigned int clientPort = ntohs(clientAddr.sin_port); + + printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER")); + + struct timeval tv; + tv.tv_sec = 10; /* 10 secs timeout for read and write */ + + struct linger so_linger; + so_linger.l_onoff = 1; + so_linger.l_linger = 0; + + int maxfdp1; + fd_set rset; + fd_set wset; + + setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(so_linger)); + // no reliable, but does not harm, as we use select() as well + setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + int flag = 1; + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); + + static char buf[1024*8]; + bzero(buf, sizeof(buf)); + int const bytesToWrite = strlen(request.toStdString().c_str()); + strncpy(buf, request.toStdString().c_str(), sizeof(buf)-1); + + int loop = 0; + int bytesWritten = 0; + while (bytesWritten < bytesToWrite) { + errno = 0; + FD_ZERO(&wset); + FD_SET(sockfd, &wset); + maxfdp1 = sockfd + 1; + tv.tv_sec = 60; /* 60 secs timeout for read and write -> APISM cuts the connection after 30s */ + tv.tv_usec = 0; + + int const w = select(maxfdp1, NULL, &wset, NULL, &tv); + if (w < 0) { // error + if (errno == EINTR) { + printErrorMessage(port, clientIP, clientPort, + QString("INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")"); + continue; + } else { + printErrorMessage(port, clientIP, clientPort, + QString("SELECT-ERROR (WRITE) %1(").arg(loop) + strerror(errno) + ")"); + ::close(sockfd); + return std::nullopt; + } + } else + if (w == 0) { // timeout + printErrorMessage(port, clientIP, clientPort, + QString("SELECT-TIMEOUT (WRITE) %1(").arg(loop) + strerror(errno) + ")"); + if (++loop < 10) { + QThread::msleep(500); + continue; + } + ::close(sockfd); + return std::nullopt; + } else + if (w > 0) { + int n = ::sendto(sockfd, buf+bytesWritten, bytesToWrite-bytesWritten, 0, NULL, 0); + if (n >= 0) { + bytesWritten += n; + } else { + if (errno == EWOULDBLOCK) { + if (++loop < 10) { + QThread::msleep(500); + continue; + } + printErrorMessage(port, clientIP, clientPort, + QString("WRITE TIMEOUT %1(").arg(loop) + strerror(errno) + ")"); + ::close(sockfd); + return std::nullopt; + } else + if (errno == EINTR) { + printErrorMessage(port, clientIP, clientPort, + QString("WRITE INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")"); + continue; + } + } + } + } + + // DO NOT USE SHUTDOWN! APISM CAN NOT COPE WITH IT + // errno = 0; + // if (shutdown(sockfd, SHUT_WR) < 0) { + // printErrorMessage(port, clientIP, clientPort, + // QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")"); + // } + + printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>"); + + loop = 0; + bzero(buf, sizeof(buf)); + int bytesToRead = sizeof(buf)-1; + int bytesRead = 0; + while (bytesRead < bytesToRead) { + errno = 0; + FD_ZERO(&rset); + FD_SET(sockfd, &rset); + maxfdp1 = sockfd + 1; + tv.tv_sec = 60; /* 60 secs timeout for read and write */ + tv.tv_usec = 0; + + QString const selectStart = QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + + int const r = select(maxfdp1, &rset, NULL, NULL, &tv); + if (r < 0) { // error + if (errno == EINTR) { + printErrorMessage(port, clientIP, clientPort, + QString("INTERRUPTED BY SIGNAL (2) (") + strerror(errno) + ")"); + continue; + } else { + printErrorMessage(port, clientIP, clientPort, + QString("SELECT-ERROR (READ) %1(").arg(loop) + strerror(errno) + ")"); + ::close(sockfd); + return std::nullopt; + } + } else + if (r == 0) { // timeout + printErrorMessage(port, clientIP, clientPort, + QString("SELECT-TIMEOUT (READ) %1(").arg(loop) + strerror(errno) + ")"); + if (++loop < 10) { + QThread::msleep(500); + continue; + } + ::close(sockfd); + return std::nullopt; + } else + if (r > 0) { + if (FD_ISSET(sockfd, &rset)) { + int n = ::recvfrom(sockfd, buf+bytesRead, bytesToRead-bytesRead, + 0, NULL, NULL); + if (n > 0) { // + bytesRead += n; + } else + if (n == 0) { + // The return value will be 0 when the peer has performed an orderly shutdown. + printErrorMessage(port, clientIP, clientPort, + QString("PEER CLOSED CONNECTION (") + strerror(errno) + ") START AT" + + selectStart + " NOW " + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); + ::close(sockfd); + return std::nullopt; + } else + if (n < 0) { + if (errno == EWOULDBLOCK) { // check just in case + if (++loop < 10) { + QThread::msleep(500); + continue; + } + printErrorMessage(port, clientIP, clientPort, + QString("READ TIMEOUT %1(").arg(loop) + strerror(errno) + ")"); + ::close(sockfd); + return std::nullopt; + } + if (errno == EINTR) { + printErrorMessage(port, clientIP, clientPort, + QString("INTERRUPTED BY SIGNAL (2) (") + strerror(errno) + ")"); + continue; + } + } + } + } + + // printInfoMessage(port, clientIP, clientPort, QString("MESSAGE RECEIVED ") + buf); + QString response(buf); + + if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) { + response = response.mid(0, idx); + } else + if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED + printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE"); + ::close(sockfd); + return std::nullopt; + } + + QJsonParseError parseError; + QJsonDocument document(QJsonDocument::fromJson(response.toUtf8(), &parseError)); + if (parseError.error == QJsonParseError::NoError) { + if (document.isObject()) { // done: received valid APISM response + printInfoMessage(port, clientIP, clientPort, + QString("VALID APISM RESPONSE .. \n") + response); + ::close(sockfd); + return response; + } else { + printInfoMessage(port, clientIP, clientPort, + QString("CORRUPTED RESPONSE ") + response); + ::close(sockfd); + return std::nullopt; + } + } else { + if (!response.contains("RECORD")) { + // maybe APISM does not send valid JSON: "RECORD SAVED" etc. + printDebugMessage(port, clientIP, clientPort, + QString("PARSE ERROR ") + response + " " + parseError.errorString()); + } + ::close(sockfd); + return std::nullopt; + } + } + return std::nullopt; +} + +QString IsmasClient::updateNewsToIsmas(char const *event, + int percent, + int resultCode, + char const *step, + char const *step_result, + char const *version) { + char buf[1024]; + memset(buf, 0, sizeof(buf)); + + QDateTime const local(QDateTime::currentDateTime()); + + QDateTime utc(local); + utc.setTimeSpec(Qt::UTC); + + int const diff = (int)local.secsTo(utc); // diff between UTC and local time + + QTime t(0, 0, 0); + t = t.addSecs((uint)diff); + + QString const st(QString("%1%2").arg(diff < 0 ? "-" : "+").arg(t.toString("hh:mm"))); + QString const ts(local.toString(Qt::ISODateWithMs) + st); + + snprintf(buf, sizeof(buf)-1, + "{" + "\"REASON\":\"SW_UP\"," + "\"TIMESTAMP\":\"%s\"," + "\"EVENT_ID\":\"%d\"," + "\"EVENT\":\"%s\"," + "\"EVENTSTATE\":1," + "\"PARAMETER\": {" + "\"PERCENT\" : %d," + "\"RESULTCODE\" : %d," + "\"STEP\" : \"%s\"," + "\"STEP_RESULT\" : \"%s\"," + "\"VERSION\" : \"%s\"" + "}" + "}", ts.toStdString().c_str(), static_cast(QCoreApplication::applicationPid()), event, percent, resultCode, + step, step_result, version); + return buf; +} + +QString IsmasClient::errorBackendNotConnected(QString const &info, + QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + RESULT_CODE::ISMAS_NO_CONNECTION_ERROR, + "CHECK BACKEND CONNECTIVITY", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::errorGitClone(QString const &info, + QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + RESULT_CODE::GIT_CLONE_ERROR, + "CLONE CUSTOMER REPOSITORY FAILED", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::backendConnected(QString const &info, + QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "CHECK BACKEND CONNECTIVITY", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::execOpkgCommand(QString const &info, + QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "EXECUTE OPKG COMMAND", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::rsyncFile(QString const &info, QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "RSYNC FILE", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::updateTriggerSet(QString const &info, QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "CHECK UPDATE TRIGGER", + info.toStdString().c_str(), + version.toStdString().c_str()); + +} + +QString IsmasClient::errorUpdateTrigger(QString const &info, QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + RESULT_CODE::ISMAS_TRIGGER_ERROR, + "CHECK UPDATE TRIGGER", + info.toStdString().c_str(), + version.toStdString().c_str()); + +} + +QString IsmasClient::updateOfPSASendVersion(PSAInstalled const &psa) { + //static int const constexpr SIZE = 4096*8; + static char buf[4096*2]; + memset(buf, 0, sizeof(buf)); + + // local data="#M=APISM#C=CMD_SENDVERSION#J= + snprintf(buf, sizeof(buf)-1, + "{" + "\"VERSION_INFO\" : {" + "\"REASON\":\"%s\"," + "\"CREATED\":\"%s\"," + "\"HASH\":\"%s\"" + "}," + "\"TARIFF\" : {" + "\"VERSION\" : \"%s\"," + "\"PROJECT\" : \"%s\"," + "\"ZONE\" : %d," + "\"INFO\" : \"%s\"," + "\"BLOB\" : \"%s\"," + "\"LAST-COMMIT\" : \"%s\"," + "\"SIZE\" : %d," + "\"LOADED\" : \"%s\"" + "}," + "\"OPKG_COMMANDS\" : {" + "\"BLOB\" : \"%s\"," + "\"LAST-COMMIT\" : \"%s\"," + "\"SIZE\" : %d," + "\"LOADED\" : \"%s\"" + "}," + "\"JSON\" : {" + "\"DC2C_CASH\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_CONF\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_DEVICE\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_01\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_02\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_03\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_04\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_05\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_06\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_07\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_08\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_09\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_10\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_11\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_12\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_13\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_14\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_15\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_16\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_17\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_18\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_19\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_20\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_21\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_22\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_23\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_24\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_25\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_26\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_27\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_28\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_29\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_30\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_31\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}," + "\"DC2C_PRINT_32\" : {" + "\"BLOB\" : \"%s\"," + "\"SIZE\" : %d" + "}" + "}," + "\"HARDWARE\" : {" + "\"DEVICES\" : [\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"]" + "}," + "\"OS\" : {" + "\"Linux\": \"%s\"" + "}," + "\"CONFIG\" : {" + "\"PTU5\" : {" + "\"CPU_SERIAL\" : \"%s\"" + "}," + "\"DC\" : {" + "\"HW-VERSION\" : \"%s\"," + "\"SW-VERSION\" : \"%s\"," + "\"SIZE\" : %d," + "\"GITBLOB\" : \"%s\"," + "\"GITLASTCOMMIT\" : \"%s\"" + "}," + "\"PRINTER\" : {" + "}," + "\"BNA\" : {" + "}" + "}," + "\"SOFTWARE\": {" + "\"APISM\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"ATBQT\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"ATB-UPDATE-TOOL\" : {" + "\"VERSION\" : \"%s\"" + "}" + "}," + "\"PLUGINS\" : {" + "\"libATBDeviceControllerPlugin.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libIngenicoISelf_CCPlugin.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libMOBILISIS_CalculatePricePlugin.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libMOBILISIS_CalculatePricePlugin_ConfigUi.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libPRM_CalculatePricePlugin.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libPRM_CalculatePricePlugin_ConfigUi.so\" : {" + "\"VERSION\" : \"%s\"" + "}," + "\"libTCP_ZVT_CCPlugin.so\" : {" + "\"VERSION\" : \"%s\"" + "}" + "}," + "\"PTU-PACKAGE-VERSIONS\" : %s" + "}", + psa.versionInfo.reason.toStdString().c_str(), + psa.versionInfo.created.toStdString().c_str(), + psa.versionInfo.lastCommit.toStdString().c_str(), + + psa.tariff.version.toStdString().c_str(), + psa.tariff.project.toStdString().c_str(), + psa.tariff.zone, + psa.tariff.info.toStdString().c_str(), + psa.tariff.blob.toStdString().c_str(), + psa.tariff.lastCommit.toStdString().c_str(), + psa.tariff.size, + psa.tariff.loadTime.toStdString().c_str(), + + psa.opkg.blob.toStdString().c_str(), + psa.opkg.lastCommit.toStdString().c_str(), + psa.opkg.size, + psa.opkg.loadTime.toStdString().c_str(), + + psa.cash.blob.toStdString().c_str(), + psa.cash.size, + psa.conf.blob.toStdString().c_str(), + psa.conf.size, + psa.device.blob.toStdString().c_str(), + psa.device.size, + + psa.print[0].blob.toStdString().c_str(), + psa.print[0].size, + psa.print[1].blob.toStdString().c_str(), + psa.print[1].size, + psa.print[2].blob.toStdString().c_str(), + psa.print[2].size, + psa.print[3].blob.toStdString().c_str(), + psa.print[3].size, + psa.print[4].blob.toStdString().c_str(), + psa.print[4].size, + psa.print[5].blob.toStdString().c_str(), + psa.print[5].size, + psa.print[6].blob.toStdString().c_str(), + psa.print[6].size, + psa.print[7].blob.toStdString().c_str(), + psa.print[7].size, + psa.print[8].blob.toStdString().c_str(), + psa.print[8].size, + psa.print[9].blob.toStdString().c_str(), + psa.print[9].size, + psa.print[10].blob.toStdString().c_str(), + psa.print[10].size, + psa.print[11].blob.toStdString().c_str(), + psa.print[11].size, + psa.print[12].blob.toStdString().c_str(), + psa.print[12].size, + psa.print[13].blob.toStdString().c_str(), + psa.print[13].size, + psa.print[14].blob.toStdString().c_str(), + psa.print[14].size, + psa.print[15].blob.toStdString().c_str(), + psa.print[15].size, + psa.print[16].blob.toStdString().c_str(), + psa.print[16].size, + psa.print[17].blob.toStdString().c_str(), + psa.print[17].size, + psa.print[18].blob.toStdString().c_str(), + psa.print[18].size, + psa.print[19].blob.toStdString().c_str(), + psa.print[19].size, + psa.print[20].blob.toStdString().c_str(), + psa.print[20].size, + psa.print[21].blob.toStdString().c_str(), + psa.print[21].size, + psa.print[22].blob.toStdString().c_str(), + psa.print[22].size, + psa.print[23].blob.toStdString().c_str(), + psa.print[23].size, + psa.print[24].blob.toStdString().c_str(), + psa.print[24].size, + psa.print[25].blob.toStdString().c_str(), + psa.print[25].size, + psa.print[26].blob.toStdString().c_str(), + psa.print[26].size, + psa.print[27].blob.toStdString().c_str(), + psa.print[27].size, + psa.print[28].blob.toStdString().c_str(), + psa.print[28].size, + psa.print[29].blob.toStdString().c_str(), + psa.print[29].size, + psa.print[30].blob.toStdString().c_str(), + psa.print[30].size, + psa.print[31].blob.toStdString().c_str(), + psa.print[31].size, + + psa.hw.linuxVersion.toStdString().c_str(), + psa.hw.cpuSerial.toStdString().c_str(), + + psa.dc.versionHW.toStdString().c_str(), + psa.dc.versionSW.toStdString().c_str(), + psa.dc.size, + psa.dc.gitBlob.toStdString().c_str(), + psa.dc.gitLastCommit.toStdString().c_str(), + + psa.sw.apismVersion.toStdString().c_str(), + psa.sw.atbQTVersion.toStdString().c_str(), + psa.sw.atbUpdateToolVersion.toStdString().c_str(), + + psa.pluginVersion.deviceController.toStdString().c_str(), + psa.pluginVersion.ingenicoISelfCC.toStdString().c_str(), + psa.pluginVersion.mobilisisCalculatePrice.toStdString().c_str(), + psa.pluginVersion.mobilisisCalculatePriceConfigUi.toStdString().c_str(), + psa.pluginVersion.prmCalculatePrice.toStdString().c_str(), + psa.pluginVersion.prmCalculatePriceConfigUi.toStdString().c_str(), + psa.pluginVersion.tcpZVT.toStdString().c_str(), + + psa.ptuPackageVersion.toStdString().c_str()); + + qInfo() << buf; + + return buf; +} + +#if 0 +// prepare +QString IsmasClient::sendLastVersion(UPDATE_COMPONENT updateComponent, + PSAInstalled const &psa) { + static char buf[4096*2]; + memset(buf, 0, sizeof(buf)); + + switch (updateComponent) { + case UPDATE_COMPONENT::TARIFF: + snprintf(buf, sizeof(buf)-1, + "{" + "\"VERSION_INFO\" : {" + "\"UPDATE_REASON\":\"%s\"," + "\"CREATED\":\"%s\"," + "\"GIT_COMMIT\":\"%s\"" + "}," + "\"TARIFF\" : {" + "\"VERSION\" : \"%s\"," + "\"PROJECT\" : \"%s\"," + "\"ZONE\" : %d," + "\"INFO\" : \"%s\"," + "\"SIZE\" : %d\"" + "}," + "}", + psa.tariff.versionInfo.reason.toStdString().c_str(), + psa.tariff.versionInfo.created.toStdString().c_str(), + psa.tariff.versionInfo.lastCommit.toStdString().c_str(), + + psa.tariff.version.toStdString().c_str(), + psa.tariff.project.toStdString().c_str(), + psa.tariff.zone, + psa.tariff.info.toStdString().c_str(), + psa.tariff.size); + break; + case UPDATE_COMPONENT::SOFTWARE_ATBQT: + break; + case UPDATE_COMPONENT::SOFTWARE_APISM: + break; + case UPDATE_COMPONENT::SOFTWARE_ATB_UPDATE_TOOL: + break; + case UPDATE_COMPONENT::CONFIG_PTU5_CPU_SERIAL: + break; + case UPDATE_COMPONENT::CONFIG_DEVICE_CONTROLLER: + break; + case UPDATE_COMPONENT::CONFIG_PRINTER: + break; + case UPDATE_COMPONENT::CONFIG_BNA: + break; + case UPDATE_COMPONENT::PLUGIN_ATB_DEVICE_CONTROLLER: + break; + case UPDATE_COMPONENT::PLUGIN_INGENICO_CC: + break; + case UPDATE_COMPONENT::PLUGIN_MOBILISIS_CALC_PRICE: + break; + case UPDATE_COMPONENT::PLUGIN_MOBILISIS_CALC_PRICE_UI: + break; + case UPDATE_COMPONENT::PLUGIN_PRM_CALC_PRICE: + break; + case UPDATE_COMPONENT::PLUGIN_PRM_CALC_PRICE_UI: + break; + case UPDATE_COMPONENT::PLUGIN_TCP_ZVT_CC: + break; + case UPDATE_COMPONENT::OPKG_COMMANDS: + break; + case UPDATE_COMPONENT::HARDWARE_DEVICES: + break; + case UPDATE_COMPONENT::OS: + break; + case UPDATE_COMPONENT::DC2C_CASH_JSON: + break; + case UPDATE_COMPONENT::DC2C_CONF_JSON: + break; + case UPDATE_COMPONENT::DC2C_DEVICE_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT01_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT02_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT03_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT04_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT05_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT06_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT07_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT08_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT09_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT10_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT11_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT12_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT13_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT14_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT15_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT16_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT17_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT18_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT19_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT20_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT21_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT22_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT23_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT24_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT25_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT26_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT27_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT28_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT29_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT30_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT31_JSON: + break; + case UPDATE_COMPONENT::DC2C_PRINT32_JSON: + break; + } + + qInfo() << buf; + + return buf; +} +#endif + +QString IsmasClient::updateOfPSAContinues(QString currentStage, + QString currentStageInfo, + QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + currentStage.toStdString().c_str(), + currentStageInfo.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::updateOfPSAStarted(QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "START", + "detected WAIT state: start update process", + version.toStdString().c_str()); +} + +QString IsmasClient::checkoutBranch(QString const &info, QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "BRANCH-CHECKOUT", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::cloneAndCheckoutCustomerRepository(QString const &info, QString const &version) { // clone and checkout customer repository + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "CLONE-CHECKOUT", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::gitFetch(QString const &info, QString const &version) { + return updateNewsToIsmas("U0010", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "GIT-FETCH", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::errorGitFetch(int resultCode, QString const &info, QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + resultCode, + "GIT-FETCH-FAILED", + info.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::updateOfPSAActivated(QString const &version) { // sent even after success + m_progressInPercent = 0; + return updateNewsToIsmas("U0002", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "UPDATE ACTIVATED", + "reset WAIT state", + version.toStdString().c_str()); +} + +QString IsmasClient::updateOfPSASucceeded(QString const &version) { + m_progressInPercent = 100; + return updateNewsToIsmas("U0001", + m_progressInPercent, + RESULT_CODE::SUCCESS, + "UPDATE SUCCESS", + "update process succeeded", + version.toStdString().c_str()); +} + +QString IsmasClient::sanityCheckFailed(int resultCode, QString reason, QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + resultCode, + "SANITY-CHECK-FAILED", + reason.toStdString().c_str(), + version.toStdString().c_str()); +} + +QString IsmasClient::jsonParseFailed(int resultCode, QString reason, QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + resultCode, + "JSON-PARSE-ERROR", + reason.toStdString().c_str(), + version.toStdString().c_str()); +} + +std::optional IsmasClient::finalResult(int resultCode, + QString reason, + QString const &version) { + Q_UNUSED(resultCode); + Q_UNUSED(reason); + Q_UNUSED(version); + + /* + m_progressInPercent = 100; + if (resultCode == RESULT_CODE::SUCCESS) { + return updateNewsToIsmas("U0002", + m_progressInPercent, + resultCode, + "FINAL-UPDATE-RESULT", + reason.toStdString().c_str(), + version.toStdString().c_str()); + } + if (resultCode == RESULT_CODE::INSTALL_ERROR) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + resultCode, + "FINAL-UPDATE-RESULT", + reason.toStdString().c_str(), + version.toStdString().c_str()); + } + */ + return std::nullopt; +} + +QString IsmasClient::updateOfPSAFailed(int resultCode, QString step, + QString reason, QString const &version) { + return updateNewsToIsmas("U0003", + m_progressInPercent, + resultCode, + step.toStdString().c_str(), + reason.toStdString().c_str(), + version.toStdString().c_str()); +} + +char const *IsmasClient::reason[REASON::ENTRIES] = { + "TIME-TRIGGERED", "SERVICE", "DEV-TEST" +}; + +QString IsmasClient::getReasonForLastSendVersion() { + QString const &parentName = Utils::getParentName(); + if (parentName == "ATBQT") { + return reason[REASON::SERVICE]; + } + if (parentName == "systemd") { + return reason[REASON::TIME_TRIGGERED]; + } + return reason[REASON::DEV_TEST]; +}