card_person.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include <string>
  2. #include <thread>
  3. #include "card_person.h"
  4. #include "loc_point.h"
  5. #include "card_message_handle.h"
  6. #include "area.h"
  7. #include "mine.h"
  8. #include "site_area.h"
  9. #include "his_location.h"
  10. #include "three_rates.h"
  11. #include "select_tool.h"
  12. #include "monkey_car/monkeycar_person.h"
  13. #include "websocket/ws_common.h"
  14. person::person(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl)
  15. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  16. ,m_workLine(wl)
  17. {
  18. m_message_handle.reset(new card_message_handle(this));
  19. m_his_location_card.reset(new location_staff(m_id,m_type));
  20. }
  21. person::~person()
  22. {
  23. }
  24. void person::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  25. {
  26. m_message_handle->on_message(loop,loc,is_history);
  27. }
  28. void person::clear()
  29. {
  30. //m_site_area.reset(new site_area_hover);
  31. m_area_tool.reset(new area_tool);
  32. m_mine_tool.reset(new mine_tool);
  33. card_location_base::clear();
  34. }
  35. void person::site_hover(int sid)
  36. {
  37. if(m_time<=0)
  38. {
  39. return;
  40. }
  41. log_info("__thread_id site_hover:%d,%x [%x]",m_id,std::this_thread::get_id(),m_site_area.get());
  42. m_site_area->on_point(m_id,sid,nullptr, m_type);
  43. }
  44. std::shared_ptr<area_hover> person::get_area_hover()
  45. {
  46. return m_area_tool->m_area_hover;
  47. }
  48. std::shared_ptr<mine_tool> person::get_mine_tool()
  49. {
  50. return m_mine_tool;
  51. }
  52. std::shared_ptr<site_area_hover> person::get_site_area()
  53. {
  54. return m_site_area;
  55. }
  56. void person::do_business(const point &pt,double acc)
  57. {
  58. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  59. m_site_area->on_point(m_id,0,this, m_type);
  60. handle_three_rates(pt);
  61. }
  62. void person::reset(std::shared_ptr<monkey_person> mp)
  63. {
  64. m_monkeyPerson = mp;
  65. }
  66. void person::handle_three_rates(const point & pt)
  67. {
  68. card_pos cp;
  69. cp.work_line=m_workLine;
  70. cp.biz_stat = get_stat();
  71. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  72. const auto lm = m_area_tool->getLandmark();
  73. cp.enter_time = std::get<0>(lm)*1000;
  74. cp.area_id = std::get<3>(lm);
  75. put_three_rates(cp);
  76. }
  77. void person::on_timer()
  78. {
  79. if(!m_mine_tool->is_attendance())
  80. return;
  81. YA::_CARD_POS_ cp;
  82. uint64_t _time=0;
  83. point pt = getSmoothPoint(_time);
  84. const auto lm = m_area_tool->getLandmark();
  85. cp.enter_area_time = std::get<0>(lm)*1000;
  86. cp.rec_time = std::get<1>(lm);
  87. int32_t map_id = std::get<2>(lm);
  88. int32_t area_id = std::get<3>(lm);
  89. cp.map_id=map_id;cp.area_id=area_id;
  90. cp.landmark_id = std::get<4>(lm);
  91. cp.lm_direction = std::get<5>(lm);
  92. cp.landmark_dis=std::get<6>(lm);
  93. cp.biz_stat = get_stat();
  94. cp.down_time = m_mine_tool->get_down_time();
  95. cp.work_time = m_mine_tool->get_work_time();
  96. cp.is_on_duty= m_mine_tool->is_on_duty();
  97. log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d",m_id,_time,pt.x,pt.y,area_id,map_id);
  98. m_his_location_card->push(_time,pt,area_id,map_id);
  99. upt_card_pos(cp,pt);
  100. }
  101. point person::getSmoothPoint(uint64_t& t)
  102. {
  103. point pt;
  104. loc_point lp = m_smo_tool->smooth_strategy();
  105. m_speed = lp.m_speed;
  106. m_stat = lp.m_stat;
  107. pt.x = lp.x;
  108. pt.y = -lp.y;
  109. t=lp.m_time;
  110. if(auto p = m_monkeyPerson.lock() )
  111. {
  112. if(p->is_on_bus())
  113. {
  114. m_stat = 7;
  115. pt = p->getPoint(t);
  116. log_info("getpoint_oncar:%d,%lld",m_id,t);
  117. }
  118. }
  119. return pt;
  120. }