Try to establish a connection to backend 50x.

This commit is contained in:
Gerhard Hoffmann 2023-08-09 16:17:28 +02:00
parent e523d3cc2c
commit 042e6dfa38

View File

@ -301,14 +301,14 @@ void Worker::privateUpdate() {
} }
bool Worker::backendConnected() { bool Worker::backendConnected() {
static int repeat = 0; if (m_withoutIsmasDirectPort) { // useful for testing
return true;
if (repeat == 0) {
emit appendText("\nConnecting backend ...");
} }
if (repeat < 3) { emit appendText("\nConnecting backend ...");
qInfo() << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
for (int repeat = 0; repeat < 50; ++repeat) {
qInfo() << "REPEAT" << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
startProgressLoop(); startProgressLoop();
std::optional<QString> result std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse( = IsmasClient::sendRequestReceiveResponse(
@ -334,7 +334,7 @@ bool Worker::backendConnected() {
return false; return false;
} }
setProgress(progress + 10); setProgress(progress + 1);
QJsonObject obj = document.object(); QJsonObject obj = document.object();
QStringList keys = obj.keys(); QStringList keys = obj.keys();
@ -356,11 +356,11 @@ bool Worker::backendConnected() {
return true; return true;
} }
} }
if (status.startsWith("Connecting") || status.startsWith("Re-Connecting")) { emit showErrorMessage("Check backend connection",
QThread::sleep(1); QString ("REPEAT %1 Broker=<").arg(repeat)
++repeat; + status + ">, ISMAS=<" + (ismas ? "true>" : "false>"));
return backendConnected(); QThread::sleep(6);
} continue;
} }
} }
} }
@ -386,15 +386,14 @@ bool Worker::backendConnected() {
} }
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 ..."); emit appendText("\nUpdate trigger set ...");
QString triggerValue(""); QString triggerValue("");
for (int repeat = 0; repeat < 50; ++repeat) {
startProgressLoop(); startProgressLoop();
if (std::optional<QString> result if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse( = IsmasClient::sendRequestReceiveResponse(
@ -404,6 +403,9 @@ bool Worker::updateTriggerSet() {
setProgress(progress); 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) {
@ -426,6 +428,8 @@ bool Worker::updateTriggerSet() {
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()) {
@ -476,6 +480,11 @@ bool Worker::updateTriggerSet() {
v = obj.value("TRG"); v = obj.value("TRG");
if (v.isString()) { if (v.isString()) {
triggerValue = v.toString(); triggerValue = v.toString();
qInfo() << "REPEAT" << repeat
<< "In updateTriggerSet() TRG value=<"
<< triggerValue << ">";
if (triggerValue == "WAIT") { if (triggerValue == "WAIT") {
setProgress(100); setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET, m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
@ -489,8 +498,10 @@ bool Worker::updateTriggerSet() {
return true; return true;
} else { } else {
emit showErrorMessage("check update trigger", emit showErrorMessage("check update trigger",
QString ("TRG key=<") + triggerValue QString ("TRG value=<") + triggerValue
+ ">\n(reset download button?)"); + ">\n(reset download button?)");
QThread::sleep(6);
continue;
} }
} }
} else { } else {
@ -500,11 +511,20 @@ bool Worker::updateTriggerSet() {
emit showErrorMessage("check update trigger", "Fileupload not a json-object"); emit showErrorMessage("check update trigger", "Fileupload not a json-object");
} }
} }
if (obj.contains("error")) {
QString value = obj.value("error").toString();
emit showErrorMessage("check update trigger", QString("REPEAT %1 error=<").arg(repeat) + value + ">");
qInfo() << "REPEAT" << repeat << "In updateTriggerSet() error=<"
<< value << ">";
}
} else { } else {
stopProgressLoop(); stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10; int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress); setProgress(progress);
emit showErrorMessage("check update trigger", "no ISMAS response"); emit showErrorMessage("check update trigger", "no ISMAS response");
QThread::sleep(6);
}
} }
setProgress(100); setProgress(100);
@ -672,6 +692,10 @@ bool Worker::updateFiles(quint8 percent) {
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(")")
+ 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);
} }
} }
} }