MonitorObject.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include <list>
  5. #include <vector>
  6. #include <yyjson.h>
  7. class CDevice;
  8. enum class DAOCHA_POSITION {
  9. MP_UNKNOWN = 0,
  10. MP_FIX,
  11. MP_INVERT,
  12. MP_QUARTO,
  13. };
  14. struct ST_MOMP_INFO
  15. {
  16. uint8_t check = 0xaa;
  17. uint8_t binstall_1 = 0;
  18. uint8_t binstall_2 = 0;
  19. uint8_t binstall_3 = 0;
  20. string name1;
  21. string name1utf;
  22. string name2;
  23. string name2utf;
  24. string name3;
  25. string name3utf;
  26. string out_name;
  27. string in_name;
  28. string imei;
  29. uint8_t idx = -1;
  30. CDevice *pDeivce = nullptr;
  31. uint32_t zzjno = 0;
  32. string mo;
  33. string mp;
  34. string name; //名称
  35. public:
  36. //临时状态
  37. bool bFirstOnline = true;
  38. public:
  39. //牵引点中间内存缓存数据
  40. //定位常态保持力值
  41. int fix_const_retension_force = INT_MIN;
  42. //反位常态保持力值
  43. int invert_const_retension_force = INT_MIN;
  44. //道岔位置
  45. //DAOCHA_POSITION epos = DAOCHA_POSITION::MP_UNKNOWN;
  46. std::map<time_t, DAOCHA_POSITION> mapPos;
  47. int m_nPowerZeroOffset = 0; //阻力零值补偿
  48. ~ST_MOMP_INFO(){
  49. check = 0x00;
  50. }
  51. };
  52. class CMonitorObject
  53. {
  54. public:
  55. CMonitorObject();
  56. virtual ~CMonitorObject();
  57. public:
  58. std::string id;
  59. std::string name;
  60. std::string type;
  61. std::string up;
  62. std::list<CMonitorObject*> m_lstMo;
  63. //type = mo.mp 时 生效 设备(转辙机编号)
  64. uint16_t eqpno = 0; //牵引点以上节点没有no。牵引点有自身no, 牵引点再往下一层为采集类型码AcqTypeCode
  65. CMonitorObject* parent = nullptr;
  66. uint8_t check = 0xaa;
  67. };
  68. class CMonitorObjectMng
  69. {
  70. CMonitorObjectMng();
  71. virtual ~CMonitorObjectMng();
  72. public:
  73. static CMonitorObjectMng* Instance() { return &obj; };
  74. friend class CResistAlarmMng;
  75. BOOL LoadMonitorTree();
  76. BOOL LoadHistoryData();
  77. //转换IMEI和idx 转换成 mo mp
  78. bool IMEI2MOMP(const std::string imei, const int idx, std::string& mo, std::string& mp);
  79. bool IMEI2MOMP(const std::string& imei_idx, std::string& mo_mp);
  80. bool MOMP2IMEI(const std::string& mo, const std::string& mp, std::string& imei, int& idx);
  81. bool MOMP2IMEI(const std::string& momp, std::string& imeiidx);
  82. bool MOMP2IMEI(const std::string& momp, std::string& imei, int& idx);
  83. //获取战场站点名
  84. bool GetStationNameByMomP(const std::string& momp, std::string& station, std::string& momp_name);
  85. bool GetStationNameByMomP(const std::string& mo, const std::string& mp, std::string& station, std::string& momp_name);
  86. //获取测力曲线名称
  87. bool GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3);
  88. bool GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3, std::string& out_name, std::string& in_name);
  89. //设置测力曲线名称
  90. void SetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3);
  91. //获取转换阻力方向名称
  92. bool GetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name);
  93. //设置转换阻力方向名称
  94. void SetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name);
  95. static bool spiltByPoint(const std::string&src, std::string& dst1, std::string& dst2);
  96. std::string concatStringByPoint(const std::string& src1, const std::string& src2);
  97. //通过ID来获取树节点
  98. CMonitorObject* GetTreeByID(const string& id);
  99. CMonitorObject* GetTreeByEpqID(uint16_t id);
  100. //根据momp来获取道岔对象
  101. //获取所有Type对象
  102. bool GetAllObjByType(std::vector<CMonitorObject*>& vctObj, const string& type);
  103. //序列化
  104. uint32_t GeneralMoPack(uint8_t** pack, int* len);
  105. void GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* doc, yyjson_mut_val* val);
  106. uint32_t GeneralMpPack(uint8_t** pack, int* len);
  107. //const std::map<std::string, std::vector<string>>* GetMoMpName()const { return &m_mapMoMpName; }
  108. const std::map<std::string, std::string>* GetImeiIdxMoMp()const { return &m_mapImeiIdxMoMp; }
  109. inline auto GetZZJNO(const string& momp) {
  110. return m_mapMoMpInfo[momp]->zzjno;
  111. }
  112. inline auto GetZZJEPOS(const string& momp)
  113. {
  114. auto& epos = m_mapMoMpInfo[momp];
  115. if (epos->mapPos.empty())
  116. {
  117. return DAOCHA_POSITION::MP_UNKNOWN;
  118. }
  119. return epos->mapPos.rbegin()->second;
  120. }
  121. //删除ZZJ历史记录,保留最新的一个
  122. void ClearZZJHistroyEPOS(time_t t);
  123. //判断ZZJ状态是否发生变化
  124. bool IsZZJEPOSChanged(const string& momp, DAOCHA_POSITION ePos, time_t t) const
  125. {
  126. auto epos = m_mapMoMpInfo.find(momp);
  127. if (epos == m_mapMoMpInfo.end() || epos->second->mapPos.empty())
  128. {
  129. return false;
  130. }
  131. if (epos->second->mapPos.size() == 1)
  132. {
  133. return epos->second->mapPos.begin()->second != ePos;
  134. }
  135. for (auto it = epos->second->mapPos.begin(); it != epos->second->mapPos.end(); it++)
  136. {
  137. if (it->first <= t) continue;
  138. if (it->second != ePos)
  139. {
  140. return true;
  141. }
  142. }
  143. return false;
  144. }
  145. void UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos);
  146. inline auto GetMoMpInfo(const string& momp)
  147. {
  148. return m_mapMoMpInfo[momp];
  149. }
  150. inline ST_MOMP_INFO* GetMoMpInfoByZZJno(const int zzjno)
  151. {
  152. for (auto& it : m_mapMoMpInfo)
  153. {
  154. if (it.second->zzjno == zzjno)
  155. return it.second;
  156. }
  157. return nullptr;
  158. }
  159. private:
  160. static CMonitorObject* GetTreeByID(CMonitorObject* p, const string& id);
  161. static CMonitorObject* GetTreeByEpqID(CMonitorObject* p, uint16_t id);
  162. static void GetAllObjByType(CMonitorObject* p, std::vector<CMonitorObject*>& vctObj, const string& type);
  163. BOOL LoadMoMap();
  164. void GetChild(std::list<CMonitorObject*>& lst, CMonitorObject* parent);
  165. bool GetStationNameByMomP(CMonitorObject* pInfo, const std::string& momp, std::string& station, std::string& momp_name);
  166. void Clear();
  167. CMonitorObject* m_treeroot = nullptr;//整棵树
  168. std::map<std::string, std::string> m_mapImeiIdxMoMp;//设备号对应momp
  169. std::map<std::string, std::string> m_mapMoMpImeiIdx;
  170. std::map<std::string, ST_MOMP_INFO*> m_mapMoMpInfo;//mo, mp 对应信息
  171. private:
  172. static CMonitorObjectMng obj;
  173. };