card_base.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. extern config_file config;
  14. card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid)
  15. :card(id,dis,t,deptid,level_id,cid)
  16. {
  17. select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
  18. }
  19. void card_location_base::do_status(int st)
  20. {
  21. module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
  22. }
  23. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  24. {
  25. //ct timestamp;
  26. //m_ct = lm[0].m_card_ct;
  27. //m_time = lm[0].m_loc_time;
  28. loc_point pt = m_sel_tool->select_solution(vp,lm);
  29. pt.y=-pt.y;
  30. if(pt.m_useless)
  31. {
  32. x = pt.x;
  33. y = pt.y;
  34. //Msg m;
  35. //m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
  36. //cardMgr::instance()->tryPut(m);
  37. double acc = lm[0].m_acc;
  38. log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%.2f,y:%.2f acc:%.2f",m_id,m_ct,m_time,pt.x,pt.y,acc);
  39. do_business(lm.front().m_sit, pt, acc);
  40. }
  41. }
  42. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  43. {
  44. m_ct = loc.m_card_ct;
  45. m_time = loc.m_time_stamp;
  46. m_message_handle->on_message(loop,loc,is_history);
  47. }
  48. //前端推送位置函数.
  49. void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, const point &pt)
  50. {
  51. // YA::_CARD_POS_ cp;
  52. cp.x = pt.x;
  53. cp.y = pt.y;
  54. cp.z = pt.z;
  55. cp.Type=m_type;
  56. cp.ID = m_id;
  57. cp.speed = abs(ceil(m_speed));
  58. cp.running_stat = m_stat;
  59. cp.dept_id = m_deptid;
  60. cp.display=m_display;
  61. cp.rec_time=m_time;
  62. cp.level_id = m_level_id;
  63. swsTimerThrd.upt_card_pos(cp);
  64. }
  65. void card_location_base::del_card_pos()
  66. {
  67. YA::_CARD_POS_ cp;
  68. cp.ID = m_id;
  69. cp.Type=m_type;
  70. swsTimerThrd.del_card_pos(cp);
  71. }
  72. int card_location_base::get_stat()
  73. {
  74. //盲区>呼救>呼叫>超时>超速>正常
  75. uint64_t now = time(0)*1000;
  76. if(now-m_time>CARD_LOST_TIME_OUT)
  77. {
  78. return STATUS_LOST;
  79. }
  80. else if(auto ev_ptr = event_list::instance()->get_event_card(m_id, m_type, ET_CARD_HELP))
  81. {
  82. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  83. }
  84. else if(CALL_NONE != get_mine_tool()->m_status_call)
  85. {
  86. return STATUS_CALL;
  87. }
  88. else if(event_list::instance()->get_event_card(m_id, m_type,
  89. is_person()? ET_CARD_AREA_OVER_TIME_PERSON: ET_CARD_AREA_OVER_TIME_VEHICLE))
  90. {
  91. return STATUS_AREA_OVER_TIME;
  92. }
  93. else if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_OVER_SPEED))
  94. {
  95. return STATUS_OVER_SPEED;
  96. }
  97. return STATUS_NORMAL;
  98. }
  99. void card_location_base::clear()
  100. {
  101. // uint16_t m_display; //1显示0不显示,往前端推送
  102. m_speed=0; //速度
  103. m_is_attendance=0; //井上井下状态 0初始状态 1 井上 2 井下
  104. m_stat=0; //运动静止状态
  105. //m_ct; //ct
  106. m_time=0; //时间戳
  107. }
  108. void card_location_base::put_three_rates(card_pos & cp)
  109. {
  110. cp.rec_time=m_time;cp.type=m_type;cp.id=m_id;
  111. cp.identifier_id=m_cid;cp.running_stat=m_stat;cp.final_v=m_speed;
  112. log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
  113. three_rates::get_instance()->put(cp);
  114. }
  115. bool card_location_base::is_person() const
  116. {
  117. return tool_other::is_person(m_type);
  118. }
  119. bool card_location_base::is_vehicle() const
  120. {
  121. return tool_other::is_vehicle(m_type);
  122. }
  123. card_location_base::~card_location_base()
  124. {
  125. }
  126. std::shared_ptr<card_location_base> card_location_base::make_person(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  127. int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string & dname)
  128. {
  129. return std::make_shared<person>(type,cardid,needdisplay,t, deptid,level_id,cid,wl,sname,dname);
  130. }
  131. std::shared_ptr<card_location_base> card_location_base::make_car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  132. int32_t deptid, int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  133. {
  134. return std::make_shared<car>(type,cardid,needdisplay,t, deptid, categoryid, type_id,level_id,cid);
  135. }