card_car.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 "three_rates.h"
  7. #include "select_tool.h"
  8. #include "websocket/ws_common.h"
  9. #include "special_area.h"
  10. #include "common_tool.h"
  11. #include "tool_time.h"
  12. #include "mine_business.h"
  13. #include "loc_point.h"
  14. #include "module_service/module_call.h"
  15. #include "ya_setting.h"
  16. car::car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
  17. int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  18. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  19. ,m_vehicle_category_id(categoryid)
  20. ,m_vehicle_type_id(type_id)
  21. {
  22. m_message_handle.reset(new card_message_handle(this));
  23. //m_his_location_card.reset(new location_vehicle(m_id,m_type,cid));
  24. }
  25. car::~car(){}
  26. std::shared_ptr<mine_tool> car::get_mine_tool()
  27. {
  28. return m_mine_tool;
  29. }
  30. void car::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
  31. {
  32. m_area_tool->set_area_info(mapid,scale,areaid,*this,t,type);
  33. }
  34. void car::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  35. {
  36. m_acc=acc;
  37. m_area_tool->on_point(shared_from_this(),pt);
  38. m_timeval = m_time;
  39. log_info("[anti_coll] m_id = %d, m_timeval = %lld", m_id, m_timeval);
  40. handle_three_rates(pt);
  41. handle_traffic_light(pt);
  42. if(m_enable_anti_collision){
  43. handle_anti_coll(pt, site->m_id);
  44. }
  45. uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
  46. mine_business::inst()->make_arg(id,pt,m_time);
  47. }
  48. int car::get_vehicle_type_id()
  49. {
  50. return m_vehicle_type_id;
  51. }
  52. void car::handle_anti_coll(const point& pt, const int& sid)
  53. {
  54. log_info("[anti_coll] handle anti collision");
  55. // 车卡下发最紧急的呼叫类型
  56. std::map<int, call_card> cards;
  57. auto tmp_cards = card_list::instance()->m_map;
  58. for(auto k : CYaSetting::m_sys_setting.mp_anti_collision){
  59. log_info("[anti_coll] key=%d, value=%.2f", k.first, k.second);
  60. for(auto& c : tmp_cards)
  61. {
  62. if(c.second->m_type == CT_VEHICLE){
  63. continue;
  64. }
  65. bool s = false;
  66. int d = (c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) / 1000.0;
  67. s = ((c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) /1000.0 <= 30);
  68. if(pt.dist(*c.second) < k.second && s){
  69. int call_level = 5 - k.first;
  70. log_info("[anti_coll] distance=%.3f, level=%d, thre_value=%.3f, time_diff=%d", pt.dist(*c.second), call_level, k.second, d);
  71. auto it = cards.find(c.second->m_id);
  72. if(it != cards.end()){
  73. if(c.second->m_call_level > call_level){
  74. c.second->m_call_level = call_level;
  75. }
  76. }else{
  77. cards.insert(std::make_pair(c.second->m_id, call_card(c.second->m_id, c.second->m_type, call_level, CCT_CALL_APOINT, sid)));
  78. }
  79. log_info("[anti_coll] card_id=%d, ctype=%d, call_level=%d, call_type_id=%d, site_id=%d",c.second->m_id, c.second->m_type, call_level, CCT_CALL_APOINT, sid);
  80. }
  81. }
  82. }
  83. if(cards.size() > 0){
  84. // find the best emengency call
  85. int call_level = 6;
  86. for(auto c : cards){
  87. if(c.second.call_level_id < call_level){
  88. call_level = c.second.call_level_id;
  89. }
  90. }
  91. cards.insert(std::make_pair(m_id, call_card(m_id, 2, call_level, CCT_CALL_APOINT, sid)));
  92. }else{
  93. log_info("[anti_coll] no card trigger anti collision rules.");
  94. return;
  95. }
  96. module_call::instance()->send_anti_collision(cards);
  97. }
  98. void car::handle_three_rates(const point &pt)
  99. {
  100. card_pos cp;
  101. m_biz_stat = get_stat();
  102. cp.biz_stat = m_biz_stat;
  103. cp.x = pt.x;
  104. cp.y = pt.y;
  105. cp.z = pt.z;
  106. //const auto lm = m_area_tool->getLandmark();
  107. //cp.enter_time = std::get<0>(lm)*1000;
  108. //cp.area_id = std::get<3>(lm);
  109. cp.map_id = m_area_tool->get_mapid();
  110. cp.vibration = m_acc;
  111. put_three_rates(cp);
  112. }
  113. void car::handle_traffic_light(const point& p)
  114. {
  115. card_pos cp;
  116. cp.x = p.x;
  117. cp.y = p.y;
  118. cp.z = p.z;
  119. cp.map_id = m_area_tool->get_mapid();
  120. cp.vibration = m_acc;
  121. put_traffic_light(cp);
  122. }
  123. void car::on_timer()
  124. {
  125. if(!empty())
  126. make_package();
  127. }
  128. int car::get_area()
  129. {
  130. int status = m_biz_stat;
  131. int special_id = -1;
  132. if(status == STATUS_LOST)
  133. {
  134. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  135. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  136. }
  137. return special_id;
  138. }
  139. void car::make_package()
  140. {
  141. YA::_CARD_POS_ cp;
  142. loc_point pt = getSmoothPoint();
  143. cp.area_info=m_area_tool->m_area_info;
  144. cp.map_id =m_area_tool->get_mapid();
  145. int32_t biz_stat=m_biz_stat;
  146. cp.biz_stat=biz_stat;
  147. cp.down_time = m_mine_tool->get_down_time();
  148. cp.work_time = m_mine_tool->get_work_time();
  149. uint32_t on_duty=0;
  150. // if(m_mine_tool->m_is_attendance)
  151. on_duty=m_mine_tool->is_on_duty();
  152. cp.is_on_duty=on_duty;
  153. upt_card_pos(cp,pt);
  154. make_his_location(pt.m_time,pt);
  155. uint64_t _now=tool_time::now_to_ms();
  156. uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
  157. if(t>10*1000)
  158. {
  159. m_area_tool->on_point(shared_from_this(),pt);
  160. m_biz_stat=get_stat();
  161. }
  162. // if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  163. // {
  164. // cp.area_id = special_id;
  165. // swsClientMgr.SendSpecialAreaProcess(cp);
  166. // }
  167. }
  168. void car::get_card(bool f)
  169. {
  170. if(f)
  171. mine_business::inst()->put(shared_from_this());
  172. }
  173. loc_point car::getSmoothPoint()
  174. {
  175. loc_point lp = m_smo_tool->smooth_strategy();
  176. m_speed = lp.m_speed;
  177. m_stat = lp.m_stat;
  178. lp.y = -lp.y;
  179. return lp;
  180. }