123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #include <sstream>
- #include "card_car.h"
- #include "card_message_handle.h"
- #include "his_location.h"
- #include "area.h"
- #include "mine.h"
- #include "select_tool.h"
- #include "websocket/ws_common.h"
- #include "special_area.h"
- #include "common_tool.h"
- #include "tool_time.h"
- #include "mine_business.h"
- #include "loc_point.h"
- #include "module_service/module_call.h"
- #include "sys_setting.h"
- #include "event.h"
- #include "struct_def.h"
- car::car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
- int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
- :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
- ,m_vehicle_category_id(categoryid)
- ,m_vehicle_type_id(type_id)
- {
- m_message_handle.reset(new card_message_handle(this));
- //m_his_location_card.reset(new location_vehicle(m_id,m_type,cid));
- }
- car::~car(){}
- std::shared_ptr<mine_tool> car::get_mine_tool()
- {
- return m_mine_tool;
- }
- void car::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
- {
- m_area_tool->set_area_info(mapid, scale, areaid, *this, t, type);
- }
- void car::do_business(const std::shared_ptr<site>&site,const point &pt)
- {
- m_area_tool->on_point(shared_from_this(),pt);
- m_timeval = m_time;
- //handle_traffic_light(pt, site->m_id);
- //if(m_enable_anti_collision){
- if(CYaSetting::m_sys_setting.m_enable_anti_coll){
- handle_anti_coll(pt, site->m_id);
- }
- uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
- mine_business::inst()->make_arg(id,pt,m_time);
- }
- int car::get_vehicle_type_id()
- {
- return m_vehicle_type_id;
- }
- void car::handle_anti_coll(const point& pt, const int& sid)
- {
- // 车卡下发最紧急的呼叫类型
- std::map<int, float> cd; // 人卡与车卡的距离,key为人卡id,value为距离
- std::map<int, call_card> cards;
- auto tmp_cards = card_list::instance()->m_map;
- log_info("[anti_coll] card'size = %d", tmp_cards.size());
- double min_d = 9999999.9;
- double cur_v = 0.0;
- for(auto k : CYaSetting::m_sys_setting.mp_anti_collision){
- //log_info("[anti_coll] key=%d, value=%.2f", k.first, k.second);
- for(auto& c : tmp_cards)
- {
- // 车卡不参与车车之间防碰撞
- if(c.second->m_type == CT_VEHICLE){
- continue;
- }
- // 司机卡不参与人车之间的防碰撞
- if(c.second->m_id>=9000&&c.second->m_id<=9999){
- continue;
- }
- // 避免历史定位数据的影响
- uint64_t now = time(0)*1000;
- if(m_time - now > 60){
- continue;
- }
- bool s = false;
- int d = (c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) / 1000.0;
- s = ((c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) /1000.0 <= 30);
- //float dist = pt.dist(*c.second);
- float dist = pt.dist(c.second->m_v_point);
- log_info("[anti_coll] vid=%d, pid=%d, dist=%.2f", m_id, c.second->m_id, dist);
- if(dist < k.second && s){
- int call_level = 5 - k.first;
- log_info("[anti_coll] distance=%.3f, level=%d, thre_value=%.3f, time_diff=%d", dist, call_level, k.second, d);
-
- if(min_d > k.second){
- min_d = k.second;
- cur_v = dist;
- }
- auto itc = cd.find(c.second->m_id);
- if(itc == cd.end()){
- cd.insert(std::make_pair(c.second->m_id, dist));
- }else{
- itc->second = dist;
- }
- auto it = cards.find(c.second->m_id);
- if(it != cards.end()){
- if(c.second->m_call_level > call_level){
- c.second->m_call_level = call_level;
- }
- }else{
- 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)));
- }
- 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);
- }
- }
- }
- std::string desc = "";
- uint64_t id = tool_other::type_id_to_u64(m_type, m_id);
- if(cards.size() == 0){
- // delete event from event_list
- event_tool::instance()->handle_event(OT_CARD, ET_PERSON_VEHICLE_ANTI_COLLISION, id, 0, 0, false);
- }else{
- size_t i = 0;
- for(auto c : cd)
- {
- desc += std::to_string(c.first);
- std::ostringstream buf;
- buf<<c.second;
- desc += "," + buf.str();
- if(i != (cards.size() - 1)){
- desc += ";";
- }
- ++i;
- }
- log_info("[anti_coll] the distance's list between person and vehicle : %s", desc.c_str());
- event_tool::instance()->handle_event(OT_CARD, ET_PERSON_VEHICLE_ANTI_COLLISION, id, min_d, cur_v, true, DT_COMMON, desc);
- }
- if(cards.size() > 0){
- // find the best emengency call
- int call_level = 6;
- for(auto c : cards){
- if(c.second.call_level_id < call_level){
- call_level = c.second.call_level_id;
- }
- }
- cards.insert(std::make_pair(m_id, call_card(m_id, 2, call_level, CCT_CALL_APOINT, sid)));
- module_call::instance()->send_anti_collision(cards);
- }else{
- //log_info("[anti_coll] no card trigger anti collision rules.");
- return;
- }
- //module_call::instance()->send_anti_collision(cards);
- }
- /*
- * @brief 红绿灯业务模块
- * @param const point& p 定位数据
- * @param const int& sid 分站id
- * @return 无
- * @note
- * @warning
- * @bug
- * */
- void car::handle_traffic_light(const point& p, const int& sid)
- {
- card_pos cp;
- cp.x = p.x;
- cp.y = p.y;
- cp.z = p.z;
- cp.biz_stat = get_stat();
- cp.map_id = m_area_tool->get_mapid();
- cp.vibration = m_acc;
- cp.reader_id = sid;
- put_traffic_light(cp);
- }
- void car::on_timer()
- {
- if(!empty())
- make_package();
- }
- int car::get_area()
- {
- int status = m_biz_stat;
- int special_id = -1;
- if(status == STATUS_LOST)
- {
- special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
- log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
- }
- return special_id;
- }
- void car::make_package()
- {
- sys::_CARD_POS_ cp;
- loc_point pt = getSmoothPoint();
- cp.area_info = m_area_tool->m_area_info;
- cp.map_id = m_area_tool->get_mapid();
- cp.biz_stat = get_stat();
- //cp.down_time = m_mine_tool->get_down_time();
- cp.work_time = m_mine_tool->get_work_time();
- cp.is_on_duty= m_mine_tool->is_on_duty();
-
- cp.down_time = m_last_point.x;
- cp.z = m_last_point.y;
-
- upt_card_pos(cp, pt);
- uint64_t _now = tool_time::now_to_ms();
- pt.m_time = _now;
- make_his_location(pt.m_time, pt);
- uint64_t t = _now>m_timeval?_now-m_timeval:m_timeval-_now;
- if(t>10*1000)
- {
- m_area_tool->on_point(shared_from_this(),pt);
- m_biz_stat=get_stat();
- }
- }
- void car::get_card(bool f)
- {
- if(f)
- mine_business::inst()->put(shared_from_this());
- }
- loc_point car::getSmoothPoint()
- {
- loc_point lp = m_smo_tool->smooth_strategy();
- m_speed = lp.m_speed;
- m_stat = lp.m_stat;
- lp.y = -lp.y;
- return lp;
- }
|