Browse Source

优化路径拆分
实现分站同步协议783A

zzj 5 years ago
parent
commit
c7ebcf1f78
6 changed files with 111 additions and 74 deletions
  1. 1 0
      ant.cpp
  2. 62 68
      card_path.cpp
  3. 9 0
      card_person.cpp
  4. 0 5
      module_service/area_business_person_attendance.cpp
  5. 38 0
      net-service.cpp
  6. 1 1
      znet.cpp

+ 1 - 0
ant.cpp

@@ -445,6 +445,7 @@ void sit_list::read_ant_path(int id)
 
 	card_path::init();
 
+	test_find_path(card_path::inst(),point(4727.00,418.07),point(4724.73,598.32));
 	test_find_path(card_path::inst(),point(4727,-8.06),point(2200,-75));
 	test_find_path(card_path::inst(),point(4727,-8.06),point(2600,-100));
 	test_find_path(card_path::inst(),point(2768.50,-75.00),point(2768.50,-161.58));

+ 62 - 68
card_path.cpp

@@ -53,10 +53,11 @@ struct vertex_list;
 struct base_path:std::array<int,2>
 {
 	int sid;
-	base_path(int i1=-1,int i2=-1)
+	base_path(int i1=-1,int i2=-1,int _sid=0)
 	{
 		at(0)=i1;
 		at(1)=i2;
+		sid=_sid;
 	}
 
 	bool operator<(const base_path&o)const
@@ -107,7 +108,7 @@ struct vertex_list
 		return (((((unsigned)p.x)>>2)<<16) + (((unsigned)p.y)>>2));
 	}
 
-	int find(const point&p,double x=1)const
+	int find(const point&p,double x=0.01)const
 	{
 		int rc=-1;
 		double t;
@@ -279,41 +280,40 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 			point p1;
 			if(sscanf(vv,"%lf,%lf,%lf,%lf",&p0.x,&p0.y,&p1.x,&p1.y)==4)
 			{
-				int p00=v.add(p0,0,999);
-				int p10=v.add(p1,0,999);
+				point p_0=point::min(p0,p1);
+				point p_1=point::max(p0,p1);
 
-				ret.push_back(base_path(p00,p10));
+				int p00=v.add(p_0,0,0);
+				int p10=v.add(p_1,0,0);
+
+				ret.push_back(base_path(p00,p10,0));
 			}
 		}
 		break;
 	}while(1);
 
-#ifdef __DEBUG__
-	log_path(ret,v);
-    printf("++++++++++++++++++++++++++++++++++++++++++++");
-#endif
-	std::sort(ret.begin(),ret.end());
-#ifdef __DEBUG__
-	log_path(ret,v);
-    printf("++++++++++++++++++++++++++++++++++++++++++++");
-#endif
-	ret.erase(std::unique(ret.begin(),ret.end()),ret.end());
-#ifdef __DEBUG__
-	log_path(ret,v);
-    printf("+++++++++++++++++nnnnn+++++++++++++++++++++++++++");
-#endif
-
-	std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
+	auto remove_dup=[](std::vector<base_path>&ret){
+		std::sort(ret.begin(),ret.end());
+		ret.erase(std::unique(ret.begin(),ret.end()),ret.end());
+	};
 
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
+	auto remove_empty=[](std::vector<base_path>&ret,vertex_list&v){
+		ret.erase(std::remove_if(ret.begin(),ret.end(),[&v](base_path&p){
+						point&p0=v[p[0]];
+						point&p1=v[p[1]];
+						return p0.dist(p1)<.00001;
+						}),
+					ret.end());
+	};
 
-		return arg<0;
-	});
+	auto sort_path=[](std::vector<base_path> & ret,vertex_list&v){
+		std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
+				return point::min(v[p1[0]],v[p1[1]]) < point::min(v[p2[0]],v[p2[1]]);
+		});
+	};
 
+	remove_dup(ret);
+	sort_path(ret,v);
 	log_path(ret,v,"合并前");
 	//合并相同
 	for(int i=0,len=ret.size();i<len;i++)
@@ -322,16 +322,22 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		for(int j=i+1;j<len;j++)
 		{
 			line_v lj=ret[j].as_line(v);
-			if(!lj.is_same(li,2.5))
+			if(!lj.is_same(li,1)) //li线段两个点在lj直线上
 				continue;
 
-			line_v ij=lj.projection(li);
+			line_v ij=lj.projection(li);//重叠
 
 			if(ij.empty())
 				continue;
 
-			point p0=point::min(v[ret[j][0]],v[ret[i][0]]);
-			point p1=point::max(v[ret[j][1]],v[ret[i][1]]);
+			
+
+			point p0=li.as_line().projection(v[ret[j][0]]);
+			point p1=li.as_line().projection(v[ret[j][1]]);
+
+
+			p0=point::min(p0,v[ret[i][0]]);
+			p1=point::max(p1,v[ret[i][1]]);
 
 			ret[j][0]=v.add(p0,0);
 			ret[j][1]=v.add(p1,0);
@@ -346,17 +352,7 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		return p[0]==0||p[1]==0;
 	}),ret.end());
 
-	std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
-
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
-
-		return arg<0;
-	});
-
+	sort_path(ret,v);
 	log_path(ret,v,"合并后");
 
 	//非路径交点配置
