global.h 4.2 KB

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