card_base.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include <memory>
  2. #include <message.h>
  3. #include "card_message_handle.h"
  4. #include "card_person.h"
  5. #include "card_car.h"
  6. #include "config_file.h"
  7. #include "select_tool.h"
  8. #include "module_service/module_mgr.h"
  9. #include "websocket/wsClientMgr.h"
  10. #include "websocket/wsTimerThread.h"
  11. #include "three_rates.h"
  12. #include "his_location.h"
  13. #include "event.h"
  14. #include "module_service/module_call.h"
  15. #include "mine.h"
  16. #include "common_tool.h"
  17. #include "ant.h"
  18. #include "area.h"
  19. #include "cardMgr.h"
  20. extern config_file config;
  21. card_location_base::card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid)
  22. :card(id,dis,t,deptid,level_id,cid)
  23. {
  24. select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
  25. }
  26. void card_location_base::do_status(int st)
  27. {
  28. module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
  29. }
  30. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  31. {
  32. loc_point pt = m_sel_tool->select_solution(vp,lm);
  33. pt.y=-pt.y;
  34. if(pt.m_useless)
  35. {
  36. x = tool_other::round(pt.x,3);
  37. y = tool_other::round(pt.y,3);
  38. //Msg m;
  39. //m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
  40. //cardMgr::instance()->tryPut(m);
  41. double acc = lm[0].m_acc;
  42. m_acc = lm[0].m_acc;
  43. log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%f,y:%f acc:%.2f",m_id,m_ct,m_time,x,y,acc);
  44. do_business(lm.front().m_sit, pt, acc);
  45. }
  46. else
  47. {
  48. log_warn("坐标不可用:card_id:%d,ct:%d,x:%f,y:%f",m_id,m_ct,pt.x,pt.y);
  49. }
  50. }
  51. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  52. {
  53. m_ct = loc.m_card_ct;
  54. m_time = loc.m_time_stamp;
  55. auto site_ptr = sit_list::instance()->get(loc.m_site_id);
  56. if(!site_ptr)
  57. {
  58. log_warn("接收到分站%d的数据,CARD=%d, CT=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct);
  59. return;
  60. }
  61. auto area_tool=get_area_tool();
  62. area_tool->set_site(site_ptr);
  63. if(site_ptr->is_up_site())
  64. {
  65. log_info("%d被井上分站[%d]收到",m_id,site_ptr->id());
  66. area_tool->on_point(shared_from_this(),point(1,1));
  67. this->site_hover(loc.m_site_id);
  68. }
  69. else
  70. {
  71. if(site_ptr->is_path_empty())
  72. {
  73. log_warn("接收到分站%d的数据,CT=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
  74. }
  75. m_message_handle->on_message(loop,loc,is_history);
  76. }
  77. }
  78. //前端推送位置函数.
  79. void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
  80. {
  81. // YA::_CARD_POS_ cp;
  82. point _p;
  83. if(pt.empty())
  84. {
  85. _p=*this;pt=_p;
  86. }
  87. else
  88. _p=pt;
  89. cp.x = tool_other::round(_p.x,3);
  90. cp.y = tool_other::round(_p.y,3);
  91. //cp.z = pt.z;
  92. cp.Type=m_type;
  93. cp.ID = m_id;
  94. cp.speed = abs(ceil(m_speed));
  95. cp.running_stat = m_stat;
  96. cp.dept_id = m_deptid;
  97. cp.display=m_display;
  98. cp.rec_time=m_time;
  99. cp.level_id = m_level_id;
  100. swsTimerThrd.upt_card_pos(cp);
  101. }
  102. void card_location_base::del_card_pos()
  103. {
  104. YA::_CARD_POS_ cp;
  105. cp.ID = m_id;
  106. cp.Type=m_type;
  107. swsTimerThrd.del_card_pos(cp);
  108. }
  109. int card_location_base::get_stat()
  110. {
  111. //盲区>呼救>呼叫>超时>超速>正常
  112. uint64_t now = time(0)*1000;
  113. if(now-m_time>CARD_LOST_TIME_OUT)
  114. {
  115. return STATUS_LOST;
  116. }
  117. else if(auto ev_ptr = event_list::instance()->get_event_card(m_id, m_type, ET_CARD_HELP))
  118. {
  119. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  120. }
  121. else if(CALL_NONE != get_mine_tool()->m_status_call)
  122. {
  123. return STATUS_CALL;
  124. }
  125. else if(is_person())
  126. {
  127. if(event_list::instance()->get_event_card(m_id, m_type,ET_CARD_AREA_OVER_TIME_PERSON)||
  128. event_list::instance()->get_event_card(m_id, m_type,ET_CARD_OVER_TIME_PERSON))
  129. return STATUS_AREA_OVER_TIME;
  130. }
  131. else if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_OVER_SPEED))
  132. {
  133. return STATUS_OVER_SPEED;
  134. }
  135. return STATUS_NORMAL;
  136. }
  137. void card_location_base::clear()
  138. {
  139. // uint16_t m_display; //1显示0不显示,往前端推送
  140. m_speed=0; //速度
  141. m_is_attendance=0; //井上井下状态 0初始状态 1 井上 2 井下
  142. m_stat=0; //运动静止状态
  143. //m_ct; //ct
  144. m_time=0; //时间戳
  145. }
  146. void card_location_base::put_three_rates(card_pos & cp)
  147. {
  148. cp.rec_time=m_time;cp.type=m_type;cp.id=m_id;
  149. cp.identifier_id=m_cid;cp.running_stat=m_stat;cp.final_v=m_speed;
  150. cp.dpt_id = m_deptid;
  151. std::shared_ptr<area_tool> _areatool = get_area_tool();
  152. if(nullptr != _areatool && nullptr != _areatool->m_site)
  153. {
  154. cp.reader_x = _areatool->m_site->x;
  155. cp.reader_y = _areatool->m_site->y;
  156. cp.reader_id = _areatool->m_site->m_id;
  157. }
  158. log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
  159. three_rates::get_instance()->put(cp);
  160. }
  161. bool card_location_base::is_person() const
  162. {
  163. return tool_other::is_person(m_type);
  164. }
  165. bool card_location_base::is_vehicle() const
  166. {
  167. return tool_other::is_vehicle(m_type);
  168. }
  169. card_location_base::~card_location_base()
  170. {
  171. }
  172. std::shared_ptr<card_location_base> card_location_base::make_person(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  173. int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string & dname,int worktype_id)
  174. {
  175. return std::make_shared<person>(type,cardid,needdisplay,t, deptid,level_id,cid,wl,sname,dname,worktype_id);
  176. }
  177. std::shared_ptr<card_location_base> card_location_base::make_car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  178. int32_t deptid, int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  179. {
  180. return std::make_shared<car>(type,cardid,needdisplay,t, deptid, categoryid, type_id,level_id,cid);
  181. }