card_car.cpp 3.8 KB

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