Ver código fonte

dev: 添加安全员工程逻辑

Yao 1 mês atrás
pai
commit
51120768ff
5 arquivos alterados com 77 adições e 68 exclusões
  1. 18 14
      blastopepage.cpp
  2. 3 3
      blastopepage.h
  3. 48 45
      fireWidget/firingwidget.cpp
  4. 6 6
      fireWidget/firingwidget.h
  5. 2 0
      global.h

+ 18 - 14
blastopepage.cpp

@@ -422,7 +422,7 @@ void BlastOpePage::loadDataFromSource(int currentPage, int pageSize) {
         if (index.isValid()) {
             ui->tableView->setIndexWidget(index, widget);
             connect(button, &QPushButton::clicked,
-                    [this, row, button]() { handleRowOperateButtonClick(row, button); });
+                    [this, row, button]() { handleSingleBlastButtonClick(row, button); });
         }
     }
 }
@@ -441,19 +441,19 @@ void BlastOpePage::onComboBoxIndexChanged(int index) {
     loadDataFromSource(currentPage, pageSize);
 }
 
-void BlastOpePage::updateProgressBar(int value, int row) {
+void BlastOpePage::updateProgressBar(int firingStage, int row) {
     if (!progressBars.isEmpty()) {
         QProgressBar *progressBar1 = progressBars[row].bar1;
         QProgressBar *progressBar2 = progressBars[row].bar2;
         QProgressBar *progressBar3 = progressBars[row].bar3;
-        switch (value) {
+        switch (firingStage) {
             case 1:
-                // 检查状态
+                // 组网状态
                 progressBar1->setRange(0, 0);  // 设置范围为0到100
                 progressBar1->setValue(0);
                 break;
             case 2:
-                // 检查完成
+                // 组网完成
                 progressBar1->setRange(0, 100);  // 设置范围为0到100
                 progressBar1->setValue(100);
                 break;
@@ -491,13 +491,13 @@ void BlastOpePage::updateProgressBar(int value, int row) {
     }
 }
 
-void BlastOpePage::onUpdateBlastStatus(int status, int row) {
+void BlastOpePage::onFiringStageUpdated(int stage, int row) {
     QModelIndex index = model->index(row, 7);
     if (index.isValid()) {
         QColor customColor;
         QFont boldFont;
         boldFont.setBold(true);
-        switch (status) {
+        switch (stage) {
             case 0:
                 model->setData(index, "待起爆");
                 customColor = QColor("#44035b");
@@ -546,7 +546,7 @@ void BlastOpePage::onUpdateBlastStatus(int status, int row) {
     }
 }
 
-void BlastOpePage::handleRowOperateButtonClick(int row, QPushButton *button) {
+void BlastOpePage::handleSingleBlastButtonClick(int row, QPushButton *button) {
     QStandardItem *uuidItem = model->item(row, 10);
     QString uuid;
     if (uuidItem) {
@@ -561,10 +561,12 @@ void BlastOpePage::handleRowOperateButtonClick(int row, QPushButton *button) {
         button->setText(stopBlastButtonTxt);
         firingWidget *widget = new firingWidget(row, false, uuid);
         connect(widget, &firingWidget::progressChanged, this, &BlastOpePage::updateProgressBar);
-        connect(widget, &firingWidget::updateBlastStatus, this, &BlastOpePage::onUpdateBlastStatus);
+        connect(widget, &firingWidget::updateBlastStatus, this,
+                &BlastOpePage::onFiringStageUpdated);
         connect(widget, &firingWidget::updateButton, this, &BlastOpePage::updateOpBtn);
         connect(widget, &firingWidget::countdown, this, &BlastOpePage::showCountDownWidget);
-        connect(widget, &firingWidget::updateProjectStatus, this, &BlastOpePage::updateProject);
+        connect(widget, &firingWidget::updateProjectStatus, this,
+                &BlastOpePage::handlerUpdateProjectStatus);
         connect(widget, &firingWidget::closeFiring, this, &BlastOpePage::destroyFiringWidget);
         if (isShowTriggeringWidget) {
             widget->show();
@@ -607,7 +609,9 @@ void BlastOpePage::updateOpBtn(int status, int row) {
     }
 }
 
-void BlastOpePage::updateProject(QString uuid) { dao.updateBlastStatusByUuid(uuid, "3"); }
+void BlastOpePage::handlerUpdateProjectStatus(QString uuid, const QString &newStatus) {
+    dao.updateBlastStatusByUuid(uuid, newStatus);
+}
 
 void BlastOpePage::destroyFiringWidget(const QString &uuid) {
     firingWidget *widget = uuidWidgetMap.value(uuid);
@@ -673,11 +677,11 @@ void BlastOpePage::on_btnSelect_clicked() {
         connect(widgetSelect, &firingWidget::progressChanged, this,
                 &BlastOpePage::updateProgressBar);
         connect(widgetSelect, &firingWidget::updateBlastStatus, this,
-                &BlastOpePage::onUpdateBlastStatus);
+                &BlastOpePage::onFiringStageUpdated);
         connect(widgetSelect, &firingWidget::selectSignal, this, &BlastOpePage::handleSelect);
         connect(widgetSelect, &firingWidget::updateButton, this, &BlastOpePage::updateOpBtn);
         connect(widgetSelect, &firingWidget::updateProjectStatus, this,
-                &BlastOpePage::updateProject);
+                &BlastOpePage::handlerUpdateProjectStatus);
         connect(widgetSelect, &firingWidget::closeFiring, this,
                 &BlastOpePage::destroyFiringWidgetSelect);
         widgetSelect->show();
@@ -712,7 +716,7 @@ void BlastOpePage::handleSelect(QString uuid) {
                 [this]() {
                     for (const auto &row : uuidMap.keys()) {
                         qDebug() << "Key:" << row;
-                        onUpdateBlastStatus(10, row);
+                        onFiringStageUpdated(10, row);
                     }
                 },
                 Qt::SingleShotConnection);

+ 3 - 3
blastopepage.h

@@ -46,10 +46,10 @@ class BlastOpePage : public QWidget {
     void PageChanged(int page);
     void onComboBoxIndexChanged(int index);
     void updateProgressBar(int value, int row);
-    void onUpdateBlastStatus(int status, int row);
+    void onFiringStageUpdated(int status, int row);
     void updateOpBtn(int status, int row);
     void showCountDownWidget(QString uuid, const QString &topic, const QString &message);
-    void updateProject(QString uuid);
+    void handlerUpdateProjectStatus(QString uuid, const QString &status);
     void destroyFiringWidget(const QString &uuid);
     void on_btnSelect_clicked();
     void onItemCheckboxChanged(QStandardItem *item);
@@ -70,7 +70,7 @@ class BlastOpePage : public QWidget {
     void initPagination();
     QJsonObject sendPostRequest(const QUrl &url, const QJsonObject &data);
     QJsonObject getMetaInfo();
-    void handleRowOperateButtonClick(int row, QPushButton *button);
+    void handleSingleBlastButtonClick(int row, QPushButton *button);
     bool checkUuidsSame();
 
    private:

+ 48 - 45
fireWidget/firingwidget.cpp

@@ -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() {}
 

+ 6 - 6
fireWidget/firingwidget.h

@@ -43,10 +43,10 @@ class ErrorBlastStatusList {
    private:
     // Internal function to get the error map (lazy initialization)
     static const std::map<int, QString> &getErrorMap() {
-        static const std::map<int, QString> errorMap = {{DEV_ERROR, "Device exception"},
-                                                        {BUS_SHORT, "Bus short circuit"},
-                                                        {BUS_VOLTAGE_ERR, "Bus voltage abnormal"},
-                                                        {DET_OFFLINE_ERR, "Detonator offline"}};
+        static const std::map<int, QString> errorMap = {{DEV_ERROR, "设备异常"},
+                                                        {BUS_SHORT, "总线短路"},
+                                                        {BUS_VOLTAGE_ERR, "总线电压异常"},
+                                                        {DET_OFFLINE_ERR, "雷管掉线"}};
         return errorMap;
     }
 };
@@ -74,7 +74,7 @@ class firingWidget : public QWidget {
     void onMqttConnected();
     // 双键按下
     void onButtonPressedReceived(const QString &topic, const QString &message);
-    void onLastStageChanged(int newStage);
+    void hanldeFiringStageChanged(int newStage);
     void onBlastSucess(const QJsonObject &data);
 
    signals:
@@ -84,7 +84,7 @@ class firingWidget : public QWidget {
     void updateBlastStatus(int status, int row);
     void selectSignal(QString uuid);
     void updateButton(int status, int row);
-    void updateProjectStatus(QString uuid);
+    void updateProjectStatus(QString uuid, QString status);
     void updateData(const QJsonObject &jsonObj);
     void safeChecked(const QJsonObject &jsonObj);
     void countdown(QString uuid, const QString &topic, const QString &message);

+ 2 - 0
global.h

@@ -23,6 +23,7 @@ namespace BlastStatus {
 const QString Created = "1";
 const QString Registered = "2";
 const QString Blasted = "3";
+const QString ErrorOccured = "4";
 const QString SafeChecked = "5";
 }  // namespace BlastStatus
 
@@ -30,6 +31,7 @@ namespace BlastStatusNames {
 const QString Created = "未注册";
 const QString Registered = "已注册";
 const QString Blasted = "爆破完成";
+const QString ErrorOccured = "爆破异常";
 const QString SafeChecked = "已安全检查";
 }  // namespace BlastStatusNames