global.h 3.7 KB

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