global.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef GLOBAL_H
  2. #define GLOBAL_H
  3. #include <QString>
  4. #include <QUrl>
  5. #include <QUrlQuery>
  6. #include "../mqtt/mqttclient.h"
  7. #include "../utils/logger.h"
  8. extern MqttClient* mainMqttClient;
  9. /* global variables which can configured in config file */
  10. extern QUrl apiBackendUrl; // 声明全局变量
  11. extern QString firewidgetPort; // 点火装置串口号
  12. extern QString gpsPort; // gps串口号
  13. extern QString databaseHost; // pc数据库地址
  14. extern QString mqttClientId; // mqtt客户端ID
  15. extern QString MQTT_TOPIC_COMPANY_PROJECTS_SUB; // 每个部署点(公司)唯一地址
  16. extern QString MQTT_TOPIC_COMPANY_PROJECTS_PUBLISH; // 发布工程的topic
  17. extern QString COMPANY_CODE;
  18. extern bool isShowTriggeringWidget; // 是否显示点火装置触发中调试组件
  19. extern bool isFaceVerificationEnabled; // 是否启用人脸识别
  20. // 用来获取雷管参数
  21. extern QString DET_PARAM_XMBH; // 项目编号
  22. extern QString DET_PARAM_DWDM; // 单位代码
  23. extern QString DET_PARAM_HTID; // 合同ID
  24. extern QString DET_PARAM_SBBH; // 设备编号
  25. extern void loadConfig(); // 声明全局函数
  26. extern QString globalAuthority;
  27. extern QString labLat; // 新增的全局变量声明
  28. extern QString labLon; // 新增的全局变量声明
  29. // BlastingProjManager namespace for managing blasting projects
  30. namespace BlastingProjManager {
  31. inline std::vector<QString> blastingProjectUuids;
  32. inline void addBlastingProject(const QString& uuid) { blastingProjectUuids.push_back(uuid); }
  33. inline void removeBlastingProject(const QString& uuid) {
  34. auto it = std::find(blastingProjectUuids.begin(), blastingProjectUuids.end(), uuid);
  35. if (it != blastingProjectUuids.end()) {
  36. blastingProjectUuids.erase(it);
  37. }
  38. }
  39. inline int getBlastingProjectCount() { return blastingProjectUuids.size(); }
  40. inline const std::vector<QString>& getBlastingProjectUuids() { return blastingProjectUuids; }
  41. } // namespace BlastingProjManager
  42. /* BlastStatus*/
  43. namespace BlastStatus {
  44. const QString Created = "1";
  45. const QString Registered = "2";
  46. const QString Blasted = "3";
  47. const QString ErrorOccurred = "4";
  48. } // namespace BlastStatus
  49. namespace BlastStatusNames {
  50. const QString Created = "未注册";
  51. const QString Registered = "已注册";
  52. const QString Blasted = "爆破完成";
  53. const QString ErrorOccurred = "爆破异常";
  54. } // namespace BlastStatusNames
  55. namespace ErrorBlastStatus {
  56. // Error code constants
  57. const int DEV_ERROR = 0xA0;
  58. const int BUS_SHORT = 0xA1;
  59. const int BUS_VOLTAGE_ERR = 0xA2;
  60. const int DET_OFFLINE_ERR = 0xA3;
  61. // Internal function to get the error map (lazy initialization)
  62. inline const std::map<int, QString>& getErrorMap() {
  63. static const std::map<int, QString> errorMap = {{DEV_ERROR, "设备异常"},
  64. {BUS_SHORT, "总线短路"},
  65. {BUS_VOLTAGE_ERR, "总线电压异常"},
  66. {DET_OFFLINE_ERR, "雷管掉线"}};
  67. return errorMap;
  68. }
  69. // Check if a status code exists in the error list
  70. inline bool isErrorStatus(int code) { return getErrorMap().find(code) != getErrorMap().end(); }
  71. // Get error message for a status code
  72. inline QString getErrorMessage(int code) {
  73. const auto& map = getErrorMap();
  74. auto it = map.find(code);
  75. return (it != map.end()) ? it->second : "Unknown error";
  76. }
  77. } // namespace ErrorBlastStatus
  78. // namespace FiringStages
  79. namespace FiringStages {
  80. const static int Starting = 0;
  81. const static int QuickTesting = 1; // 起爆检测测试中
  82. const static int QuickTestFinished = 2; // 起爆检测测试完成
  83. const static int NetCharging = 3; // 起爆检测充电中
  84. const static int NetChargingFinished = 4; // 起爆检测充电完成
  85. const static int Blasting = 5; // 爆破中
  86. const static int BlastFinished = 6; // 爆破完成
  87. const static int CancelConfirmed = 7; // 确认取消
  88. const static int PendingTriggerButtonClick = 10; // 待触发按钮触发起爆
  89. const static int ForceCanceled = 11; // 强制取消
  90. } // namespace FiringStages
  91. // namespace FiringStages
  92. #endif // GLOBAL_H