Ver Fonte

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

lixioayao há 5 anos atrás
pai
commit
7825669108
5 ficheiros alterados com 49 adições e 48 exclusões
  1. 5 5
      card_base.cpp
  2. 5 1
      message.cpp
  3. 36 41
      net-service.cpp
  4. 1 0
      net-service.h
  5. 2 1
      znet.cpp

+ 5 - 5
card_base.cpp

@@ -118,12 +118,12 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
 
 		double acc = lm[0].m_acc;
         m_acc = lm[0].m_acc;
-		log_info("useful:type:%d,card_id:%d,site:%d,ct:%d,timestamp:%llu, loc_point,x:%f,y:%f acc:%.2f",m_type,m_id,sid,m_ct,m_time,x,y,acc);
+		log_info("useful:type=%d,card=%d,site=%d,ct=%d,timestamp=%llu, loc_point,x=%f,y=%f acc=%.2f",m_type,m_id,sid,m_ct,m_time,x,y,acc);
 		do_business(lm.front().m_sit, pt, acc);
 	}
 	else
 	{
-		log_warn("坐标不可用:site_id:%d,type:%d,card_id:%d,ct:%d,x:%f,y:%f",sid,m_type,m_id,m_ct,pt.x,pt.y);
+		log_warn("坐标不可用:site=%d,type=%d,card=%d,ct=%d,x=%f,y=%f",sid,m_type,m_id,m_ct,pt.x,pt.y);
 	}
 }
 
@@ -134,7 +134,7 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	auto site_ptr = sit_list::instance()->get(loc.m_site_id);
 	if(!site_ptr)
 	{
-		log_warn("接收到分站%d的数据,CARD=%d, CT=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct);
+		log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct);
 		return;
 	}
 
@@ -144,7 +144,7 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 
 	if(site_ptr->is_up_site())
 	{
-        log_info("%d被井上分站[%d]收到",m_id,site_ptr->id());
+        log_info("card=%d被井上分站[site=%d]收到",m_id,site_ptr->id());
 		area_tool->on_point(shared_from_this(),point(1,1));
 		this->site_hover(loc.m_site_id);
 	}
