66 Commits

Author SHA1 Message Date
769626581f Use head -n 1 in gitLastCommit(). 2023-08-11 11:12:59 +02:00
0e97ce7dc2 Take the pipe symbol into account in output of git getch command. 2023-08-11 11:12:09 +02:00
34334676fc Use print-utis from utils.h. 2023-08-11 11:11:14 +02:00
853787cd4b Added lastCommit to tariff-struct. Added jsonParseFailed(). 2023-08-11 11:09:51 +02:00
a932ed5471 Hide button on error message box. 2023-08-11 11:07:16 +02:00
c338884fc7 Use print-util in utils.h. 2023-08-11 11:06:38 +02:00
ed6df98653 Set progress bar timer to 500ms.
Yield thread to give worker thread its share of CPU time.
2023-08-11 11:05:33 +02:00
9eb458c4c5 Start Application after 1 second delay. 2023-08-11 11:05:02 +02:00
202e83268b Added utilities
void printCriticalErrorMsg(QString const &errorMsg);
    void printInfoMsg(QString const &infoMsg);
    void printLineEditInfo(QStringList const &lines);
    QString getTariffLoadTime(QString fileName);
2023-08-11 11:03:21 +02:00
8f26bfee0f Get last commit date and loadtime of tariff-file. 2023-08-11 11:02:15 +02:00
1af136e39d Set delay when trying to fetch value of update-trigger. 2023-08-11 11:01:26 +02:00
a550d55004 Get triggerValue directly from JSON. 2023-08-11 11:00:52 +02:00
a37a22d3f9 Show message boxes when running UpdateTool manually. 2023-08-11 11:00:02 +02:00
a8941f4ef4 Set progress values. 2023-08-11 10:59:26 +02:00
746565dbe0 Add messages sent to ISMAS. 2023-08-11 10:58:29 +02:00
79906df12e Add some qt debug aoutput. 2023-08-11 10:56:36 +02:00
edf1d105e7 Deactivate backendConnected(). 2023-08-11 10:55:53 +02:00
6c4b02cb56 Use print-utils to print some debug messages. 2023-08-11 10:52:31 +02:00
04d5061d79 Added some constants. 2023-08-11 10:49:34 +02:00
042e6dfa38 Try to establish a connection to backend 50x. 2023-08-09 16:17:28 +02:00
e523d3cc2c Added/chenged some debug output. 2023-08-09 16:16:36 +02:00
927197d0d1 Removed restart of APISM. 2023-08-09 16:14:59 +02:00
72cb738af5 Removed handling of pipe symbol (if available in git output). 2023-08-09 16:12:56 +02:00
0fb38013f7 Work with device controller file directly, not via link.
Add startProgress/stopProgress().
2023-08-09 15:09:44 +02:00
5f1376cf1e Removed buttons reserved for future use.
Start application automatically, not via Start-Button.
2023-08-09 15:08:22 +02:00
5db7b4224e Made start/stopProgress() public. 2023-08-09 15:06:20 +02:00
7c7adc94e6 Removed Start-button, because it is not needed.
Removed buttons reserved for future use.
2023-08-09 15:05:04 +02:00
89c2d3a8ae Added some debug output. 2023-08-09 15:03:14 +02:00
c2b52aa91d Only check for keyword RECORD to be more general. 2023-08-09 15:01:43 +02:00
329c770aa0 Use a message box with color red and a timer to click on ok after 5 secs. 2023-08-07 14:01:51 +02:00
cdb045b72b Fixed onAppendText() and onReplaceLast():
Watch out for special suffixes.
2023-08-07 13:59:44 +02:00
6d43cf4c9f Send custom events to the progress bar according to the state of the update process.
Changed the handling of messages for the text edit.
2023-08-07 13:56:51 +02:00
4caa0c0d83 Removed obsolete out-commented lines. 2023-08-07 13:55:52 +02:00
4d2d38e45c Default parameter for onReplaceLast() 2023-08-07 13:53:48 +02:00
9a55ce18e4 Chawnged font to Misc Fixed 2023-08-07 13:53:04 +02:00
223c7a8f8d Added errorGitClone(). 2023-08-07 13:51:47 +02:00
ce72d3d14d For the error EWOULDBLOCK try again 10 times until quitting. 2023-08-07 13:50:59 +02:00
8b66c47e49 Added errorGitClone() 2023-08-07 13:50:14 +02:00
4ff3b0efdf Advance the progress bar in the foreground when a long running task
in the background (e.g. git clone).
2023-08-06 20:44:26 +02:00
1fd2269753 onAppendText() only appends text.
onReplaceLast() replaces the last line in the text edit window.
2023-08-06 14:14:47 +02:00
a8994423f4 Change font size for full screen window. 2023-08-06 14:11:41 +02:00
4594c913e0 Using syslog for debugging. 2023-08-06 07:34:17 +02:00
cf9033e898 Send custom event from worker(-thread) to MainWindow in order to update
progress bar.
2023-08-05 18:50:50 +02:00
b09ccfd4f5 Add custom ProgressEvent class for future use. 2023-08-04 14:10:47 +02:00
6b4c486549 Add m_ismasClient.updateOfPSASucceeded() for a successful run. 2023-08-04 13:53:55 +02:00
9c44656104 Add parameter -vv fot the rsync command to see more debugoutput. 2023-08-04 13:52:57 +02:00
d57914957d Add text-edit entry if git pull is successful. 2023-08-04 13:50:19 +02:00
c4f12ce75a Added terminal-debug-output. 2023-08-04 13:49:32 +02:00
4ad370ea46 Extended displayed messages in text-edit. 2023-08-04 13:48:40 +02:00
44ad3caf2b Stop exit timer in onQuit.
Activate error message boxes.
2023-08-04 13:45:56 +02:00
427a272f8f Connect exit-button with clicked(). 2023-08-04 13:45:19 +02:00
96fb50e68d Moved init. of text-edit upwards.
Hide reserved buttons.
2023-08-04 13:44:16 +02:00
19274546c9 set main window fullscreen 2023-08-04 13:39:17 +02:00
d2d730589b changed return type of returnCode() ti 'int' 2023-08-04 13:38:33 +02:00
f88b0edb2a Fix for the case when several branches are edited: 'git fetch' will
display several lines then, not only one.
2023-08-04 13:35:42 +02:00
c62299aa72 Read from /mnt/system_data/ instead of /etc. 2023-08-04 13:33:25 +02:00
c054668eac Ask for the reurn code of the process, not only for process exit status. 2023-08-04 13:31:12 +02:00
82352713f1 Added 6 more buttons for future use and for the fullscreen layout. 2023-08-04 13:30:18 +02:00
48073ab1f0 update to next version 2023-08-03 10:14:23 +02:00
c6e98f50c2 call onQuit() directly whem timer runs out 2023-08-03 10:14:09 +02:00
ef88fdc9a4 Fix: config for deployment 2023-08-03 09:50:26 +02:00
8889aaca2a Fix: path for deployment 2023-08-03 09:44:08 +02:00
9b08420ac1 Use exit() instead of quit() to be able to add a returnCode in case of failure. 2023-08-03 09:06:50 +02:00
0ee92f0181 disbale exit-button as long as update process is running 2023-08-02 17:51:35 +02:00
a995cae000 set exit timer to 10 secs 2023-08-02 16:54:47 +02:00
0b7d504a7a Fixed missing git pull command.
Fixed missing update for text-edit when only clone the customer repository.
2023-08-02 16:53:19 +02:00
19 changed files with 1227 additions and 467 deletions

View File

