#include #include #include #include #include #include #include #include struct card_location_base { virtual void on_location(const std::vector&vp)=0; virtual ~card_location_base(){}; }; //一张卡一个ct的所有不同天线的信息 struct one_ct_message_handle { static loc_tool_main m_loc_tool; ev::timer m_min_timer,m_max_timer; std::vector m_msg_list; card_location_base*m_card; const algo_config*m_ac=nullptr; int m_ct; bool m_min_timeout=false; one_ct_message_handle(card_location_base*card) { m_card=card; m_ct=-1; } void reset() { m_ct=-1; m_min_timeout=false; m_msg_list.clear(); } void on_min_timer() { m_min_timer.stop(); if((int)m_msg_list.size()>=m_ac->best_msg_cnt) { m_max_timer.stop(); calc_location(); } } void on_max_timer() { m_max_timer.stop(); calc_location(); } bool once_flag=false; void once_init(ev::dynamic_loop&loop) { if(once_flag) return; once_flag=true; m_min_timer.set(loop); m_min_timer.set(this); m_max_timer.set(loop); m_max_timer.set(this); } void on_message(ev::dynamic_loop&loop, const message_locinfo&loc) { once_init(loop); if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct) { m_msg_list.clear(); } ant*a=ant_list::instance()->get(loc.m_site_id, loc.m_ant_id); m_loc_tool.on_loc_message(a, loc); if(m_msg_list.empty()) { m_ct=loc.m_card_ct; m_ac=&a->config(); m_min_timeout=false; m_msg_list.push_back(loc_message(a,loc.m_tof)); //启动本CT的最小、最大两个定时器 m_min_timer.start(m_ac->min_wait_time); m_max_timer.start(m_ac->min_wait_time); return; } m_msg_list.push_back(loc_message(a,loc.m_tof)); if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt) { calc_location(); m_max_timer.stop(); } } void calc_location() { std::vector rc=std::move(m_loc_tool.calc_location(m_msg_list)); if(!rc.empty()) m_card->on_location(std::move(rc)); reset(); } }; struct card_message_handle { card_location_base*m_card; std::vector m_msg_list; std::array m_ct_list; card_message_handle(card_location_base*card) { m_card=card; for(size_t i=0;ion_message(loop, loc); } }; struct card:card_location_base { card_message_handle m_message_handle; card() :m_message_handle(this) { } ~card() { } void on_message(ev::dynamic_loop&loop, const message_locinfo&loc,bool is_history) { m_message_handle.on_message(loop, loc, is_history); } void on_location(const std::vector&points) { } }; loc_tool_main one_ct_message_handle::m_loc_tool; struct card_list_impl:card_list { std::vector m_list; card_list_impl() { m_list.reserve(1<<16); } void init_card_from_db() { } card*get(uint64_t card_id)const { uint32_t cid=0xFFFF&card_id; if(cid>=m_list.size()) return nullptr; return m_list[cid]; } void on_message(ev::dynamic_loop&loop, const message_locinfo&loc,bool is_history) { card*c=get(loc.m_card_id); if(c==nullptr) { log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id); return; } c->on_message(loop, loc, is_history); } }; card_list *card_list::instance() { static card_list_impl _impl; return &_impl; }