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 += \
main.cpp \
progress_event.cpp \
mainwindow.cpp \
utils.cpp \
update.cpp \
@@ -89,6 +90,7 @@ SOURCES += \
HEADERS += \
update.h \
progress_event.h \
utils.h \
mainwindow.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
# 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="
<< result;
Utils::printCriticalErrorMsg(QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=") + result);
}
return false;
}
@@ -86,7 +85,7 @@ bool GitClient::gitCheckoutBranch() {
// TODO: nachsehen, ob der Branch ueberhaupt existiert
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)
? QString("zg1/zone%1").arg(zoneNr) : "master";
@@ -96,7 +95,7 @@ bool GitClient::gitCheckoutBranch() {
Command c(gitCommand);
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;
}
@@ -108,13 +107,10 @@ bool GitClient::gitCloneAndCheckoutBranch() {
return true;
} else {
// TODO
// m_worker->terminateUpdateProcess();
}
//}
} else {
// TODO
//m_worker->terminateUpdateProcess();
}
Utils::printCriticalErrorMsg(QString("CLONE ") + m_repositoryPath + " AND CHECKOUT FAILED");
return false;
}
@@ -131,24 +127,37 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
Command c(gitCommand);
if (c.execute(m_customerRepository)) { // execute command in local customerRepo
QString s = c.getCommandResult().trimmed();
Utils::printInfoMsg("GIT DIFF RESULT " + s);
QStringList lines = Update::split(s, '\n');
QStringList fileNames;
// each line has the format "etc/psa_config/DC2C_print01.json | 1 +
// or the format "etc/psa_config/DC2C_print01.json (new) | 1 +
// the filenames are relativ to the repository
for (int i = 0; i < lines.size(); ++i) {
// TODO: koennte auch (delete) kommen ?
int newIndex = lines.at(i).indexOf("(new)"); // for new files
// int goneIndex = lines.at(i).indexOf("(gone)"); // for removed files
QString const &line = lines.at(i);
int newIndex = line.indexOf("(new"); // for new files
int goneIndex = line.indexOf("(gone"); // for removed files
int modeIndex = line.indexOf("(mode");
int pipeIndex = line.indexOf('|');
if (newIndex != -1) {
QString fileName = lines.at(i).mid(0, newIndex).trimmed();
fileNames << fileName;
} else {
int pipeIndex = lines.at(i).indexOf('|');
if (pipeIndex != -1) {
QString fileName = lines.at(i).mid(0, pipeIndex).trimmed();
fileNames << fileName;
}
QString file = line.left(newIndex).trimmed();
qInfo() << "FILE (NEW)" << file;
fileNames << file;
} else
if (modeIndex != -1) {
QString const file = line.left(modeIndex).trimmed();
qInfo() << "FILE (MODE)" << file;
fileNames << file;
} else
if (goneIndex != -1) {
QString const file = line.left(goneIndex).trimmed();
qCritical() << "FILE (GONE)" << file;
} else
if (pipeIndex != -1) {
QString const file = line.left(pipeIndex).trimmed();
qInfo() << "FILE (PIPE)" << file;
fileNames << file;
}
}
if (!fileNames.isEmpty()) {
@@ -164,14 +173,7 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
*/
std::optional<QString> GitClient::gitFetch() {
if (QDir(m_customerRepository).exists()) {
// 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));
qInfo() << "BRANCH NAME" << m_branchName;
Command c("git fetch");
if (c.execute(m_customerRepository)) {
@@ -179,36 +181,54 @@ std::optional<QString> GitClient::gitFetch() {
if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n');
if (!lines.empty()) {
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
QRegularExpressionMatch match = re.match(lines.last());
if (match.hasMatch()) {
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);
} else {
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount();
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
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
QRegularExpressionMatch match = re.match(lines.at(i));
if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
return match.captured(2);
} else {
emit m_worker->showErrorMessage("git fetch",
QString("(wrong cap-count (%1)").arg(re.captureCount()));
}
} else {
emit m_worker->showErrorMessage("git fetch",
"no regex-match for commits");
Utils::printCriticalErrorMsg("NO REGEX MATCH FOR COMMITS");
}
}
} else {
qCritical() << "ERROR NO MATCH OF COMMITS FOR 'GIT FETCH'";
}
if (!found) {
emit m_worker->showErrorMessage("git fetch",
QString("unkown branch name ") + m_branchName);
Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName);
}
} 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 {
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 {
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;
}
@@ -229,7 +249,7 @@ bool GitClient::gitPull() {
qInfo() << "PULLED INTO" << m_customerRepository;
return true;
}
qCritical() << "PULL INTO" << m_customerRepository << "FAILED";
Utils::printCriticalErrorMsg(QString("PULL INTO " + m_customerRepository + " FAILED"));
}
return false;
}
@@ -248,13 +268,15 @@ QString GitClient::gitLastCommit(QString fileName) {
if (QDir(m_customerRepository).exists()) {
QString const filePath
= QDir::cleanPath(m_customerRepository + QDir::separator() + fileName);
QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName);
Command c("bash");
if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) {
QString const r = c.getCommandResult();
int const idx = r.indexOf("commit ");
if (idx != -1) {
return r.mid(idx + 8).trimmed();
if (QFile(filePath).exists()) {
QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName);
Command c("bash");
if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) {
QString const r = c.getCommandResult();
int const idx = r.indexOf("commit ");
if (idx != -1) {
return r.mid(idx + 8).trimmed();
}
}
}
}