@@ -77,6 +77,7 @@ contains( CONFIG, DesktopLinux ) {
SOURCES += \ SOURCES += \
main.cpp \ main.cpp \
progress_event.cpp \
mainwindow.cpp \ mainwindow.cpp \
utils.cpp \ utils.cpp \
update.cpp \ update.cpp \
@@ -89,6 +90,7 @@ SOURCES += \
HEADERS += \ HEADERS += \
update.h \ update.h \
progress_event.h \
utils.h \ utils.h \
mainwindow.h \ mainwindow.h \
git/git_client.h \ git/git_client.h \
@@ -114,7 +116,12 @@ OTHER_FILES += \
# git subtree pull --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash # git subtree pull --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash
# include(./DCPlugin/DCPlugin.pri) # include(./DCPlugin/DCPlugin.pri)
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin ##########################################################################################
!isEmpty(target.path): INSTALLS += target # for running program on target through QtCreator
contains( CONFIG, PTU5 ) {
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/app/tools/atbupdate/
!isEmpty(target.path): INSTALLS += target
}

View File

@@ -48,8 +48,7 @@ bool GitClient::gitCloneCustomerRepository() {
} }
} }
} }
qCritical() << "ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=" Utils::printCriticalErrorMsg(QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=") + result);
<< result;
} }
return false; return false;
} }
@@ -86,7 +85,7 @@ bool GitClient::gitCheckoutBranch() {
// TODO: nachsehen, ob der Branch ueberhaupt existiert // TODO: nachsehen, ob der Branch ueberhaupt existiert
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr"); int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
m_branchName = (zoneNr != 0) m_branchName = (zoneNr != 0)
? QString("zg1/zone%1").arg(zoneNr) : "master"; ? QString("zg1/zone%1").arg(zoneNr) : "master";
@@ -96,7 +95,7 @@ bool GitClient::gitCheckoutBranch() {
Command c(gitCommand); Command c(gitCommand);
return c.execute(m_customerRepository); // execute command in customerRepo return c.execute(m_customerRepository); // execute command in customerRepo
} }
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST"; Utils::printCriticalErrorMsg(QString("ERROR ") + m_customerRepository + " DOES NOT EXIST");
return false; return false;
} }
@@ -108,13 +107,10 @@ bool GitClient::gitCloneAndCheckoutBranch() {
return true; return true;
} else { } else {
// TODO // TODO
// m_worker->terminateUpdateProcess();
} }
//} //}
} else {
// TODO
//m_worker->terminateUpdateProcess();
} }
Utils::printCriticalErrorMsg(QString("CLONE ") + m_repositoryPath + " AND CHECKOUT FAILED");
return false; return false;
} }
@@ -131,24 +127,37 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
Command c(gitCommand); Command c(gitCommand);
if (c.execute(m_customerRepository)) { // execute command in local customerRepo if (c.execute(m_customerRepository)) { // execute command in local customerRepo
QString s = c.getCommandResult().trimmed(); QString s = c.getCommandResult().trimmed();
Utils::printInfoMsg("GIT DIFF RESULT " + s);
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
QStringList fileNames; QStringList fileNames;
// each line has the format "etc/psa_config/DC2C_print01.json | 1 + // each line has the format "etc/psa_config/DC2C_print01.json | 1 +
// or the format "etc/psa_config/DC2C_print01.json (new) | 1 + // or the format "etc/psa_config/DC2C_print01.json (new) | 1 +
// the filenames are relativ to the repository // the filenames are relativ to the repository
for (int i = 0; i < lines.size(); ++i) { for (int i = 0; i < lines.size(); ++i) {
// TODO: koennte auch (delete) kommen ? QString const &line = lines.at(i);
int newIndex = lines.at(i).indexOf("(new)"); // for new files int newIndex = line.indexOf("(new"); // for new files
// int goneIndex = lines.at(i).indexOf("(gone)"); // for removed files int goneIndex = line.indexOf("(gone"); // for removed files
int modeIndex = line.indexOf("(mode");
int pipeIndex = line.indexOf('|');
if (newIndex != -1) { if (newIndex != -1) {
QString fileName = lines.at(i).mid(0, newIndex).trimmed(); QString file = line.left(newIndex).trimmed();
fileNames << fileName; qInfo() << "FILE (NEW)" << file;
} else { fileNames << file;
int pipeIndex = lines.at(i).indexOf('|'); } else
if (modeIndex != -1) {
QString const file = line.left(modeIndex).trimmed();
qInfo() << "FILE (MODE)" << file;
fileNames << file;
} else
if (goneIndex != -1) {
QString const file = line.left(goneIndex).trimmed();
qCritical() << "FILE (GONE)" << file;
} else
if (pipeIndex != -1) { if (pipeIndex != -1) {
QString fileName = lines.at(i).mid(0, pipeIndex).trimmed(); QString const file = line.left(pipeIndex).trimmed();
fileNames << fileName; qInfo() << "FILE (PIPE)" << file;
} fileNames << file;
} }
} }
if (!fileNames.isEmpty()) { if (!fileNames.isEmpty()) {
@@ -164,14 +173,7 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
*/ */
std::optional<QString> GitClient::gitFetch() { std::optional<QString> GitClient::gitFetch() {
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
qInfo() << "BRANCH NAME" << m_branchName;
// TODO
UpdateStatus status (UPDATE_STATUS::GIT_FETCH_UPDATES, "GIT FETCH UPDATES");
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT FETCH UPDATES", status.m_statusDescription));
Command c("git fetch"); Command c("git fetch");
if (c.execute(m_customerRepository)) { if (c.execute(m_customerRepository)) {
@@ -179,36 +181,54 @@ std::optional<QString> GitClient::gitFetch() {
if (!s.isEmpty()) { if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
if (!lines.empty()) { if (!lines.empty()) {
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
// lines can look like this:
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
// 41ec581..5d25ac3 master -> origin/master
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
bool found = false;
for (int i=0; i < lines.size(); ++i) {
if (lines.at(i).contains(m_branchName)) {
found = true;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
QRegularExpressionMatch match = re.match(lines.last()); QRegularExpressionMatch match = re.match(lines.at(i));
if (match.hasMatch()) { if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
// TODO
status = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString("GIT SUCCESSFULLY FETCHED ") + m_customerRepository);
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT_FETCH_UPDATES SUCCESS", status.m_statusDescription));
return match.captured(2); return match.captured(2);
} else { } else {
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount(); emit m_worker->showErrorMessage("git fetch",
QString("(wrong cap-count (%1)").arg(re.captureCount()));
} }
} else { } else {
qCritical() << "ERROR NO MATCH OF COMMITS FOR 'GIT FETCH'"; emit m_worker->showErrorMessage("git fetch",
"no regex-match for commits");
Utils::printCriticalErrorMsg("NO REGEX MATCH FOR COMMITS");
}
}
}
if (!found) {
emit m_worker->showErrorMessage("git fetch",
QString("unkown branch name ") + m_branchName);
Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName);
} }
} else { } else {
qCritical() << "ERROR WRONG FORMAT FOR RESULT FOR 'GIT FETCH'" << s; emit m_worker->showErrorMessage("git fetch",
QString("wrong format for result of 'git fetch' ") + s);
Utils::printCriticalErrorMsg(QString("WRONG FORMAT FOR RESULT OF 'GIT FETCH' ") + s);
} }
} else { } else {
qCritical() << "ERROR EMPTY RESULT FROM 'GIT FETCH'"; emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'");
Utils::printCriticalErrorMsg("EMPTY RESULT FOR 'GIT FETCH'");
} }
} }
} else { } else {
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST"; emit m_worker->showErrorMessage("git fetch", QString("repository ") + m_customerRepository + " does not exist");
Utils::printCriticalErrorMsg(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST");
} }
return std::nullopt; return std::nullopt;
} }
@@ -229,7 +249,7 @@ bool GitClient::gitPull() {
qInfo() << "PULLED INTO" << m_customerRepository; qInfo() << "PULLED INTO" << m_customerRepository;
return true; return true;
} }
qCritical() << "PULL INTO" << m_customerRepository << "FAILED"; Utils::printCriticalErrorMsg(QString("PULL INTO " + m_customerRepository + " FAILED"));
} }
return false; return false;
} }
@@ -248,6 +268,7 @@ QString GitClient::gitLastCommit(QString fileName) {
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
QString const filePath QString const filePath
= QDir::cleanPath(m_customerRepository + QDir::separator() + fileName); = QDir::cleanPath(m_customerRepository + QDir::separator() + fileName);
if (QFile(filePath).exists()) {
QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName); QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName);
Command c("bash"); Command c("bash");
if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) { if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) {
@@ -258,6 +279,7 @@ QString GitClient::gitLastCommit(QString fileName) {
} }
} }
} }
}
return ""; return "";
} }

View File

@@ -148,6 +148,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
int const bytesToWrite = strlen(request.toStdString().c_str()); int const bytesToWrite = strlen(request.toStdString().c_str());
strncpy(buf, request.toStdString().c_str(), sizeof(buf)-1); strncpy(buf, request.toStdString().c_str(), sizeof(buf)-1);
int loop = 0;
int bytesWritten = 0; int bytesWritten = 0;
while (bytesWritten < bytesToWrite) { while (bytesWritten < bytesToWrite) {
int n = ::sendto(sockfd, buf+bytesWritten, bytesToWrite-bytesWritten, 0, NULL, 0); int n = ::sendto(sockfd, buf+bytesWritten, bytesToWrite-bytesWritten, 0, NULL, 0);
@@ -155,14 +156,18 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
bytesWritten += n; bytesWritten += n;
} else { } else {
if (errno == EWOULDBLOCK) { if (errno == EWOULDBLOCK) {
if (++loop < 10) {
QThread::msleep(500);
continue;
}
printErrorMessage(port, clientIP, clientPort, printErrorMessage(port, clientIP, clientPort,
QString("TIMEOUT (") + strerror(errno) + ")"); QString("WRITE TIMEOUT %1(").arg(loop) + strerror(errno) + ")");
::close(sockfd); ::close(sockfd);
return std::nullopt; return std::nullopt;
} else } else
if (errno == EINTR) { if (errno == EINTR) {
printErrorMessage(port, clientIP, clientPort, printErrorMessage(port, clientIP, clientPort,
QString("INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")"); QString("WRITE INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")");
continue; continue;
} }
} }
@@ -177,6 +182,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT ") + buf); printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT ") + buf);
loop = 0;
bzero(buf, sizeof(buf)); bzero(buf, sizeof(buf));
int bytesToRead = sizeof(buf)-1; int bytesToRead = sizeof(buf)-1;
int bytesRead = 0; int bytesRead = 0;
@@ -196,8 +202,12 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
} else } else
if (n < 0) { if (n < 0) {
if (errno == EWOULDBLOCK) { if (errno == EWOULDBLOCK) {
if (++loop < 10) {
QThread::msleep(500);
continue;
}
printErrorMessage(port, clientIP, clientPort, printErrorMessage(port, clientIP, clientPort,
QString("TIMEOUT (") + strerror(errno) + ")"); QString("READ TIMEOUT %1(").arg(loop) + strerror(errno) + ")");
::close(sockfd); ::close(sockfd);
return std::nullopt; return std::nullopt;
} }
@@ -214,8 +224,8 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) { if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) {
response = response.mid(0, idx); response = response.mid(0, idx);
} else } else
if (response == "RECORD SAVED") { if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
printInfoMessage(port, clientIP, clientPort, "IGNORED 'RECORD SAVED' RESPONSE"); printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
::close(sockfd); ::close(sockfd);
return std::nullopt; return std::nullopt;
} }
@@ -283,6 +293,15 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
version.toStdString().c_str()); 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) { QString IsmasClient::backendConnected(QString const &info, QString const &version) {
return updateNewsToIsmas("U0010", return updateNewsToIsmas("U0010",
m_progressInPercent, m_progressInPercent,
@@ -734,11 +753,21 @@ QString IsmasClient::sanityCheckFailed(int resultCode, QString reason, QString c
version.toStdString().c_str()); version.toStdString().c_str());
} }
QString IsmasClient::updateOfPSAFailed(int resultCode, QString reason, QString const &version) { QString IsmasClient::jsonParseFailed(int resultCode, QString reason, QString const &version) {
return updateNewsToIsmas("U0003", return updateNewsToIsmas("U0003",
m_progressInPercent, m_progressInPercent,
resultCode, resultCode,
"UPDATE ERROR", "JSON-PARSE-ERROR",
reason.toStdString().c_str(),
version.toStdString().c_str());
}
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(), reason.toStdString().c_str(),
version.toStdString().c_str()); version.toStdString().c_str());
} }

View File

@@ -12,6 +12,7 @@ struct PSAInstalled {
int zone; int zone;
int size; int size;
QString blob; QString blob;
QString lastCommit;
QString info; QString info;
QString loadTime; QString loadTime;
} tariff; } tariff;
@@ -144,6 +145,7 @@ public:
QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository 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 checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch
QString errorBackendNotConnected(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 backendConnected(QString const &info, QString const &version = QString());
QString updateTriggerSet(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()); QString errorUpdateTrigger(QString const &info, QString const &version = QString());
@@ -154,8 +156,9 @@ public:
// and update accepted // and update accepted
QString updateOfPSASucceeded(QString const &version = QString()); // update process succeeded QString updateOfPSASucceeded(QString const &version = QString()); // update process succeeded
QString updateOfPSAContinues(QString currentStage, QString currentStageInfo, QString const &version = QString()); QString updateOfPSAContinues(QString currentStage, QString currentStageInfo, QString const &version = QString());
QString updateOfPSAFailed(int resultCode, QString reason, QString const &version = QString()); QString updateOfPSAFailed(int resultCode, QString step, QString reason, QString const &version = QString());
QString sanityCheckFailed(int resultCode, QString reason, QString const &version = QString()); QString sanityCheckFailed(int resultCode, QString reason, QString const &version = QString());
QString jsonParseFailed(int resultCode, QString reason, QString const &version = QString());
QString updateOfPSASendVersion(PSAInstalled const &psa); QString updateOfPSASendVersion(PSAInstalled const &psa);

View File

@@ -46,14 +46,15 @@ int main(int argc, char *argv[]) {
} }
// qputenv("XDG_RUNTIME_DIR", "/run/user/0"); // qputenv("XDG_RUNTIME_DIR", "/run/user/0");
openlog("ATB-UPDATE", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
QApplication a(argc, argv); QApplication a(argc, argv);
QApplication::setApplicationName("ATBUpdateTool"); QApplication::setApplicationName("ATBUpdateTool");
QApplication::setApplicationVersion(APP_VERSION); QApplication::setApplicationVersion(APP_VERSION);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput); atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtInfoMsg); setDebugLevel(LOG_NOTICE);
//setDebugLevel(QtMsgType::QtDebugMsg);
} }
QCommandLineParser parser; QCommandLineParser parser;
@@ -145,7 +146,10 @@ int main(int argc, char *argv[]) {
dryRun); dryRun);
MainWindow mw(&worker); MainWindow mw(&worker);
worker.setMainWindow(&mw);
mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
mw.setWindowState(Qt::WindowFullScreen);
mw.show(); mw.show();
return a.exec(); return a.exec();

