ソースを参照

时间戳检查移动到 site 类

zzj 6 年 前
コミット
4cacfcec12
4 ファイル変更41 行追加16 行削除
  1. 23 0
      ant.h
  2. 7 6
      net-service.cpp
  3. 10 9
      znet.cpp
  4. 1 1
      znet.h

+ 23 - 0
ant.h

@@ -9,6 +9,7 @@
 #include <deque>
 #include <tuple>
 #include <memory>
+#include <memory.h>
 #include <algorithm>
 #include <sstream>
 #include "log.h"
@@ -148,6 +149,28 @@ struct site:point,std::enable_shared_from_this<site>
     site(int id=-1);
 
 
+	char m_timestamp[8]={0};
+	bool check_timestamp(const char*time)
+	{
+		//秒、分、时、天、周、月、年, 脑残的设计
+		
+		char buf[6];
+		buf[0]=time[6];
+		buf[1]=time[5];
+		buf[2]=time[3];
+		buf[3]=time[2];
+		buf[4]=time[1];
+		buf[5]=time[0];
+
+		if(memcmp(m_timestamp,buf,6)<=0)
+		{
+			memcpy(m_timestamp,buf,6);
+			return true;
+		}
+		return false;
+	}
+
+
     int index()const;
     const algo_config&config()const;
     int id()const

+ 7 - 6
net-service.cpp

@@ -58,12 +58,6 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 		{
 			case CHAR_LOCATEDATA_TOF_EXTEND://tof-扩展
 				{
-					if(!clt->check_timestamp(data+10))
-					{
-						logn_error(1,"分站数据时间戳错误:%s",clt->name().c_str());
-						break;
-					}
-
 					uint32_t site_id;
 					uint8_t  power;
 					is>>site_id>>skip(11)>>power;
@@ -73,6 +67,13 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 						logn_error(1,"在全局分站列表中找不到分站:%d", site_id);
 						break;
 					}
+
+					if(!site_ptr->check_timestamp(data+10))
+					{
+						logn_error(1,"分站数据时间戳错误:%s",clt->name().c_str());
+						break;
+					}
+
 					site_ptr->set_client(clt);
 					site_ptr->on_power_status((power&1)==0);
 

+ 10 - 9
znet.cpp

@@ -202,7 +202,7 @@ struct sock_client:fd_io,client_ex
 	size_t m_opos=0;
 	bool   m_can_write{false};
 
-	char m_timestamp[8];
+//	char m_timestamp[8];
 
 	sock_client(io_context&ic,const char*name,int fd,int recv_time_out,int max_package_size)
 		:fd_io(ic,fd,EV_READ|EV_WRITE)
@@ -229,7 +229,7 @@ struct sock_client:fd_io,client_ex
 //		m_send_timer.start();
 
 		m_b=(char*)malloc(m_size);
-		m_timestamp[0]=0;
+//		m_timestamp[0]=0;
 	}
 
 	~sock_client()
@@ -237,7 +237,7 @@ struct sock_client:fd_io,client_ex
 		free(m_b);
 	}
 
-
+#if 0
 	bool check_timestamp(const char*time)
 	{
 		//秒、分、时、天、周、月、年, 脑残的设计
@@ -257,6 +257,7 @@ struct sock_client:fd_io,client_ex
 		}
 		return false;
 	}
+#endif
 
 	int type()
 	{
@@ -294,12 +295,12 @@ struct sock_client:fd_io,client_ex
 		buf[p++]=(tv.tv_usec/1000)&0xff;
 
 		//为防止分站重启时发送上来过大的时间
-		m_timestamp[5]=buf[p++]=t->tm_sec;
-		m_timestamp[4]=buf[p++]=t->tm_min;
-		m_timestamp[3]=buf[p++]=t->tm_hour;
-		m_timestamp[2]=buf[p++]=t->tm_mday;
-		m_timestamp[1]=buf[p++]=t->tm_mon;
-		m_timestamp[0]=buf[p++]=t->tm_year;
+		buf[p++]=t->tm_sec;
+		buf[p++]=t->tm_min;
+		buf[p++]=t->tm_hour;
+		buf[p++]=t->tm_mday;
+		buf[p++]=t->tm_mon;
+		buf[p++]=t->tm_year;
 
 		uint16_t ccrc=do_crc((unsigned char*)buf+2,10);
 

+ 1 - 1
znet.h

@@ -14,7 +14,7 @@ struct client:std::enable_shared_from_this<client>
 	virtual void close()=0;
 	virtual void send(std::vector<char>&&b)=0;
 
-	virtual bool check_timestamp(const char*)=0;
+//	virtual bool check_timestamp(const char*)=0;
 
 	virtual ~client(){}
 };