@@ -152,7 +152,7 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	{
 		if(site_ptr->is_path_empty())
 		{
-			log_warn("接收到分站%d的数据,CT=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
+			log_warn("接收到分站的数据,site=%d,ct=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
 		}
 		m_message_handle->on_message(loop,loc,is_history);
 	}

+ 5 - 1
message.cpp

@@ -55,6 +55,10 @@ void message_locinfo::load(zistream&is,bool tdoa)
 	uint32_t i;
 	//卡类型、卡号、CT、电池状态
 	is>>b>>m_card_id>>m_card_ct>>m_batty_status;
+
+
+	m_card_id &= 0xFFFF; //卡号不会大于65535,分站上传数据的bug
+
 	m_card_type=b;
 	m_batty_status&=0x3;
 
@@ -95,7 +99,7 @@ void message_locinfo::load(zistream&is,bool tdoa)
 	uint16_t sp1=0,sp2=0;
 	is>>sp1>>sp2;
 	m_rssi=10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74;
-	log_info("timestamp=%llu,type:%d,card_id:%d,site:%d,ct:%d,status:%d,acc=%d,tof=%llu,ant_id:%d,spq=%d",
+	log_info("timestamp=%llu,type=%d,card=%d,site=%d,ct=%d,status=%d,acc=%d,tof=%llu,ant_id=%d,spq=%d",
 			m_time_stamp,m_card_type,m_card_id,m_site_id,m_card_ct,m_batty_status,m_acc,m_tof,m_ant_id,m_rssi);
 }
 

+ 36 - 41
net-service.cpp

@@ -40,6 +40,37 @@ void net_service::on_connect(const std::shared_ptr<client>& clt)
 {
      
 }
+
+static bool check_message_time(const std::shared_ptr<client> &clt, const std::shared_ptr<site> &site_ptr, struct tm*p_site_tm, int site_ct, int power)
+{
+	bool result=true;
+
+	char timebuf[64]{0};
+	strftime(timebuf,64,"%F %T",p_site_tm);
+
+	logn_info(1,"分站数据信息:net=%s,site=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_ptr->m_id,timebuf,
+			site_ct, site_ptr->m_power_check_enable?((power&1)?"ac":"dc"):"??");
+
+	time_t site_time=mktime(p_site_tm);
+	double diff=difftime(site_time, site_ptr->last_site_time());
+	if(diff<-3) //允许2秒的时间抖动
+	{
+		logn_error(1,"分站时间回退,数据将被丢弃:net=%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
+		result=false;
+	}
+
+	diff=difftime(site_time, time(nullptr));
+	if(fabs(diff)>3) 
+	{
+		logn_error(1,"分站时间与服务器时间相差太大:%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
+		result=false;
+	}
+
+	site_ptr->set_site_time(site_time);
+
+	return result;
+}
+
 void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,size_t len)
 {
 	bool message_handled=true;
@@ -68,7 +99,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					const auto &site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
 					if(!site_ptr)
 					{
-						logn_error(1,"在全局分站列表中找不到分站:%s,%d", clt->name().c_str(), site_id);
+						logn_error(1,"未定义分站:net=%s,site=%d", clt->name().c_str(), site_id);
 						break;
 					}
 
@@ -78,21 +109,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                         break;
                     }
 
-					{
-						char timebuf[64]{0};
-						strftime(timebuf,64,"%F %T",&site_tm);
-						logn_info(1,"分站数据信息:net=%s,sid=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_id,timebuf,
-										site_ct, site_ptr->m_power_check_enable?((power&1)?"ac":"dc"):"??");
-
-						time_t site_time=mktime(&site_tm);
-						double diff=difftime(site_time, site_ptr->last_site_time());
-						if(diff<-3) //允许2秒的时间抖动
-						{
-							logn_error(1,"分站时间回退,数据将被丢弃:%s,diff=%d",clt->name().c_str(),(int)diff);
-						}
-
-						site_ptr->set_site_time(site_time);
-					}
+					check_message_time(clt,site_ptr,&site_tm,site_ct,power);
 
                     if(clt->type()!=2){
 					    site_ptr->set_client(clt);
@@ -146,31 +163,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                         break;
                     }
 
-					{
-						char timebuf[64]{0};
-						struct tm site_tm={0};
-						localtime_r(&site_time, &site_tm);
-
-						strftime(timebuf,64,"%F %T",&site_tm);
-						const char*power_flag="??";
-						if(site_ptr->m_power_check_enable)
-						{
-							if(power==1)
-								power_flag="dc";
-							if(power==2)
-								power_flag="ac";
-						}
-
-						logn_info(1,"分站数据信息:net=%s,sid=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_id,timebuf, site_ct, power_flag);
-
-						double diff=difftime(site_time, site_ptr->last_site_time());
-						if(diff<-3) //允许2秒的时间抖动
-						{
-							logn_error(1,"分站时间回退,数据将被丢弃:%s,diff=%d",clt->name().c_str(),(int)diff);
-						}
-
-						site_ptr->set_site_time(site_time);
-					}
+					struct tm site_tm={0};
+					localtime_r(&site_time, &site_tm);
+					check_message_time(clt,site_ptr,&site_tm,site_ct,power);
 
                     if(clt->type()!=2){
 					    site_ptr->set_client(clt);

+ 1 - 0
net-service.h

@@ -14,6 +14,7 @@ struct net_service:service_callback
 
 	net_service();
 	~net_service();
+
 	void on_message(const std::shared_ptr<client> &clt,const char*data,size_t len);
 	void on_timer();
     void on_connect(const std::shared_ptr<client> &clt);

+ 2 - 1
znet.cpp

@@ -440,13 +440,14 @@ struct sock_client:fd_io,client_ex
 				if(m_clen<msg_len)
 					break;
 
-				logn_bin(1,name().c_str(),m_b,msg_len);//输出二进制日志
 				if(check_crc(m_b,msg_len))
 				{
 					on_message(m_b,msg_len);
+					logn_bin(1,name().c_str(),m_b,msg_len);//输出二进制日志
 				}
 				else
 				{
+					logn_bin(1,name().c_str(),m_b,msg_len);//输出二进制日志
 					logn_error(1,"check_crc_error,close socket. site=%s.",m_name.c_str());
 					return -1;
 				}