|
@@ -14,6 +14,7 @@
|
|
|
#include <QUrlQuery>
|
|
|
|
|
|
#include "../backendapimanager.h"
|
|
|
+#include "../global.h"
|
|
|
#include "../logger.h"
|
|
|
#include "ui_firingwidget.h"
|
|
|
|
|
@@ -46,7 +47,7 @@ firingWidget::firingWidget(const int &row, const bool &select, const QString &uu
|
|
|
mqttThread->start();
|
|
|
connect(mqttThread, &MqttThread::projectMqttMessageReceived, this,
|
|
|
&firingWidget::handleProjectFiringMqttMessage);
|
|
|
- connect(this, &firingWidget::lastStageChanged, this, &firingWidget::onLastStageChanged);
|
|
|
+ connect(this, &firingWidget::lastStageChanged, this, &firingWidget::hanldeFiringStageChanged);
|
|
|
connect(this, &firingWidget::updateData, this, &firingWidget::onBlastSucess);
|
|
|
startBlasting();
|
|
|
}
|
|
@@ -90,38 +91,36 @@ void firingWidget::startBlasting() {
|
|
|
});
|
|
|
connectionCheckTimer->start(2000);
|
|
|
}
|
|
|
-void firingWidget::cancelBlasting();
|
|
|
-void firingWidget::on_sendTest_4_clicked();
|
|
|
-
|
|
|
-void firingWidget::startHeartbeatMonitor() {
|
|
|
- m_isHeartBeating = true;
|
|
|
- QThread *heartbeatThread = new QThread();
|
|
|
- QTimer *heartbeatTimer = new QTimer(nullptr);
|
|
|
- heartbeatTimer->setInterval(3000); // 3 seconds interval
|
|
|
- heartbeatTimer->moveToThread(heartbeatThread);
|
|
|
-
|
|
|
- connect(heartbeatThread, &QThread::started, heartbeatTimer,
|
|
|
- static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
- connect(heartbeatThread, &QThread::finished, heartbeatTimer, &QTimer::stop);
|
|
|
- connect(heartbeatThread, &QThread::finished, heartbeatTimer, &QTimer::deleteLater);
|
|
|
- connect(heartbeatThread, &QThread::finished, heartbeatThread, &QThread::deleteLater);
|
|
|
-
|
|
|
- connect(heartbeatTimer, &QTimer::timeout, this, [this]() {
|
|
|
- if (!m_isHeartBeating) {
|
|
|
- Logger::getInstance().error("爆破器心跳检测失败,连接可能已断开");
|
|
|
- QMetaObject::invokeMethod(
|
|
|
- this,
|
|
|
- [this]() {
|
|
|
- QMessageBox::critical(this, "连接错误", "爆破器心跳检测失败,连接可能已断开");
|
|
|
- cancelBlasting();
|
|
|
- },
|
|
|
- Qt::QueuedConnection);
|
|
|
- }
|
|
|
- m_isHeartBeating = false; // Reset flag for next interval
|
|
|
- });
|
|
|
|
|
|
- heartbeatThread->start();
|
|
|
-}
|
|
|
+// void firingWidget::startHeartbeatMonitor() {
|
|
|
+// m_isHeartBeating = true;
|
|
|
+// QThread *heartbeatThread = new QThread();
|
|
|
+// QTimer *heartbeatTimer = new QTimer(nullptr);
|
|
|
+// heartbeatTimer->setInterval(3000); // 3 seconds interval
|
|
|
+// heartbeatTimer->moveToThread(heartbeatThread);
|
|
|
+//
|
|
|
+// connect(heartbeatThread, &QThread::started, heartbeatTimer,
|
|
|
+// static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
+// connect(heartbeatThread, &QThread::finished, heartbeatTimer, &QTimer::stop);
|
|
|
+// connect(heartbeatThread, &QThread::finished, heartbeatTimer, &QTimer::deleteLater);
|
|
|
+// connect(heartbeatThread, &QThread::finished, heartbeatThread, &QThread::deleteLater);
|
|
|
+//
|
|
|
+// connect(heartbeatTimer, &QTimer::timeout, this, [this]() {
|
|
|
+// if (!m_isHeartBeating) {
|
|
|
+// Logger::getInstance().error("爆破器心跳检测失败,连接可能已断开");
|
|
|
+// QMetaObject::invokeMethod(
|
|
|
+// this,
|
|
|
+// [this]() {
|
|
|
+// QMessageBox::critical(this, "连接错误",
|
|
|
+// "爆破器心跳检测失败,连接可能已断开"); cancelBlasting();
|
|
|
+// },
|
|
|
+// Qt::QueuedConnection);
|
|
|
+// }
|
|
|
+// m_isHeartBeating = false; // Reset flag for next interval
|
|
|
+// });
|
|
|
+//
|
|
|
+// heartbeatThread->start();
|
|
|
+// }
|
|
|
void firingWidget::on_pushButton_2_clicked() { emit countdown(m_uuid, topic, "message"); }
|
|
|
|
|
|
// NOTE: aborted, changed to upload in the smartmine server side.
|
|
@@ -209,9 +208,6 @@ void firingWidget::handleProjectFiringMqttMessage(const QByteArray &message,
|
|
|
if (jsonObj.contains("type") && jsonObj["type"].toInt() == 1) {
|
|
|
if (jsonObj.contains("data") && jsonObj["data"].isObject()) {
|
|
|
QJsonObject dataObject = jsonObj["data"].toObject();
|
|
|
- if (!dataObject.contains("status")) {
|
|
|
- qDebug() << "Received JSON does not contain 'status' field.";
|
|
|
- }
|
|
|
int status = dataObject["status"].toInt();
|
|
|
if (ErrorBlastStatusList::isErrorStatus(status)) {
|
|
|
Logger::getInstance().error(
|
|
@@ -220,9 +216,7 @@ void firingWidget::handleProjectFiringMqttMessage(const QByteArray &message,
|
|
|
QMessageBox::critical(nullptr, "爆破器报错",
|
|
|
QString("错误错误信息: %1")
|
|
|
.arg(ErrorBlastStatusList::getErrorMessage(status)));
|
|
|
-
|
|
|
- emit updateBlastStatus(status, m_row);
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
+ cancelBlasting();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -276,7 +270,7 @@ void firingWidget::handleProjectFiringMqttMessage(const QByteArray &message,
|
|
|
ui->pushButton_2->setEnabled(false);
|
|
|
emit progressChanged(6, m_row);
|
|
|
emit updateBlastStatus(6, m_row);
|
|
|
- emit updateProjectStatus(m_uuid);
|
|
|
+ emit updateProjectStatus(m_uuid, BlastStatus::Blasted);
|
|
|
emit updateButton(6, m_row);
|
|
|
ui->pushButton_2->setText("已完成起爆");
|
|
|
navProgress->setState(6);
|
|
@@ -311,7 +305,11 @@ void firingWidget::onCountdownFinished(const QString &topic, const QString &mess
|
|
|
sendMqttMessage(topic, message.toUtf8());
|
|
|
}
|
|
|
|
|
|
-void firingWidget::onMqttConnected() { m_isMqttConnected = true; }
|
|
|
+void firingWidget::onMqttConnected() {
|
|
|
+ Logger::getInstance().info(
|
|
|
+ QString("Project(%1) firing MQTT connected successfully.").arg(m_uuid));
|
|
|
+ m_isMqttConnected = true;
|
|
|
+}
|
|
|
|
|
|
void firingWidget::onButtonPressedReceived(const QString &topic, const QString &message) {
|
|
|
QByteArray data = "\r\nDISABLE_BUTTON\r\n";
|
|
@@ -338,7 +336,7 @@ void firingWidget::onSafeChecked(const QString projectUuid) {
|
|
|
}
|
|
|
|
|
|
// 状态改变
|
|
|
-void firingWidget::onLastStageChanged(int newStage) {
|
|
|
+void firingWidget::hanldeFiringStageChanged(int newStage) {
|
|
|
QString topic = "hxgc/" + m_uuid + "/P";
|
|
|
QString message;
|
|
|
QString buttonText;
|
|
@@ -411,10 +409,15 @@ void firingWidget::onLastStageChanged(int newStage) {
|
|
|
}
|
|
|
|
|
|
void firingWidget::cancelBlasting() {
|
|
|
- QString message = "取消流程";
|
|
|
- if (!message.isEmpty()) {
|
|
|
- sendMqttMessage(topic, message.toUtf8());
|
|
|
- }
|
|
|
+ emit progressChanged(0, m_row); // 重置进度
|
|
|
+ emit updateBlastStatus(0, m_row);
|
|
|
+ emit updateProjectStatus(m_uuid, BlastStatus::Created);
|
|
|
+ // TODO: 重置状态为已注册
|
|
|
+
|
|
|
+ // QString message = "取消流程";
|
|
|
+ // if (!message.isEmpty()) {
|
|
|
+ // sendMqttMessage(topic, message.toUtf8());
|
|
|
+ // }
|
|
|
}
|
|
|
void firingWidget::on_sendTest_4_clicked() {}
|
|
|
|