card_base.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. m_his_location_card.reset(new location_card(m_id,m_type,cid));
  26. }
  27. void card_location_base::do_status(int st)
  28. {
  29. time_t now=time(0);
  30. bool help_flag=false;
  31. if((m_help_bit & 1) && (st & STATUS_HELP))
  32. {
  33. // 1111111111
  34. // ^
  35. m_help_last_time=now;
  36. }
  37. else if((m_help_bit & 1) && (st & STATUS_HELP)==0)
  38. {
  39. // 11111111100000
  40. // ^
  41. m_help_bit<<=1;
  42. }
  43. else if((m_help_bit & 1)==0 && (st & STATUS_HELP))
  44. {
  45. // 00000000011111
  46. // ^
  47. if((m_help_bit&0x3)==2)
  48. {
  49. log_warn("handle_m_help,card_id:%d\n",m_id);
  50. help_flag=true;
  51. }
  52. m_help_last_time=now;
  53. m_help_bit<<=1;
  54. m_help_bit|=1;
  55. }
  56. else
  57. {
  58. // 11111111100000
  59. // ^
  60. if(now-m_help_last_time>60)
  61. {
  62. m_help_bit=0;
  63. }
  64. }
  65. if(!help_flag)
  66. {
  67. st = st & (0xFFFFFFFF ^ STATUS_HELP);
  68. }
  69. module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
  70. }
  71. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  72. {
  73. loc_point pt = m_sel_tool->select_solution(vp,lm);
  74. pt.y=-pt.y;
  75. if(pt.m_useless)
  76. {
  77. x = tool_other::round(pt.x,3);
  78. y = tool_other::round(pt.y,3);
  79. Msg m;
  80. m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
  81. cardMgr::instance()->tryPut(m);
  82. double acc = lm[0].m_acc;
  83. m_acc = lm[0].m_acc;
  84. log_info("useful:type:%d,card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%f,y:%f acc:%.2f",m_type,m_id,m_ct,m_time,x,y,acc);
  85. do_business(lm.front().m_sit, pt, acc);
  86. }
  87. else
  88. {
  89. int sid=0;
  90. auto site_ptr=get_area_tool()->m_site;
  91. if(site_ptr)
  92. {
  93. sid=site_ptr->m_id;
  94. }
  95. log_warn("坐标不可用:site_id:%d,type:%d,card_id:%d,ct:%d,x:%f,y:%f",sid,m_type,m_id,m_ct,pt.x,pt.y);
  96. }
  97. }
  98. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  99. {
  100. m_ct = loc.m_card_ct;
  101. m_time = loc.m_time_stamp;
  102. auto site_ptr = sit_list::instance()->get(loc.m_site_id);
  103. if(!site_ptr)
  104. {
  105. log_warn("接收到分站%d的数据,CARD=%d, CT=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct);
  106. return;
  107. }
  108. auto area_tool=get_area_tool();
  109. area_tool->set_site(site_ptr);
  110. if(site_ptr->is_up_site())
  111. {
  112. log_info("%d被井上分站[%d]收到",m_id,site_ptr->id());
  113. area_tool->on_point(shared_from_this(),point(1,1));
  114. this->site_hover(loc.m_site_id);
  115. }
  116. else
  117. {
  118. if(site_ptr->is_path_empty())
  119. {
  120. log_warn("接收到分站%d的数据,CT=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
  121. }
  122. m_message_handle->on_message(loop,loc,is_history);
  123. }
  124. }
  125. //前端推送位置函数.
  126. void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
  127. {
  128. // YA::_CARD_POS_ cp;
  129. point _p;
  130. if(pt.empty())
  131. {
  132. _p=*this;pt=_p;
  133. }
  134. else
  135. _p=pt;
  136. cp.x = tool_other::round(_p.x,3);
  137. cp.y = tool_other::round(_p.y,3);
  138. //cp.z = pt.z;
  139. cp.Type=m_type;
  140. cp.ID = m_id;
  141. cp.speed = abs(ceil(m_speed));
  142. cp.running_stat = m_stat;
  143. cp.dept_id = m_deptid;
  144. cp.display=m_display;
  145. cp.rec_time=m_time;
  146. cp.level_id = m_level_id;
  147. swsTimerThrd.upt_card_pos(cp);
  148. }
  149. void card_location_base::del_card_pos()
  150. {
  151. YA::_CARD_POS_ cp;
  152. cp.ID = m_id;
  153. cp.Type=m_type;
  154. swsTimerThrd.del_card_pos(cp);
  155. }
  156. int card_location_base::get_stat()
  157. {
  158. //盲区>呼救>呼叫>超时>超速>正常
  159. uint64_t now = time(0)*1000;
  160. uint64_t tlost=now>m_time?now-m_time:m_time-now;
  161. log_info("card_lost:%03d%010d,[%lu-%lu]tlost:%lu---%s",m_type,m_id,now,m_time,tlost,tlost>CARD_LOST_TIME_OUT?"True":"False");
  162. if(tlost>CARD_LOST_TIME_OUT)
  163. {
  164. return STATUS_LOST;
  165. }
  166. else if(auto ev_ptr = event_list::instance()->get_event_card(m_id, m_type, ET_CARD_HELP))
  167. {
  168. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  169. }
  170. else if(CALL_NONE != get_mine_tool()->m_status_call)
  171. {
  172. return STATUS_CALL;
  173. }
  174. else if(is_person())
  175. {
  176. if(event_list::instance()->get_event_card(m_id, m_type,ET_CARD_AREA_OVER_TIME_PERSON)||
  177. event_list::instance()->get_event_card(m_id, m_type,ET_CARD_OVER_TIME_PERSON))
  178. return STATUS_AREA_OVER_TIME;
  179. }
  180. else if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_OVER_SPEED))
  181. {
  182. return STATUS_OVER_SPEED;
  183. }
  184. return STATUS_NORMAL;
  185. }
  186. void card_location_base::clear()
  187. {
  188. // uint16_t m_display; //1显示0不显示,往前端推送
  189. m_speed=0; //速度
  190. m_stat=0; //运动静止状态
  191. //m_ct; //ct
  192. m_time=0; //时间戳
  193. }
  194. void card_location_base::put_three_rates(card_pos & cp)
  195. {
  196. if(!three_rates_flag)return;
  197. cp.rec_time=m_time;cp.type=m_type;cp.id=m_id;
  198. cp.identifier_id=m_cid;cp.running_stat=m_stat;cp.final_v=m_speed;
  199. cp.dpt_id = m_deptid;
  200. std::shared_ptr<area_tool> _areatool = get_area_tool();
  201. if(nullptr != _areatool && nullptr != _areatool->m_site)
  202. {
  203. cp.reader_x = _areatool->m_site->x;
  204. cp.reader_y = _areatool->m_site->y;
  205. cp.reader_id = _areatool->m_site->m_id;
  206. }
  207. log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
  208. three_rates::get_instance()->put(cp);
  209. }
  210. bool card_location_base::is_person() const
  211. {
  212. return tool_other::is_person(m_type);
  213. }
  214. bool card_location_base::is_vehicle() const
  215. {
  216. return tool_other::is_vehicle(m_type);
  217. }
  218. card_location_base::~card_location_base()
  219. {
  220. }
  221. std::shared_ptr<card_location_base> card_location_base::make_person(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  222. int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string & dname,int worktype_id)
  223. {
  224. return std::make_shared<person>(type,cardid,needdisplay,t, deptid,level_id,cid,wl,sname,dname,worktype_id);
  225. }
  226. std::shared_ptr<card_location_base> card_location_base::make_car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  227. int32_t deptid, int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  228. {
  229. return std::make_shared<car>(type,cardid,needdisplay,t, deptid, categoryid, type_id,level_id,cid);
  230. }