Browse Source

增加虚拟连接,推送模拟数据

lixioayao 5 years ago
parent
commit
70561ede14
4 changed files with 19 additions and 7 deletions
  1. 1 0
      message.h
  2. 12 5
      net-service.cpp
  3. 5 2
      znet.cpp
  4. 1 0
      znet.h

+ 1 - 0
message.h

@@ -14,6 +14,7 @@ struct zistream;
 #define CHAR_TDOA_READER_SYNC_TIME 0xa78d			// TDOA分站时间同步
 #define CHAR_ADHOC	0x803b							// 上传自组网数据
 #define CHAR_CTRL_READER_CMD 0x804c					// 向分站发送控制指令,控制分站向上位机发送数据
+#define CHAR_VIRTUAL_DATA_PUSH_CMD 0x699a			//虚拟数据推送
 
 //	分站传上来的卡定位数据,包括tof,tdoa
 struct message_locinfo:task

+ 12 - 5
net-service.cpp

@@ -89,10 +89,11 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 						sprintf(timebuf,"%d-%d %d:%d:%d",*(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]);
 					}
-
-					site_ptr->set_client(clt);
-					site_ptr->on_power_status((power&1)==0);
-                    //clt->set_site_id(site_id);
+                    if(clt->type()!=2){
+					    site_ptr->set_client(clt);
+					    site_ptr->on_power_status((power&1)==0);
+                        //clt->set_site_id(site_id);
+                    }
 
 					struct timeval tv;
 					gettimeofday(&tv,NULL);
@@ -112,7 +113,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 						t->m_cmd_code=cmd;
 						t->m_hash_id=m.m_card_id;
 						if(m.m_card_type==5)
-						mine_business::inst()->make_reverse_condition(m.m_card_type,m.m_card_id,m.m_ant_id,m.m_card_ct,m.m_tof,m.m_site_id);
+						    mine_business::inst()->make_reverse_condition(m.m_card_type,m.m_card_id,m.m_ant_id,m.m_card_ct,m.m_tof,m.m_site_id);
 						m_loc_worker->request(t);
 					}
 				}
@@ -146,6 +147,12 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 			case CHAR_LOCATEDATAHIS_TDOA_EXTEND://tdoa his
 			case CHAR_CTRL_READER_CMD://ctrl site message
 			case CHAR_ADHOC://自组网数据
+            case CHAR_VIRTUAL_DATA_PUSH_CMD://虚拟数据链接
+                {
+                    logn_info(1,"接收到虚拟链接:%s",clt->name().c_str());
+                    clt->set(2);
+                }
+                break;
 			default:
 				message_handled=false;
 		}

+ 5 - 2
znet.cpp

@@ -266,7 +266,10 @@ struct sock_client:fd_io,client_ex
 	{
 		return m_type;
 	}
-
+    void set(int t)
+    {
+        m_type=t;
+    }
 	void close()
 	{
 		m_close_flag.store(true);
@@ -413,7 +416,7 @@ struct sock_client:fd_io,client_ex
 					return -1;
 				}
 
-				if(msg_len<=8)
+				if(msg_len<=6)
 				{
 					logn_error(1,"package too small:%d,close socket. site=%s.",msg_len,m_name.c_str());
 					return -1;

+ 1 - 0
znet.h

@@ -10,6 +10,7 @@ struct client:std::enable_shared_from_this<client>
 	virtual std::string name()=0;
 	virtual int type()=0;			//分站:1,模拟客户端:2
 	virtual int handle()=0;
+    virtual void set(int type)=0; //设置分站类型
 
 	virtual void close()=0;
 	virtual void send(std::vector<char>&&b)=0;