card_car.cpp 3.7 KB

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