|
@@ -17,8 +17,8 @@ int site::index()const
|
|
|
site::site(int id)
|
|
|
:m_algo(0)
|
|
|
,m_num_dims(0)
|
|
|
- ,m_id(id)
|
|
|
- ,m_path_empty(true)
|
|
|
+ ,m_id(id)
|
|
|
+ ,m_path_empty(true)
|
|
|
{
|
|
|
m_time=time(0);
|
|
|
}
|
|
@@ -28,139 +28,325 @@ const algo_config&site::config()const
|
|
|
return g_config[index()];
|
|
|
}
|
|
|
|
|
|
-bool visit_site_status::visit(std::shared_ptr<site> s)
|
|
|
+void ant::set_path(const std::vector<line_v>&v_line,std::vector<line_v>::const_iterator itm)
|
|
|
{
|
|
|
- time_t now=time(0);
|
|
|
- int diff = now-s->m_time;
|
|
|
- event_tool::instance()->handle_event(OT_DEVICE_READER,ET_READER_ERROR,s->m_id,READER_TIMEOUT,diff,[diff](){return diff>READER_TIMEOUT;});
|
|
|
- return true;
|
|
|
+ auto it=itm;
|
|
|
+ for(int i=0;i<2 && it!=v_line.end();++it,++i)
|
|
|
+ m_path[0][i]=*it;
|
|
|
+
|
|
|
+ it=itm-1;
|
|
|
+ for(int i=0;i<2 && it>=v_line.begin();--it,++i)
|
|
|
+ {
|
|
|
+ m_path[1][i]=*it;
|
|
|
+ m_path[1][i].swap_point();
|
|
|
+ }
|
|
|
+
|
|
|
+ for(auto&p:m_path)
|
|
|
+ {
|
|
|
+ log_info("site-path: %s",p.to_str().c_str());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void sit_list::read_ant_path(int id)
|
|
|
+void ant::set_path(const std::vector<line_v>&v_line_)
|
|
|
{
|
|
|
- std::string sql = "SELECT reader_id,tof_flag,b_x,b_y,b_z,e_x,e_y,e_z,spacing_ratio FROM dat_reader_path_tof_n";
|
|
|
+ std::vector<line_v> vl(v_line_);
|
|
|
+ vl.reserve(vl.size()+2);
|
|
|
+ //找到距离天线最近的端点
|
|
|
+ auto min_it=vl.begin();
|
|
|
+ double dist=10;
|
|
|
+ for(auto it=vl.begin();it!=vl.end();it++)
|
|
|
+ {
|
|
|
+ double d=it->as_line().dist(*this);
|
|
|
+ if(d<dist)
|
|
|
+ {
|
|
|
+ dist=d;
|
|
|
+ min_it=it;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(min_it==vl.end())
|
|
|
+ {
|
|
|
+ log_error("分站路径距离分站太远site_id=%d",m_id);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if(-1 == id)
|
|
|
- {
|
|
|
- sql.append(";");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- sql.append(" where reader_id=");
|
|
|
- sql.append(std::to_string(id));
|
|
|
- sql.append(";");
|
|
|
+ if(abs(min_it->v[0].dist(*this)-dist)<1)
|
|
|
+ {
|
|
|
+ set_path(vl,min_it);
|
|
|
+ }
|
|
|
+ else if(abs(min_it->v[1].dist(*this)-dist)<1)
|
|
|
+ {
|
|
|
+ set_path(vl,min_it+1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ point proj=min_it->projection(*this);
|
|
|
+ vl.insert(min_it+1,line_v(proj,min_it->v[1]));
|
|
|
+ min_it->set_point(1,proj);
|
|
|
+
|
|
|
+ if(min_it->v[0].z)//slope ..555
|
|
|
+ {
|
|
|
+ double slope=min_it->v[0].z;
|
|
|
+ double len_a=min_it->v[0].dist((min_it+1)->v[1]);
|
|
|
+ double len_0=slope*min_it->length()/len_a;
|
|
|
+ double len_1=slope-len_0;
|
|
|
+
|
|
|
+ min_it->v[0].z=min_it->v[1].z=len_0;
|
|
|
+ (min_it+1)->v[0].z=(min_it+1)->v[1].z=len_1;
|
|
|
+ }
|
|
|
+
|
|
|
+ set_path(vl,min_it+1);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- std_debug("修改path sql=%s", sql.c_str());
|
|
|
- log_info("修改path sql=%s", sql.c_str());
|
|
|
- }
|
|
|
+void site::set_path(const std::vector<line_v>&v_line)
|
|
|
+{
|
|
|
+ if(v_line.empty())
|
|
|
+ return;
|
|
|
+
|
|
|
+ const auto&find_line=[](const point&pt,int first,std::vector<line_v>&vl){
|
|
|
+ for(auto it=vl.begin();it!=vl.end();it++)
|
|
|
+ {
|
|
|
+ if(it->v[first].dist(pt)<1)
|
|
|
+ return it;
|
|
|
+ if(it->v[first?0:1].dist(pt)<1)
|
|
|
+ {
|
|
|
+ point p=it->v[0];
|
|
|
+ it->v[0]=it->v[1];
|
|
|
+ it->v[1]=p;
|
|
|
+ return it;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return vl.end();
|
|
|
+ };
|
|
|
+
|
|
|
+ //构造一个首尾相连的结构
|
|
|
+
|
|
|
+ std::vector<line_v> vl(v_line.begin()+1,v_line.end());
|
|
|
+ std::vector<line_v> target(v_line.begin(),v_line.begin()+1);
|
|
|
+#if 0
|
|
|
+ target[0][0].z=target[0][1].z=slope[0];
|
|
|
+ for(int i=0,c=vl.size();i<c;i++)
|
|
|
+ vl[i][0].z=vl[i][1].z=slope[i+1];
|
|
|
+#endif
|
|
|
|
|
|
- std::string Error;
|
|
|
- YADB::CDBResultSet DBRes;
|
|
|
- sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
|
- int nCount = DBRes.GetRecordCount( Error );
|
|
|
- if (nCount < 1)
|
|
|
- {
|
|
|
- log_error("修改path失败,数据库中找不到(dat_reader_path_tof_n): 分站id=%d", id);
|
|
|
- return ;
|
|
|
- }
|
|
|
+ for(;;)
|
|
|
+ {
|
|
|
+ auto it=find_line(target.back().v[1],0,vl);
|
|
|
+ if(it==vl.end())
|
|
|
+ break;
|
|
|
|
|
|
- log_info( "read_ant_path. The record count=%ld\n", nCount );
|
|
|
- while ( DBRes.GetNextRecod(Error) )
|
|
|
- {
|
|
|
- int reader_id = 0;
|
|
|
- DBRes.GetField( "reader_id",reader_id, Error );
|
|
|
+ target.insert(target.end(),it,it+1);
|
|
|
+ vl.erase(it);
|
|
|
+ }
|
|
|
|
|
|
- auto site_ptr=sit_list::instance()->get(reader_id);
|
|
|
- if(nullptr==site_ptr)
|
|
|
- continue;
|
|
|
+ for(;;)
|
|
|
+ {
|
|
|
+ auto it=find_line(target.front().v[0],1,vl);
|
|
|
+ if(it==vl.end())
|
|
|
+ break;
|
|
|
|
|
|
- int pid=0;
|
|
|
- DBRes.GetField( "tof_flag",pid, Error );
|
|
|
+ target.insert(target.begin(),it,it+1);
|
|
|
+ vl.erase(it);
|
|
|
+ }
|
|
|
|
|
|
- double b_x= 0;
|
|
|
- DBRes.GetField( "b_x",b_x, Error );
|
|
|
+ log_info("初始化分站路径:site_id=%d",m_id);
|
|
|
|
|
|
- double b_y= 0;
|
|
|
- DBRes.GetField( "b_y",b_y, Error );
|
|
|
+ for(auto&a:m_ant)
|
|
|
+ {
|
|
|
+ a.set_path(target);
|
|
|
+ }
|
|
|
+ m_path_empty= !m_ant[0][0].valid() && !m_ant[0][1].valid() ;
|
|
|
+}
|
|
|
|
|
|
- double b_z= 0;
|
|
|
- DBRes.GetField( "b_z",b_z, Error );
|
|
|
+std::vector<point> ant::getsol(const double &dist) const
|
|
|
+{
|
|
|
+ std::vector<point> v;
|
|
|
+ for(const auto & p : m_path)
|
|
|
+ {
|
|
|
+ if(!p.valid())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ point pt;
|
|
|
+ double d = dist;
|
|
|
+
|
|
|
+ if(dist <= p.m_line[0].length())
|
|
|
+ {
|
|
|
+ d += d*p.m_line[0][0].z;
|
|
|
+ pt = point(p.m_line[0][0].x + d*p.m_line[0].cos() , p.m_line[0][0].y + d*p.m_line[0].sin());
|
|
|
+ }
|
|
|
+ else if(p.m_line[1].length()>0)
|
|
|
+ {
|
|
|
+ d -= p.m_line[0].length()*(1-d*p.m_line[0][1].z);
|
|
|
+ d += d*p.m_line[1][0].z;
|
|
|
+
|
|
|
+ pt = point(p.m_line[1][0].x+d*p.m_line[1].cos(),p.m_line[1][0].y+d*p.m_line[1].sin());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ v.push_back(pt);
|
|
|
+ }
|
|
|
+ return std::move(v);
|
|
|
+}
|
|
|
|
|
|
- double e_x= 0;
|
|
|
- DBRes.GetField( "e_x",e_x, Error );
|
|
|
+bool visit_site_status::visit(std::shared_ptr<site> s)
|
|
|
+{
|
|
|
+ time_t now=time(0);
|
|
|
+ int diff = now-s->m_time;
|
|
|
+ event_tool::instance()->handle_event(OT_DEVICE_READER,ET_READER_ERROR,s->m_id,READER_TIMEOUT,diff,[diff](){return diff>READER_TIMEOUT;});
|
|
|
+ return true;
|
|
|
+}
|
|
|
|
|
|
- double e_y= 0;
|
|
|
- DBRes.GetField( "e_y",e_y, Error );
|
|
|
+void sit_list::read_ant_path(int id)
|
|
|
+{
|
|
|
+ std::string sql = "SELECT reader_id,tof_flag,b_x,b_y,b_z,e_x,e_y,e_z,spacing_ratio FROM dat_reader_path_tof_n";
|
|
|
|
|
|
- double e_z= 0;
|
|
|
- DBRes.GetField( "e_z",e_z, Error );
|
|
|
+ std::map<int,std::vector<line_v>> map_path;
|
|
|
|
|
|
- double spacing_ratio = 0;
|
|
|
- DBRes.GetField( "spacing_ratio",spacing_ratio, Error );
|
|
|
- log_info("ant_path:%d,%.2f,%.2f,%.2f,%.2f",reader_id,b_x,b_y,e_x,e_y);
|
|
|
- point p1(b_x,-b_y);
|
|
|
- point p2(e_x,-e_y);
|
|
|
- auto &sit_ = *site_ptr;
|
|
|
- if(-1!=id)//清空path
|
|
|
- {
|
|
|
- sit_.clear_path();
|
|
|
- log_info( "修改path 清空path,分站id=%d\n", id );
|
|
|
- }
|
|
|
+ if(-1 == id)
|
|
|
+ {
|
|
|
+ sql.append(";");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql.append(" where reader_id=");
|
|
|
+ sql.append(std::to_string(id));
|
|
|
+ sql.append(";");
|
|
|
+
|
|
|
+ std_debug("修改path sql=%s", sql.c_str());
|
|
|
+ log_info("修改path sql=%s", sql.c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string Error;
|
|
|
+ YADB::CDBResultSet DBRes;
|
|
|
+ sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
|
+ int nCount = DBRes.GetRecordCount( Error );
|
|
|
+ if (nCount < 1)
|
|
|
+ {
|
|
|
+ log_error("修改path失败,数据库中找不到(dat_reader_path_tof_n): 分站id=%d", id);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- if(pid == 0)
|
|
|
- {
|
|
|
- line_v l(p1,p2);
|
|
|
- {
|
|
|
- point px = l.line::projection(sit_);
|
|
|
- sit_.set(px);
|
|
|
- for(int i=0;i<2;i++)
|
|
|
- {
|
|
|
- path p;
|
|
|
- p.m_slope[0] = spacing_ratio;
|
|
|
- p.m_line[0] = line_v(px,l[i]);
|
|
|
- sit_.m_ant[i].m_path.push_back(p);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ant &a = pid<0?sit_.m_ant[0]:sit_.m_ant[1];
|
|
|
- if(a.m_path.size()!=0)
|
|
|
- {
|
|
|
- path &p = a.m_path[0];
|
|
|
- p.m_line[abs(pid)-1] = line_v(p1,p2);
|
|
|
- p.m_slope[abs(pid)-1] = spacing_ratio;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- path p;
|
|
|
- p.m_line[abs(pid)-1] = line_v(p1,p2);
|
|
|
- p.m_slope[abs(pid)-1] = spacing_ratio;
|
|
|
- a.m_path.push_back(p);
|
|
|
- }
|
|
|
- if(abs(pid)==1)
|
|
|
- sit_.set(p1);
|
|
|
- }
|
|
|
- }
|
|
|
+ log_info( "read_ant_path. The record count=%ld\n", nCount );
|
|
|
+ while ( DBRes.GetNextRecod(Error) )
|
|
|
+ {
|
|
|
+ int reader_id = 0;
|
|
|
+ DBRes.GetField( "reader_id",reader_id, Error );
|
|
|
+
|
|
|
+ auto site_ptr=sit_list::instance()->get(reader_id);
|
|
|
+ if(nullptr==site_ptr)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ int pid=0;
|
|
|
+ DBRes.GetField( "tof_flag",pid, Error );
|
|
|
+
|
|
|
+ double b_x= 0;
|
|
|
+ DBRes.GetField( "b_x",b_x, Error );
|
|
|
+
|
|
|
+ double b_y= 0;
|
|
|
+ DBRes.GetField( "b_y",b_y, Error );
|
|
|
+
|
|
|
+ double b_z= 0;
|
|
|
+ DBRes.GetField( "b_z",b_z, Error );
|
|
|
+
|
|
|
+ double e_x= 0;
|
|
|
+ DBRes.GetField( "e_x",e_x, Error );
|
|
|
+
|
|
|
+ double e_y= 0;
|
|
|
+ DBRes.GetField( "e_y",e_y, Error );
|
|
|
+
|
|
|
+ double e_z= 0;
|
|
|
+ DBRes.GetField( "e_z",e_z, Error );
|
|
|
+
|
|
|
+ double spacing_ratio = 0;
|
|
|
+ DBRes.GetField( "spacing_ratio",spacing_ratio, Error );
|
|
|
+ log_info("ant_path:%d,%.2f,%.2f,%.2f,%.2f",reader_id,b_x,b_y,e_x,e_y);
|
|
|
+ point p1(b_x,-b_y, spacing_ratio);
|
|
|
+ point p2(e_x,-e_y, spacing_ratio);
|
|
|
+
|
|
|
+ map_path.insert(std::make_pair(reader_id,std::vector<line_v>()));
|
|
|
+ map_path.find(reader_id)->second.push_back(line_v(p1,p2));
|
|
|
+#if 0
|
|
|
+
|
|
|
+ auto &sit_ = *site_ptr;
|
|
|
+ if(-1!=id)//清空path
|
|
|
+ {
|
|
|
+ sit_.clear_path();
|
|
|
+ log_info( "修改path 清空path,分站id=%d\n", id );
|
|
|
+ }
|
|
|
+
|
|
|
+ if(pid == 0)
|
|
|
+ {
|
|
|
+ line_v l(p1,p2);
|
|
|
+ {
|
|
|
+ point px = l.line::projection(sit_);
|
|
|
+ sit_.set(px);
|
|
|
+ for(int i=0;i<2;i++)
|
|
|
+ {
|
|
|
+ path p;
|
|
|
+ p.m_slope[0] = spacing_ratio;
|
|
|
+ p.m_line[0] = line_v(px,l[i]);
|
|
|
+ sit_.m_ant[i].m_path.push_back(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ant &a = pid<0?sit_.m_ant[0]:sit_.m_ant[1];
|
|
|
+ if(a.m_path.size()!=0)
|
|
|
+ {
|
|
|
+ path &p = a.m_path[0];
|
|
|
+ p.m_line[abs(pid)-1] = line_v(p1,p2);
|
|
|
+ p.m_slope[abs(pid)-1] = spacing_ratio;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ path p;
|
|
|
+ p.m_line[abs(pid)-1] = line_v(p1,p2);
|
|
|
+ p.m_slope[abs(pid)-1] = spacing_ratio;
|
|
|
+ a.m_path.push_back(p);
|
|
|
+ }
|
|
|
+ if(abs(pid)==1)
|
|
|
+ sit_.set(p1);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ }
|
|
|
|
|
|
- if(-1==id)
|
|
|
- {
|
|
|
- for(auto&_s:sit_list::instance()->m_map)
|
|
|
- {
|
|
|
- _s.second->deal_path();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- auto sit_ptr=sit_list::instance()->get(id);
|
|
|
- if(sit_ptr)
|
|
|
- {
|
|
|
- sit_ptr->deal_path();
|
|
|
- log_info( "修改path成功,分站id=%d\n", id );
|
|
|
- }
|
|
|
- }
|
|
|
+#if 0
|
|
|
+ if(-1==id)
|
|
|
+ {
|
|
|
+ for(auto&_s:sit_list::instance()->m_map)
|
|
|
+ {
|
|
|
+ _s.second->deal_path();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ auto sit_ptr=sit_list::instance()->get(id);
|
|
|
+ if(sit_ptr)
|
|
|
+ {
|
|
|
+ sit_ptr->deal_path();
|
|
|
+ log_info( "修改path成功,分站id=%d\n", id );
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ for(auto&vl:map_path)
|
|
|
+ {
|
|
|
+ auto sit_ptr=sit_list::instance()->get(vl.first);
|
|
|
+ if(!sit_ptr)
|
|
|
+ {
|
|
|
+ log_error("定义了分站路径,但是没有定义分站:%d",vl.first);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ sit_ptr->set_path(vl.second);
|
|
|
+ }
|
|
|
|
|
|
- card_path::init();
|
|
|
+ card_path::init();
|
|
|
}
|
|
|
|
|
|
void sit_list::init_site(int id)
|