Try to establish a connection to backend 50x.
This commit is contained in:
parent
e523d3cc2c
commit
042e6dfa38
248
worker.cpp
248
worker.cpp
@ -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,125 +386,145 @@ 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("");
|
||||||
|
|
||||||
startProgressLoop();
|
for (int repeat = 0; repeat < 50; ++repeat) {
|
||||||
if (std::optional<QString> result
|
startProgressLoop();
|
||||||
= IsmasClient::sendRequestReceiveResponse(
|
if (std::optional<QString> result
|
||||||
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
= IsmasClient::sendRequestReceiveResponse(
|
||||||
stopProgressLoop();
|
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
||||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
stopProgressLoop();
|
||||||
setProgress(progress);
|
int progress = (m_mainWindow->progressValue()/10) + 10;
|
||||||
|
setProgress(progress);
|
||||||
|
|
||||||
QString msg = result.value();
|
QString msg = result.value();
|
||||||
QJsonParseError parseError;
|
|
||||||
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
|
|
||||||
if (parseError.error != QJsonParseError::NoError) {
|
|
||||||
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
|
|
||||||
<< parseError.error << parseError.errorString();
|
|
||||||
emit showErrorMessage("check update trigger",
|
|
||||||
QString("invalid json ") + msg.mid(0, 20));
|
|
||||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!document.isObject()) {
|
|
||||||
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
|
||||||
emit showErrorMessage("check update trigger",
|
|
||||||
QString("not a json object") + msg);
|
|
||||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
setProgress(progress + 1);
|
qInfo() << "REPEAT" << repeat << "APISM RESPONSE" << msg;
|
||||||
|
|
||||||
QJsonObject obj = document.object();
|
QJsonParseError parseError;
|
||||||
// sanity check: cust_nr and machine_nr of PSA correct ?
|
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
|
||||||
if (obj.contains("Dev_ID")) {
|
if (parseError.error != QJsonParseError::NoError) {
|
||||||
QJsonValue v = obj.value("Dev_ID");
|
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
|
||||||
if (v.isObject()) {
|
<< parseError.error << parseError.errorString();
|
||||||
QJsonObject obj = v.toObject();
|
emit showErrorMessage("check update trigger",
|
||||||
if (obj.contains("Custom_ID") && obj.contains("Device_ID")) {
|
QString("invalid json ") + msg.mid(0, 20));
|
||||||
QJsonValue const c = obj.value("Custom_ID");
|
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||||
QJsonValue const m = obj.value("Device_ID");
|
return false;
|
||||||
int customerNr = c.toInt(-1);
|
}
|
||||||
int machineNr = m.toInt(-1);
|
if (!document.isObject()) {
|
||||||
if (customerNr != m_customerNr) {
|
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
||||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
|
emit showErrorMessage("check update trigger",
|
||||||
QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
|
QString("not a json object") + msg);
|
||||||
.arg(customerNr).arg(m_customerNr));
|
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||||
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
|
return false;
|
||||||
|
|
||||||
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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (machineNr != m_machineNr) {
|
|
||||||
setProgress(100);
|
|
||||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
|
|
||||||
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
|
|
||||||
.arg(machineNr).arg(m_machineNr));
|
|
||||||
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
|
|
||||||
|
|
||||||
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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
setProgress(progress + 1);
|
setProgress(progress + 1);
|
||||||
|
|
||||||
if (obj.contains("Fileupload")) {
|
QJsonObject obj = document.object();
|
||||||
QJsonValue v = obj.value("Fileupload");
|
// sanity check: cust_nr and machine_nr of PSA correct ?
|
||||||
if (v.isObject()) {
|
// note: this check has to be done here, as the cust_nr and the machine_nr
|
||||||
obj = v.toObject();
|
// of the PSA are sent by ISMAS.
|
||||||
if (obj.contains("TRG")) {
|
if (obj.contains("Dev_ID")) {
|
||||||
v = obj.value("TRG");
|
QJsonValue v = obj.value("Dev_ID");
|
||||||
if (v.isString()) {
|
if (v.isObject()) {
|
||||||
triggerValue = v.toString();
|
QJsonObject obj = v.toObject();
|
||||||
if (triggerValue == "WAIT") {
|
if (obj.contains("Custom_ID") && obj.contains("Device_ID")) {
|
||||||
setProgress(100);
|
QJsonValue const c = obj.value("Custom_ID");
|
||||||
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_TRIGGER_SET,
|
QJsonValue const m = obj.value("Device_ID");
|
||||||
QString("UPDATE TRIGGER SET. CONTINUE. "));
|
int customerNr = c.toInt(-1);
|
||||||
|
int machineNr = m.toInt(-1);
|
||||||
|
if (customerNr != m_customerNr) {
|
||||||
|
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
|
||||||
|
QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
|
||||||
|
.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.updateTriggerSet(m_updateStatus.m_statusDescription, ""));
|
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||||
|
m_updateStatus.m_statusDescription));
|
||||||
|
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (machineNr != m_machineNr) {
|
||||||
|
setProgress(100);
|
||||||
|
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
|
||||||
|
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
|
||||||
|
.arg(machineNr).arg(m_machineNr));
|
||||||
|
emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription);
|
||||||
|
|
||||||
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
|
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||||
return true;
|
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||||
} else {
|
m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||||
emit showErrorMessage("check update trigger",
|
m_updateStatus.m_statusDescription));
|
||||||
QString ("TRG key=<") + triggerValue
|
emit replaceLast("Update trigger set ...", UPDATE_STEP_FAIL);
|
||||||
+ ">\n(reset download button?)");
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
emit showErrorMessage("check update trigger", "TRG key not contained");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
emit showErrorMessage("check update trigger", "Fileupload not a json-object");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setProgress(progress + 1);
|
||||||
|
|
||||||
|
if (obj.contains("Fileupload")) {
|
||||||
|
QJsonValue v = obj.value("Fileupload");
|
||||||
|
if (v.isObject()) {
|
||||||
|
obj = v.toObject();
|
||||||
|
if (obj.contains("TRG")) {
|
||||||
|
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,
|
||||||
|
QString("UPDATE TRIGGER SET. CONTINUE. "));
|
||||||
|
|
||||||
|
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||||
|
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||||
|
m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, ""));
|
||||||
|
|
||||||
|
emit replaceLast("Update trigger set ...", UPDATE_STEP_OK);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
emit showErrorMessage("check update trigger",
|
||||||
|
QString ("TRG value=<") + triggerValue
|
||||||
|
+ ">\n(reset download button?)");
|
||||||
|
QThread::sleep(6);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit showErrorMessage("check update trigger", "TRG key not contained");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
stopProgressLoop();
|
|
||||||
int progress = (m_mainWindow->progressValue()/10) + 10;
|
|
||||||
setProgress(progress);
|
|
||||||
emit showErrorMessage("check update trigger", "no ISMAS response");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user