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() {
static int repeat = 0;
if (repeat == 0) {
emit appendText("\nConnecting backend ...");
if (m_withoutIsmasDirectPort) { // useful for testing
return true;
}
if (repeat < 3) {
qInfo() << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
emit appendText("\nConnecting backend ...");
for (int repeat = 0; repeat < 50; ++repeat) {
qInfo() << "REPEAT" << repeat << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
startProgressLoop();
std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
@ -334,7 +334,7 @@ bool Worker::backendConnected() {
return false;
}
setProgress(progress + 10);
setProgress(progress + 1);
QJsonObject obj = document.object();
QStringList keys = obj.keys();
@ -356,11 +356,11 @@ bool Worker::backendConnected() {
return true;
}
}
if (status.startsWith("Connecting") || status.startsWith("Re-Connecting")) {
QThread::sleep(1);
++repeat;
return backendConnected();
}
emit showErrorMessage("Check backend connection",
QString ("REPEAT %1 Broker=<").arg(repeat)
+ status + ">, ISMAS=<" + (ismas ? "true>" : "false>"));
QThread::sleep(6);
continue;
}
}
}
@ -386,15 +386,14 @@ bool Worker::backendConnected() {
}
bool Worker::updateTriggerSet() {
// nmap -Pn 62.141.45.68 -p 8883
// Host is up (0.053s latency).
//
// PORT STATE SERVICE
// 8883/tcp open secure-mqtt
if (m_withoutIsmasDirectPort) { // useful for testing
return true;
}
emit appendText("\nUpdate trigger set ...");
QString triggerValue("");
for (int repeat = 0; repeat < 50; ++repeat) {
startProgressLoop();
if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
@ -404,6 +403,9 @@ bool Worker::updateTriggerSet() {
setProgress(progress);
QString msg = result.value();
qInfo() << "REPEAT" << repeat << "APISM RESPONSE" << msg;
QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) {
@ -426,6 +428,8 @@ bool Worker::updateTriggerSet() {
QJsonObject obj = document.object();
// sanity check: cust_nr and machine_nr of PSA correct ?
// note: this check has to be done here, as the cust_nr and the machine_nr
// of the PSA are sent by ISMAS.
if (obj.contains("Dev_ID")) {
QJsonValue v = obj.value("Dev_ID");
if (v.isObject()) {
@ -476,6 +480,11 @@ bool Worker::updateTriggerSet() {
v = obj.value("TRG");
if (v.isString()) {
triggerValue = v.toString();
qInfo() << "REPEAT" << repeat
<< "In updateTriggerSet() TRG value=<"
<< triggerValue << ">";
if (triggerValue == "WAIT") {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
@ -489,8 +498,10 @@ bool Worker::updateTriggerSet() {
return true;
} else {
emit showErrorMessage("check update trigger",
QString ("TRG key=<") + triggerValue
QString ("TRG value=<") + triggerValue
+ ">\n(reset download button?)");
QThread::sleep(6);
continue;
}
}
} else {
@ -500,11 +511,20 @@ bool Worker::updateTriggerSet() {
emit showErrorMessage("check update trigger", "Fileupload not a json-object");
}
}
if (obj.contains("error")) {
QString value = obj.value("error").toString();
emit showErrorMessage("check update trigger", QString("REPEAT %1 error=<").arg(repeat) + value + ">");
qInfo() << "REPEAT" << repeat << "In updateTriggerSet() error=<"
<< value << ">";
}
} else {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress);
emit showErrorMessage("check update trigger", "no ISMAS response");
QThread::sleep(6);
}
}
setProgress(100);
@ -672,6 +692,10 @@ bool Worker::updateFiles(quint8 percent) {
m_displayIndex = 1;
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update opkg pakets ... "), UPDATE_STEP_DONE);
} else {
m_displayIndex = 1;
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update opkg pakets ... "), UPDATE_STEP_FAIL);
}
}
}