zzj 5 سال پیش
والد
کامیت
8accad54d2
4فایلهای تغییر یافته به همراه67 افزوده شده و 62 حذف شده
  1. 56 0
      ant.cpp
  2. 1 55
      ant.h
  3. 5 2
      net-service.cpp
  4. 5 5
      znet.cpp

+ 56 - 0
ant.cpp

@@ -29,6 +29,62 @@ const algo_config&site::config()const
 {
 	return g_config[index()];
 }
+
+bool site::check_timestamp(const char*tm_buf)
+{
+	//秒、分、时、天、周、月、年
+
+	struct tm t={0};
+
+
+	char buf[6];
+	buf[0]=tm_buf[5];
+	buf[1]=tm_buf[4];
+	buf[2]=tm_buf[3];
+	buf[3]=tm_buf[2];
+	buf[4]=tm_buf[1];
+	buf[5]=tm_buf[0];
+
+	t.tm_year=buf[0]+100;
+	t.tm_mon=buf[1];
+	t.tm_mday=buf[2];
+	t.tm_hour=buf[3];
+	t.tm_min=buf[4];
+	t.tm_sec=buf[5];
+
+	time_t now=time(0);
+	time_t site_tm=mktime(&t);
+	int off=abs(now-site_tm);
+
+	if(off>0)
+	{
+		off=log(off)/log(2);
+	}
+
+	m_timeoff_count[off]++;
+
+	if(m_package_count++ % 300 ==0 )
+	{
+		std::ostringstream stm;
+		for(uint32_t i=0;i<m_timeoff_count.size();i++)
+		{
+			if(m_timeoff_count[i]==0)
+				continue;
+
+			stm<<"("<<i<<":"<<m_timeoff_count[i]<<"),";
+		}
+
+		log_info("site-time-stat:site_id=%d,%s",m_id,stm.str().c_str());
+	}
+
+	if(memcmp(m_timestamp,buf,6)<=0)
+	{
+		memcpy(m_timestamp,buf,6);
+		return true;
+	}
+	return false;
+}
+
 void ant::set_path(const std::vector<line_v>&v_line,std::vector<line_v>::const_iterator itm)
 {
 	auto it=itm;

+ 1 - 55
ant.h

@@ -129,61 +129,7 @@ struct site:point,std::enable_shared_from_this<site>
 	int  m_package_count=0;
 
     site(int id=-1);
-	bool check_timestamp(const char*tm_buf)
-	{
-		//秒、分、时、天、周、月、年
-
-		struct tm t={0};
-		
-
-		char buf[6];
-		buf[0]=tm_buf[6];
-		buf[1]=tm_buf[5];
-		buf[2]=tm_buf[3];
-		buf[3]=tm_buf[2];
-		buf[4]=tm_buf[1];
-		buf[5]=tm_buf[0];
-
-		t.tm_year=buf[0]+100;
-		t.tm_mon=buf[1]-1;
-		t.tm_mday=buf[2];
-		t.tm_hour=buf[3];
-		t.tm_min=buf[4];
-		t.tm_sec=buf[5];
-
-		time_t now=time(0);
-		time_t site_tm=mktime(&t);
-		int off=abs(now-site_tm);
-
-		if(off>0)
-		{
-			off=log(off)/log(2);
-		}
-
-		m_timeoff_count[off]++;
-
-		if(m_package_count++ % 300 ==0 )
-		{
-			std::ostringstream stm;
-			for(uint32_t i=0;i<m_timeoff_count.size();i++)
-			{
-				if(m_timeoff_count[i]==0)
-					continue;
-
-				stm<<"("<<i<<":"<<m_timeoff_count[i]<<"),";
-			}
-
-			log_info("site-time-stat:site_id=%d,%s",m_id,stm.str().c_str());
-		}
-
-		if(memcmp(m_timestamp,buf,6)<=0)
-		{
-			memcpy(m_timestamp,buf,6);
-			return true;
-		}
-		return false;
-	}
-
+	bool check_timestamp(const char*tm_buf);
 
     int index()const;
     const algo_config&config()const;

+ 5 - 2
net-service.cpp

@@ -81,13 +81,16 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					{
 						char timebuf[64]{0};
 						unsigned char*t=(unsigned char*)data+10;
-						sprintf(timebuf,"%d-%d %d:%d:%d",*(t+4)+1,*(t+3),*(t+2),*(t+1),*(t+0));
+						sprintf(timebuf,"%d-%02d-%02d %02d:%02d:%02d",t[5]+2000,t[4]+1,t[3],t[2],t[1],t[0]);
 						logn_info(1,"分站数据信息:%s net=%s,sid=%d,tm=%s,sct=%d",(power&1)==0?"true":"false",clt->name().c_str(),site_id,timebuf,t[-2]*256+t[-1]);
 					}
 #if 1
 					if(!site_ptr->check_timestamp(data+10))
 					{
-						logn_error(1,"分站数据时间戳错误:%s",clt->name().c_str());
+						char timebuf[64]{0};
+						unsigned char*t=(unsigned char*)&site_ptr->m_timestamp[0];
+						sprintf(timebuf,"%d-%02d-%02d %02d:%02d:%02d",t[0]+2000,t[1]+1,t[2],t[3],t[4],t[5]);
+						logn_error(1,"分站数据时间戳错误:%s,pre-time=%s",clt->name().c_str(),timebuf);
 						break;
 					}
 #endif

+ 5 - 5
znet.cpp

@@ -296,8 +296,7 @@ struct sock_client:fd_io,client_ex
 	{
 //	从第一个字节开始,分别表示毫秒(2字节)、秒、分、时、天、月、年
 
-		log_info("分站同步:%s",m_name.c_str());
-		char buf[14]={0,12,0x78,0x3b};
+		unsigned char buf[14]={0,12,0x78,0x3b};
 
 		struct timeval tv;
 		gettimeofday(&tv,0);
@@ -309,7 +308,6 @@ struct sock_client:fd_io,client_ex
 		buf[p++]=(tv.tv_usec/1000)>>8;
 		buf[p++]=(tv.tv_usec/1000)&0xff;
 
-		//为防止分站重启时发送上来过大的时间
 		buf[p++]=t->tm_sec;
 		buf[p++]=t->tm_min;
 		buf[p++]=t->tm_hour;
@@ -317,13 +315,15 @@ struct sock_client:fd_io,client_ex
 		buf[p++]=t->tm_mon;
 		buf[p++]=t->tm_year-100;
 
-		uint16_t ccrc=do_crc((unsigned char*)buf+2,10);
+		uint16_t ccrc=do_crc(buf+2,10);
 
 		buf[p++]=ccrc>>8;
 		buf[p++]=ccrc&0xff;
 
-		std::vector<char> tmp(buf,buf+14);
+		std::vector<char> tmp((char*)buf,(char*)buf+14);
 		send(std::move(tmp));
+
+		log_info("分站同步:ip=%s,time=%d-%02d-%02d %02d:%02d:%02d",m_name.c_str(),buf[11]+2000,buf[10]+1,buf[9],buf[8],buf[7],buf[6]);
 	}
 
 	void on_send_timeout()