global.h 4.0 KB

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