Browse Source

修改时间同步

zzj 5 years ago
parent
commit
28d07bf630
3 changed files with 9 additions and 9 deletions
  1. 2 2
      ant.cpp
  2. 3 4
      net-service.cpp
  3. 4 3
      znet.cpp

+ 2 - 2
ant.cpp

@@ -38,8 +38,8 @@ bool site::check_timestamp(const char*tm_buf)
 
 
 	char buf[6];
-	buf[0]=tm_buf[5];
-	buf[1]=tm_buf[4];
+	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];

+ 3 - 4
net-service.cpp

@@ -81,19 +81,18 @@ 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-%02d-%02d %02d:%02d:%02d",t[5]+2000,t[4]+1,t[3],t[2],t[1],t[0]);
+						sprintf(timebuf,"%d-%02d-%02d %02d:%02d:%02d",t[6]+2000,t[5]+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))
 					{
 						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
+
                     if(clt->type()!=2){
 					    site_ptr->set_client(clt);
 					    site_ptr->on_power_status((power&1)==0);

+ 4 - 3
znet.cpp

@@ -296,7 +296,7 @@ struct sock_client:fd_io,client_ex
 	{
 //	从第一个字节开始,分别表示毫秒(2字节)、秒、分、时、天、月、年
 
-		unsigned char buf[14]={0,12,0x78,0x3b};
+		unsigned char buf[15]={0,12,0x78,0x3b};
 
 		struct timeval tv;
 		gettimeofday(&tv,0);
@@ -312,6 +312,7 @@ struct sock_client:fd_io,client_ex
 		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;
 		buf[p++]=t->tm_year-100;
 
@@ -320,10 +321,10 @@ struct sock_client:fd_io,client_ex
 		buf[p++]=ccrc>>8;
 		buf[p++]=ccrc&0xff;
 
-		std::vector<char> tmp((char*)buf,(char*)buf+14);
+		std::vector<char> tmp((char*)buf,(char*)buf+15);
 		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]);
+		log_info("分站同步:ip=%s,time=%d-%02d-%02d %02d:%02d:%02d",m_name.c_str(),buf[12]+2000,buf[11]+1,buf[9],buf[8],buf[7],buf[6]);
 	}
 
 	void on_send_timeout()