card_car.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "card_car.h"
  2. #include "card_message_handle.h"
  3. #include "his_location.h"
  4. #include "area.h"
  5. #include "mine.h"
  6. #include "site_area.h"
  7. #include "three_rates.h"
  8. #include "select_tool.h"
  9. #include "websocket/ws_common.h"
  10. #include "special_area.h"
  11. #include "websocket/wsClientMgr.h"
  12. #include "common_tool.h"
  13. #include "tool_time.h"
  14. #include "mine_business.h"
  15. car::car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
  16. int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  17. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  18. ,m_vehicle_category_id(categoryid)
  19. ,m_vehicle_type_id(type_id)
  20. {
  21. m_message_handle.reset(new card_message_handle(this));
  22. m_his_location_card.reset(new location_vehicle(m_id,m_type));
  23. }
  24. car::~car(){}
  25. void car::site_hover(int sid)
  26. {
  27. if(m_time<=0)return;
  28. m_site_area->on_point(m_id,sid,0, m_type);
  29. }
  30. std::shared_ptr<area_hover> car::get_area_hover()
  31. {
  32. return m_area_tool->get_area_first();
  33. }
  34. std::shared_ptr<mine_tool> car::get_mine_tool()
  35. {
  36. return m_mine_tool;
  37. }
  38. std::shared_ptr<site_area_hover> car::get_site_area()
  39. {
  40. return m_site_area;
  41. }
  42. void car::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  43. {
  44. m_acc=acc;
  45. m_area_tool->on_point(site,shared_from_this(),pt);
  46. m_timeval=m_time;
  47. m_site_area->on_point(m_id,0,this, m_type);
  48. m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
  49. handle_three_rates(pt);
  50. uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
  51. mine_business::inst()->make_arg(id,pt,m_time);
  52. }
  53. int car::get_vehicle_type_id()
  54. {
  55. return m_vehicle_type_id;
  56. }
  57. void car::handle_three_rates(const point &pt)
  58. {
  59. card_pos cp;
  60. m_biz_stat=get_stat();
  61. cp.biz_stat = m_biz_stat;
  62. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  63. const auto lm = m_area_tool->getLandmark();
  64. // cp.enter_time = std::get<0>(lm)*1000;
  65. // cp.area_id = std::get<3>(lm);
  66. cp.map_id = std::get<2>(lm);
  67. cp.vibration=m_acc;
  68. put_three_rates(cp);
  69. }
  70. void car::on_timer()
  71. {
  72. make_package();
  73. }
  74. int car::get_area()
  75. {
  76. int status = m_biz_stat;
  77. int special_id = -1;
  78. if(status == STATUS_LOST)
  79. {
  80. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  81. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  82. }
  83. return special_id;
  84. }
  85. void car::make_package()
  86. {
  87. YA::_CARD_POS_ cp;
  88. loc_point pt = getSmoothPoint();
  89. const auto lm = m_area_tool->getLandmark();
  90. cp.enter_area_time = std::get<0>(lm);
  91. cp.rec_time = std::get<1>(lm);
  92. uint32_t map_id = std::get<2>(lm);
  93. uint32_t area_id = std::get<3>(lm);
  94. cp.map_id =map_id;cp.area_id=area_id;
  95. cp.landmark_id = std::get<4>(lm);
  96. cp.lm_direction = std::get<5>(lm);
  97. cp.landmark_dis=std::get<6>(lm);
  98. int32_t biz_stat=m_biz_stat;
  99. cp.biz_stat=biz_stat;
  100. cp.down_time = m_mine_tool->get_down_time();
  101. cp.work_time = m_mine_tool->get_work_time();
  102. cp.is_on_duty=m_mine_tool->is_on_duty();
  103. upt_card_pos(cp,pt);
  104. m_his_location_card->push(pt.m_time,pt,area_id,map_id);
  105. uint64_t _now=tool_time::now_to_ms();
  106. uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
  107. if(t>10*1000)
  108. {
  109. auto site = m_site_area->get_site();
  110. m_area_tool->on_point(site,shared_from_this(),pt);
  111. m_biz_stat=get_stat();
  112. }
  113. // if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  114. // {
  115. // cp.area_id = special_id;
  116. // swsClientMgr.SendSpecialAreaProcess(cp);
  117. // }
  118. // uint64_t _now=tool_time::now_to_ms();
  119. // uint64_t t=_now>m_time?_now-m_time:m_time-_now;
  120. // if(t<45*1000 && !empty())
  121. // f=true;
  122. // return f;
  123. }
  124. loc_point car::getSmoothPoint()
  125. {
  126. loc_point lp = m_smo_tool->smooth_strategy();
  127. m_speed = lp.m_speed;
  128. m_stat = lp.m_stat;
  129. lp.y = -lp.y;
  130. return lp;
  131. }
  132. std::tuple<time_t,time_t,int,int,int,int,double,double> car::getLandmark()
  133. {
  134. return m_area_tool->getLandmark();
  135. }