Compare commits
19 Commits
4ff3b0efdf
...
042e6dfa38
Author | SHA1 | Date | |
---|---|---|---|
042e6dfa38 | |||
e523d3cc2c | |||
927197d0d1 | |||
72cb738af5 | |||
0fb38013f7 | |||
5f1376cf1e | |||
5db7b4224e | |||
7c7adc94e6 | |||
89c2d3a8ae | |||
c2b52aa91d | |||
329c770aa0 | |||
cdb045b72b | |||
6d43cf4c9f | |||
4caa0c0d83 | |||
4d2d38e45c | |||
9a55ce18e4 | |||
223c7a8f8d | |||
ce72d3d14d | |||
8b66c47e49 |
@ -48,8 +48,9 @@ bool GitClient::gitCloneCustomerRepository() {
|
||||
}
|
||||
}
|
||||
}
|
||||
qCritical() << "ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT="
|
||||
<< result;
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=" << result;
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -96,7 +97,9 @@ bool GitClient::gitCheckoutBranch() {
|
||||
Command c(gitCommand);
|
||||
return c.execute(m_customerRepository); // execute command in customerRepo
|
||||
}
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST";
|
||||
qCritical() << QString(80, '*');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -108,12 +111,12 @@ bool GitClient::gitCloneAndCheckoutBranch() {
|
||||
return true;
|
||||
} else {
|
||||
// TODO
|
||||
// m_worker->terminateUpdateProcess();
|
||||
}
|
||||
//}
|
||||
} else {
|
||||
// TODO
|
||||
//m_worker->terminateUpdateProcess();
|
||||
qCritical() << QString(80, '*');
|
||||
qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -132,23 +135,41 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
|
||||
if (c.execute(m_customerRepository)) { // execute command in local customerRepo
|
||||
QString s = c.getCommandResult().trimmed();
|
||||
QStringList lines = Update::split(s, '\n');
|
||||
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "GIT DIFF RESULT" << lines;
|
||||
qInfo() << QString(80, '*');
|
||||
|
||||
QStringList fileNames;
|
||||
// each line has the format "etc/psa_config/DC2C_print01.json | 1 +
|
||||
// or the format "etc/psa_config/DC2C_print01.json (new) | 1 +
|
||||
// the filenames are relativ to the repository
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
// TODO: koennte auch (delete) kommen ?
|
||||
int newIndex = lines.at(i).indexOf("(new)"); // for new files
|
||||
// int goneIndex = lines.at(i).indexOf("(gone)"); // for removed files
|
||||
QString const &line = lines.at(i);
|
||||
int newIndex = line.indexOf("(new"); // for new files
|
||||
int goneIndex = line.indexOf("(gone"); // for removed files
|
||||
int modeIndex = line.indexOf("(mode");
|
||||
// int pipeIndex = line.indexOf('|');
|
||||
if (newIndex != -1) {
|
||||
QString fileName = lines.at(i).mid(0, newIndex).trimmed();
|
||||
fileNames << fileName;
|
||||
} else {
|
||||
int pipeIndex = lines.at(i).indexOf('|');
|
||||
if (pipeIndex != -1) {
|
||||
QString fileName = lines.at(i).mid(0, pipeIndex).trimmed();
|
||||
fileNames << fileName;
|
||||
}
|
||||
QString file = line.left(newIndex).trimmed();
|
||||
qInfo() << "FILE (NEW)" << file;
|
||||
fileNames << file;
|
||||
} else
|
||||
if (modeIndex != -1) {
|
||||
QString const file = line.left(modeIndex).trimmed();
|
||||
qInfo() << "FILE (MODE)" << file;
|
||||
fileNames << file;
|
||||
} else
|
||||
//if (pipeIndex != -1) {
|
||||
// QString const file = line.left(pipeIndex).trimmed();
|
||||
// qInfo() << "FILE (PIPE)" << file;
|
||||
// fileNames << file;
|
||||
//} else
|
||||
if (goneIndex != -1) {
|
||||
QString const file = line.left(goneIndex).trimmed();
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "FILE (GONE)" << file;
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
}
|
||||
if (!fileNames.isEmpty()) {
|
||||
@ -164,8 +185,9 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
|
||||
*/
|
||||
std::optional<QString> GitClient::gitFetch() {
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
|
||||
qCritical() << "BRANCH NAME" << m_branchName;
|
||||
qCritical() << QString(80, '*');
|
||||
qInfo() << "BRANCH NAME" << m_branchName;
|
||||
qCritical() << QString(80, '*');
|
||||
|
||||
Command c("git fetch");
|
||||
if (c.execute(m_customerRepository)) {
|
||||
@ -198,26 +220,39 @@ std::optional<QString> GitClient::gitFetch() {
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
"regex-match for commits");
|
||||
"no regex-match for commits");
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "NO REGEX MATCH FOR COMMITS";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("unkown branch name ") + m_branchName);
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "UNKNOWN BRANCH NAME" << m_branchName;
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("wrong format for result of 'git fetch' ") + s);
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "WRONG FORMAT FOR RESULT OF 'GIT FETCH'" << s;
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
"empty result for 'git fetch'");
|
||||
emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'");
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "EMPTY RESULT FOR 'GIT FETCH'";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("repository ") + m_customerRepository + " does not exist");
|
||||
emit m_worker->showErrorMessage("git fetch", QString("repository ") + m_customerRepository + " does not exist");
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "REPOSITORY" << m_customerRepository << "DOES NOT EXIST";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -238,7 +273,9 @@ bool GitClient::gitPull() {
|
||||
qInfo() << "PULLED INTO" << m_customerRepository;
|
||||
return true;
|
||||
}
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "PULL INTO" << m_customerRepository << "FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -148,6 +148,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
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) {
|
||||
int n = ::sendto(sockfd, buf+bytesWritten, bytesToWrite-bytesWritten, 0, NULL, 0);
|
||||
@ -155,14 +156,18 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
bytesWritten += n;
|
||||
} else {
|
||||
if (errno == EWOULDBLOCK) {
|
||||
if (++loop < 10) {
|
||||
QThread::msleep(500);
|
||||
continue;
|
||||
}
|
||||
printErrorMessage(port, clientIP, clientPort,
|
||||
QString("TIMEOUT (") + strerror(errno) + ")");
|
||||
QString("WRITE TIMEOUT %1(").arg(loop) + strerror(errno) + ")");
|
||||
::close(sockfd);
|
||||
return std::nullopt;
|
||||
} else
|
||||
if (errno == EINTR) {
|
||||
printErrorMessage(port, clientIP, clientPort,
|
||||
QString("INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")");
|
||||
QString("WRITE INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -177,6 +182,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
|
||||
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT ") + buf);
|
||||
|
||||
loop = 0;
|
||||
bzero(buf, sizeof(buf));
|
||||
int bytesToRead = sizeof(buf)-1;
|
||||
int bytesRead = 0;
|
||||
@ -196,8 +202,12 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
} else
|
||||
if (n < 0) {
|
||||
if (errno == EWOULDBLOCK) {
|
||||
if (++loop < 10) {
|
||||
QThread::msleep(500);
|
||||
continue;
|
||||
}
|
||||
printErrorMessage(port, clientIP, clientPort,
|
||||
QString("TIMEOUT (") + strerror(errno) + ")");
|
||||
QString("READ TIMEOUT %1(").arg(loop) + strerror(errno) + ")");
|
||||
::close(sockfd);
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -214,8 +224,8 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) {
|
||||
response = response.mid(0, idx);
|
||||
} else
|
||||
if (response == "RECORD SAVED") {
|
||||
printInfoMessage(port, clientIP, clientPort, "IGNORED 'RECORD SAVED' RESPONSE");
|
||||
if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
|
||||
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
|
||||
::close(sockfd);
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -283,6 +293,15 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
|
||||
version.toStdString().c_str());
|
||||
}
|
||||
|
||||
QString IsmasClient::errorGitClone(int percent, QString const &info, QString const &version) {
|
||||
return updateNewsToIsmas("U0003",
|
||||
percent,
|
||||
RESULT_CODE::INSTALL_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,
|
||||
|
@ -144,6 +144,7 @@ public:
|
||||
QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository
|
||||
QString checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch
|
||||
QString errorBackendNotConnected(QString const &info, QString const &version = QString()); // checkout branch
|
||||
QString errorGitClone(int percent, QString const &info, QString const &version = QString());
|
||||
QString backendConnected(QString const &info, QString const &version = QString());
|
||||
QString updateTriggerSet(QString const &info, QString const &version = QString());
|
||||
QString errorUpdateTrigger(QString const &info, QString const &version = QString());
|
||||
|
@ -32,15 +32,9 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
ui->updateStatus->setText(lst.join('\n'));
|
||||
ui->updateStatus->setEnabled(true);
|
||||
|
||||
ui->reserved_1->setVisible(false);
|
||||
ui->reserved_2->setVisible(false);
|
||||
ui->reserved_3->setVisible(false);
|
||||
ui->reserved_4->setVisible(false);
|
||||
ui->reserved_5->setVisible(false);
|
||||
ui->reserved_6->setVisible(false);
|
||||
|
||||
m_startTimer = new QTimer(this);
|
||||
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
||||
// connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
||||
connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(update()));
|
||||
m_startTimer->setSingleShot(true);
|
||||
m_startTimer->start(5 * 1000);
|
||||
|
||||
@ -49,9 +43,6 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
m_exitTimer->setSingleShot(true);
|
||||
m_exitTimer->start(1800 * 1000);
|
||||
|
||||
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
||||
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
|
||||
connect(ui->start, SIGNAL(clicked()), m_worker, SLOT(update()));
|
||||
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit()));
|
||||
connect(m_worker, SIGNAL(disableExit()), this, SLOT(onDisableExit()));
|
||||
connect(m_worker, SIGNAL(enableExit()), this, SLOT(onEnableExit()));
|
||||
@ -136,7 +127,7 @@ void MainWindow::onEnableExit() {
|
||||
|
||||
void MainWindow::onRestartExitTimer() {
|
||||
m_exitTimer->stop();
|
||||
m_exitTimer->start(10 * 1000);
|
||||
m_exitTimer->start(60 * 1000);
|
||||
}
|
||||
|
||||
void MainWindow::onQuit() {
|
||||
@ -147,39 +138,64 @@ void MainWindow::onQuit() {
|
||||
|
||||
void MainWindow::onAppendText(QString text, QString suffix) {
|
||||
QString editText = ui->updateStatus->toPlainText();
|
||||
if (suffix.size() > 0) {
|
||||
if (!suffix.isNull() && suffix.size() > 0) {
|
||||
qInfo() << "TEXT" << text << "SUFFIX" << suffix;
|
||||
if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) {
|
||||
editText += QString("\n").leftJustified(m_width-3, '=');
|
||||
editText += " ";
|
||||
}
|
||||
editText += (QString("\n") + text).leftJustified(m_width - (2 + suffix.size()) ) + suffix;
|
||||
} else {
|
||||
editText += text.leftJustified(m_width-9);
|
||||
}
|
||||
|
||||
QStringList lines = editText.split('\n');
|
||||
QStringList const lines = editText.split('\n');
|
||||
for (int i=0; i<lines.size(); ++i) {
|
||||
qDebug() << lines.at(i);
|
||||
} qDebug() << ""; qDebug() << "";
|
||||
qInfo() << lines.at(i);
|
||||
} qInfo() << ""; qInfo() << "";
|
||||
|
||||
ui->updateStatus->setPlainText(editText);
|
||||
ui->updateStatus->setPlainText(editText.trimmed());
|
||||
ui->updateStatus->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::onReplaceLast(QString text, QString suffix) {
|
||||
qInfo() << "REPL TEXT" << text << "SUFFIX" << suffix;
|
||||
|
||||
QString editText = ui->updateStatus->toPlainText();
|
||||
QStringList lines = editText.split('\n');
|
||||
if (lines.size() > 0) {
|
||||
lines.removeLast();
|
||||
if (!suffix.isNull() && suffix.size() > 0 && suffix != "\n") {
|
||||
lines += text.leftJustified(m_width-10) + suffix;
|
||||
} else {
|
||||
lines += text.leftJustified(m_width-10);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<lines.size(); ++i) {
|
||||
qDebug() << lines.at(i);
|
||||
} qDebug() << ""; qDebug() << "";
|
||||
qInfo() << lines.at(i);
|
||||
} qInfo() << ""; qInfo() << "";
|
||||
|
||||
ui->updateStatus->setText(lines.join('\n'));
|
||||
ui->updateStatus->setText(lines.join('\n').trimmed());
|
||||
ui->updateStatus->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::onShowErrorMessage(QString title, QString text) {
|
||||
QMessageBox::critical(this, title, text, QMessageBox::Ok);
|
||||
text = text.leftJustified(50, ' ');
|
||||
QMessageBox msgBox(QMessageBox::NoIcon, title,
|
||||
text, QMessageBox::Ok,
|
||||
nullptr, Qt::FramelessWindowHint);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setStyleSheet("QDialog {background-color: red;}"
|
||||
"QPushButton {background-color: blue;}");
|
||||
QTimer *t = new QTimer(this);
|
||||
connect(t, SIGNAL(timeout()), msgBox.defaultButton(), SLOT(click()));
|
||||
t->setSingleShot(true);
|
||||
t->start(5 * 1000);
|
||||
|
||||
if(msgBox.exec() == QMessageBox::Ok) {
|
||||
// do something
|
||||
} else {
|
||||
// do something else
|
||||
}
|
||||
disconnect(t, SIGNAL(timeout()), msgBox.defaultButton(), SLOT(click()));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void onAppendText(QString, QString suffix = "");
|
||||
void onReplaceLast(QString, QString);
|
||||
void onReplaceLast(QString, QString suffix = "");
|
||||
void onShowErrorMessage(QString, QString);
|
||||
void onStopStartTimer();
|
||||
void onRestartExitTimer();
|
||||
|
109
mainwindow.ui
109
mainwindow.ui
@ -22,114 +22,41 @@
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>11</x>
|
||||
<y>11</y>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>781</width>
|
||||
<height>461</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="start">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Terminus</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="exit">
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="reserved_1">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="reserved_2">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QPushButton" name="reserved_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="5">
|
||||
<widget class="QPushButton" name="reserved_4">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="6">
|
||||
<widget class="QPushButton" name="reserved_6">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="7">
|
||||
<widget class="QPushButton" name="reserved_5">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="8">
|
||||
<widget class="QTextEdit" name="updateStatus">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Monospace</family>
|
||||
<pointsize>14</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="8">
|
||||
<item row="3" column="1">
|
||||
<widget class="QProgressBar" name="updateProgress">
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="3" colspan="3">
|
||||
<widget class="QTextEdit" name="updateStatus">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Misc Fixed</family>
|
||||
<pointsize>11</pointsize>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
73
update.cpp
73
update.cpp
@ -8,6 +8,7 @@
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegExp>
|
||||
|
||||
//#include <iostream>
|
||||
//#include <fstream>
|
||||
@ -350,21 +351,25 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
|
||||
10 : bl_stopBL() // leave bl and start (the new) application
|
||||
*/
|
||||
bool Update::updateBinary(char const *fileToSendToDC) {
|
||||
qInfo() << "updating device controller binary" << fileToSendToDC;
|
||||
qInfo() << "UPDATING DEVICE CONTROLLER BINARY" << fileToSendToDC;
|
||||
QFile fn(fileToSendToDC);
|
||||
bool r;
|
||||
if ((r = fn.exists()) == true) {
|
||||
QString const linkTarget = fn.symLinkTarget();
|
||||
QFileInfo fi(linkTarget);
|
||||
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
|
||||
if ((r = updateDC(linkTarget)) == true) {
|
||||
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
|
||||
QFileInfo fi(fn);
|
||||
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ")";
|
||||
if ((r = updateDC(fileToSendToDC)) == true) {
|
||||
qCritical() << QString(80, '*');
|
||||
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") DONE";
|
||||
qCritical() << QString(80, '*');
|
||||
} else {
|
||||
qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
} else {
|
||||
qCritical() << "symlink" << fileToSendToDC
|
||||
<< "does not exist -> NO UPDATE OF DC FIRMWARE";
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << fileToSendToDC << "does not exist -> NO UPDATE OF DC FIRMWARE";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -514,7 +519,6 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
||||
}
|
||||
|
||||
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
|
||||
//
|
||||
// ACHTUNG !!!
|
||||
//
|
||||
@ -523,11 +527,6 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
bool serialOpened = false;
|
||||
bool serialOpen = false;
|
||||
|
||||
if (filesToWorkOn.size() == 0) {
|
||||
qCritical() << "NOTHING TO UPDATE";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!serialOpen) {
|
||||
if (!isSerialOpen()) { // open serial only if not already open
|
||||
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) {
|
||||
@ -537,18 +536,23 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
}
|
||||
}
|
||||
serialOpen = true;
|
||||
qCritical() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
|
||||
qInfo() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
|
||||
}
|
||||
|
||||
bool res = false;
|
||||
QList<QString>::const_iterator it;
|
||||
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
|
||||
bool res = false;
|
||||
m_worker->startProgressLoop();
|
||||
QString fToWorkOn = (*it).trimmed();
|
||||
fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn);
|
||||
|
||||
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) &&
|
||||
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) {
|
||||
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
|
||||
if (fToWorkOn.contains(version)) {
|
||||
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "DO-UPDATE FILE-TO-WORK-ON" << fToWorkOn;
|
||||
qInfo() << QString(80, '*');
|
||||
|
||||
qDebug() << "sending sw/hw-requests...";
|
||||
for (int i=0; i < 3; ++i) { // send explicit reuests to get
|
||||
// current SW/HW-versions
|
||||
m_hw->request_DC2_SWversion();
|
||||
@ -558,12 +562,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
|
||||
QString const hwVersion = m_hw->dc_getHWversion().toLower();
|
||||
QString const fwVersion = m_hw->dc_getSWversion().toLower();
|
||||
|
||||
qInfo() << "current dc-hardware-version" << hwVersion;
|
||||
qInfo() << "current dc-firmware-version" << fwVersion;
|
||||
|
||||
QFile fn(fToWorkOn);
|
||||
QFileInfo linkTarget(fn.symLinkTarget());
|
||||
if (!linkTarget.exists()) { // check for broken link
|
||||
QFileInfo finfo(fn);
|
||||
if (!fn.exists()) { // check for broken link
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "FILE-TO-WORK-ON" << fn << "DOES NOT EXIST";
|
||||
qCritical() << QString(80, '*');
|
||||
res = false;
|
||||
} else {
|
||||
if (false) {
|
||||
@ -574,13 +582,12 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
} else {
|
||||
res = true;
|
||||
|
||||
qCritical() << "downloading" << fToWorkOn.trimmed() << "->"
|
||||
<< linkTarget.completeBaseName() << "to DC";
|
||||
qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
|
||||
#if UPDATE_DC == 1
|
||||
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
|
||||
QThread::sleep(1); // wait to be sure that there are no more
|
||||
// commands sent to dc-hardware
|
||||
qDebug() << "SET AUTO-REQUEST=FALSE";
|
||||
qInfo() << "SET AUTO-REQUEST=FALSE";
|
||||
|
||||
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
|
||||
qCritical() << "downloaded binary" << fToWorkOn;
|
||||
@ -591,13 +598,13 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
}
|
||||
|
||||
m_hw->dc_autoRequest(true); // turn auto-request setting on
|
||||
qDebug() << "SET AUTO-REQUEST=TRUE";
|
||||
qDebug() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
|
||||
qInfo() << "SET AUTO-REQUEST=TRUE";
|
||||
qInfo() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
|
||||
|
||||
QThread::sleep(10); // wait to be sure that responses
|
||||
// have been received
|
||||
qCritical() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
|
||||
qCritical() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
|
||||
qInfo() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
|
||||
qInfo() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -660,10 +667,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
|
||||
res = false;
|
||||
}
|
||||
m_worker->stopProgressLoop();
|
||||
m_worker->setProgress(100);
|
||||
|
||||
if (res == false) {
|
||||
break;
|
||||
}
|
||||
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
|
||||
|
||||
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
|
||||
qDebug() << "SET AUTO-REQUEST=TRUE";
|
||||
|
||||
return true;
|
||||
return res;
|
||||
}
|
||||
|
431
worker.cpp
431
worker.cpp
@ -69,7 +69,8 @@ Worker::Worker(hwinf *hw,
|
||||
, m_filesToUpdate()
|
||||
, m_updateProcessRunning(false)
|
||||
, m_returnCode(0)
|
||||
, m_progressValue{0} {
|
||||
, m_progressValue(0)
|
||||
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
|
||||
|
||||
QDir::setCurrent(m_workingDirectory);
|
||||
|
||||
@ -137,42 +138,35 @@ void Worker::update() {
|
||||
}
|
||||
|
||||
void Worker::privateUpdate() {
|
||||
QPushButton *start = qobject_cast<QPushButton *>(QObject::sender());
|
||||
start->setEnabled(false);
|
||||
|
||||
#if 0
|
||||
emit appendText("\nConnecting backend ...");
|
||||
|
||||
for (int i=0;i <= 100; ++i) {
|
||||
setProgress(i);
|
||||
QThread::msleep(100);
|
||||
}
|
||||
emit replaceLast("Connecting backend ...", UPDATE_STEP_OK);
|
||||
emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS);
|
||||
emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL);
|
||||
setProgress(0);
|
||||
|
||||
startProgressLoop();
|
||||
QThread::sleep(5); // long running process
|
||||
stopProgressLoop();
|
||||
for (int i=m_mainWindow->progressValue()/10; i <= 100; ++i) {
|
||||
setProgress(i);
|
||||
QThread::msleep(100);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
|
||||
emit stopStartTimer();
|
||||
emit disableExit();
|
||||
m_updateProcessRunning = true;
|
||||
|
||||
bool sentIsmasLastVersionNotification = false;
|
||||
|
||||
//emit appendText("\nRestart APISM ...");
|
||||
//startProgressLoop();
|
||||
//Command c("systemctl restart apism");
|
||||
//if (c.execute("/tmp")) {
|
||||
// QThread::sleep(10); // give APISM some time to reconnect
|
||||
// stopProgressLoop();
|
||||
// emit replaceLast("Restart APISM ...", UPDATE_STEP_DONE);
|
||||
//} else {
|
||||
// stopProgressLoop();
|
||||
// emit replaceLast("Restart APISM ...", UPDATE_STEP_FAIL);
|
||||
//}
|
||||
|
||||
emit disableExit();
|
||||
|
||||
m_returnCode = -1;
|
||||
QDir customerRepository(m_customerRepository);
|
||||
if (!customerRepository.exists()) {
|
||||
emit appendText("\nInitializing customer environment ...");
|
||||
startProgressLoop();
|
||||
if (m_gc.gitCloneAndCheckoutBranch()) {
|
||||
emit appendText("\nInitializing customer environment", UPDATE_STEP_DONE);
|
||||
stopProgressLoop();
|
||||
emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE);
|
||||
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
|
||||
QString("CLONED AND CHECKED OUT: ") + m_customerRepository);
|
||||
@ -182,82 +176,90 @@ void Worker::privateUpdate() {
|
||||
m_ismasClient.cloneAndCheckoutCustomerRepository(
|
||||
m_updateStatus.m_statusDescription));
|
||||
|
||||
setProgress(progress + 10);
|
||||
|
||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.updateOfPSASucceeded(""));
|
||||
|
||||
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
|
||||
|
||||
setProgress(100);
|
||||
m_ismasClient.setProgressInPercent(100);
|
||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
|
||||
|
||||
m_returnCode = 0;
|
||||
}
|
||||
} else {
|
||||
qCritical() << "CHECKOUT BRANCH...";
|
||||
// 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, ""));
|
||||
stopProgressLoop();
|
||||
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
|
||||
qCritical() << "CHECKED OUT BRANCH";
|
||||
if (backendConnected()) { qCritical() << "BACKEND CONNECTED";
|
||||
progress = 20;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (updateTriggerSet()) { qCritical() << "UPDATE TRIGGER SET";
|
||||
progress = 30;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (customerEnvironment()) { qCritical() << "CUSTOMER ENVIRONMENT";
|
||||
progress = 40;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (filesToUpdate()) { qCritical() << "FILES TO UPDATE";
|
||||
progress = 50;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (updateFiles(progress)) { qCritical() << "UPDATE FILES";
|
||||
progress = 60;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (syncCustomerRepositoryAndFS()) { qCritical() << "SYNC REPOSITORY";
|
||||
progress = 70;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
if (sendIsmasLastVersionNotification()) { qCritical() << "SEND LAST NOTIFICATION";
|
||||
progress = 80;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL);
|
||||
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_FAILURE,
|
||||
QString("CLONE OR CHECKOUT FAILED: ") + m_customerRepository);
|
||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription));
|
||||
|
||||
m_returnCode = -3;
|
||||
}
|
||||
} else {
|
||||
qInfo() << "CHECKOUT BRANCH...";
|
||||
emit appendText("\nInitializing customer environment ...");
|
||||
startProgressLoop();
|
||||
if (m_gc.gitCheckoutBranch()) {
|
||||
stopProgressLoop();
|
||||
emit replaceLast("Initializing customer environment ...", UPDATE_STEP_DONE);
|
||||
setProgress(100);
|
||||
|
||||
m_ismasClient.setProgressInPercent(10);
|
||||
//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, ""));
|
||||
|
||||
qInfo() << "CHECKED OUT BRANCH";
|
||||
if (backendConnected()) {
|
||||
m_ismasClient.setProgressInPercent(20);
|
||||
if (updateTriggerSet()) {
|
||||
m_ismasClient.setProgressInPercent(30);
|
||||
if (customerEnvironment()) {
|
||||
m_ismasClient.setProgressInPercent(40);
|
||||
if (filesToUpdate()) {
|
||||
m_ismasClient.setProgressInPercent(50);
|
||||
if (updateFiles(50)) {
|
||||
m_ismasClient.setProgressInPercent(60);
|
||||
if (syncCustomerRepositoryAndFS()) {
|
||||
m_ismasClient.setProgressInPercent(70);
|
||||
if (sendIsmasLastVersionNotification()) {
|
||||
m_ismasClient.setProgressInPercent(80);
|
||||
sentIsmasLastVersionNotification = true;
|
||||
if (saveLogFile()) { qCritical() << "SAVE LOG FILE";
|
||||
progress = 90;
|
||||
setProgress(progress);
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
emit appendText(QString("Update process "), UPDATE_STEP_SUCCESS);
|
||||
if (saveLogFile()) {
|
||||
m_ismasClient.setProgressInPercent(90);
|
||||
|
||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.updateOfPSASucceeded(""));
|
||||
|
||||
// mark update as activated -> this resets the WAIT button
|
||||
progress = 100;
|
||||
setProgress(progress);
|
||||
|
||||
m_ismasClient.setProgressInPercent(progress);
|
||||
m_ismasClient.setProgressInPercent(95);
|
||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.updateOfPSAActivated());
|
||||
|
||||
m_returnCode = 0;
|
||||
} else {
|
||||
m_returnCode = -12;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -11;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -10;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -9;
|
||||
}
|
||||
@ -276,18 +278,8 @@ void Worker::privateUpdate() {
|
||||
} else {
|
||||
m_returnCode = -4;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -3;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -2;
|
||||
}
|
||||
} else {
|
||||
m_returnCode = -1;
|
||||
}
|
||||
}
|
||||
|
||||
setProgress(100);
|
||||
m_ismasClient.setProgressInPercent(100);
|
||||
|
||||
if (!sentIsmasLastVersionNotification) {
|
||||
@ -296,37 +288,54 @@ void Worker::privateUpdate() {
|
||||
}
|
||||
|
||||
if (m_returnCode != 0) {
|
||||
emit appendText(QString("Update process "), UPDATE_STEP_FAIL);
|
||||
stopProgressLoop();
|
||||
emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL);
|
||||
} else {
|
||||
emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS);
|
||||
}
|
||||
|
||||
setProgress(100);
|
||||
m_updateProcessRunning = false;
|
||||
emit enableExit();
|
||||
emit restartExitTimer();
|
||||
}
|
||||
|
||||
bool Worker::backendConnected() {
|
||||
static int repeat = 0;
|
||||
if (m_withoutIsmasDirectPort) { // useful for testing
|
||||
return true;
|
||||
}
|
||||
|
||||
if (repeat < 3) {
|
||||
qCritical() << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
|
||||
emit appendText("\nConnecting backend ...");
|
||||
|
||||
for (int repeat = 0; repeat < 50; ++repeat) {
|
||||
qInfo() << "REPEAT" << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
|
||||
startProgressLoop();
|
||||
std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}");
|
||||
if (result) {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
|
||||
QString msg = result.value();
|
||||
qCritical() << "In backendConnected() -> APISM response" << msg;
|
||||
qInfo() << "In backendConnected() -> APISM response" << msg;
|
||||
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 replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
if (!document.isObject()) {
|
||||
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
||||
emit replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
||||
setProgress(progress + 1);
|
||||
|
||||
QJsonObject obj = document.object();
|
||||
QStringList keys = obj.keys();
|
||||
for (QString const& key : keys ) {
|
||||
@ -336,30 +345,36 @@ bool Worker::backendConnected() {
|
||||
obj = v.toObject();
|
||||
bool ismas = obj.value("ISMAS").toBool();
|
||||
QString status = obj.value("Broker").toString();
|
||||
|
||||
qCritical() << "In backendConnected() STATUS" << status;
|
||||
|
||||
qInfo() << "REPEAT" << repeat << "In backendConnected() Broker=<"
|
||||
<< status << ">, ISMAS=<" << (ismas ? "true>" : "false>");
|
||||
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);
|
||||
setProgress(100);
|
||||
emit replaceLast("Connecting backend ...", UPDATE_STEP_OK);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (status.startsWith("Connecting") || status.startsWith("Re-Connecting")) {
|
||||
QThread::sleep(1);
|
||||
++repeat;
|
||||
return backendConnected();
|
||||
emit showErrorMessage("Check backend connection",
|
||||
QString ("REPEAT %1 Broker=<").arg(repeat)
|
||||
+ status + ">, ISMAS=<" + (ismas ? "true>" : "false>"));
|
||||
QThread::sleep(6);
|
||||
continue;
|
||||
}
|
||||
emit appendText("\nBackend connected", UPDATE_STEP_FAIL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
setProgress(100);
|
||||
|
||||
emit replaceLast("Connecting backend", UPDATE_STEP_FAIL);
|
||||
emit showErrorMessage("Error", "Backend not available");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qCritical() << "In backendConnected() ERROR";
|
||||
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_NOT_CONNECTED,
|
||||
QString("NO BACKEND CONNECTION"));
|
||||
@ -371,18 +386,26 @@ bool Worker::backendConnected() {
|
||||
}
|
||||
|
||||
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
|
||||
if (m_withoutIsmasDirectPort) { // useful for testing
|
||||
return true;
|
||||
}
|
||||
|
||||
emit appendText("\nUpdate trigger set ...");
|
||||
QString triggerValue("");
|
||||
|
||||
for (int repeat = 0; repeat < 50; ++repeat) {
|
||||
startProgressLoop();
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
|
||||
QString msg = result.value();
|
||||
|
||||
qInfo() << "REPEAT" << repeat << "APISM RESPONSE" << msg;
|
||||
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
@ -390,17 +413,23 @@ bool Worker::updateTriggerSet() {
|
||||
<< parseError.error << parseError.errorString();
|
||||
emit showErrorMessage("check update trigger",
|
||||
QString("invalid json ") + msg.mid(0, 20));
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
if (!document.isObject()) {
|
||||
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
||||
emit showErrorMessage("check update trigger",
|
||||
QString("not a json object") + msg);
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
||||
setProgress(progress + 1);
|
||||
|
||||
QJsonObject obj = document.object();
|
||||
// sanity check: cust_nr and machine_nr of PSA correct ?
|
||||
// note: this check has to be done here, as the cust_nr and the machine_nr
|
||||
// of the PSA are sent by ISMAS.
|
||||
if (obj.contains("Dev_ID")) {
|
||||
QJsonValue v = obj.value("Dev_ID");
|
||||
if (v.isObject()) {
|
||||
@ -420,9 +449,11 @@ bool Worker::updateTriggerSet() {
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
m_updateStatus.m_statusDescription));
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
if (machineNr != m_machineNr) {
|
||||
setProgress(100);
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
|
||||
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
|
||||
.arg(machineNr).arg(m_machineNr));
|
||||
@ -432,11 +463,15 @@ bool Worker::updateTriggerSet() {
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
m_updateStatus.m_statusDescription));
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setProgress(progress + 1);
|
||||
|
||||
if (obj.contains("Fileupload")) {
|
||||
QJsonValue v = obj.value("Fileupload");
|
||||
if (v.isObject()) {
|
||||
@ -445,9 +480,13 @@ bool Worker::updateTriggerSet() {
|
||||
v = obj.value("TRG");
|
||||
if (v.isString()) {
|
||||
triggerValue = v.toString();
|
||||
if (triggerValue == "WAIT") {
|
||||
emit appendText("\nUpdate trigger set", UPDATE_STEP_OK);
|
||||
|
||||
qInfo() << "REPEAT" << repeat
|
||||
<< "In updateTriggerSet() TRG value=<"
|
||||
<< triggerValue << ">";
|
||||
|
||||
if (triggerValue == "WAIT") {
|
||||
setProgress(100);
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
|
||||
QString("UPDATE TRIGGER SET. CONTINUE. "));
|
||||
|
||||
@ -455,11 +494,14 @@ bool Worker::updateTriggerSet() {
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, ""));
|
||||
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
|
||||
return true;
|
||||
} else {
|
||||
emit showErrorMessage("check update trigger",
|
||||
QString ("TRG key=<") + triggerValue
|
||||
QString ("TRG value=<") + triggerValue
|
||||
+ ">\n(reset download button?)");
|
||||
QThread::sleep(6);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -469,76 +511,158 @@ bool Worker::updateTriggerSet() {
|
||||
emit showErrorMessage("check update trigger", "Fileupload not a json-object");
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("error")) {
|
||||
QString value = obj.value("error").toString();
|
||||
emit showErrorMessage("check update trigger", QString("REPEAT %1 error=<").arg(repeat) + value + ">");
|
||||
qInfo() << "REPEAT" << repeat << "In updateTriggerSet() error=<"
|
||||
<< value << ">";
|
||||
}
|
||||
} else {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
emit showErrorMessage("check update trigger", "no ISMAS response");
|
||||
QThread::sleep(6);
|
||||
}
|
||||
}
|
||||
|
||||
setProgress(100);
|
||||
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, ""));
|
||||
|
||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Worker::customerEnvironment() {
|
||||
emit appendText("\nPrepare customer environment ...");
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
startProgressLoop();
|
||||
if (m_gc.gitCheckoutBranch()) {
|
||||
emit appendText("\nPrepare customer environment", UPDATE_STEP_DONE);
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(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, ""));
|
||||
|
||||
setProgress(100);
|
||||
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_DONE);
|
||||
qInfo() << "PREPARE CUSTOMER ENVIRONMENT DONE";
|
||||
return true;
|
||||
} else {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
emit showErrorMessage("cust-env",
|
||||
QString("Checkout ") + m_customerRepository + " failed");
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "CHECKOUT OF" << m_customerRepository << "FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
} else {
|
||||
emit showErrorMessage("cust-env", m_customerRepository + " does not exist");
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << m_customerRepository << "DOES NOT EXIST";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
|
||||
setProgress(100);
|
||||
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Worker::filesToUpdate() {
|
||||
emit appendText("\nFetch changes files ...");
|
||||
startProgressLoop();
|
||||
if (std::optional<QString> changes = m_gc.gitFetch()) {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress);
|
||||
|
||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES,
|
||||
QString("FETCHING OF ") + m_customerRepositoryPath +
|
||||
QString(" INTO ") + m_customerRepository);
|
||||
|
||||
setProgress(progress + 10);
|
||||
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) {
|
||||
setProgress(progress + 20);
|
||||
if (m_gc.gitPull()) {
|
||||
emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_DONE);
|
||||
m_filesToUpdate = changedFileNames.value();
|
||||
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "FILES-TO-UPDATE" << m_filesToUpdate;
|
||||
qInfo() << QString(80, '*');
|
||||
|
||||
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);
|
||||
emit appendText(QString("Found %1 files to update :").arg(size), UPDATE_STEP_DONE);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
emit appendText(QString("\n ") + m_filesToUpdate.at(i));
|
||||
}
|
||||
} else {
|
||||
emit appendText("Found 1 file to update :", UPDATE_STEP_DONE);
|
||||
emit appendText(QString("\n ") + m_filesToUpdate.at(0));
|
||||
}
|
||||
if (m_gc.gitPull()) {
|
||||
emit appendText(QString("\nFetch changes files "), UPDATE_STEP_DONE);
|
||||
return true;
|
||||
}
|
||||
emit showErrorMessage("files to update", "pulling files failed");
|
||||
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "PULLING FILES FAILED";
|
||||
qCritical() << QString(80, '*');
|
||||
|
||||
} else {
|
||||
emit showErrorMessage("files to update", "no files to update (checked-in any files?)");
|
||||
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "NO FILES TO UPDATE (CHECKED IN ANY FILES?)";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
setProgress(progress + 30);
|
||||
} else {
|
||||
stopProgressLoop();
|
||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||
setProgress(progress + 30);
|
||||
|
||||
emit showErrorMessage("files to update",
|
||||
QString("no changes in ") + m_customerRepository +
|
||||
" (checked-in any files?)");
|
||||
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "NO CHANGES IN" << m_customerRepository << "(CHECKED IN ANY FILES?)";
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
|
||||
emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_FAIL);
|
||||
setProgress(100);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Worker::updateFiles(quint8 percent) {
|
||||
QStringList filesToDownload;
|
||||
m_displayIndex = 0;
|
||||
|
||||
startProgressLoop();
|
||||
for (int i = 0; i < m_filesToUpdate.size(); ++i) {
|
||||
QString fName = m_filesToUpdate.at(i);
|
||||
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "FNAME" << fName;
|
||||
qInfo() << QString(80, '*');
|
||||
|
||||
if (fName.contains("opkg_commands", Qt::CaseInsensitive)) {
|
||||
emit appendText("\n( ) Update opkg pakets ...");
|
||||
// execute opkg commands
|
||||
if (QDir::setCurrent(m_customerRepository)) {
|
||||
QFile f(fName);
|
||||
@ -566,8 +690,12 @@ bool Worker::updateFiles(quint8 percent) {
|
||||
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);
|
||||
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
|
||||
+ QString(" Update opkg pakets ... "), UPDATE_STEP_DONE);
|
||||
} else {
|
||||
m_displayIndex = 1;
|
||||
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
|
||||
+ QString(" Update opkg pakets ... "), UPDATE_STEP_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -575,22 +703,39 @@ bool Worker::updateFiles(quint8 percent) {
|
||||
} else
|
||||
if (fName.contains("print", Qt::CaseInsensitive)) {
|
||||
filesToDownload << fName; // download printer-config-files
|
||||
} else
|
||||
if (fName == "dc2c.bin") {
|
||||
} else {
|
||||
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
|
||||
if (fName.contains(version)) {
|
||||
filesToDownload << fName; // download device controller
|
||||
}
|
||||
}
|
||||
|
||||
if (filesToDownload.size() > 0) {
|
||||
qCritical() << "FILES_TO_WORK_ON" << filesToDownload;
|
||||
}
|
||||
|
||||
return m_update->doUpdate(m_displayIndex, filesToDownload);
|
||||
stopProgressLoop();
|
||||
setProgress(100);
|
||||
bool ret = true;
|
||||
|
||||
if (filesToDownload.size() > 0) {
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "FILES_TO_WORK_ON" << filesToDownload;
|
||||
qInfo() << QString(80, '*');
|
||||
ret = m_update->doUpdate(m_displayIndex, filesToDownload);
|
||||
} else {
|
||||
qInfo() << QString(80, '*');
|
||||
qInfo() << "NO FILES_TO_WORK_ON";
|
||||
qInfo() << QString(80, '*');
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Worker::syncCustomerRepositoryAndFS() {
|
||||
setProgress(0);
|
||||
emit appendText("\nSync customer environment with filesystem ...");
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
if (QDir::setCurrent(m_customerRepository)) {
|
||||
int progress = 10;
|
||||
setProgress(progress);
|
||||
QString const params("-vv "
|
||||
"--recursive "
|
||||
"--progress "
|
||||
@ -607,29 +752,37 @@ bool Worker::syncCustomerRepositoryAndFS() {
|
||||
QString cmd;
|
||||
bool error = false;
|
||||
foreach (cmd, cmds) {
|
||||
progress += 5;
|
||||
setProgress(progress);
|
||||
if (!error) {
|
||||
Command c("bash");
|
||||
qInfo() << "EXECUTING CMD..." << cmd;
|
||||
if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) {
|
||||
QStringList result = c.getCommandResult().split('\n');
|
||||
for (int i = 0; i < result.size(); ++i) {
|
||||
qCritical() << result.at(i);
|
||||
qInfo() << result.at(i);
|
||||
}
|
||||
qCritical() << "SUCCESS";
|
||||
qInfo() << "SUCCESS";
|
||||
} else {
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << "CMD" << cmd << "FAILED";
|
||||
qCritical() << c.getCommandResult().split('\n');
|
||||
qCritical() << QString(80, '*');
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
progress += 5;
|
||||
setProgress(progress);
|
||||
if (!error) {
|
||||
emit appendText(QString("\nSync customer environment with filesystem "),
|
||||
UPDATE_STEP_DONE);
|
||||
setProgress(100);
|
||||
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
setProgress(100);
|
||||
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -637,7 +790,7 @@ 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);
|
||||
emit appendText(QString("Send last version info "), UPDATE_STEP_DONE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -736,9 +889,11 @@ bool Worker::executeOpkgCommand(QString opkgCommand) {
|
||||
.arg(c.getCommandResult()));
|
||||
return true;
|
||||
} else {
|
||||
qCritical() << QString(80, '*');
|
||||
qCritical() << UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE,
|
||||
QString("EXECUTE OPKG COMMAND %1 FAILED")
|
||||
.arg(opkgCommand));
|
||||
qCritical() << QString(80, '*');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
5
worker.h
5
worker.h
@ -127,6 +127,7 @@ class Worker : public QObject {
|
||||
|
||||
MainWindow *m_mainWindow;
|
||||
int m_progressValue;
|
||||
bool m_withoutIsmasDirectPort;
|
||||
|
||||
bool executeOpkgCommand(QString opkgCommand);
|
||||
QString getOsVersion() const;
|
||||
@ -159,6 +160,8 @@ public:
|
||||
|
||||
void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; }
|
||||
void setProgress(int progress);
|
||||
void startProgressLoop();
|
||||
void stopProgressLoop();
|
||||
|
||||
IsmasClient &getIsmasClient() { return m_ismasClient; }
|
||||
IsmasClient const &getIsmasClient() const { return m_ismasClient; }
|
||||
@ -205,8 +208,6 @@ private:
|
||||
PSAInstalled getPSAInstalled();
|
||||
QString sendCmdSendVersionToIsmas();
|
||||
void privateUpdate();
|
||||
void startProgressLoop();
|
||||
void stopProgressLoop();
|
||||
};
|
||||
|
||||
#endif // WORKER_H_INCLUDED
|
||||
|
Loading…
x
Reference in New Issue
Block a user