View File

@@ -2,6 +2,7 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "worker.h" #include "worker.h"
#include "utils.h" #include "utils.h"
#include "progress_event.h"
#include <QDateTime> #include <QDateTime>
#include <QMessageBox> #include <QMessageBox>
@@ -11,32 +12,14 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_worker(worker) , m_worker(worker)
, m_width(52) { , m_width(70)
, m_progressRunning(false)
, m_progressValue(0) {
ui->setupUi(this); ui->setupUi(this);
ui->updateProgress->setRange(1, 100); ui->updateProgress->setRange(0, 100);
ui->updateProgress->reset(); ui->updateProgress->reset();
m_startTimer = new QTimer(this);
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
m_startTimer->setSingleShot(true);
m_startTimer->start(5 * 1000);
m_exitTimer = new QTimer(this);
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
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(stopStartTimer()), this, SLOT(onStopStartTimer()));
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
connect(m_worker, SIGNAL(setProgress(quint8)), this, SLOT(onSetProgress(quint8)));
QStringList lst; QStringList lst;
QString start = QDateTime::currentDateTime().toString(Qt::ISODate); QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
lst << QString("Start: ") + start.leftJustified(m_width-10); lst << QString("Start: ") + start.leftJustified(m_width-10);
@@ -48,6 +31,28 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
ui->updateStatus->setText(lst.join('\n')); ui->updateStatus->setText(lst.join('\n'));
ui->updateStatus->setEnabled(true); ui->updateStatus->setEnabled(true);
m_startTimer = new QTimer(this);
connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(update()));
m_startTimer->setSingleShot(true);
m_startTimer->start(1000);
m_exitTimer = new QTimer(this);
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
m_exitTimer->setSingleShot(true);
m_exitTimer->start(1800 * 1000);
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit()));
connect(m_worker, SIGNAL(disableExit()), this, SLOT(onDisableExit()));
connect(m_worker, SIGNAL(enableExit()), this, SLOT(onEnableExit()));
connect(m_worker, SIGNAL(stopStartTimer()), this, SLOT(onStopStartTimer()));
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
connect(m_worker, SIGNAL(replaceLast(QString, QString)), this, SLOT(onReplaceLast(QString,QString)));
ui->updateStatus->setText(lst.join('\n'));
ui->updateStatus->setEnabled(true);
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
@@ -56,42 +61,137 @@ MainWindow::~MainWindow() {
delete ui; delete ui;
} }
void MainWindow::customEvent(QEvent *event) {
if (event->type() == ProgressEvent::type()) {
ProgressEvent *pevent = (ProgressEvent *)event;
int const progress = pevent->progressPercent();
QObject const *sender = pevent->sender();
if (sender == this) {
switch(progress) {
case 0: {
ui->updateProgress->reset();
} break;
case START_PROGRESS_LOOP: {
m_progressRunning = true;
ui->updateProgress->reset();
m_progressValue = 10;
QApplication::postEvent(this, new ProgressEvent(this, m_progressValue));
} break;
case STOP_PROGRESS_LOOP: {
m_progressRunning = false;
m_progressValue -= 10;
m_worker->setProgress(m_progressValue/10);
} break;
default: {
if (m_progressRunning) {
m_progressValue = progress;
ui->updateProgress->setValue(progress/10);
QApplication::postEvent(this, new ProgressEvent(this, progress+10));
QThread::msleep(500);
}
}
}
} else
if (sender == m_worker) {
switch(progress) {
case 0: {
ui->updateProgress->reset();
} break;
case START_PROGRESS_LOOP: {
QApplication::postEvent(this, new ProgressEvent(this, START_PROGRESS_LOOP));
} break;
case STOP_PROGRESS_LOOP: {
QApplication::postEvent(this, new ProgressEvent(this, STOP_PROGRESS_LOOP));
} break;
default:{
ui->updateProgress->setValue(progress);
}}
} else {
qCritical() << "!!! UNKNOWN SENDER !!!";
}
}
QThread::yieldCurrentThread();
}
void MainWindow::onStopStartTimer() { void MainWindow::onStopStartTimer() {
m_startTimer->stop(); m_startTimer->stop();
} }
void MainWindow::onDisableExit() {
ui->exit->setEnabled(false);
}
void MainWindow::onEnableExit() {
ui->exit->setEnabled(true);
}
void MainWindow::onRestartExitTimer() { void MainWindow::onRestartExitTimer() {
m_exitTimer->stop(); m_exitTimer->stop();
m_exitTimer->start(5 * 1000); m_exitTimer->start(60 * 1000);
} }
void MainWindow::onQuit() { void MainWindow::onQuit() {
if (!m_worker->updateProcessRunning()) { m_exitTimer->stop();
qApp->quit(); qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode());
} qApp->exit(m_worker->returnCode());
}
void MainWindow::onSetProgress(quint8 v) {
ui->updateProgress->setValue(v);
} }
void MainWindow::onAppendText(QString text, QString suffix) { void MainWindow::onAppendText(QString text, QString suffix) {
QString editText = ui->updateStatus->toPlainText(); QString editText = ui->updateStatus->toPlainText();
QStringList lines = editText.split('\n'); if (!suffix.isNull() && suffix.size() > 0) {
for (int i=0; i<lines.size(); ++i) { qInfo() << "TEXT" << text << "SUFFIX" << suffix;
qCritical() << lines.at(i); if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) {
}
if (!suffix.contains("[SUCCESS]")) {
editText += text.leftJustified(m_width-9) + suffix;
ui->updateStatus->setPlainText(editText);
} else {
editText += QString("\n").leftJustified(m_width-3, '='); editText += QString("\n").leftJustified(m_width-3, '=');
editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]"; editText += " ";
} }
ui->updateStatus->setText(editText); editText += (QString("\n") + text).leftJustified(m_width - (2 + suffix.size()) ) + suffix;
} else {
editText += text.leftJustified(m_width-9);
}
Utils::printLineEditInfo(editText.split('\n'));
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);
}
}
Utils::printLineEditInfo(lines);
ui->updateStatus->setText(lines.join('\n').trimmed());
ui->updateStatus->setEnabled(true); ui->updateStatus->setEnabled(true);
} }
void MainWindow::onShowErrorMessage(QString title, QString text) { 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.defaultButton()->setVisible(false);
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
}
} }

View File

