card_car.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. car::car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
  14. int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
  15. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  16. ,m_vehicle_category_id(categoryid)
  17. ,m_vehicle_type_id(type_id)
  18. {
  19. m_message_handle.reset(new card_message_handle(this));
  20. //m_his_location_card.reset(new location_vehicle(m_id,m_type,cid));
  21. }
  22. car::~car(){}
  23. std::shared_ptr<mine_tool> car::get_mine_tool()
  24. {
  25. return m_mine_tool;
  26. }
  27. void car::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
  28. {
  29. m_area_tool->set_area_info(mapid,scale,areaid,*this,t,type);
  30. }
  31. void car::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  32. {
  33. m_acc=acc;
  34. m_area_tool->on_point(shared_from_this(),pt);
  35. m_timeval=m_time;
  36. handle_three_rates(pt);
  37. uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
  38. mine_business::inst()->make_arg(id,pt,m_time);
  39. }
  40. int car::get_vehicle_type_id()
  41. {
  42. return m_vehicle_type_id;
  43. }
  44. void car::handle_three_rates(const point &pt)
  45. {
  46. card_pos cp;
  47. m_biz_stat=get_stat();
  48. cp.biz_stat = m_biz_stat;
  49. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  50. //const auto lm = m_area_tool->getLandmark();
  51. // cp.enter_time = std::get<0>(lm)*1000;
  52. // cp.area_id = std::get<3>(lm);
  53. cp.map_id = m_area_tool->get_mapid();
  54. cp.vibration=m_acc;
  55. put_three_rates(cp);
  56. }
  57. void car::on_timer()
  58. {
  59. if(!empty())
  60. make_package();
  61. }
  62. int car::get_area()
  63. {
  64. int status = m_biz_stat;
  65. int special_id = -1;
  66. if(status == STATUS_LOST)
  67. {
  68. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  69. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  70. }
  71. return special_id;
  72. }
  73. void car::make_package()
  74. {
  75. YA::_CARD_POS_ cp;
  76. loc_point pt = getSmoothPoint();
  77. cp.area_info=m_area_tool->m_area_info;
  78. cp.map_id =m_area_tool->get_mapid();
  79. int32_t biz_stat=m_biz_stat;
  80. cp.biz_stat=biz_stat;
  81. cp.down_time = m_mine_tool->get_down_time();
  82. cp.work_time = m_mine_tool->get_work_time();
  83. uint32_t on_duty=0;
  84. // if(m_mine_tool->m_is_attendance)
  85. on_duty=m_mine_tool->is_on_duty();
  86. cp.is_on_duty=on_duty;
  87. //log_info("%s,down_time:%f,today:%lu,duty:%u",tool_other::type_id_to_str(m_type,m_id).c_str(),cp.down_time,tool_time::morning_of_today_ms(),on_duty);
  88. upt_card_pos(cp,pt);
  89. //int sid=0; if(auto st=m_area_tool->m_site)sid=st->m_area_id; m_his_location_card->push(pt.m_time,pt,sid,cp.map_id);
  90. uint64_t _now=tool_time::now_to_ms();
  91. uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
  92. if(t>10*1000)
  93. {
  94. m_area_tool->on_point(shared_from_this(),pt);
  95. m_biz_stat=get_stat();
  96. }
  97. // if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  98. // {
  99. // cp.area_id = special_id;
  100. // swsClientMgr.SendSpecialAreaProcess(cp);
  101. // }
  102. }
  103. void car::get_card(bool f)
  104. {
  105. if(f)
  106. mine_business::inst()->put(shared_from_this());
  107. }
  108. loc_point car::getSmoothPoint()
  109. {
  110. loc_point lp = m_smo_tool->smooth_strategy();
  111. m_speed = lp.m_speed;
  112. m_stat = lp.m_stat;
  113. lp.y = -lp.y;
  114. return lp;
  115. }