#ifndef FIRINGWIDGET_H #define FIRINGWIDGET_H #include #include #include #include "../backendapimanager.h" #include "../blastRecord/hblastrecord.h" #include "../blastRecord/hblastrecorddao.h" #include "../blastRecordDet/hblastrecorddetdao.h" #include "../blastRegRecord/hblastregrecorddao.h" #include "../databasemanager.h" #include "../des3encryption.h" #include "../logger.h" #include "../mqtt/mqttclient.h" #include "../mqttthread.h" #include "../serial/serialtool.h" #include "navprogress.h" namespace Ui { class firingWidget; } // Error status codes for device and bus issues class ErrorBlastStatusList { public: // Error code constants static const int DEV_ERROR = 0xA0; // Device exception static const int BUS_SHORT = 0xA1; // Bus short circuit static const int BUS_VOLTAGE_ERR = 0xA2; // Bus voltage abnormal static const int DET_OFFLINE_ERR = 0xA3; // Detonator offline // Check if a status code exists in the error list static bool isErrorStatus(int code) { return getErrorMap().find(code) != getErrorMap().end(); } // Get error message for a status code static QString getErrorMessage(int code) { const auto &map = getErrorMap(); auto it = map.find(code); return (it != map.end()) ? it->second : "Unknown error"; } private: // Internal function to get the error map (lazy initialization) static const std::map &getErrorMap() { static const std::map errorMap = {{DEV_ERROR, "设备异常"}, {BUS_SHORT, "总线短路"}, {BUS_VOLTAGE_ERR, "总线电压异常"}, {DET_OFFLINE_ERR, "雷管掉线"}}; return errorMap; } }; // The map will be initialized in the cpp file class firingWidget : public QWidget { Q_OBJECT public: explicit firingWidget(const int &row, const bool &select, const QString &uuid = "", QWidget *parent = nullptr); ~firingWidget(); void cancelBlasting(); void testonBlastSucess(const QJsonObject &data); public slots: void onCountdownFinished(const QString &topic, const QString &message); private slots: void on_pushButton_2_clicked(); void on_sendTest_4_clicked(); void handleProjectFiringMqttMessage(const QByteArray &message, const QMqttTopicName &topic); void onMqttConnected(); // 双键按下 void onButtonPressedReceived(const QString &topic, const QString &message); void hanldeFiringStageChanged(int newStage); void onBlastSucess(const QJsonObject &data); signals: void progressChanged(int value, int row); void lastStageChanged(int newStage); void projSafeChckSuccess(QString projectUuid); void updateBlastStatus(int status, int row); void selectSignal(QString uuid); void updateButton(int status, int row); 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); void closeFiring(QString uuid); private: void uploadBlastRecordToServer(HBlastRecord *blastRecord); HBlastRecord *recordBlastProject(const QJsonObject &jsonObj); HBlastEquipmentRecord *recordBlastEquipment(const QString blastProjectUUID, const QJsonObject ®Obj); QList recordBlastProjectDets(const QString projectUUID, const QString equipmentUUID, const QJsonArray regsArray); bool uploadToDanLing(const QJsonObject &jsonObj); void saveAndUploadRecord(const QJsonObject &jsonObj); void sendMqttMessage(const QString &topic, const QByteArray &message); void startBlasting(); void onSafeChecked(const QString projectUuid); private: Ui::firingWidget *ui; MqttClient *pcPorjectBC; HBlastRecordDao daoProj; HBlastRecordDetDao daoDet; HBlastRegRecordDao daoReg; NavProgress *navProgress; MqttThread *mqttThread; SerialTool *serialTool = nullptr; QString m_uuid; // 用于存储 uuid QString reg_uuid; // 用于存储 uuid QString blast_uuid; // 用于存储 uuid QString topic; int m_row; int lastStage = -1; // 用于记录上一次的 stage 状态 bool m_isMqttConnected = false; bool m_select; QMetaObject::Connection connection; // 声明 connection 变量 QMetaObject::Connection connectionPress; QString lat; QString lon; }; #endif // FIRINGWIDGET_H