@@ -13,16 +13,26 @@ QT_END_NAMESPACE
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
protected:
void customEvent(QEvent *event) override;
public: public:
MainWindow(Worker *worker, QWidget *parent = nullptr); MainWindow(Worker *worker, QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
static const int START_PROGRESS_LOOP = -1;
static const int STOP_PROGRESS_LOOP = -2;
int progressValue() const { return m_progressValue; }
public slots: public slots:
void onAppendText(QString, QString); void onAppendText(QString, QString suffix = "");
void onReplaceLast(QString, QString suffix = "");
void onShowErrorMessage(QString, QString); void onShowErrorMessage(QString, QString);
void onSetProgress(quint8);
void onStopStartTimer(); void onStopStartTimer();
void onRestartExitTimer(); void onRestartExitTimer();
void onEnableExit();
void onDisableExit();
private slots: private slots:
void onQuit(); void onQuit();
@@ -33,5 +43,7 @@ private:
int m_width; int m_width;
QTimer *m_startTimer; QTimer *m_startTimer;
QTimer *m_exitTimer; QTimer *m_exitTimer;
bool m_progressRunning;
int m_progressValue;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>370</width> <width>800</width>
<height>358</height> <height>480</height>
</rect> </rect>
</property> </property>
<property name="font"> <property name="font">
@@ -19,56 +19,44 @@
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>11</y> <y>10</y>
<width>351</width> <width>781</width>
<height>341</height> <height>461</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="3" column="2">
<widget class="QTextEdit" name="updateStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<family>Noto Sans</family>
<pointsize>8</pointsize>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QProgressBar" name="updateProgress">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<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">
<widget class="QPushButton" name="exit"> <widget class="QPushButton" name="exit">
<property name="text"> <property name="text">
<string>Exit</string> <string>Exit</string>
</property> </property>
</widget> </widget>
</item> </item>
<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> </layout>
</widget> </widget>
</widget> </widget>

View File

@@ -6,13 +6,13 @@
#include <QFileInfo> #include <QFileInfo>
#include <QMessageLogContext> #include <QMessageLogContext>
#define OUTPUT_LEN (1024*8)
static char const *DBG_NAME[] = { "DBG ", "WARN ", "CRIT ", "FATAL", "INFO " };
static bool installedMsgHandler = false; static bool installedMsgHandler = false;
static QtMsgType debugLevel = QtInfoMsg; static int debugLevel = LOG_NOTICE;
QtMsgType getDebugLevel() { return debugLevel; } int getDebugLevel() { return debugLevel; }
void setDebugLevel(QtMsgType newDebugLevel) { void setDebugLevel(int newDebugLevel) {
debugLevel = newDebugLevel; debugLevel = newDebugLevel;
} }
@@ -45,75 +45,51 @@ QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler) {
/// ///
#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
// static constexpr const char *format = "dd.MM.yyyy hh:mm:ss"; Q_UNUSED(context);
QByteArray localMsg = msg.toLocal8Bit(); QString const localMsg = QString(DBG_NAME[type]) + msg.toLocal8Bit();
QString fileName(context.file ? context.file : "N/A");
QString function(context.function ? context.function : "N/A"); switch (debugLevel) {
char buf[OUTPUT_LEN]{}; case LOG_DEBUG: { // debug-level message
memset(buf, 0x00, sizeof(buf)); syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
QString const datetime = QDateTime::currentDateTime().toString(Qt::ISODateWithMs); } break;
switch (type) { case LOG_INFO: { // informational message
case QtDebugMsg: { if (type != QtDebugMsg) {
if (debugLevel == QtDebugMsg) { syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
snprintf(buf, sizeof(buf)-1, "%s DEBG [%s:%s:%04u] %s",
datetime.toStdString().c_str(),
function.toStdString().c_str(),
fileName.toStdString().c_str(),
context.line,
localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtInfoMsg: { case LOG_NOTICE: { // normal, but significant, condition
if (debugLevel == QtInfoMsg || debugLevel == QtDebugMsg) { if (type != QtDebugMsg) {
snprintf(buf, sizeof(buf)-1, "%s DEBG [%s:%s:%04u] %s", syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
datetime.toStdString().c_str(),
function.toStdString().c_str(),
fileName.toStdString().c_str(),
context.line,
localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtWarningMsg: { case LOG_WARNING: { // warning conditions
if (debugLevel == QtInfoMsg || debugLevel == QtDebugMsg || debugLevel == QtWarningMsg) { if (type != QtInfoMsg && type != QtDebugMsg) {
snprintf(buf, sizeof(buf)-1, "%s DEBG [%s:%s:%04u] %s", syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
datetime.toStdString().c_str(),
function.toStdString().c_str(),
fileName.toStdString().c_str(),
context.line,
localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtCriticalMsg: { case LOG_ERR: { // error conditions
if (debugLevel == QtInfoMsg || debugLevel == QtDebugMsg if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|| debugLevel == QtWarningMsg || debugLevel == QtCriticalMsg) { syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
snprintf(buf, sizeof(buf)-1, "%s DEBG [%s:%s:%04u] %s",
datetime.toStdString().c_str(),
function.toStdString().c_str(),
fileName.toStdString().c_str(),
context.line,
localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtFatalMsg: { case LOG_CRIT: { // critical conditions
if (debugLevel == QtInfoMsg || debugLevel == QtDebugMsg if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|| debugLevel == QtWarningMsg || debugLevel == QtCriticalMsg syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|| debugLevel == QtFatalMsg) { }
snprintf(buf, sizeof(buf)-1, "%s DEBG [%s:%s:%04u] %s", } break;
datetime.toStdString().c_str(), case LOG_ALERT: { // action must be taken immediately
function.toStdString().c_str(), if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
fileName.toStdString().c_str(), syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
context.line, }
localMsg.constData()); } break;
fprintf(stderr, "%s\n", buf); case LOG_EMERG: { // system is unusable
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
} }
} break; } break;
default: { default: {
fprintf(stderr, "%s No ErrorLevel defined! %s\n", //fprintf(stderr, "%s No ErrorLevel defined! %s\n",
datetime.toStdString().c_str(), msg.toStdString().c_str()); // datetime.toStdString().c_str(), msg.toStdString().c_str());
} }
} }
} }

View File

@@ -2,9 +2,12 @@
#define MESSAGE_HANDLER_H_INCLUDED #define MESSAGE_HANDLER_H_INCLUDED
#include <QtGlobal> #include <QtGlobal>
#ifdef __linux__
#include <syslog.h>
#endif
QtMsgType getDebugLevel(); int getDebugLevel();
void setDebugLevel(QtMsgType newDebugLevel); void setDebugLevel(int newDebugLevel);
bool messageHandlerInstalled(); bool messageHandlerInstalled();
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler); QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler);

View File

@@ -128,13 +128,11 @@ struct T_vaultRecord
uint32_t AbsReserve; uint32_t AbsReserve;
uint32_t AbsNrOfCuts; uint32_t AbsNrOfCuts;
//16
char label3buffer[4]; // mw > char label3buffer[4]; // mw >
// Verkauf, Tuer zu: // Verkauf, Tuer zu:
uint32_t VKcoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen uint32_t VKcoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen
uint32_t VKcoinsReturned[6]; // nur fuer Wechsler, Anzahl Muenzen pro Typ, soviel wurde zurueckgegeben uint32_t VKcoinsReturned[6]; // nur fuer Wechsler, Anzahl Muenzen pro Typ, soviel wurde zurueckgegeben
//88
// Service, Tuer offen: // Service, Tuer offen:
uint16_t ServCoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen uint16_t ServCoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen
@@ -144,12 +142,10 @@ struct T_vaultRecord
uint16_t currentTubeContent[6]; // nur fuer Wechsler, aktueller Fuellstand uint16_t currentTubeContent[6]; // nur fuer Wechsler, aktueller Fuellstand
uint16_t resint5; uint16_t resint5;
uint16_t resint6; uint16_t resint6;
// 56
char label4buffer[4]; // box> char label4buffer[4]; // box>
uint16_t coinsInVault[16]; uint16_t coinsInVault[16];
uint16_t billsInStacker[8]; uint16_t billsInStacker[8];
// 48
char label5buffer[4]; // val> char label5buffer[4]; // val>
// actually constant unless exchange rate is changed // actually constant unless exchange rate is changed
@@ -159,11 +155,17 @@ struct T_vaultRecord
uint16_t exchangeRate; uint16_t exchangeRate;
uint16_t resint9; uint16_t resint9;
// 64 // new from 1.8.23
uint32_t cutsSinceCBchange;
uint32_t CBcontent_cent;
uint32_t CBnrofCoins;
char endofblock[4]; // end> char endofblock[4]; // end
// 332 bytes
// 316 byte Block im Speicher uint16_t CRC16; // Xmodem16 from startbuffer[0] to endofblock[3]
uint16_t resint11;
char endofRecord[4]; // ----
}; };
@@ -317,7 +319,8 @@ struct T_devices
UCHAR kindOfPrinter; // 0:off 1:Gebe UCHAR kindOfPrinter; // 0:off 1:Gebe
UCHAR kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza Csquare (MW) UCHAR kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza Csquare (MW)
UCHAR kindOfMifareReader; // by now only stronglink SL025 =1 UCHAR kindOfMifareReader; // by now only stronglink SL025 =1
UCHAR suppressSleepMode; // 0:sleep allowed 1: no sleep UCHAR solarPower; // 1:sleep allowed 0: no sleep
//UCHAR suppressSleepMode; // 0:sleep allowed 1: no sleep
UCHAR kindOfModem; // 0:off 1:Sunlink UCHAR kindOfModem; // 0:off 1:Sunlink
UCHAR kindOfCreditcard; // 0:off 1:Feig NFC UCHAR kindOfCreditcard; // 0:off 1:Feig NFC
@@ -336,6 +339,8 @@ struct T_devices
UINT VaultFullWarnLevel; UINT VaultFullWarnLevel;
UINT VaultFullErrorLevel; UINT VaultFullErrorLevel;
UINT BattEmptyWarnLevel;
UINT BattEmptyErrorLevel;
}; };
@@ -1151,14 +1156,13 @@ public:
// to be forwarded to Ismas // to be forwarded to Ismas
virtual bool prn_printAccountReceipt(void) const =0; virtual bool prn_printAccountReceipt(void) const =0;
// print all 8 backuped accounting receipts
// return true if sending to DC OK, false if cmd-stack is full // return true if sending to DC OK, false if cmd-stack is full
virtual bool prn_printTestTicket(void) const =0; virtual bool prn_printTestTicket(void) const =0;
// return true if sending to DC OK, false if cmd-stack is full // return true if sending to DC OK, false if cmd-stack is full
virtual bool cash_startPayment(uint32_t amount) const =0; virtual bool cash_startPayment(uint32_t amount) const =0;
// 17.4.23TS: extended to 32bit // 17.4.23TS: extended to 32bit
@@ -1273,7 +1277,7 @@ public:
virtual uint16_t log_getLatestAccountNumber(void) const=0; virtual uint16_t log_getLatestAccountNumber(void) const=0;
// new function 27.6.2023 // new function 27.6.2023
// latest = highest // latest = highest of the backup's
virtual uint8_t log_getAvailableVaultBlocks(void) const=0; virtual uint8_t log_getAvailableVaultBlocks(void) const=0;
// return 0x0011 1111 if all 6 blocks are loaded (one bit per block) // return 0x0011 1111 if all 6 blocks are loaded (one bit per block)
@@ -1297,7 +1301,45 @@ public:
// 2: done and error // 2: done and error
virtual bool log_getVaultData(uint8_t *data) const =0; virtual bool log_getVaultData(uint8_t *data) const =0;
// get vault record in linear 8bit buffer with 320 byte // get vault record in linear 8bit buffer with 384 byte
// new from 1.8.23
virtual bool prn_printOneAccountReceipt(uint16_t accountNr) const =0;
// print one out of eight stored last accounting receipts
// function log_getHoldAccountNumbers() gives a list of acc-Nr. of the stored receipts
virtual bool prn_printAllAvailAccountReceipts(void) const =0;
// same as: prn_printAccountReceipt() from line 1153
// return true if sending to DC OK, false if cmd-stack is full
virtual bool log_verifyVaultRecordByCrc(void) const =0;
// return true if CRC16 is correct, data are 100% OK. Security level 1:65536
// verification is strongly recommended before further processing
// in case of "false"-result please reload from DC
virtual uint16_t log_DC_getNextAccountNumber(void) const=0;
// the current cash box content will be backuped with this number on next cashbox-change
virtual void log_DC_setNextAccountNumber(uint16_t newAccountingNumber) const=0;
// the current cash box content will be backuped with this number on next cashbox-change
// use only in case of hardware replacements or errors which derailed the number
virtual void log_DC_deleteAllVaultrecordsInDc(void) const=0;
// use only in case of hardware replacements or errors which derailed the number
virtual void log_DC_deleteAllTotalCounters(void) const=0;
// use only in case of hardware replacements or errors which derailed the number
virtual void dc_setNewCustomerNumber(uint16_t newCustNr) const =0;
virtual void dc_setNewMachineNumber(uint16_t newMachNr) const =0;
virtual void dc_setNewBorough(uint16_t newBorough) const =0;
virtual void dc_setNewZone(uint16_t newZone) const =0;
@@ -1356,6 +1398,10 @@ signals:
// 15.06.2023 V4.2 bring into same order as hwapi in order to set the THIS_IS_CA_MASTER correct // 15.06.2023 V4.2 bring into same order as hwapi in order to set the THIS_IS_CA_MASTER correct
// 19.06.2023 V4.3 added some qCriticals to see emits // 19.06.2023 V4.3 added some qCriticals to see emits
// 01.08.2023 V4.4 some new values at the end of struct T_vaultRecord
// two more values in struct T_devices
// 7 new functions at the end of the file
//#define HWINF_iid "Atb.Psa2020.software.HWapi/3.1" //#define HWINF_iid "Atb.Psa2020.software.HWapi/3.1"
//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.1" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.1"
@@ -1366,7 +1412,8 @@ signals:
//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.0" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.0"
//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.1" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.1"
//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.2" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.2"
#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.3" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.3"
#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.4"

View File

@@ -62,10 +62,11 @@ bool Command::execute(QString workingDirectory, QStringList args) {
if (p->waitForFinished(m_waitForFinishTimeout)) { if (p->waitForFinished(m_waitForFinishTimeout)) {
//qDebug() << "PROCESS" << m_command << "FINISHED"; //qDebug() << "PROCESS" << m_command << "FINISHED";
if (p->exitStatus() == QProcess::NormalExit) { if (p->exitStatus() == QProcess::NormalExit) {
//qInfo() << "EXECUTED" << m_command if (p->exitCode() == 0) {
// << "with code" << p->exitCode();
// qInfo() << "RESULT" << m_commandResult;
return true; return true;
} else {
qCritical() << "EXECUTED" << m_command << "with code" << p->exitCode();
}
} else { } else {
qCritical() << "PROCESS" << m_command << "CRASHED with code" qCritical() << "PROCESS" << m_command << "CRASHED with code"
<< p->exitCode(); << p->exitCode();

20
progress_event.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "progress_event.h"
QEvent::Type ProgressEvent::customEventType = QEvent::None;
ProgressEvent::ProgressEvent(QObject const *sender, int progressPercent)
: QEvent(ProgressEvent::type())
, m_sender(sender)
, m_progressPercent(progressPercent) {
}
ProgressEvent::~ProgressEvent() {
}
QEvent::Type ProgressEvent::type() {
if (customEventType == QEvent::None) {
int generatedType = QEvent::registerEventType();
customEventType = static_cast<QEvent::Type>(generatedType);
}
return customEventType;
}

26
progress_event.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef PROGRESS_EVENT_H_INCLUDED
#define PROGRESS_EVENT_H_INCLUDED
#include <QEvent>
class ProgressEvent : public QEvent {
QObject const *m_sender;
int m_progressPercent;
public:
explicit ProgressEvent(QObject const *sender, int progressPercent);
virtual ~ProgressEvent();
static QEvent::Type type();
QObject const *sender() { return m_sender; }
QObject const *sender() const { return m_sender; }
void setProgress(int progressPercent) { m_progressPercent = progressPercent; }
int progressPercent() { return m_progressPercent; }
int progressPercent() const { return m_progressPercent; }
private:
static QEvent::Type customEventType;
};
#endif // PROGRESS_EVENT_H_INCLUDED

View File

@@ -8,6 +8,7 @@
#include <QDebug> #include <QDebug>
#include <QTextStream> #include <QTextStream>
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegExp>
//#include <iostream> //#include <iostream>
//#include <fstream> //#include <fstream>
@@ -350,21 +351,25 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
10 : bl_stopBL() // leave bl and start (the new) application 10 : bl_stopBL() // leave bl and start (the new) application
*/ */
bool Update::updateBinary(char const *fileToSendToDC) { bool Update::updateBinary(char const *fileToSendToDC) {
qInfo() << "updating device controller binary" << fileToSendToDC; qInfo() << "UPDATING DEVICE CONTROLLER BINARY" << fileToSendToDC;
QFile fn(fileToSendToDC); QFile fn(fileToSendToDC);
bool r; bool r;
if ((r = fn.exists()) == true) { if ((r = fn.exists()) == true) {
QString const linkTarget = fn.symLinkTarget(); QFileInfo fi(fn);
QFileInfo fi(linkTarget); qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ")";
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")"; if ((r = updateDC(fileToSendToDC)) == true) {
if ((r = updateDC(linkTarget)) == true) { qCritical() << QString(80, '*');
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done"; qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") DONE";
qCritical() << QString(80, '*');
} else { } 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 { } else {
qCritical() << "symlink" << fileToSendToDC qCritical() << QString(80, '*');
<< "does not exist -> NO UPDATE OF DC FIRMWARE"; qCritical() << fileToSendToDC << "does not exist -> NO UPDATE OF DC FIRMWARE";
qCritical() << QString(80, '*');
} }
return r; return r;
} }
@@ -514,7 +519,6 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
} }
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
// //
// ACHTUNG !!! // ACHTUNG !!!
// //
@@ -523,11 +527,6 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
bool serialOpened = false; bool serialOpened = false;
bool serialOpen = false; bool serialOpen = false;
if (filesToWorkOn.size() == 0) {
qCritical() << "NOTHING TO UPDATE";
return true;
}
if (!serialOpen) { if (!serialOpen) {
if (!isSerialOpen()) { // open serial only if not already open if (!isSerialOpen()) { // open serial only if not already open
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) { 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; 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; QList<QString>::const_iterator it;
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) { for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
bool res = false; m_worker->startProgressLoop();
QString fToWorkOn = (*it).trimmed(); QString fToWorkOn = (*it).trimmed();
fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn);
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) && static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) { 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 for (int i=0; i < 3; ++i) { // send explicit reuests to get
// current SW/HW-versions // current SW/HW-versions
m_hw->request_DC2_SWversion(); 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 hwVersion = m_hw->dc_getHWversion().toLower();
QString const fwVersion = m_hw->dc_getSWversion().toLower(); QString const fwVersion = m_hw->dc_getSWversion().toLower();
qInfo() << "current dc-hardware-version" << hwVersion; qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion; qInfo() << "current dc-firmware-version" << fwVersion;
QFile fn(fToWorkOn); QFile fn(fToWorkOn);
QFileInfo linkTarget(fn.symLinkTarget()); QFileInfo finfo(fn);
if (!linkTarget.exists()) { // check for broken link if (!fn.exists()) { // check for broken link
qCritical() << QString(80, '*');
qCritical() << "FILE-TO-WORK-ON" << fn << "DOES NOT EXIST";
qCritical() << QString(80, '*');
res = false; res = false;
} else { } else {
if (false) { if (false) {
@@ -574,13 +582,12 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
} else { } else {
res = true; res = true;
qCritical() << "downloading" << fToWorkOn.trimmed() << "->" qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
<< linkTarget.completeBaseName() << "to DC";
#if UPDATE_DC == 1 #if UPDATE_DC == 1
m_hw->dc_autoRequest(false);// default: turn auto-request setting off m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(1); // wait to be sure that there are no more QThread::sleep(1); // wait to be sure that there are no more
// commands sent to dc-hardware // commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE"; qInfo() << "SET AUTO-REQUEST=FALSE";
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) { if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << fToWorkOn; 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 m_hw->dc_autoRequest(true); // turn auto-request setting on
qDebug() << "SET AUTO-REQUEST=TRUE"; qInfo() << "SET AUTO-REQUEST=TRUE";
qDebug() << "WAIT 10 SECS TO RECEIVE RESPONSES..."; qInfo() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
QThread::sleep(10); // wait to be sure that responses QThread::sleep(10); // wait to be sure that responses
// have been received // have been received
qCritical() << "updated dc-hardware-version" << m_hw->dc_getHWversion(); qInfo() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qCritical() << "updated dc-firmware-version" << m_hw->dc_getSWversion(); qInfo() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
#endif #endif
} }
} }
@@ -660,10 +667,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn; qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
res = false; res = false;
} }
m_worker->stopProgressLoop();
m_worker->setProgress(100);
if (res == false) {
break;
}
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) { } // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
qDebug() << "SET AUTO-REQUEST=TRUE"; qDebug() << "SET AUTO-REQUEST=TRUE";
return true; return res;
} }

View File

@@ -1,8 +1,9 @@
#include "utils.h" #include "utils.h"
#include "message_handler.h"
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QDebug>
int Utils::read1stLineOfFile(QString fileName) { int Utils::read1stLineOfFile(QString fileName) {
QFile f(fileName); QFile f(fileName);
@@ -33,3 +34,46 @@ QString Utils::zoneName(quint8 i) {
} }
return "N/A"; return "N/A";
} }
void Utils::printCriticalErrorMsg(QString const &errorMsg) {
qCritical() << QString(80, '!');
qCritical() << errorMsg;
qCritical() << QString(80, '!');
}
void Utils::printInfoMsg(QString const &infoMsg) {
qCritical() << QString(80, '=');
qCritical() << infoMsg;
qCritical() << QString(80, '=');
}
void Utils::printLineEditInfo(QStringList const &lines) {
if (getDebugLevel() == LOG_DEBUG) {
for (int i=0; i<lines.size(); ++i) {
qInfo() << lines.at(i);
} qInfo() << ""; qInfo() << "";
}
}
QString Utils::getTariffLoadTime(QString fileName) {
QFileInfo fInfo(fileName);
if (fInfo.exists()) {
QDateTime lastModifiedTime = fInfo.lastModified();
if (lastModifiedTime.isValid()) {
return lastModifiedTime.toString(Qt::ISODateWithMs);
} else {
printCriticalErrorMsg(fileName + " HAS INVALID MODIFIED-TIME");
QDateTime birthTime = fInfo.birthTime();
if (birthTime.isValid()) {
return birthTime.toString(Qt::ISODateWithMs);
} else {
printCriticalErrorMsg(fileName + " HAS INVALID BIRTH-TIME");
}
}
} else {
printCriticalErrorMsg(fileName + " DOES NOT EXIST");
}
return "N/A";
}

View File

@@ -3,11 +3,18 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStringList>
#include <QFile> #include <QFile>
#include <QFileInfo>
#include <QDateTime>
namespace Utils { namespace Utils {
int read1stLineOfFile(QString fileName); int read1stLineOfFile(QString fileName);
QString zoneName(quint8 i); QString zoneName(quint8 i);
void printCriticalErrorMsg(QString const &errorMsg);
void printInfoMsg(QString const &infoMsg);
void printLineEditInfo(QStringList const &lines);
QString getTariffLoadTime(QString fileName);
} }
#endif // UTILS_H_INCLUDED #endif // UTILS_H_INCLUDED

View File

@@ -21,10 +21,13 @@
#include "message_handler.h" #include "message_handler.h"
#include "plugins/interfaces.h" #include "plugins/interfaces.h"
#include "ismas/ismas_client.h" #include "ismas/ismas_client.h"
#include "progress_event.h"
#include "mainwindow.h"
#include "utils.h"
QString const Worker::UPDATE_STEP_OK(" [ ok]"); QString const Worker::UPDATE_STEP_OK(" [ ok]");
QString const Worker::UPDATE_STEP_DONE(" [done]"); QString const Worker::UPDATE_STEP_DONE(" [done]");
QString const Worker::UPDATE_STEP_FAIL(" [fail]"); QString const Worker::UPDATE_STEP_FAIL(" [FAIL]");
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]"); QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
Worker::Worker(hwinf *hw, Worker::Worker(hwinf *hw,
@@ -65,7 +68,10 @@ Worker::Worker(hwinf *hw,
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS) , m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
, m_waitForNewUpdates(this) , m_waitForNewUpdates(this)
, m_filesToUpdate() , m_filesToUpdate()
, m_updateProcessRunning(false) { , m_updateProcessRunning(true)
, m_returnCode(0)
, m_progressValue(0)
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
QDir::setCurrent(m_workingDirectory); QDir::setCurrent(m_workingDirectory);
@@ -88,7 +94,7 @@ Worker::Worker(hwinf *hw,
int cnt = 0; int cnt = 0;
while (!m_workerThread.isRunning()) { while (!m_workerThread.isRunning()) {
if (++cnt > 5) { if (++cnt > 5) {
qCritical() << "starting worker thread FAILED"; Utils::printCriticalErrorMsg("starting worker thread FAILED");
return; return;
} }
QThread::sleep(1); QThread::sleep(1);
@@ -101,7 +107,7 @@ Worker::~Worker() {
while (!m_workerThread.isFinished()) { while (!m_workerThread.isFinished()) {
if (!m_workerThread.wait(1000)) { if (!m_workerThread.wait(1000)) {
if (++cnt > 5) { if (++cnt > 5) {
qCritical() << "stopping worker thread FAILED"; Utils::printCriticalErrorMsg("stopping worker thread FAILED");
return; return;
} }
} }
@@ -111,24 +117,58 @@ Worker::~Worker() {
} }
} }
void Worker::setProgress(int progress) {
if (m_mainWindow) {
m_progressValue = progress;
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, progress));
}
}
void Worker::startProgressLoop() {
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::START_PROGRESS_LOOP));
}
void Worker::stopProgressLoop() {
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::STOP_PROGRESS_LOOP));
}
static std::once_flag once; static std::once_flag once;
void Worker::update() { void Worker::update() {
// user should not start the update process several times
std::call_once(once, &Worker::privateUpdate, this); std::call_once(once, &Worker::privateUpdate, this);
} }
void Worker::privateUpdate() { void Worker::privateUpdate() {
// user should not start the update process several times
QPushButton *start = qobject_cast<QPushButton *>(QObject::sender());
start->setEnabled(false);
emit stopStartTimer();
m_updateProcessRunning = true; m_updateProcessRunning = true;
bool sentIsmasLastVersionNotification = false; 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); QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) { if (!customerRepository.exists()) {
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
if (m_gc.gitCloneAndCheckoutBranch()) { if (m_gc.gitCloneAndCheckoutBranch()) {
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, m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
QString("CLONED AND CHECKED OUT: ") + m_customerRepository); QString("CLONED AND CHECKED OUT: ") + m_customerRepository);
@@ -137,171 +177,371 @@ void Worker::privateUpdate() {
m_ismasClient.cloneAndCheckoutCustomerRepository( m_ismasClient.cloneAndCheckoutCustomerRepository(
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
setProgress(progress + 10);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded("")); m_ismasClient.updateOfPSASucceeded(""));
} 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 { } else {
// checkout branch stopProgressLoop();
if (m_gc.gitCheckoutBranch()) {
int progress = 10; int progress = (m_mainWindow->progressValue()/10) + 10;
m_ismasClient.setProgressInPercent(progress); setProgress(progress);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH,
QString("CHECKED OUT BRANCH: ") + m_gc.branchName()); 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, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch( m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription));
m_updateStatus.m_statusDescription, ""));
emit setProgress(progress); m_returnCode = -3;
}
} else {
m_ismasClient.setProgressInPercent(10);
if (backendConnected()) { if (backendConnected()) {
progress = 20; m_ismasClient.setProgressInPercent(20);
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (updateTriggerSet()) { if (updateTriggerSet()) {
emit setProgress(progress); m_ismasClient.setProgressInPercent(30);
m_ismasClient.setProgressInPercent(progress);
if (customerEnvironment()) { if (customerEnvironment()) {
emit setProgress(progress); m_ismasClient.setProgressInPercent(40);
m_ismasClient.setProgressInPercent(progress);
if (filesToUpdate()) { if (filesToUpdate()) {
emit setProgress(progress); // send message to ISMAS about files which have been
m_ismasClient.setProgressInPercent(progress); // checked in into git repository
if (updateFiles(progress)) { m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
emit setProgress(progress); QString("Files to update: ") + m_filesToUpdate.join(','));
m_ismasClient.setProgressInPercent(progress); IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
m_ismasClient.setProgressInPercent(50);
if (updateFiles(50)) {
m_ismasClient.setProgressInPercent(60);
if (syncCustomerRepositoryAndFS()) { if (syncCustomerRepositoryAndFS()) {
emit setProgress(progress); m_ismasClient.setProgressInPercent(70);
m_ismasClient.setProgressInPercent(progress);
if (sendIsmasLastVersionNotification()) { if (sendIsmasLastVersionNotification()) {
emit setProgress(progress); m_ismasClient.setProgressInPercent(80);
m_ismasClient.setProgressInPercent(progress);
sentIsmasLastVersionNotification = true; sentIsmasLastVersionNotification = true;
if (saveLogFile()) { if (saveLogFile()) {
emit setProgress(progress); m_ismasClient.setProgressInPercent(90);
m_ismasClient.setProgressInPercent(progress);
emit appendText(QString(""), UPDATE_STEP_SUCCESS); 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 // mark update as activated -> this resets the WAIT button
progress = 100; m_ismasClient.setProgressInPercent(95);
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated()); m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -11;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Sending ISMAS last version failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-SEND-LAST-VERSION",
m_updateStatus.m_statusDescription));
m_returnCode = -10;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Syncing files to update failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"RSYNC-UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -9;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Updating files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -8;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("No files to update"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"FETCH-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
m_returnCode = -7;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_REQUEST_FAILURE,
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
m_returnCode = -6;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE,
QString("ISMAS update trigger wrong"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"CHECK-UPDATE-TRIGGER",
m_updateStatus.m_statusDescription));
m_returnCode = -5;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_BACKEND_CHECK_FAILURE,
QString("ISMAS backend not available"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-BACKEND-CHECK",
m_updateStatus.m_statusDescription));
m_returnCode = -4;
} }
} }
}
} m_ismasClient.setProgressInPercent(100);
}
}
}
}
}
}
if (!sentIsmasLastVersionNotification) { if (!sentIsmasLastVersionNotification) {
// try even if the backend is not connected // try even if the backend is not connected
sendIsmasLastVersionNotification(); sendIsmasLastVersionNotification();
} }
if (m_returnCode != 0) {
stopProgressLoop();
emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL);
} else {
emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS);
}
setProgress(100);
m_updateProcessRunning = false; m_updateProcessRunning = false;
emit enableExit();
emit restartExitTimer(); emit restartExitTimer();
} }
bool Worker::backendConnected() { bool Worker::backendConnected() {
static int repeat = 0; // deactivated: REQ_SELF does not really help. Observation was that even
// id ISMAS is reported as 'true', a following check of the update-trigger
// button has no access to ISMAS.
return true;
if (repeat < 3) { emit appendText("\nConnecting backend ...");
if (false) { // so linker removes dead code
for (int repeat = 0; repeat < 50; ++repeat) {
qInfo() << "REPEAT" << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
startProgressLoop();
std::optional<QString> result std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse( = IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}"); IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}");
if (result) { if (result) {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress);
QString msg = result.value(); QString msg = result.value();
qInfo() << "In backendConnected() -> APISM response" << msg;
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError)); QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) { if (parseError.error != QJsonParseError::NoError) {
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):" qCritical() << "(1) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
<< parseError.error << parseError.errorString(); << parseError.error << parseError.errorString();
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("(2) INVALID JSON %1 %2 %3")
.arg(msg)
.arg(parseError.error)
.arg(parseError.errorString()));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
emit replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
return false; return false;
} }
if (!document.isObject()) { if (!document.isObject()) {
qCritical() << "FILE IS NOT A JSON OBJECT!"; qCritical() << "FILE IS NOT A JSON OBJECT!";
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("NOT A JSON-OBJECT %1").arg(msg));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
emit replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
return false; return false;
} }
setProgress(progress + 1);
QJsonObject obj = document.object(); QJsonObject obj = document.object();
QStringList keys = obj.keys(); QStringList keys = obj.keys().filter("CMD_GET_APISMSTATUS_RESPONSE");
for (QString const& key : keys ) { if (keys.size() == 1) {
if (key.contains("CMD_GET_APISMSTATUS_RESPONSE")) { QString const key = keys.at(0);
QJsonValue v = obj.value(key); QJsonValue v = obj.value(key);
if (v.isObject()) { if (v.isObject()) {
obj = v.toObject(); obj = v.toObject();
bool ismas = obj.value("ISMAS").toBool(); bool ismas = obj.value("ISMAS").toBool();
QString status = obj.value("Broker").toString(); QString status = obj.value("Broker").toString();
qInfo() << "REPEAT" << repeat << "In backendConnected() Broker=<"
qCritical() << "XXXXXXXXXX STATUS" << status; << status << ">, ISMAS=<" << (ismas ? "true>" : "false>");
if (ismas) { if (ismas) {
if (status == "Connected") { if (status == "Connected") {
// do not send, as this would result in a corrupted wait button // do not send, as this would result in a corrupted wait button
// but update the user-interface // but update the user-interface
emit appendText("\nBackend connected", UPDATE_STEP_OK); setProgress(100);
emit replaceLast("Connecting backend ...", UPDATE_STEP_OK);
return true; return true;
} }
} }
if (status.startsWith("Connecting") || status.startsWith("Re-Connecting")) {
QThread::sleep(1); m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_CHECK,
++repeat; QString ("REPEAT %1 Broker=<").arg(repeat)
return backendConnected(); + status + ">, ISMAS=<" + (ismas ? "true>" : "false>"));
//IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
// QString("#M=APISM#C=CMD_EVENT#J=") +
// m_ismasClient.updateOfPSAContinues("BACKEND-CHECK", m_updateStatus.m_statusDescription));
qInfo() << "BACKEND-CHECK" << m_updateStatus.m_statusDescription;
emit showErrorMessage("Check backend connection", m_updateStatus.m_statusDescription);
QThread::sleep(6);
continue;
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_CHECK_FAILURE,
"CMD_GET_APISM_STATUS_RESPONSE KEY NOT A JSON-OBJECT");
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));
emit showErrorMessage("check backend connection", m_updateStatus.m_statusDescription);
emit replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
return false;
} }
emit appendText("\nBackend connected", UPDATE_STEP_FAIL); } else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_CHECK_FAILURE,
"CMD_GET_APISMSTATUS_RESPONSE KEY NOT AVAILABLE");
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));
emit showErrorMessage("check backend connection", m_updateStatus.m_statusDescription);
emit replaceLast("Connecting backend ...", UPDATE_STEP_FAIL);
return false;
}
} 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"); emit showErrorMessage("Error", "Backend not available");
}
}
}
}
}
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_NOT_CONNECTED, m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_NOT_CONNECTED,
QString("NO BACKEND CONNECTION")); QString("NO BACKEND CONNECTION"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorBackendNotConnected(m_updateStatus.m_statusDescription, "")); m_ismasClient.errorBackendNotConnected(m_updateStatus.m_statusDescription, ""));
}
return false; return false;
} }
bool Worker::updateTriggerSet() { bool Worker::updateTriggerSet() {
// nmap -Pn 62.141.45.68 -p 8883 if (m_withoutIsmasDirectPort) { // useful for testing
// Host is up (0.053s latency). return true;
// }
// PORT STATE SERVICE
// 8883/tcp open secure-mqtt
emit appendText("\nUpdate trigger set ...");
QString triggerValue(""); QString triggerValue("");
for (int repeat = 0; repeat < 50; ++repeat) {
qInfo() << "UPDATE TRIGGER SET -> REPEAT" << repeat;
startProgressLoop();
if (std::optional<QString> result if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse( = IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) { IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress);
QString msg = result.value(); QString msg = result.value();
qInfo() << "REPEAT" << repeat << "APISM RESPONSE" << msg;
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError)); QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) { if (parseError.error != QJsonParseError::NoError) {
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):" qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
<< parseError.error << parseError.errorString(); << parseError.error << parseError.errorString();
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("(2) INVALID JSON %1 %2 %3")
.arg(msg)
.arg(parseError.error)
.arg(parseError.errorString()));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
emit showErrorMessage("check update trigger", emit showErrorMessage("check update trigger",
QString("invalid json ") + msg.mid(0, 20)); QString("invalid json ") + msg.mid(0, 20));
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false; return false;
} }
if (!document.isObject()) { if (!document.isObject()) {
qCritical() << "FILE IS NOT A JSON OBJECT!"; qCritical() << "FILE IS NOT A JSON OBJECT!";
emit showErrorMessage("check update trigger", setProgress(100);
QString("not a json object") + msg); m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("NOT A JSON-OBJECT %1").arg(msg));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription));
emit showErrorMessage("check update trigger", QString("not a json object") + msg);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false; return false;
} }
progress += 1;
setProgress(progress);
QJsonObject obj = document.object(); QJsonObject obj = document.object();
// sanity check: cust_nr and machine_nr of PSA correct ? // 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")) { if (obj.contains("Dev_ID")) {
QJsonValue v = obj.value("Dev_ID"); QJsonValue v = obj.value("Dev_ID");
if (v.isObject()) { if (v.isObject()) {
@@ -312,130 +552,292 @@ bool Worker::updateTriggerSet() {
int customerNr = c.toInt(-1); int customerNr = c.toInt(-1);
int machineNr = m.toInt(-1); int machineNr = m.toInt(-1);
if (customerNr != m_customerNr) { if (customerNr != m_customerNr) {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)") QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
.arg(customerNr).arg(m_customerNr)); .arg(customerNr).arg(m_customerNr));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false; return false;
} }
if (machineNr != m_machineNr) { if (machineNr != m_machineNr) {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)") QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
.arg(machineNr).arg(m_machineNr)); .arg(machineNr).arg(m_machineNr));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false; return false;
} }
qInfo() << "MACHINE-AND-CUSTOMER-CHECK" << m_updateStatus.m_statusDescription;
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID DOES NOT CONTAIN Custom_ID AND/OR Device_ID");
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));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false;
} }
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID KEY NOT A JSON-OBJECT");
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));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false;
} }
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID KEY NOT AVAILABLE");
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));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false;
} }
progress += 1;
setProgress(progress);
if (obj.contains("Fileupload")) { if (obj.contains("Fileupload")) {
QJsonValue v = obj.value("Fileupload"); QJsonValue v = obj.value("Fileupload");
if (v.isObject()) { if (v.isObject()) {
obj = v.toObject(); obj = v.toObject();
if (obj.contains("TRG")) { if (obj.contains("TRG")) {
v = obj.value("TRG"); triggerValue = obj.value("TRG").toString();
if (v.isString()) {
triggerValue = v.toString(); qInfo() << "REPEAT" << repeat
<< "In updateTriggerSet() TRG value=<"
<< triggerValue << ">";
if (triggerValue == "WAIT") { if (triggerValue == "WAIT") {
emit appendText("\nUpdate trigger set", UPDATE_STEP_OK); setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SANITY_CHECK_OK,
QString("MACHINE-NR (%1) AND CUST-NR (%2) OK")
.arg(m_machineNr).arg(m_customerNr));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("MACHINE-AND-CUSTOMER-CHECK",
m_updateStatus.m_statusDescription));
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET, m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
QString("UPDATE TRIGGER SET. CONTINUE. ")); QString("UPDATE TRIGGER SET. CONTINUE. "));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, "")); m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, ""));
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
return true; return true;
} else { } else {
emit showErrorMessage("check update trigger", // if the download-button once has the wrong value, it will never recover
QString ("TRG key=<") + triggerValue setProgress(100);
+ ">\n(reset download button?)"); m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
} QString("TRIGGER-VALUE ") + triggerValue + " NOT 'WAIT'");
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));
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
return false;
} }
} else { } else {
emit showErrorMessage("check update trigger", "TRG key not contained"); setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"TRG KEY NOT AVAILABLE");
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));
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
return false;
} }
} else { } else {
emit showErrorMessage("check update trigger", "Fileupload not a json-object"); setProgress(100);
} m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Fileupload NOT A JSON-OBJECT");
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));
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
return false;
} }
} else { } else {
emit showErrorMessage("check update trigger", "no ISMAS response"); setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Fileupload KEY NOT AVAILABLE");
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));
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
return false;
} }
if (obj.contains("error")) {
progress += 1;
setProgress(progress);
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 << ">";
QThread::sleep(6);
}
} else {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
progress += 1;
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, m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_NOT_SET_OR_WRONG,
QString("UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") + QString("UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") +
triggerValue + ")"); triggerValue + ")");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorUpdateTrigger(m_updateStatus.m_statusDescription, "")); m_ismasClient.errorUpdateTrigger(m_updateStatus.m_statusDescription, ""));
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
return false; return false;
} }
bool Worker::customerEnvironment() { bool Worker::customerEnvironment() {
emit appendText("\nPrepare customer environment ...");
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
startProgressLoop();
if (m_gc.gitCheckoutBranch()) { 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, m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH,
QString("CHECKED-OUT BRANCH ") + m_gc.branchName()); QString("CHECKED-OUT BRANCH ") + m_gc.branchName());
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch(m_updateStatus.m_statusDescription, "")); m_ismasClient.checkoutBranch(m_updateStatus.m_statusDescription, ""));
setProgress(100);
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_DONE);
qInfo() << "PREPARE CUSTOMER ENVIRONMENT DONE";
return true; return true;
} else { } else {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress);
emit showErrorMessage("cust-env", emit showErrorMessage("cust-env",
QString("Checkout ") + m_customerRepository + " failed"); QString("Checkout ") + m_customerRepository + " failed");
Utils::printCriticalErrorMsg(QString("CHECKOUT OF " + m_customerRepository + "FAILED"));
} }
} else { } else {
emit showErrorMessage("cust-env", m_customerRepository + " does not exist"); emit showErrorMessage("cust-env", m_customerRepository + " does not exist");
Utils::printCriticalErrorMsg(m_customerRepository + " DOES NOT EXIST");
} }
setProgress(100);
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_FAIL);
return false; return false;
} }
bool Worker::filesToUpdate() { bool Worker::filesToUpdate() {
emit appendText("\nFetch changes files ...");
startProgressLoop();
if (std::optional<QString> changes = m_gc.gitFetch()) { 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, m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES,
QString("FETCHING OF ") + m_customerRepositoryPath + QString("FETCHING OF ") + m_customerRepositoryPath +
QString(" INTO ") + m_customerRepository); QString(" INTO ") + m_customerRepository);
setProgress(progress + 10);
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) { 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(); m_filesToUpdate = changedFileNames.value();
Utils::printInfoMsg("FILES-TO-UPDATE " + m_filesToUpdate.join(','));
int const size = m_filesToUpdate.size(); int const size = m_filesToUpdate.size();
if (size > 1) { if (size > 1) {
emit appendText(QString("\nFound %1 files to update ").arg(size), 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 { } else {
emit appendText(QString("\nFound 1 file to update "), UPDATE_STEP_DONE); emit appendText("Found 1 file to update :", UPDATE_STEP_DONE);
emit appendText(QString("\n ") + m_filesToUpdate.at(0));
} }
return true; return true;
}
emit showErrorMessage("files to update", "pulling files failed");
Utils::printCriticalErrorMsg("PULLING FILES FAILED");
} else { } else {
emit showErrorMessage("files to update", "no files to update (checked-in any files?)"); emit showErrorMessage("files to update", "no files to update (checked-in any files?)");
Utils::printCriticalErrorMsg("NO FILES TO UPDATE (CHECKED IN ANY FILES?)");
} }
setProgress(progress + 30);
} else { } else {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress + 30);
emit showErrorMessage("files to update", emit showErrorMessage("files to update",
QString("no changes in ") + m_customerRepository + QString("no changes in ") + m_customerRepository +
" (checked-in any files?)"); " (checked-in any files?)");
Utils::printCriticalErrorMsg("NO CHANGES IN "
+ m_customerRepository
+ " (CHECKED IN ANY FILES?)");
} }
emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_FAIL);
setProgress(100);
return false; return false;
} }
bool Worker::updateFiles(quint8 percent) { bool Worker::updateFiles(quint8 percent) {
QStringList filesToDownload; QStringList filesToDownload;
m_displayIndex = 0; m_displayIndex = 0;
startProgressLoop();
for (int i = 0; i < m_filesToUpdate.size(); ++i) { for (int i = 0; i < m_filesToUpdate.size(); ++i) {
QString fName = m_filesToUpdate.at(i); QString const fName = m_filesToUpdate.at(i);
Utils::printInfoMsg(QString("FNAME ") + fName);
if (fName.contains("opkg_commands", Qt::CaseInsensitive)) { if (fName.contains("opkg_commands", Qt::CaseInsensitive)) {
emit appendText("\n( ) Update opkg pakets ...");
// execute opkg commands // execute opkg commands
if (QDir::setCurrent(m_customerRepository)) { if (QDir::setCurrent(m_customerRepository)) {
QFile f(fName); QFile f(fName);
@@ -463,8 +865,12 @@ bool Worker::updateFiles(quint8 percent) {
f.close(); f.close();
if (cmdCount > 0) { if (cmdCount > 0) {
m_displayIndex = 1; m_displayIndex = 1;
emit appendText(QString("\n(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")") emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update opkg pakets "), UPDATE_STEP_DONE); + 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);
} }
} }
} }
@@ -472,21 +878,37 @@ bool Worker::updateFiles(quint8 percent) {
} else } else
if (fName.contains("print", Qt::CaseInsensitive)) { if (fName.contains("print", Qt::CaseInsensitive)) {
filesToDownload << fName; // download printer-config-files filesToDownload << fName; // download printer-config-files
} else } else {
if (fName == "dc2c.bin") { static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
if (fName.contains(version)) {
filesToDownload << fName; // download device controller filesToDownload << fName; // download device controller
} }
} }
}
qCritical() << "XXXXXXXXXXXXXXXXXXX FILES_TO_WORK_ON" << filesToDownload; stopProgressLoop();
setProgress(100);
bool ret = true;
return m_update->doUpdate(m_displayIndex, filesToDownload); if (filesToDownload.size() > 0) {
Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + filesToDownload.join(','));
ret = m_update->doUpdate(m_displayIndex, filesToDownload);
} else {
Utils::printCriticalErrorMsg("NO FILES_TO_DOWNLOAD_TO_PSA_HW");
}
return ret;
} }
bool Worker::syncCustomerRepositoryAndFS() { bool Worker::syncCustomerRepositoryAndFS() {
setProgress(0);
emit appendText("\nSync customer environment with filesystem ...");
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
if (QDir::setCurrent(m_customerRepository)) { if (QDir::setCurrent(m_customerRepository)) {
QString const params("--recursive " int progress = 10;
setProgress(progress);
QString const params("-vv "
"--recursive "
"--progress " "--progress "
"--checksum " "--checksum "
"--exclude=.* " "--exclude=.* "
@@ -501,24 +923,34 @@ bool Worker::syncCustomerRepositoryAndFS() {
QString cmd; QString cmd;
bool error = false; bool error = false;
foreach (cmd, cmds) { foreach (cmd, cmds) {
progress += 5;
setProgress(progress);
if (!error) { if (!error) {
Command c("bash"); Command c("bash");
qInfo() << "EXECUTING CMD..." << cmd; qInfo() << "EXECUTING CMD..." << cmd;
if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) { if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) {
qCritical() << c.getCommandResult() << "SUCCESS"; QStringList result = c.getCommandResult().split('\n');
for (int i = 0; i < result.size(); ++i) {
qInfo() << result.at(i);
}
} else { } else {
qCritical() << "CMD" << cmd << "FAILED"; Utils::printCriticalErrorMsg(QString("CMD ") + cmd + " FAILED: "
+ c.getCommandResult());
error = true; error = true;
} }
} }
} }
progress += 5;
setProgress(progress);
if (!error) { if (!error) {
emit appendText(QString("\nSync customer environment with filesystem "), setProgress(100);
UPDATE_STEP_DONE); emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE);
return true; return true;
} }
} }
} }
setProgress(100);
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_FAIL);
return false; return false;
} }
@@ -526,7 +958,7 @@ bool Worker::sendIsmasLastVersionNotification() {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_SENDVERSION#J=") + QString("#M=APISM#C=CMD_SENDVERSION#J=") +
m_ismasClient.updateOfPSASendVersion(getPSAInstalled())); 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; return true;
} }
@@ -619,14 +1051,12 @@ bool Worker::executeOpkgCommand(QString opkgCommand) {
Command c(opkgCommand); Command c(opkgCommand);
if (c.execute(m_workingDirectory)) { if (c.execute(m_workingDirectory)) {
QString const r = c.getCommandResult(); QString const r = c.getCommandResult();
qInfo() << UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND_SUCCESS, Utils::printInfoMsg(QString("EXECUTE OPKG COMMAND %1 OK: %2")
QString("EXECUTE OPKG COMMAND %1 OK: %2")
.arg(opkgCommand) .arg(opkgCommand)
.arg(c.getCommandResult())); .arg(c.getCommandResult()));
return true; return true;
} else { } else {
qCritical() << UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND_FAILURE, Utils::printCriticalErrorMsg(QString("EXECUTE OPKG COMMAND %1 FAILED")
QString("EXECUTE OPKG COMMAND %1 FAILED")
.arg(opkgCommand)); .arg(opkgCommand));
} }
return false; return false;
@@ -646,19 +1076,23 @@ PSAInstalled Worker::getPSAInstalled() {
PSAInstalled psaInstalled; PSAInstalled psaInstalled;
QString printSysDir("/etc/psa_config"); QString printSysDir("/etc/psa_config");
QString tariffSysDir("/etc/psa_tariff"); QString tariffSysDir("/etc/psa_tariff");
QString tariffRepoDir("etc/psa_tariff");
QString absPathName; QString absPathName;
QString absPathNameRepository;
if (m_zoneNr != 0) { if (m_zoneNr != 0) {
QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0'); QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0');
psaInstalled.tariff.name = QString("tariff%1.json").arg(n); psaInstalled.tariff.name = QString("tariff%1.json").arg(n);
absPathName = QDir::cleanPath(tariffSysDir + QDir::separator() + psaInstalled.tariff.name); absPathName = QDir::cleanPath(tariffSysDir + QDir::separator() + psaInstalled.tariff.name);
psaInstalled.tariff.blob = m_gc.gitBlob(absPathName); psaInstalled.tariff.blob = m_gc.gitBlob(absPathName);
absPathNameRepository = QDir::cleanPath(tariffRepoDir + QDir::separator() + psaInstalled.tariff.name);
psaInstalled.tariff.lastCommit = m_gc.gitLastCommit(absPathNameRepository);
psaInstalled.tariff.size = getFileSize(absPathName); psaInstalled.tariff.size = getFileSize(absPathName);
psaInstalled.tariff.zone = m_zoneNr; psaInstalled.tariff.zone = m_zoneNr;
psaInstalled.tariff.loadTime = Utils::getTariffLoadTime(absPathName);
} }
psaInstalled.tariff.project = "Szeged"; psaInstalled.tariff.project = "Szeged";
psaInstalled.tariff.info = "N/A"; psaInstalled.tariff.info = "N/A";
psaInstalled.tariff.loadTime = "N/A"; // QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
psaInstalled.tariff.version = "N/A"; psaInstalled.tariff.version = "N/A";
psaInstalled.hw.linuxVersion = m_osVersion; psaInstalled.hw.linuxVersion = m_osVersion;

