Compare commits

..

11 Commits

9 changed files with 216 additions and 21 deletions

View File

@ -217,7 +217,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
// QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")"); // QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")");
// } // }
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT ") + buf); printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
loop = 0; loop = 0;
bzero(buf, sizeof(buf)); bzero(buf, sizeof(buf));

104
main.cpp
View File

@ -31,6 +31,7 @@
#include "utils.h" #include "utils.h"
#include <QThread> #include <QThread>
#include <QtWidgets>
#ifdef PTU5 #ifdef PTU5
#define SERIAL_PORT "ttymxc2" #define SERIAL_PORT "ttymxc2"
@ -38,6 +39,93 @@
#define SERIAL_PORT "ttyUSB0" #define SERIAL_PORT "ttyUSB0"
#endif #endif
#if 0
static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
const QSizeF &preferred = QSize(150.0, 100.0),
const QSizeF &maximum = QSizeF(200.0, 100.0),
const QString &name = "0")
{
QGraphicsProxyWidget *w = new QGraphicsProxyWidget;
w->setWidget(new QPushButton(name));
w->setData(0, name);
w->setMinimumSize(minimum);
w->setPreferredSize(preferred);
w->setMaximumSize(maximum);
w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
return w;
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0, 0, 800, 480);
QSizeF minSize(30, 100);
QSizeF prefSize(210, 100);
QSizeF maxSize(300, 100);
QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A");
QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B");
QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C");
QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D");
QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E");
QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)");
QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)");
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
w->setPos(20, 20);
w->setLayout(l);
// vertical
l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);
// horizontal
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);
scene.addItem(w);
scene.setBackgroundBrush(Qt::darkGreen);
QGraphicsView view(&scene);
view.show();
return app.exec();
}
#endif
// argv[1]: file to send to dc // argv[1]: file to send to dc
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QByteArray const value = qgetenv("LC_ALL"); QByteArray const value = qgetenv("LC_ALL");
@ -52,6 +140,22 @@ int main(int argc, char *argv[]) {
QApplication::setApplicationName("ATBUpdateTool"); QApplication::setApplicationName("ATBUpdateTool");
QApplication::setApplicationVersion(APP_VERSION); QApplication::setApplicationVersion(APP_VERSION);
#if 0
// vorbereitend
QGraphicsScene scene;
scene.setSceneRect(0, 0, 800, 480);
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
w->setPos(20, 20);
w->setLayout(l);
QGraphicsView view(&scene);
// view.show();
#endif
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput); atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(LOG_NOTICE); setDebugLevel(LOG_NOTICE);

View File

