UpdatePTUDevCtrl/worker.cpp

933 lines
40 KiB
C++
Raw Normal View History

2023-06-16 16:47:13 +02:00
#include "worker.h"
#include "update.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
2023-06-16 16:47:13 +02:00
#include <QThread>
#include <QRegularExpression>
#include <QDateTime>
#include <QString>
#include <QMessageBox>
#include <QPushButton>
#include <QJsonParseError>
#include <thread>
2023-06-16 16:47:13 +02:00
#include "message_handler.h"
#include "plugins/interfaces.h"
#include "ismas/ismas_client.h"
QString const Worker::UPDATE_STEP_OK(" [ ok]");
QString const Worker::UPDATE_STEP_DONE(" [done]");
QString const Worker::UPDATE_STEP_FAIL(" [fail]");
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
Worker::Worker(hwinf *hw,
int customerNr,
int machineNr,
int zoneNr,
QString branchName,
QString workingDirectory,
bool dryRun,
QObject *parent,
char const *serialInterface,
char const *baudrate)
: m_hw(hw)
, m_workerThread("workerThread")
, m_customerNr(customerNr)
, m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0'))
, m_machineNr(machineNr)
, m_zoneNr(zoneNr)
, m_workingDirectory(workingDirectory)
, m_branchName(branchName)
, m_customerRepositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(m_customerNrStr))
, m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr))
, m_update(new Update(m_hw, this, m_customerRepository, m_customerNrStr, m_branchName,
m_workingDirectory, dryRun, parent, serialInterface, baudrate))
, m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this)
, m_osVersion(getOsVersion())
, m_atbqtVersion(getATBQTVersion())
, m_cpuSerial(getCPUSerial())
, m_raucVersion(getRaucVersion())
, m_opkgVersion(getOpkgVersion())
, m_pluginVersionATBDeciceController(getPluginVersion("/opt/app/ATBAPP/plugins/libATBDeviceControllerPlugin.so"))
, m_pluginVersionIngenicoISelf(getPluginVersion("/opt/app/ATBAPP/plugins/libIngenicoISelf_CCPlugin.so"))
, m_pluginVersionMobilisisCalc(getPluginVersion("/opt/app/ATBAPP/plugins/libMOBILISIS_CalculatePricePlugin.so"))
, m_pluginVersionMobilisisCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libMOBILISIS_CalculatePricePlugin_ConfigUi.so"))
, m_pluginVersionPrmCalc(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin.so"))
, m_pluginVersionPrmCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin_ConfigUi.so"))
, m_pluginVersionTcpZvt(getPluginVersion("/opt/app/ATBAPP/plugins/libTCP_ZVT_CCPlugin.so"))
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
, m_waitForNewUpdates(this)
, m_filesToUpdate()
, m_updateProcessRunning(false) {
QDir::setCurrent(m_workingDirectory);
qInfo() << "CURRENT TIME ..............." << QDateTime::currentDateTime().toString(Qt::ISODate);
qInfo() << "OS VERSION ................." << m_osVersion;
qInfo() << "ATBQT VERSION .............." << m_atbqtVersion;
qInfo() << "CPU SERIAL ................." << m_cpuSerial;
qInfo() << "CUSTOMER_NR ................" << m_customerNr;
qInfo() << "CUSTOMER_NR_STR ............" << m_customerNrStr;
qInfo() << "CUSTOMER_REPOSITORY_PATH ..." << m_customerRepositoryPath;
qInfo() << "CUSTOMER_REPOSITORY ........" << m_customerRepository;
qInfo() << "MACHINE_NR ................." << m_machineNr;
qInfo() << "ZONE_NR ...................." << m_zoneNr;
qInfo() << "BRANCH_NAME ................" << m_branchName;
qInfo() << "WORKING_DIRECTORY .........." << m_workingDirectory;
this->moveToThread(&m_workerThread);
2023-06-16 16:47:13 +02:00
m_workerThread.start();
int cnt = 0;
while (!m_workerThread.isRunning()) {
if (++cnt > 5) {
qCritical() << "starting worker thread FAILED";
return;
}
QThread::sleep(1);
}
}
Worker::~Worker() {
int cnt = 0;
m_workerThread.quit();
while (!m_workerThread.isFinished()) {
if (!m_workerThread.wait(1000)) {
if (++cnt > 5) {
qCritical() << "stopping worker thread FAILED";
return;
}
}
}
if (m_update) {
delete m_update;
}
2023-06-16 16:47:13 +02:00
}
static std::once_flag once;
void Worker::update() {
std::call_once(once, &Worker::privateUpdate, this);
}
void Worker::privateUpdate() {
// user should not start the update process several times
QPushButton *start = qobject_cast<QPushButton *>(QObject::sender());
start->setEnabled(false);
emit stopStartTimer();
emit disableExit();
m_updateProcessRunning = true;
bool sentIsmasLastVersionNotification = false;
QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) {
if (m_gc.gitCloneAndCheckoutBranch()) {
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
QString("CLONED AND CHECKED OUT: ") + m_customerRepository);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.cloneAndCheckoutCustomerRepository(
m_updateStatus.m_statusDescription));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
emit setProgress(95);
m_ismasClient.setProgressInPercent(95);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
//emit setProgress(100);
//m_ismasClient.setProgressInPercent(100);
//emit appendText(QString(""), UPDATE_STEP_SUCCESS);
}
} else {
// checkout branch
if (m_gc.gitCheckoutBranch()) {
int progress = 10;
m_ismasClient.setProgressInPercent(progress);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH,
QString("CHECKED OUT BRANCH: ") + m_gc.branchName());
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch(
m_updateStatus.m_statusDescription, ""));
emit setProgress(progress);
if (backendConnected()) {
progress = 20;
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (updateTriggerSet()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (customerEnvironment()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (filesToUpdate()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (updateFiles(progress)) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (syncCustomerRepositoryAndFS()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (sendIsmasLastVersionNotification()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
// mark update as activated -> this resets the WAIT button
progress = 100;
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
}
}
}
}
}
}
}
}
}
}
if (!sentIsmasLastVersionNotification) {
// try even if the backend is not connected
sendIsmasLastVersionNotification();
emit setProgress(100);
m_ismasClient.setProgressInPercent(100);
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
}
m_updateProcessRunning = false;
emit enableExit();
emit restartExitTimer();
}
bool Worker::backendConnected() {
static int repeat = 0;
if (repeat < 3) {
std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}");
if (result) {
QString msg = result.value();
QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) {
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
<< parseError.error << parseError.errorString();
return false;
}
if (!document.isObject()) {
qCritical() << "FILE IS NOT A JSON OBJECT!";
return false;
}
QJsonObject obj = document.object();
QStringList keys = obj.keys();
for (QString const& key : keys ) {
if (key.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
QJsonValue v = obj.value(key);
if (v.isObject()) {
obj = v.toObject();
bool ismas = obj.value("ISMAS").toBool();
QString status = obj.value("Broker").toString();
qCritical() << "XXXXXXXXXX STATUS" << status;
if (ismas) {
if (status == "Connected") {
// do not send, as this would result in a corrupted wait button
// but update the user-interface
emit appendText("\nBackend connected", UPDATE_STEP_OK);
return true;
}
}
if (status.startsWith("Connecting") || status.startsWith("Re-Connecting")) {
QThread::sleep(1);
++repeat;
return backendConnected();
}
emit appendText("\nBackend connected", UPDATE_STEP_FAIL);
emit showErrorMessage("Error", "Backend not available");
}
}
}
}
}
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_NOT_CONNECTED,
QString("NO BACKEND CONNECTION"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorBackendNotConnected(m_updateStatus.m_statusDescription, ""));
return false;
}
bool Worker::updateTriggerSet() {
// nmap -Pn 62.141.45.68 -p 8883
// Host is up (0.053s latency).
//
// PORT STATE SERVICE
// 8883/tcp open secure-mqtt
QString triggerValue("");
if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
QString msg = result.value();
QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) {
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
<< parseError.error << parseError.errorString();
emit showErrorMessage("check update trigger",
QString("invalid json ") + msg.mid(0, 20));
return false;
}
if (!document.isObject()) {
qCritical() << "FILE IS NOT A JSON OBJECT!";
emit showErrorMessage("check update trigger",
QString("not a json object") + msg);
return false;
}
QJsonObject obj = document.object();
// sanity check: cust_nr and machine_nr of PSA correct ?
if (obj.contains("Dev_ID")) {
QJsonValue v = obj.value("Dev_ID");
if (v.isObject()) {
QJsonObject obj = v.toObject();
if (obj.contains("Custom_ID") && obj.contains("Device_ID")) {
QJsonValue const c = obj.value("Custom_ID");
QJsonValue const m = obj.value("Device_ID");
int customerNr = c.toInt(-1);
int machineNr = m.toInt(-1);
if (customerNr != m_customerNr) {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
.arg(customerNr).arg(m_customerNr));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
return false;
}
if (machineNr != m_machineNr) {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
.arg(machineNr).arg(m_machineNr));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
return false;
}
}
}
}
if (obj.contains("Fileupload")) {
QJsonValue v = obj.value("Fileupload");
if (v.isObject()) {
obj = v.toObject();
if (obj.contains("TRG")) {
v = obj.value("TRG");
if (v.isString()) {
triggerValue = v.toString();
if (triggerValue == "WAIT") {
emit appendText("\nUpdate trigger set", UPDATE_STEP_OK);
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
QString("UPDATE TRIGGER SET. CONTINUE. "));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, ""));
return true;
} else {
emit showErrorMessage("check update trigger",
QString ("TRG key=<") + triggerValue
+ ">\n(reset download button?)");
}
}
} else {
emit showErrorMessage("check update trigger", "TRG key not contained");
}
} else {
emit showErrorMessage("check update trigger", "Fileupload not a json-object");
}
}
} else {
emit showErrorMessage("check update trigger", "no ISMAS response");
}
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_NOT_SET_OR_WRONG,
QString("UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") +
triggerValue + ")");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorUpdateTrigger(m_updateStatus.m_statusDescription, ""));
return false;
}
bool Worker::customerEnvironment() {
if (QDir(m_customerRepository).exists()) {
if (m_gc.gitCheckoutBranch()) {
emit appendText("\nPrepare customer environment", UPDATE_STEP_DONE);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH,
QString("CHECKED-OUT BRANCH ") + m_gc.branchName());
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch(m_updateStatus.m_statusDescription, ""));
return true;
} else {
emit showErrorMessage("cust-env",
QString("Checkout ") + m_customerRepository + " failed");
}
} else {
emit showErrorMessage("cust-env", m_customerRepository + " does not exist");
}
return false;
}
bool Worker::filesToUpdate() {
if (std::optional<QString> changes = m_gc.gitFetch()) {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES,
QString("FETCHING OF ") + m_customerRepositoryPath +
QString(" INTO ") + m_customerRepository);
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) {
m_filesToUpdate = changedFileNames.value();
int const size = m_filesToUpdate.size();
if (size > 1) {
emit appendText(QString("\nFound %1 files to update ").arg(size), UPDATE_STEP_DONE);
} else {
emit appendText(QString("\nFound 1 file to update "), UPDATE_STEP_DONE);
}
if (!m_gc.gitPull()) {
emit showErrorMessage("files to update", "pulling files failed");
}
return true;
} else {
emit showErrorMessage("files to update", "no files to update (checked-in any files?)");
}
} else {
emit showErrorMessage("files to update",
QString("no changes in ") + m_customerRepository +
" (checked-in any files?)");
}
return false;
}
bool Worker::updateFiles(quint8 percent) {
QStringList filesToDownload;
m_displayIndex = 0;
for (int i = 0; i < m_filesToUpdate.size(); ++i) {
QString fName = m_filesToUpdate.at(i);
if (fName.contains("opkg_commands", Qt::CaseInsensitive)) {
// execute opkg commands
if (QDir::setCurrent(m_customerRepository)) {
QFile f(fName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly)) {
QTextStream in(&f);
int cmdCount = 0;
while (!in.atEnd()) {
QString line = in.readLine();
static const QRegularExpression comment("^\\s*#.*$");
if (line.indexOf(comment, 0) == -1) {
// found opkg command
QString opkgCommand = line.trimmed();
executeOpkgCommand(opkgCommand);
++cmdCount;
m_ismasClient.setProgressInPercent(++percent);
m_updateStatus = UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND,
QString("EXEC OPKG-COMMAND ") + opkgCommand);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.execOpkgCommand(m_updateStatus.m_statusDescription, ""));
}
}
f.close();
if (cmdCount > 0) {
m_displayIndex = 1;
emit appendText(QString("\n(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update opkg pakets "), UPDATE_STEP_DONE);
}
}
}
}
} else
if (fName.contains("print", Qt::CaseInsensitive)) {
filesToDownload << fName; // download printer-config-files
} else
if (fName == "dc2c.bin") {
filesToDownload << fName; // download device controller
}
}
qCritical() << "XXXXXXXXXXXXXXXXXXX FILES_TO_WORK_ON" << filesToDownload;
return m_update->doUpdate(m_displayIndex, filesToDownload);
}
bool Worker::syncCustomerRepositoryAndFS() {
if (QDir(m_customerRepository).exists()) {
if (QDir::setCurrent(m_customerRepository)) {
QString const params("--recursive "
"--progress "
"--checksum "
"--exclude=.* "
"--include=*.bin "
"--include=*.json "
"--include=opkg_commands "
"--include=*.ini");
QStringList cmds;
cmds << QString("rsync ") + params.simplified() + " etc/ /etc";
cmds << QString("rsync ") + params.simplified() + " opt/ /opt";
QString cmd;
bool error = false;
foreach (cmd, cmds) {
if (!error) {
Command c("bash");
qInfo() << "EXECUTING CMD..." << cmd;
if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) {
qCritical() << c.getCommandResult() << "SUCCESS";
} else {
qCritical() << "CMD" << cmd << "FAILED";
error = true;
}
}
}
if (!error) {
emit appendText(QString("\nSync customer environment with filesystem "),
UPDATE_STEP_DONE);
return true;
}
}
}
return false;
}
bool Worker::sendIsmasLastVersionNotification() {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_SENDVERSION#J=") +
m_ismasClient.updateOfPSASendVersion(getPSAInstalled()));
emit appendText(QString("\nSend last version info "), UPDATE_STEP_DONE);
return true;
}
bool Worker::saveLogFile() {
return true;
}
QString Worker::getOsVersion() const {
QString const cmd = QString("echo -n $(cat /etc/os-release | head -n 1 | cut -d'\"' -f2 | tr -d '\"')");
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QString Worker::getATBQTVersion() const {
QString const cmd = QString("echo -n $(/opt/app/ATBAPP/ATBQT -v | head -n 2 | cut -d':' -f2)");
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QString Worker::getCPUSerial() const {
QString const cmd = QString("echo -n $(cat /proc/cpuinfo | grep -i Serial | cut -d':' -f2)");
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QString Worker::getRaucVersion() const {
QString const cmd = QString("echo -n $(rauc --version)");
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QString Worker::getOpkgVersion() const {
QString const cmd = QString("echo -n $(opkg --version)");
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QString Worker::getPluginVersion(QString const &pluginFileName) const {
QString const cmd = QString("echo -n $(strings %1 | grep \\\"Version\\\" | cut -d':' -f2 | tr -d '\"' | tr -d ',')").arg(pluginFileName);
Command c("bash");
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
return c.getCommandResult();
}
return "N/A";
}
QStringList Worker::getDCVersion() const {
QStringList lst = (QStringList() << "N/A" << "N/A");
if (m_hw) {
m_hw->dc_autoRequest(true); // turn auto-request setting on
QByteArray const cmp(8, char(0));
QByteArray hw(""), sw("");
for (int i=0; i<5; ++i) {
hw = m_hw->dc_getHWversion().toUtf8();
sw = m_hw->dc_getSWversion().toUtf8();
if (!hw.startsWith(cmp)) {
lst.clear();
qInfo() << hw << sw;
lst << hw << sw;
break;
}
QThread::sleep(1);
}
}
return lst;
}
qint64 Worker::getFileSize(QString const &fileName) const {
// fileName has to be an absolute path
QFileInfo fInfo(fileName);
return fInfo.exists() ? fInfo.size() : -1;
}
bool Worker::executeOpkgCommand(QString opkgCommand) {
Command c(opkgCommand);
if (c.execute(m_workingDirectory)) {
QString const r = c.getCommandResult();
qInfo() << UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS,
QString("EXECUTE OPKG COMMAND %1 OK: %2")
.arg(opkgCommand)
.arg(c.getCommandResult()));
return true;
} else {
qCritical() << UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE,
QString("EXECUTE OPKG COMMAND %1 FAILED")
.arg(opkgCommand));
}
return false;
2023-06-16 16:47:13 +02:00
}
PSAInstalled Worker::getPSAInstalled() {
QStringList const dcVersion = getDCVersion();
QString const deviceControllerVersionHW = dcVersion.first();
QString const deviceControllerVersionSW = dcVersion.last();
qInfo() << "CURRENT DC-HW-VERSION: " << deviceControllerVersionHW;
qInfo() << "CURRENT DC-SW-VERSION: " << deviceControllerVersionSW;
QString const deviceControllerGitBlob = "N/A";
QString const deviceControllerGitLastCommit = "N/A";
PSAInstalled psaInstalled;
QString printSysDir("/etc/psa_config");
QString tariffSysDir("/etc/psa_tariff");
QString absPathName;
if (m_zoneNr != 0) {
QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0');
psaInstalled.tariff.name = QString("tariff%1.json").arg(n);
absPathName = QDir::cleanPath(tariffSysDir + QDir::separator() + psaInstalled.tariff.name);
psaInstalled.tariff.blob = m_gc.gitBlob(absPathName);
psaInstalled.tariff.size = getFileSize(absPathName);
psaInstalled.tariff.zone = m_zoneNr;
}
psaInstalled.tariff.project = "Szeged";
psaInstalled.tariff.info = "N/A";
psaInstalled.tariff.loadTime = "N/A"; // QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
psaInstalled.tariff.version = "N/A";
psaInstalled.hw.linuxVersion = m_osVersion;
psaInstalled.hw.cpuSerial = m_cpuSerial;
psaInstalled.dc.versionHW = deviceControllerVersionHW;
psaInstalled.dc.versionSW = deviceControllerVersionSW;
psaInstalled.dc.gitBlob = "N/A";
psaInstalled.dc.gitLastCommit = "N/A";
psaInstalled.dc.size = -1;
psaInstalled.sw.raucVersion = m_raucVersion;
psaInstalled.sw.opkgVersion = m_opkgVersion;
psaInstalled.sw.atbQTVersion = m_atbqtVersion;
psaInstalled.pluginVersion.deviceController = m_pluginVersionATBDeciceController;
psaInstalled.pluginVersion.ingenicoISelfCC = m_pluginVersionIngenicoISelf;
psaInstalled.pluginVersion.mobilisisCalculatePrice = m_pluginVersionMobilisisCalc;
psaInstalled.pluginVersion.mobilisisCalculatePriceConfigUi = m_pluginVersionMobilisisCalcConfig;
psaInstalled.pluginVersion.prmCalculatePrice = m_pluginVersionPrmCalc;
psaInstalled.pluginVersion.prmCalculatePriceConfigUi = m_pluginVersionPrmCalcConfig;
psaInstalled.pluginVersion.tcpZVT = m_pluginVersionTcpZvt;
psaInstalled.cash.name = "DC2C_cash.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.cash.name);
psaInstalled.cash.blob = m_gc.gitBlob(absPathName);
psaInstalled.cash.size = getFileSize(absPathName);
psaInstalled.conf.name = "DC2C_conf.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.conf.name);
psaInstalled.conf.blob = m_gc.gitBlob(absPathName);
psaInstalled.conf.size = getFileSize(absPathName);
psaInstalled.device.name = "DC2C_device.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.device.name);
psaInstalled.device.blob = m_gc.gitBlob(absPathName);
psaInstalled.device.size = getFileSize(absPathName);
for (int i=0; i < 32; ++i) {
QString const &n = QString("%1").arg(i+1).rightJustified(2, '0');
psaInstalled.print[i].name = QString("DC2C_print%1.json").arg(n);
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.print[i].name);
psaInstalled.print[i].blob = m_gc.gitBlob(absPathName);
psaInstalled.print[i].size = getFileSize(absPathName);
}
return psaInstalled;
}
QString Worker::sendCmdSendVersionToIsmas() {
QStringList const dcVersion = getDCVersion();
QString const deviceControllerVersionHW = dcVersion.first();
QString const deviceControllerVersionSW = dcVersion.last();
qInfo() << "CURRENT DC-HW-VERSION: " << deviceControllerVersionHW;
qInfo() << "CURRENT DC-SW-VERSION: " << deviceControllerVersionSW;
QString const deviceControllerGitBlob = "N/A";
QString const deviceControllerGitLastCommit = "N/A";
PSAInstalled psaInstalled;
QString printSysDir("/etc/psa_config");
QString tariffSysDir("/etc/psa_tariff");
QString absPathName;
if (m_zoneNr != 0) {
QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0');
psaInstalled.tariff.name = QString("tariff%1.json").arg(n);
absPathName = QDir::cleanPath(tariffSysDir + QDir::separator() + psaInstalled.tariff.name);
psaInstalled.tariff.blob = m_gc.gitBlob(absPathName);
psaInstalled.tariff.size = getFileSize(absPathName);
psaInstalled.tariff.zone = m_zoneNr;
}
psaInstalled.tariff.project = "Szeged";
psaInstalled.tariff.info = "N/A";
psaInstalled.tariff.loadTime = "N/A"; // QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
psaInstalled.tariff.version = "N/A";
psaInstalled.hw.linuxVersion = m_osVersion;
psaInstalled.hw.cpuSerial = m_cpuSerial;
psaInstalled.dc.versionHW = deviceControllerVersionHW;
psaInstalled.dc.versionSW = deviceControllerVersionSW;
psaInstalled.dc.gitBlob = "N/A";
psaInstalled.dc.gitLastCommit = "N/A";
psaInstalled.dc.size = -1;
psaInstalled.sw.raucVersion = m_raucVersion;
psaInstalled.sw.opkgVersion = m_opkgVersion;
psaInstalled.sw.atbQTVersion = m_atbqtVersion;
psaInstalled.pluginVersion.deviceController = m_pluginVersionATBDeciceController;
psaInstalled.pluginVersion.ingenicoISelfCC = m_pluginVersionIngenicoISelf;
psaInstalled.pluginVersion.mobilisisCalculatePrice = m_pluginVersionMobilisisCalc;
psaInstalled.pluginVersion.mobilisisCalculatePriceConfigUi = m_pluginVersionMobilisisCalcConfig;
psaInstalled.pluginVersion.prmCalculatePrice = m_pluginVersionPrmCalc;
psaInstalled.pluginVersion.prmCalculatePriceConfigUi = m_pluginVersionPrmCalcConfig;
psaInstalled.pluginVersion.tcpZVT = m_pluginVersionTcpZvt;
psaInstalled.cash.name = "DC2C_cash.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.cash.name);
psaInstalled.cash.blob = m_gc.gitBlob(absPathName);
psaInstalled.cash.size = getFileSize(absPathName);
psaInstalled.conf.name = "DC2C_conf.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.conf.name);
psaInstalled.conf.blob = m_gc.gitBlob(absPathName);
psaInstalled.conf.size = getFileSize(absPathName);
psaInstalled.device.name = "DC2C_device.json";
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.device.name);
psaInstalled.device.blob = m_gc.gitBlob(absPathName);
psaInstalled.device.size = getFileSize(absPathName);
for (int i=0; i < 32; ++i) {
QString const &n = QString("%1").arg(i+1).rightJustified(2, '0');
psaInstalled.print[i].name = QString("DC2C_print%1.json").arg(n);
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.print[i].name);
psaInstalled.print[i].blob = m_gc.gitBlob(absPathName);
psaInstalled.print[i].size = getFileSize(absPathName);
}
// QByteArray data = "#M=APISM#C=CMD_SENDVERSION#J=";
return m_ismasClient.updateOfPSASendVersion(psaInstalled);
2023-06-16 16:47:13 +02:00
}
/************************************************************************************************
* operators
*/
QDebug operator<< (QDebug debug, UpdateStatus status) {
switch(status.m_updateStatus) {
case UPDATE_STATUS::UPDATE_PROCESS_SUCCESS:
debug << QString("UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING:
debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE:
debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_TIMEOUT:
debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_SUCCESS:
debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_SUCCESS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES:
debug << QString("UPDATE_STATUS::GIT_FETCH_UPDATES: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE:
debug << QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS:
debug << QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED:
debug << QString("UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_PULL_UPDATES_SUCCESS:
debug << QString("UPDATE_STATUS::GIT_PULL_UPDATES_REQUEST: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE:
debug << QString("UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMANDS:
debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMANDS_SUCCESS:
debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS_SUCCESS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS:
debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS: ")
<< status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE:
debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE: ")
<< status.m_statusDescription;
break;
default:;
}
return debug;
}
QString& operator<< (QString& str, UpdateStatus status) {
switch(status.m_updateStatus) {
case UPDATE_STATUS::UPDATE_PROCESS_SUCCESS:
str = QString("UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING:
str = QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_SUCCESS:
str = QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES:
str = QString("UPDATE_STATUS::GIT_FETCH_UPDATES: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE:
str = QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS:
str = QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_PULL_UPDATES_SUCCESS:
str = QString("UPDATE_STATUS::GIT_PULL_UPDATES_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE:
str = QString("UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED:
str = QString("UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMANDS:
str = QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMANDS_SUCCESS:
str = QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS:
str = QString("UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS: ");
str += status.m_statusDescription;
break;
case UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE:
str = QString("UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE: ");
str += status.m_statusDescription;
break;
default:;
}
return str;
}