ResistAlarm.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #pragma once
  2. #include <map>
  3. #include <thread>
  4. #include <string>
  5. #include <list>
  6. #include "AlarmDefine.h"
  7. #include <rapidjson/stringbuffer.h>
  8. #include <mutex>
  9. class CResistAlarm
  10. {
  11. CResistAlarm();
  12. ~CResistAlarm();
  13. friend class CResistAlarmMng;
  14. public:
  15. };
  16. typedef struct tagBaseInfo
  17. {
  18. uint8_t no = 255; //0, 1, 2 //通道号
  19. eZL_ALARMTYPE type = (eZL_ALARMTYPE)0x00; //报警类型
  20. bool enable = false; //报警开关
  21. time_t tmLastCheckTime = 0;
  22. }BASE_INFO;
  23. typedef struct tagMax_Over_Limit : public tagBaseInfo
  24. {
  25. short alarm_high_limit = SHORT_MAX; //锁闭力 定向反
  26. short warn_high_limit = SHORT_MAX; //锁闭力 反向定
  27. //short d_alarm_high_limit;
  28. //short d_warn_high_limit;
  29. short f_alarm_high_limit = SHORT_MAX; //保持力 反向定
  30. short f_warn_high_limit = SHORT_MAX; //保持力 反向定
  31. }MAX_OVER_LIMIT_INFO;
  32. typedef struct tagFriction_Over_Limit : public tagBaseInfo
  33. {
  34. int up_alarm_low_limit = INT_MAX; //上超低限报警值(暂定名称) 整数
  35. int up_warn_low_limit = INT_MAX; //上超低限预警值 整数
  36. int dw_alarm_high_limit = INT_MIN; //下超高限报警值 整数
  37. int dw_warn_high_limit = INT_MIN; //下超高限预警值 整数
  38. }FRICTION_OVER_LIMIT_INFO;
  39. typedef struct tagSuobi_Over_Limit : public tagBaseInfo
  40. {
  41. int alarm_low_limit = INT_MIN; //最小告警值
  42. int warn_low_limit = INT_MIN; //最小预警值
  43. int alarm_high_limit = INT_MAX; //最大告警值
  44. int warn_high_limit = INT_MAX; //最大预警值
  45. }SUOBI_OVER_LIMIT_INFO;
  46. typedef struct tagConvertResist_Over_Limit : public tagBaseInfo
  47. {
  48. int dw_alarm_low_limit = INT_MIN; //伸出告警值
  49. int dw_warn_low_limit = INT_MIN; //伸出预警值
  50. int up_alarm_high_limit = INT_MAX; //缩进告警值
  51. int up_warn_high_limit = INT_MAX; //缩进预警值
  52. }CONVERT_RESIST_OVER_LIMIT;
  53. typedef struct tagAlarmInfo
  54. {
  55. uint32_t id; //报警唯一ID
  56. string mo; //监控对象
  57. string mp; //监控点
  58. uint8_t no; //通道
  59. eZL_ALARMTYPE type;//报警类型
  60. uint8_t level; //0 预警 1 报警
  61. SYSTEMTIME time; //报警时间
  62. string desc; //报警描述
  63. string suggest; //建议
  64. short val = 0;
  65. uint8_t ack_result = 0; //是否受理
  66. string ack_name; //受理人
  67. CTime ack_time; //受理时间
  68. string event_id; //事件ID
  69. string rel_id; //第一次报警id
  70. }ALARM_INFO;
  71. //获取报警名称
  72. inline string GetAlarmName(eZL_ALARMTYPE id)
  73. {
  74. switch (id)
  75. {
  76. case eZL_ALARMTYPE::MAX_OVER_LIMIT:
  77. return "最大值超限";
  78. case eZL_ALARMTYPE::FRICTION_OVER_LIMIT:
  79. return "摩擦力超限";
  80. case eZL_ALARMTYPE::EQUIP_OFFLINE:
  81. return "设备离线";
  82. case eZL_ALARMTYPE::SENSOR_ABNORMAL:
  83. return "传感器异常";
  84. case eZL_ALARMTYPE::CONVERT_LIMIT:
  85. return "转换阻力超限";
  86. case eZL_ALARMTYPE::SUOBI_LOCK_LIMIT:
  87. return "锁闭力超限";
  88. default:
  89. return "未知";
  90. }
  91. }
  92. typedef struct eCalcMoveInfo
  93. {
  94. string imei;
  95. uint8_t idx;
  96. string mo;
  97. string mp;
  98. eCalcMoveInfo(string a, uint8_t b, string c, string d)
  99. {
  100. imei = a;
  101. idx = b;
  102. mo = c;
  103. mp = d;
  104. }
  105. }CALC_MOVE_INFO;
  106. class CResistAlarmMng
  107. {
  108. CResistAlarmMng();
  109. ~CResistAlarmMng();
  110. friend class CLWSServer;
  111. friend class CMGDataHandler;
  112. friend class CLNHandle;
  113. public:
  114. static CResistAlarmMng* Instance() { return &obj; }
  115. BOOL Start();
  116. void Stop();
  117. //BASE_INFO* Find(string momp, uint8_t no, uint8_t type);
  118. BASE_INFO* Find(string mo, string mp, uint8_t no, eZL_ALARMTYPE type);
  119. bool Insert(string mo, string mp, uint8_t no, uint8_t type, BASE_INFO* info);
  120. //bool Insert(const string& momp, uint8_t no, uint8_t type, BASE_INFO* info);
  121. //bool ConfirmAlarm(string mo, string mp, uint8_t no, uint8_t type, const SYSTEMTIME& st);
  122. //受理报警
  123. bool AckAlarm(int alarm_id, string& name, CTime& time);
  124. //处理报警
  125. bool HandleAlarm(int alarm_id);
  126. //外部调用产生报警
  127. void GeneralAlarm(string mo, string mp, uint8_t no, eZL_ALARMTYPE type, uint8_t level, SYSTEMTIME& tAlarm);
  128. //外部调用恢复报警
  129. void RecoverAlarm(const string mo, const string mp, const uint8_t no, const eZL_ALARMTYPE type, const uint8_t level, const SYSTEMTIME& tAlarm);
  130. static bool AlarmInfo2Pack(const ALARM_INFO* pAlarmInfo, rapidjson::StringBuffer& strBuf, bool bGb2312 = false);
  131. eZL_MP_STAT GetAlarmStat(string& mo, string& mp, SYSTEMTIME& stAlarm);
  132. inline void InsertCalcMoveInfo(string imei, uint8_t idx, string mo, string mp)
  133. {
  134. m_lstCalcMoveInfo.emplace_back(imei, idx, mo, mp);
  135. }
  136. private:
  137. static CResistAlarmMng obj;
  138. static void InsertToDBByMove(string mo, string mp, time_t show_time, time_t start_time, time_t end_time, int curr_val, int show_val, uint8_t idx, uint8_t posi, string mark);
  139. //报警规则检测线程
  140. static void ThreadProcAlarmSet(DWORD_PTR);
  141. //设备报警检测线程
  142. static void ThreadProcDevice(DWORD_PTR);
  143. BOOL LoadAlarmSet();
  144. BOOL LoadAlarmID();
  145. BOOL LoadUnAck();
  146. //报警ID
  147. int m_nAlarmID = 0;
  148. time_t m_lastDetectTime = 0;
  149. bool m_bWork = false;
  150. //报警规则检测线程
  151. std::thread *m_pThreadAlarmSet = nullptr;
  152. //设备报警检测线程
  153. std::thread* m_pThreadDevice = nullptr;
  154. //计算阻力值和锁闭力值
  155. std::list<CALC_MOVE_INFO> m_lstCalcMoveInfo;
  156. //报警参数 mo.mp
  157. std::map<std::string, BASE_INFO*> m_alarm_set;
  158. //未确认报警
  159. std::mutex m_mtxAlarm;
  160. std::list<ALARM_INFO*> m_lstUnConfirmAlarm;
  161. };