@ -7,6 +7,7 @@
#include <QDateTime> #include <QDateTime>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QScrollBar>
MainWindow::MainWindow(Worker *worker, QWidget *parent) MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -42,17 +43,15 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
m_exitTimer->setSingleShot(true); m_exitTimer->setSingleShot(true);
m_exitTimer->start(1800 * 1000); m_exitTimer->start(1800 * 1000);
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit())); connect(ui->exit, SIGNAL(clicked()),this,SLOT(onQuit()));
connect(m_worker, SIGNAL(disableExit()), this, SLOT(onDisableExit())); connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit()));
connect(m_worker, SIGNAL(enableExit()), this, SLOT(onEnableExit())); connect(m_worker, SIGNAL(enableExit()),this,SLOT(onEnableExit()));
connect(m_worker, SIGNAL(stopStartTimer()), this, SLOT(onStopStartTimer())); connect(m_worker, SIGNAL(stopStartTimer()),this,SLOT(onStopStartTimer()));
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer())); connect(m_worker, SIGNAL(restartExitTimer()),this,SLOT(onRestartExitTimer()));
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString))); 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(showErrorMessage(QString,QString)),this, SLOT(onShowErrorMessage(QString,QString)));
connect(m_worker, SIGNAL(replaceLast(QString, QString)), this, SLOT(onReplaceLast(QString,QString))); connect(m_worker, SIGNAL(replaceLast(QString,QString)),this,SLOT(onReplaceLast(QString,QString)));
connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,QString)));
ui->updateStatus->setText(lst.join('\n'));
ui->updateStatus->setEnabled(true);
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
@ -137,6 +136,15 @@ void MainWindow::onQuit() {
qApp->exit(m_worker->returnCode()); qApp->exit(m_worker->returnCode());
} }
void MainWindow::scrollDownTextEdit() {
ui->updateStatus->setEnabled(true);
QTextCursor tmpCursor = ui->updateStatus->textCursor();
tmpCursor.movePosition(QTextCursor::End);
ui->updateStatus->setTextCursor(tmpCursor);
ui->updateStatus->ensureCursorVisible();
}
void MainWindow::onAppendText(QString text, QString suffix) { void MainWindow::onAppendText(QString text, QString suffix) {
QString editText = ui->updateStatus->toPlainText(); QString editText = ui->updateStatus->toPlainText();
if (!suffix.isNull() && suffix.size() > 0) { if (!suffix.isNull() && suffix.size() > 0) {
@ -151,9 +159,40 @@ void MainWindow::onAppendText(QString text, QString suffix) {
} }
Utils::printLineEditInfo(editText.split('\n')); Utils::printLineEditInfo(editText.split('\n'));
ui->updateStatus->setPlainText(editText.trimmed()); ui->updateStatus->setPlainText(editText.trimmed());
ui->updateStatus->setEnabled(true); scrollDownTextEdit();
}
void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) {
int const s = newTextLines.size();
if (s > 0) {
QString editText = ui->updateStatus->toPlainText();
QStringList lines = editText.split('\n');
QString newText;
if (lines.size() >= s) {
for (int i = 0; i < s; ++i) {
lines.removeLast();
}
if (lines.size() > 0) {
newText = lines.join('\n');
newText += '\n';
}
QStringList newLines;
for (int i = 0; i < s; ++i) {
if (i == 0 && !suffix.isNull() && suffix.size() > 0 && suffix != "\n") {
newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10) + suffix);
} else {
newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10));
}
}
lines += newLines;
newText += newLines.join(' ');
}
ui->updateStatus->setText(newText);
Utils::printLineEditInfo(lines);
scrollDownTextEdit();
}
} }
void MainWindow::onReplaceLast(QString text, QString suffix) { void MainWindow::onReplaceLast(QString text, QString suffix) {
@ -170,16 +209,21 @@ void MainWindow::onReplaceLast(QString text, QString suffix) {
} }
Utils::printLineEditInfo(lines); Utils::printLineEditInfo(lines);
ui->updateStatus->setText(lines.join('\n').trimmed()); ui->updateStatus->setText(lines.join('\n').trimmed());
ui->updateStatus->setEnabled(true); scrollDownTextEdit();
} }
void MainWindow::onShowErrorMessage(QString title, QString text) { void MainWindow::onShowErrorMessage(QString title, QString text) {
text = text.leftJustified(50, ' '); text = text.leftJustified(50, ' ');
QMessageBox msgBox(QMessageBox::NoIcon, title, QMessageBox msgBox(QMessageBox::NoIcon, title,
text, QMessageBox::Ok, text, QMessageBox::Ok,
nullptr, Qt::FramelessWindowHint); this, Qt::FramelessWindowHint);
msgBox.resize(100, 50);
// msg.setStyleSheet("background-color: rgb(0, 0, 0);")
// msg.setStyleSheet("text-color: rgb(255, 255, 255);")
msgBox.setStyleSheet("QMessageBox{border: 1px solid black; background-color:white}");
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.defaultButton()->setVisible(false); msgBox.defaultButton()->setVisible(false);
@ -188,6 +232,9 @@ void MainWindow::onShowErrorMessage(QString title, QString text) {
t->setSingleShot(true); t->setSingleShot(true);
t->start(5 * 1000); t->start(5 * 1000);
msgBox.show();
msgBox.move(0, 0);
if(msgBox.exec() == QMessageBox::Ok) { if(msgBox.exec() == QMessageBox::Ok) {
// do something // do something
} else { } else {

View File

@ -27,6 +27,7 @@ public:
public slots: public slots:
void onAppendText(QString, QString suffix = ""); void onAppendText(QString, QString suffix = "");
void onReplaceLast(QStringList, QString suffix = "");
void onReplaceLast(QString, QString suffix = ""); void onReplaceLast(QString, QString suffix = "");
void onShowErrorMessage(QString, QString); void onShowErrorMessage(QString, QString);
void onStopStartTimer(); void onStopStartTimer();
@ -38,6 +39,8 @@ private slots:
void onQuit(); void onQuit();
private: private:
void scrollDownTextEdit();
Ui::MainWindow *ui; Ui::MainWindow *ui;
Worker *m_worker; Worker *m_worker;
int m_width; int m_width;

View File

@ -55,6 +55,15 @@
<bold>true</bold> <bold>true</bold>
</font> </font>
</property> </property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -77,3 +77,12 @@ QString Utils::getTariffLoadTime(QString fileName) {
return "N/A"; return "N/A";
} }
QString Utils::rstrip(QString const &str) {
int n = str.size() - 1;
for (; n >= 0; --n) {
if (!str.at(n).isSpace()) {
return str.left(n + 1);
}
}
return "";
}

View File

@ -15,6 +15,7 @@ namespace Utils {
void printInfoMsg(QString const &infoMsg); void printInfoMsg(QString const &infoMsg);
void printLineEditInfo(QStringList const &lines); void printLineEditInfo(QStringList const &lines);
QString getTariffLoadTime(QString fileName); QString getTariffLoadTime(QString fileName);
QString rstrip(QString const &str);
} }
#endif // UTILS_H_INCLUDED #endif // UTILS_H_INCLUDED

View File

@ -506,10 +506,25 @@ bool Worker::updateTriggerSet() {
emit appendText("\n" CHECK_UPDATE_TRIGGER_SET); emit appendText("\n" CHECK_UPDATE_TRIGGER_SET);
QString triggerValue(""); QString triggerValue("");
int const startMs = QTime::currentTime().msecsSinceStartOfDay();
for (int repeat = 0; repeat < 100; ++repeat) { for (int repeat = 1; repeat <= 100; ++repeat) {
qInfo() << "UPDATE TRIGGER SET -> REPEAT" << repeat; qInfo() << "UPDATE TRIGGER SET -> REPEAT" << repeat;
if (repeat > 1) {
int const durationMs = QTime::currentTime().msecsSinceStartOfDay() - startMs;
qInfo() << "REPEAT" << repeat
<< QString("DURATION: %1.%2s").arg(durationMs / 1000).arg(durationMs % 1000);
}
if ((repeat % 10) == 0) {
qInfo() << "CHECK UPDATE TRIGGER. RESTART APISM ...";
Command c("systemctl restart apism");
if (c.execute("/tmp")) {
QThread::sleep(20); // give APISM some time to reconnect
qInfo() << "CHECK UPDATE TRIGGER. RESTARTING APISM DONE";
}
}
startProgressLoop(); startProgressLoop();
if (std::optional<QString> result if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse( = IsmasClient::sendRequestReceiveResponse(
@ -876,14 +891,18 @@ bool Worker::updateFiles(quint8 percent) {
if (f.open(QIODevice::ReadOnly)) { if (f.open(QIODevice::ReadOnly)) {
QTextStream in(&f); QTextStream in(&f);
int cmdCount = 0; int cmdCount = 0;
QStringList opkgCommands;
while (!in.atEnd()) { while (!in.atEnd()) {
QString line = in.readLine(); QString line = in.readLine();
static const QRegularExpression comment("^\\s*#.*$"); static const QRegularExpression comment("^\\s*#.*$");
if (line.indexOf(comment, 0) == -1) { if (line.indexOf(comment, 0) == -1) {
// found opkg command // found opkg command
QString opkgCommand = line.trimmed(); QString opkgCommand = line.trimmed();
executeOpkgCommand(opkgCommand);
++cmdCount; ++cmdCount;
executeOpkgCommand(opkgCommand);
QString cmd = "\n " + opkgCommand;
emit appendText(cmd);
opkgCommands << cmd;
m_ismasClient.setProgressInPercent(++percent); m_ismasClient.setProgressInPercent(++percent);
m_updateStatus = UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND, m_updateStatus = UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND,
@ -896,8 +915,10 @@ bool Worker::updateFiles(quint8 percent) {
f.close(); f.close();
if (cmdCount > 0) { if (cmdCount > 0) {
m_displayIndex = 1; m_displayIndex = 1;
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")") QString prepend = QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update opkg pakets ... "), UPDATE_STEP_DONE); + QString(" Update opkg pakets ... ");
opkgCommands.prepend(prepend);
emit replaceLast(opkgCommands, UPDATE_STEP_DONE);
} else { } else {
m_displayIndex = 1; m_displayIndex = 1;
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")") emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")

View File

@ -167,6 +167,7 @@ public:
signals: signals:
void appendText(QString, QString suffix = ""); void appendText(QString, QString suffix = "");
void replaceLast(QString, QString); void replaceLast(QString, QString);
void replaceLast(QStringList, QString);
void showErrorMessage(QString title, QString description); void showErrorMessage(QString title, QString description);
void stopStartTimer(); void stopStartTimer();
void restartExitTimer(); void restartExitTimer();