firingwidget.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef FIRINGWIDGET_H
  2. #define FIRINGWIDGET_H
  3. #include <QJsonDocument>
  4. #include <QJsonObject>
  5. #include <QWidget>
  6. #include "../backendapimanager.h"
  7. #include "../blastRecord/hblastrecord.h"
  8. #include "../blastRecord/hblastrecorddao.h"
  9. #include "../blastRecordDet/hblastrecorddetdao.h"
  10. #include "../blastRegRecord/hblastregrecorddao.h"
  11. #include "../databasemanager.h"
  12. #include "../des3encryption.h"
  13. #include "../logger.h"
  14. #include "../mqtt/mqttclient.h"
  15. #include "../mqttthread.h"
  16. #include "../serial/serialtool.h"
  17. #include "navprogress.h"
  18. namespace Ui {
  19. class firingWidget;
  20. }
  21. // Error status codes for device and bus issues
  22. class ErrorBlastStatusList {
  23. public:
  24. // Error code constants
  25. static const int DEV_ERROR = 0xA0; // Device exception
  26. static const int BUS_SHORT = 0xA1; // Bus short circuit
  27. static const int BUS_VOLTAGE_ERR = 0xA2; // Bus voltage abnormal
  28. static const int DET_OFFLINE_ERR = 0xA3; // Detonator offline
  29. // Check if a status code exists in the error list
  30. static bool isErrorStatus(int code) { return getErrorMap().find(code) != getErrorMap().end(); }
  31. // Get error message for a status code
  32. static QString getErrorMessage(int code) {
  33. const auto &map = getErrorMap();
  34. auto it = map.find(code);
  35. return (it != map.end()) ? it->second : "Unknown error";
  36. }
  37. private:
  38. // Internal function to get the error map (lazy initialization)
  39. static const std::map<int, QString> &getErrorMap() {
  40. static const std::map<int, QString> errorMap = {{DEV_ERROR, "Device exception"},
  41. {BUS_SHORT, "Bus short circuit"},
  42. {BUS_VOLTAGE_ERR, "Bus voltage abnormal"},
  43. {DET_OFFLINE_ERR, "Detonator offline"}};
  44. return errorMap;
  45. }
  46. };
  47. // The map will be initialized in the cpp file
  48. class firingWidget : public QWidget {
  49. Q_OBJECT
  50. public:
  51. explicit firingWidget(const int &row, const bool &select, const QString &uuid = "",
  52. QWidget *parent = nullptr);
  53. ~firingWidget();
  54. void cancelBlasting();
  55. void testonBlastSucess(const QJsonObject &data);
  56. public slots:
  57. void onCountdownFinished(const QString &topic, const QString &message);
  58. private slots:
  59. void on_pushButton_2_clicked();
  60. void on_sendTest_4_clicked();
  61. void handleProjectFiringMqttMessage(const QByteArray &message, const QMqttTopicName &topic);
  62. void onMqttConnected();
  63. // 双键按下
  64. void onButtonPressedReceived(const QString &topic, const QString &message);
  65. void onLastStageChanged(int newStage);
  66. void onBlastSucess(const QJsonObject &data);
  67. signals:
  68. void progressChanged(int value, int row);
  69. void lastStageChanged(int newStage);
  70. void projSafeChckSuccess(QString projectUuid);
  71. void updateBlastStatus(int status, int row);
  72. void selectSignal(QString uuid);
  73. void updateButton(int status, int row);
  74. void updateProjectStatus(QString uuid);
  75. void updateData(const QJsonObject &jsonObj);
  76. void safeChecked(const QJsonObject &jsonObj);
  77. void countdown(QString uuid, const QString &topic, const QString &message);
  78. void closeFiring(QString uuid);
  79. private:
  80. void uploadBlastRecordToServer(HBlastRecord *blastRecord);
  81. HBlastRecord *recordBlastProject(const QJsonObject &jsonObj);
  82. HBlastEquipmentRecord *recordBlastEquipment(const QString blastProjectUUID,
  83. const QJsonObject &regObj);
  84. QList<HBlastRecordDet *> recordBlastProjectDets(const QString projectUUID,
  85. const QString equipmentUUID,
  86. const QJsonArray regsArray);
  87. bool uploadToDanLing(const QJsonObject &jsonObj);
  88. void saveAndUploadRecord(const QJsonObject &jsonObj);
  89. void sendMqttMessage(const QString &topic, const QByteArray &message);
  90. void startBlasting();
  91. void onSafeChecked(const QString projectUuid);
  92. private:
  93. Ui::firingWidget *ui;
  94. MqttClient *pcPorjectBC;
  95. HBlastRecordDao daoProj;
  96. HBlastRecordDetDao daoDet;
  97. HBlastRegRecordDao daoReg;
  98. NavProgress *navProgress;
  99. MqttThread *mqttThread;
  100. SerialTool *serialTool = nullptr;
  101. QString m_uuid; // 用于存储 uuid
  102. QString reg_uuid; // 用于存储 uuid
  103. QString blast_uuid; // 用于存储 uuid
  104. QString topic;
  105. int m_row;
  106. int lastStage = -1; // 用于记录上一次的 stage 状态
  107. bool m_isMqttConnected = false;
  108. bool m_select;
  109. QMetaObject::Connection connection; // 声明 connection 变量
  110. QMetaObject::Connection connectionPress;
  111. QString lat;
  112. QString lon;
  113. };
  114. #endif // FIRINGWIDGET_H