@@ -427,12 +423,28 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 			p0[i].push_back(id);
 			p0[j].push_back(id);
 		}
-
 		p0[i].push_back(ret[i][1]);
 
-		std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){
-			return v[i0]<v[i1];
-		});
+		std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
+#if 0
+		if(p0[i].size())
+		{
+			for(int v=0;v<2;v++)
+			{
+				if(v[ret[i][v]].dist(v[p0[i].front()])<3)
+					continue;
+				if(v[ret[i][v]].dist(v[p0[i].back()])<3)
+					continue;
+
+				p0[i].push_back(ret[i][v]);
+				std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
+			}
+		}
+		else
+		{
+			std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
+		}
+#endif
 
 		auto it=std::unique(p0[i].begin(),p0[i].end());
 		p0[i].erase(it,p0[i].end());
@@ -444,27 +456,9 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		}
 	}
 
-	ret2.erase(std::remove_if(ret2.begin(),ret2.end(),[&v](base_path&p){
-		point&p0=v[p[0]];
-		point&p1=v[p[1]];
-
-		//return p0.dist(p1)<0.1 || p0.empty() || p1.empty();
-		return p0.dist(p1)<1;
-	}),ret2.end());
-
-	std::sort(ret2.begin(),ret2.end());
-	ret2.erase(std::unique(ret2.begin(),ret2.end()),ret2.end());
-
-	std::sort(ret2.begin(),ret2.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
-
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
-
-		return arg<0;
-	});
+	remove_empty(ret2,v);
+	remove_dup(ret2);
+	sort_path(ret,v);
 	log_path(ret2,v,"拆分后");
 
 	return std::move(ret2);

+ 9 - 0
card_person.cpp

@@ -129,7 +129,15 @@ void person::handle_three_rates(const point & pt)
 void person::on_timer()
 {
     if(!m_mine_tool->m_is_attendance)
+	{
+		if(m_upmine_flag.load())
+		{
+			log_warn("up_mine:att=false,upmine_flag=%d",m_upmine_flag.load());
+			m_upmine_flag=0;
+		}
+
 		return;
+	}
 	YA::_CARD_POS_ cp;
 	uint64_t _time=0;
 	point pt = getSmoothPoint(_time);
@@ -155,6 +163,7 @@ void person::on_timer()
     print_card_detained();
 	if(m_upmine_flag.load())
 	{
+		log_info("up_mine:upmine_flag=%d",m_upmine_flag.load());
 		m_upmine_flag=0;
 		m_area_tool->on_leave(shared_from_this());
 	}

+ 0 - 5
module_service/area_business_person_attendance.cpp

@@ -121,11 +121,6 @@ void area_business_person_attendance::handle_up_mine(sio::message::ptr const& da
 void area_business_person_attendance::_to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
                                                            rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
 {
-    if(!card_ptr->m_display)
-    {
-        return;
-    }
-
     auto mine_tool_ptr = card_ptr->get_mine_tool();
 
     rapidjson::Value data(rapidjson::kArrayType);

+ 38 - 0
net-service.cpp

@@ -17,6 +17,8 @@
 #include "ant.h"
 #include "card.h"
 #include "mine_business.h"
+#include "crc.h"
+
 net_service::net_service()
 {
 	m_loc_worker=worker::instance();
@@ -131,6 +133,42 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					}
 				}
 				break;
+			case 0x783A://tof 分站时间同步
+				{
+
+					//  从第一个字节开始,分别表示毫秒(2字节)、秒、分、时、天、月、年
+					unsigned char buf[20]={0,13,0x78,0x3b};
+
+					struct timeval tv;
+					gettimeofday(&tv,0);
+
+					struct tm buff={0};
+					const struct tm*t=localtime_r(&tv.tv_sec,&buff);
+
+					int p=4;
+					buf[p++]=(tv.tv_usec/1000)&0xFF;
+					buf[p++]=((tv.tv_usec/1000)>>8)&0xFF;
+
+					buf[p++]=t->tm_sec;
+					buf[p++]=t->tm_min;
+					buf[p++]=t->tm_hour;
+					buf[p++]=t->tm_mday;
+					buf[p++]=t->tm_wday;
+					buf[p++]=t->tm_mon+1;
+					buf[p++]=t->tm_year-100;
+
+					uint16_t ccrc=do_crc(buf+2,11);
+
+					buf[p++]=ccrc>>8;
+					buf[p++]=ccrc&0xff;
+
+					std::vector<char> tmp((char*)buf,(char*)buf+15);
+					clt->send(std::move(tmp));
+
+					logn_info(1,"分站时间同步:ip=%s,time=%d-%02d-%02d %02d:%02d:%02d.%03d",
+									clt->name().c_str(),buf[12]+2000,buf[11],buf[9],buf[8],buf[7],buf[6],buf[5]*256+buf[4]);
+				}
+				break;
 			case CHAR_LOCATEDATA_TDOA_EXTEND://tdoa
 				{
 					uint32_t site_id;

+ 1 - 1
znet.cpp

@@ -430,7 +430,7 @@ struct sock_client:fd_io,client_ex
 					return -1;
 				}
 
-				if(msg_len<=6)
+				if(msg_len<=1)
 				{
 					logn_error(1,"package too small:%d,close socket. site=%s.",msg_len,m_name.c_str());
 					return -1;