View File

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

View File

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

View File

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

View File

@@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include "worker.h"
#include "utils.h"
#include "progress_event.h"
#include <QDateTime>
#include <QMessageBox>
@@ -11,32 +12,14 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_worker(worker)
, m_width(52) {
, m_width(70)
, m_progressRunning(false)
, m_progressValue(0) {
ui->setupUi(this);
ui->updateProgress->setRange(1, 100);
ui->updateProgress->setRange(0, 100);
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;
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
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->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() {
@@ -56,42 +61,137 @@ MainWindow::~MainWindow() {
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() {
m_startTimer->stop();
}
void MainWindow::onDisableExit() {
ui->exit->setEnabled(false);
}
void MainWindow::onEnableExit() {
ui->exit->setEnabled(true);
}
void MainWindow::onRestartExitTimer() {
m_exitTimer->stop();
m_exitTimer->start(5 * 1000);
m_exitTimer->start(60 * 1000);
}
void MainWindow::onQuit() {
if (!m_worker->updateProcessRunning()) {
qApp->quit();
}
}
void MainWindow::onSetProgress(quint8 v) {
ui->updateProgress->setValue(v);
m_exitTimer->stop();
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode());
qApp->exit(m_worker->returnCode());
}
void MainWindow::onAppendText(QString text, QString suffix) {
QString editText = ui->updateStatus->toPlainText();
QStringList lines = editText.split('\n');
for (int i=0; i<lines.size(); ++i) {
qCritical() << lines.at(i);
}
if (!suffix.contains("[SUCCESS]")) {
editText += text.leftJustified(m_width-9) + suffix;
ui->updateStatus->setPlainText(editText);
if (!suffix.isNull() && suffix.size() > 0) {
qInfo() << "TEXT" << text << "SUFFIX" << suffix;
if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) {
editText += QString("\n").leftJustified(m_width-3, '=');
editText += " ";
}
editText += (QString("\n") + text).leftJustified(m_width - (2 + suffix.size()) ) + suffix;
} else {
editText += QString("\n").leftJustified(m_width-3, '=');
editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]";
editText += text.leftJustified(m_width-9);
}
ui->updateStatus->setText(editText);
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);
}
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 {
Q_OBJECT
protected:
void customEvent(QEvent *event) override;
public:
MainWindow(Worker *worker, QWidget *parent = nullptr);
~MainWindow();
static const int START_PROGRESS_LOOP = -1;
static const int STOP_PROGRESS_LOOP = -2;
int progressValue() const { return m_progressValue; }
public slots:
void onAppendText(QString, QString);
void onAppendText(QString, QString suffix = "");
void onReplaceLast(QString, QString suffix = "");
void onShowErrorMessage(QString, QString);
void onSetProgress(quint8);
void onStopStartTimer();
void onRestartExitTimer();
void onEnableExit();
void onDisableExit();
private slots:
void onQuit();
@@ -33,5 +43,7 @@ private:
int m_width;
QTimer *m_startTimer;
QTimer *m_exitTimer;
bool m_progressRunning;
int m_progressValue;
};
#endif // MAINWINDOW_H

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>358</height>
<width>800</width>
<height>480</height>
</rect>
</property>
<property name="font">
@@ -19,56 +19,44 @@
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>11</y>
<width>351</width>
<height>341</height>
<y>10</y>
<width>781</width>
<height>461</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="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">
<item row="3" column="2">
<widget class="QPushButton" name="exit">
<property name="text">
<string>Exit</string>
</property>
</widget>
</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>
</widget>
</widget>

View File

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

View File

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

View File

@@ -128,13 +128,11 @@ struct T_vaultRecord
uint32_t AbsReserve;
uint32_t AbsNrOfCuts;
//16
char label3buffer[4]; // mw >
// Verkauf, Tuer zu:
uint32_t VKcoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen
uint32_t VKcoinsReturned[6]; // nur fuer Wechsler, Anzahl Muenzen pro Typ, soviel wurde zurueckgegeben
//88
// Service, Tuer offen:
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 resint5;
uint16_t resint6;
// 56
char label4buffer[4]; // box>
uint16_t coinsInVault[16];
uint16_t billsInStacker[8];
// 48
char label5buffer[4]; // val>
// actually constant unless exchange rate is changed
@@ -159,11 +155,17 @@ struct T_vaultRecord
uint16_t exchangeRate;
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 kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza Csquare (MW)
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 kindOfCreditcard; // 0:off 1:Feig NFC
@@ -336,6 +339,8 @@ struct T_devices
UINT VaultFullWarnLevel;
UINT VaultFullErrorLevel;
UINT BattEmptyWarnLevel;
UINT BattEmptyErrorLevel;
};
@@ -1151,14 +1156,13 @@ public:
// to be forwarded to Ismas
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
virtual bool prn_printTestTicket(void) const =0;
// return true if sending to DC OK, false if cmd-stack is full
virtual bool cash_startPayment(uint32_t amount) const =0;
// 17.4.23TS: extended to 32bit
@@ -1273,7 +1277,7 @@ public:
virtual uint16_t log_getLatestAccountNumber(void) const=0;
// new function 27.6.2023
// latest = highest
// latest = highest of the backup's
virtual uint8_t log_getAvailableVaultBlocks(void) const=0;
// return 0x0011 1111 if all 6 blocks are loaded (one bit per block)
@@ -1297,7 +1301,45 @@ public:
// 2: done and error
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
// 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.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.1"
//#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)) {
//qDebug() << "PROCESS" << m_command << "FINISHED";
if (p->exitStatus() == QProcess::NormalExit) {
//qInfo() << "EXECUTED" << m_command
// << "with code" << p->exitCode();
// qInfo() << "RESULT" << m_commandResult;
return true;
if (p->exitCode() == 0) {
return true;
} else {
qCritical() << "EXECUTED" << m_command << "with code" << p->exitCode();
}
} else {
qCritical() << "PROCESS" << m_command << "CRASHED with code"
<< 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 <QTextStream>
#include <QRegularExpression>
#include <QRegExp>
//#include <iostream>
//#include <fstream>
@@ -350,21 +351,25 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
10 : bl_stopBL() // leave bl and start (the new) application
*/
bool Update::updateBinary(char const *fileToSendToDC) {
qInfo() << "updating device controller binary" << fileToSendToDC;
qInfo() << "UPDATING DEVICE CONTROLLER BINARY" << fileToSendToDC;
QFile fn(fileToSendToDC);
bool r;
if ((r = fn.exists()) == true) {
QString const linkTarget = fn.symLinkTarget();
QFileInfo fi(linkTarget);
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
if ((r = updateDC(linkTarget)) == true) {
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
QFileInfo fi(fn);
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ")";
if ((r = updateDC(fileToSendToDC)) == true) {
qCritical() << QString(80, '*');
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") DONE";
qCritical() << QString(80, '*');
} else {
qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
qCritical() << QString(80, '*');
qCritical() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") FAILED";
qCritical() << QString(80, '*');
}
} else {
qCritical() << "symlink" << fileToSendToDC
<< "does not exist -> NO UPDATE OF DC FIRMWARE";
qCritical() << QString(80, '*');
qCritical() << fileToSendToDC << "does not exist -> NO UPDATE OF DC FIRMWARE";
qCritical() << QString(80, '*');
}
return r;
}
@@ -514,7 +519,6 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
}
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
//
// ACHTUNG !!!
//
@@ -523,11 +527,6 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
bool serialOpened = false;
bool serialOpen = false;
if (filesToWorkOn.size() == 0) {
qCritical() << "NOTHING TO UPDATE";
return true;
}
if (!serialOpen) {
if (!isSerialOpen()) { // open serial only if not already open
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) {
@@ -537,18 +536,23 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
}
}
serialOpen = true;
qCritical() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
qInfo() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
}
bool res = false;
QList<QString>::const_iterator it;
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
bool res = false;
m_worker->startProgressLoop();
QString fToWorkOn = (*it).trimmed();
fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn);
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) &&
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) {
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
if (fToWorkOn.contains(version)) {
qInfo() << QString(80, '*');
qInfo() << "DO-UPDATE FILE-TO-WORK-ON" << fToWorkOn;
qInfo() << QString(80, '*');
qDebug() << "sending sw/hw-requests...";
for (int i=0; i < 3; ++i) { // send explicit reuests to get
// current SW/HW-versions
m_hw->request_DC2_SWversion();
@@ -558,12 +562,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
QString const hwVersion = m_hw->dc_getHWversion().toLower();
QString const fwVersion = m_hw->dc_getSWversion().toLower();
qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion;
QFile fn(fToWorkOn);
QFileInfo linkTarget(fn.symLinkTarget());
if (!linkTarget.exists()) { // check for broken link
QFileInfo finfo(fn);
if (!fn.exists()) { // check for broken link
qCritical() << QString(80, '*');
qCritical() << "FILE-TO-WORK-ON" << fn << "DOES NOT EXIST";
qCritical() << QString(80, '*');
res = false;
} else {
if (false) {
@@ -574,13 +582,12 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
} else {
res = true;
qCritical() << "downloading" << fToWorkOn.trimmed() << "->"
<< linkTarget.completeBaseName() << "to DC";
qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
#if UPDATE_DC == 1
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(1); // wait to be sure that there are no more
// commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
qInfo() << "SET AUTO-REQUEST=FALSE";
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << fToWorkOn;
@@ -591,13 +598,13 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
}
m_hw->dc_autoRequest(true); // turn auto-request setting on
qDebug() << "SET AUTO-REQUEST=TRUE";
qDebug() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
qInfo() << "SET AUTO-REQUEST=TRUE";
qInfo() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
QThread::sleep(10); // wait to be sure that responses
// have been received
qCritical() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qCritical() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
qInfo() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
#endif
}
}
@@ -660,10 +667,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
res = false;
}
m_worker->stopProgressLoop();
m_worker->setProgress(100);
if (res == false) {
break;
}
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
qDebug() << "SET AUTO-REQUEST=TRUE";
return true;
return res;
}

View File

@@ -1,8 +1,9 @@
#include "utils.h"
#include "message_handler.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
int Utils::read1stLineOfFile(QString fileName) {
QFile f(fileName);
@@ -33,3 +34,46 @@ QString Utils::zoneName(quint8 i) {
}
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 <QString>
#include <QStringList>
#include <QFile>
#include <QFileInfo>
#include <QDateTime>
namespace Utils {
int read1stLineOfFile(QString fileName);
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

File diff suppressed because it is too large Load Diff

View File

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