View File

@@ -32,6 +32,9 @@ enum class UPDATE_STATUS : quint8 {
ISMAS_WAIT_STATE_CHECK_SUCCESS, ISMAS_WAIT_STATE_CHECK_SUCCESS,
ISMAS_RESPONSE_RECEIVED, ISMAS_RESPONSE_RECEIVED,
BACKEND_CONNECTED, BACKEND_CONNECTED,
BACKEND_CHECK,
BACKEND_CHECK_FAILURE,
ISMAS_BACKEND_CHECK_FAILURE,
BACKEND_NOT_CONNECTED, BACKEND_NOT_CONNECTED,
UPDATE_TRIGGER_SET, UPDATE_TRIGGER_SET,
UPDATE_TRIGGER_NOT_SET_OR_WRONG, UPDATE_TRIGGER_NOT_SET_OR_WRONG,
@@ -59,6 +62,7 @@ enum class UPDATE_STATUS : quint8 {
DEVICE_CONTROLLER_UPDATE_SUCCESS, DEVICE_CONTROLLER_UPDATE_SUCCESS,
JSON_UPDATE, JSON_UPDATE,
JSON_UPDATE_FAILURE, JSON_UPDATE_FAILURE,
JSON_PARSE_FAILURE,
JSON_UPDATE_SUCCESS, JSON_UPDATE_SUCCESS,
UPDATE_PROCESS_SUCCESS, UPDATE_PROCESS_SUCCESS,
UPDATE_PROCESS_FAILURE, UPDATE_PROCESS_FAILURE,
@@ -67,7 +71,13 @@ enum class UPDATE_STATUS : quint8 {
ISMAS_UPDATE_INFO_CONFIRM_SUCCESS, ISMAS_UPDATE_INFO_CONFIRM_SUCCESS,
ISMAS_CURRENT_PSA_STATUS_CONFIRM, ISMAS_CURRENT_PSA_STATUS_CONFIRM,
ISMAS_CURRENT_PSA_STATUS_CONFIRM_FAILURE, ISMAS_CURRENT_PSA_STATUS_CONFIRM_FAILURE,
ISMAS_CURRENT_PSA_STATUS_CONFIRM_SUCCESS ISMAS_CURRENT_PSA_STATUS_CONFIRM_SUCCESS,
ISMAS_SANITY_CHECK_OK,
ISMAS_UPDATE_TRIGGER_SET_FAILURE,
PSA_UPDATE_FILES_FAILED,
GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
ISMAS_SEND_LAST_VERSION_FAILED,
SAVE_LOG_FILES_FAILED
}; };
struct UpdateStatus { struct UpdateStatus {
@@ -84,6 +94,7 @@ QString& operator<<(QString &str, UpdateStatus status);
#define ISMAS_UPDATE_REQUESTS (10) #define ISMAS_UPDATE_REQUESTS (10)
class MainWindow;
class hwinf; class hwinf;
class Worker : public QObject { class Worker : public QObject {
Q_OBJECT Q_OBJECT
@@ -122,6 +133,11 @@ class Worker : public QObject {
QStringList m_filesToUpdate; QStringList m_filesToUpdate;
bool m_updateProcessRunning; bool m_updateProcessRunning;
int m_displayIndex; int m_displayIndex;
int m_returnCode;
MainWindow *m_mainWindow;
int m_progressValue;
bool m_withoutIsmasDirectPort;
bool executeOpkgCommand(QString opkgCommand); bool executeOpkgCommand(QString opkgCommand);
QString getOsVersion() const; QString getOsVersion() const;
@@ -152,10 +168,16 @@ public:
char const *baudrate = "115200"); char const *baudrate = "115200");
~Worker(); ~Worker();
void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; }
void setProgress(int progress);
void startProgressLoop();
void stopProgressLoop();
IsmasClient &getIsmasClient() { return m_ismasClient; } IsmasClient &getIsmasClient() { return m_ismasClient; }
IsmasClient const &getIsmasClient() const { return m_ismasClient; } IsmasClient const &getIsmasClient() const { return m_ismasClient; }
bool updateProcessRunning() const { return m_updateProcessRunning; } bool updateProcessRunning() const { return m_updateProcessRunning; }
int returnCode() const { return m_returnCode; }
int machineNr() const { return m_machineNr; } int machineNr() const { return m_machineNr; }
int customerNr() const { return m_customerNr; } int customerNr() const { return m_customerNr; }
@@ -171,11 +193,13 @@ public:
//} //}
signals: signals:
void appendText(QString, QString); void appendText(QString, QString suffix = "");
void replaceLast(QString, QString);
void showErrorMessage(QString title, QString description); void showErrorMessage(QString title, QString description);
void setProgress(quint8);
void stopStartTimer(); void stopStartTimer();
void restartExitTimer(); void restartExitTimer();
void enableExit();
void disableExit();
public slots: public slots:
void update(); void update();