|
@@ -13,12 +13,13 @@
|
|
|
struct one_ct_message_handle
|
|
|
{
|
|
|
static loc_tool_main m_loc_tool;
|
|
|
- ev::timer *m_min_timer=nullptr,*m_max_timer=nullptr;
|
|
|
+ ev::timer m_min_timer,m_max_timer;
|
|
|
//loc_message.
|
|
|
std::vector<loc_message> 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)
|
|
|
{
|
|
@@ -26,51 +27,52 @@ struct one_ct_message_handle
|
|
|
m_ct=-1;
|
|
|
}
|
|
|
|
|
|
- ~one_ct_message_handle()
|
|
|
+ void reset()
|
|
|
{
|
|
|
- delete m_min_timer;
|
|
|
- delete m_max_timer;
|
|
|
+ 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();
|
|
|
+ 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=new ev::timer(*loop);
|
|
|
- m_min_timer->set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
|
|
|
- m_max_timer=new ev::timer(*loop);
|
|
|
- m_max_timer->set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
|
|
|
+ m_loop = loop;
|
|
|
+
|
|
|
+ m_min_timer.set(*m_loop);
|
|
|
+ m_min_timer.set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
|
|
|
+ m_max_timer.set(*m_loop);
|
|
|
+ m_max_timer.set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
|
|
|
}
|
|
|
|
|
|
void on_message(ev::dynamic_loop *loop,const message_locinfo&loc)
|
|
|
{
|
|
|
- if(loop==nullptr)
|
|
|
- return;
|
|
|
-
|
|
|
- if(m_loop == nullptr)
|
|
|
+ if(m_loop == nullptr && loop!=nullptr)
|
|
|
set(loop);
|
|
|
-
|
|
|
- if(m_ct==loc.m_card_ct && m_max_timer->remaining()<0) //超过max_timer的点,抛弃
|
|
|
+ else if(loop == nullptr)
|
|
|
return;
|
|
|
-
|
|
|
- if(!m_msg_list.empty() && m_ct!=loc.m_card_ct) //ct已经回绕,重置
|
|
|
+ if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct)
|
|
|
{
|
|
|
m_msg_list.clear();
|
|
|
}
|
|
|
-
|
|
|
auto sitPtr = sit_list::instance()->get(loc.m_site_id);
|
|
|
if(sitPtr==nullptr)
|
|
|
{
|
|
@@ -78,32 +80,36 @@ struct one_ct_message_handle
|
|
|
return;
|
|
|
}
|
|
|
auto s=sit_list::instance()->get(loc.m_site_id);
|
|
|
- //这里构造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));
|
|
|
-
|
|
|
- if(m_msg_list.size()==1)//第一个点
|
|
|
+ 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->max_wait_time);
|
|
|
+ m_min_timer.start(m_ac->min_wait_time);
|
|
|
+ m_max_timer.start(m_ac->max_wait_time);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(m_min_timer->remaining()<0 && (int)m_msg_list.size()>=m_ac->best_msg_cnt)
|
|
|
+ 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();
|
|
|
+ m_max_timer.stop();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void calc_location()
|
|
|
{
|
|
|
- auto&v = m_msg_list;
|
|
|
+ auto v = m_msg_list;
|
|
|
if(v.empty())
|
|
|
{
|
|
|
return;
|
|
@@ -116,7 +122,7 @@ struct one_ct_message_handle
|
|
|
|
|
|
if(!rc.empty()) m_card->on_location(std::move(rc),v);
|
|
|
|
|
|
- m_msg_list.clear();
|
|
|
+ reset();
|
|
|
log_info("calc_location_end:card_id=%d",m_card->m_id);
|
|
|
}
|
|
|
};
|
|
@@ -143,20 +149,6 @@ card_message_handle::~card_message_handle()
|
|
|
|
|
|
void card_message_handle::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
|
|
|
{
|
|
|
-#ifndef _RELEASE_
|
|
|
- if(m_first_call)
|
|
|
- {
|
|
|
- m_first_call=false;
|
|
|
- m_first_call_thread=std::this_thread::get_id();
|
|
|
- }
|
|
|
-
|
|
|
- if(m_first_call_thread!=std::this_thread::get_id())
|
|
|
- {
|
|
|
- log_error("%s\n","card_message_handle::on_message 无法支持多线程调用");
|
|
|
- assert(false);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
if(is_history)
|
|
|
{
|
|
|
log_warn("%s","当前代码没有处理历史消息记录。");
|