MonitorObject.h 5.8 KB

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