#include #include #include #include #include #include #include "select_tool.h" #include "loc_tool.h" enum STA_TYPE { STATUS_HELP=0, STATUS_LOW_POWER, }; struct card_message_handle; struct card_location_base { std::shared_ptr m_sel_tool=nullptr; std::shared_ptr m_smo_tool=nullptr; card_message_handle *m_message_handle=nullptr; card_location_base()=default; card_location_base(std::string type) { select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool); } virtual void on_message(zloop * loop,const message_locinfo&loc,bool is_history)=0; virtual void on_location(const std::vector&vp,const std::vector &lm ) { loc_point pt = m_sel_tool->select_solution(vp,lm); if(pt.m_useless) { std_info("loc_point,x:%.2f,y:%.2f",pt.x,pt.y); log_info("loc_point,x:%.2f,y:%.2f",pt.x,pt.y); } m_smo_tool->smooth_strategy(); } void do_status(STA_TYPE st) { } 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; //loc_message. std::vector m_msg_list; card_location_base*m_card; const algo_config*m_ac=nullptr; int m_ct; bool m_min_timeout=false; ev::dynamic_loop * m_loop = nullptr; 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(); return; } m_min_timeout=true; } void on_max_timer() { m_max_timer.stop(); calc_location(); } void set(ev::dynamic_loop * loop) { m_loop = loop; m_min_timer.set(*m_loop); m_min_timer.set(this); m_max_timer.set(*m_loop); m_max_timer.set(this); } void on_message(ev::dynamic_loop *loop,const message_locinfo&loc) { if(m_loop == nullptr && loop!=nullptr) set(loop); else if(loop == nullptr) return; if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct) { m_msg_list.clear(); } site s=(*sit_list::instance())[loc.m_site_id]; if(m_msg_list.empty()) { m_ct=loc.m_card_ct; m_ac=&s.config(); m_min_timeout=false; //这里构造loc_message 保存数据 m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id, loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc, loc.m_sync_ct,loc.m_rssi)); //启动本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(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id, loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc, loc.m_sync_ct,loc.m_rssi)); if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt) { calc_location(); m_max_timer.stop(); } } void calc_location() { auto v = m_msg_list; std::vector rc=std::move(m_loc_tool.calc_location(v)); if(!rc.empty()) m_card->on_location(std::move(rc),v); reset(); } }; struct card_message_handle { card_location_base*m_card; std::array m_ct_list; card_message_handle(card_location_base*card) { m_card=card; for(size_t i=0;i * loop,const message_locinfo&loc,bool is_history) { if(is_history) { log_warn("%s","当前代码没有处理历史消息记录。"); return; } if(loc.m_batty_status == 2) { m_card->do_status(STA_TYPE::STATUS_LOW_POWER); } else if(loc.m_callinfo == 0x80) { m_card->do_status(STA_TYPE::STATUS_HELP); } m_ct_list[loc.m_card_ct&(m_ct_list.size()-1)]->on_message(loop,loc); } }; struct person:card_location_base { person(std::string type) :card_location_base(type) { m_message_handle = new card_message_handle(this); } void on_message(zloop * loop,const message_locinfo&loc,bool is_history) { m_message_handle->on_message(loop,loc,is_history); } }; struct car:card_location_base { car(std::string type) :card_location_base(type) { m_message_handle = new card_message_handle(this); } void on_message(zloop * loop,const message_locinfo&loc,bool is_history) { m_message_handle->on_message(loop,loc,is_history); } }; 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() { for(int i=0;i<(1<<16);i++) { card_location_base * mp = new car("car1"); m_list.push_back(mp); } } card_location_base *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(zloop *loop,const message_locinfo&loc,bool is_history) { card_location_base *c=get(loc.m_card_id); if(c==nullptr) { log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id); return; } log_info("card message:site=%d,ant=%d,card=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d,stamp=%llu", loc.m_site_id,loc.m_ant_id,loc.m_card_id,loc.m_tof,loc.m_rav,loc.m_acc,loc.m_rssi,loc.m_time_stamp); c->on_message(loop,loc,is_history); } }; //card_list *card_list::instance(zloop&loop) card_list *card_list::instance() { static card_list_impl _impl; return &_impl; }