card_car.cpp 3.6 KB

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