From dc6493db59dcb0893eac50b72122f94c24056b3f Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 12 十月 2020 14:35:39 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 75 +++++++++++++------------------------ 1 files changed, 27 insertions(+), 48 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index ca6fd17..beab8a5 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -64,7 +64,6 @@ { new System.Threading.Thread(() => { - var searchCount = 3; var broadBytes = new byte[44];// byteHomeId[0] ,//H broadBytes[0] = 0xfe; broadBytes[1] = 0x29; @@ -85,57 +84,30 @@ } var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; - if (Shared.Application.IsWifi) + + //娓呯┖鎺ユ敹鍒扮殑IP + listReceiveIP.Clear(); + if (broadcastIpAddress.ToString() != "0.0.0.0") { - if (0 < listReceiveIP.Count) - { - searchCount = 3; - ZbGateway.IsRemote = false; - //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� - Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI); - } - else - { - if (searchCount < 0) - { - ZbGateway.IsRemote = true; - //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� - Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote); - } - } + //骞挎挱鍑哄幓 + FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); + } + //绛夊緟3绉�,涓嬮潰鐨勬帴鏀舵柟娉曚細鍘绘帴鏀跺箍鎾� + System.Threading.Thread.Sleep(3000); + + if (listReceiveIP.Count > 0) + { + //灞�鍩熺綉鑳藉骞挎挱寰楀埌缃戝叧 + ZbGateway.IsRemote = false; + //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� + Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI); } else { + //灞�鍩熺綉骞挎挱涓嶅埌缃戝叧 ZbGateway.IsRemote = true; //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote); - - for (int i = 0; i < ZbGateway.GateWayList.Count; i++) - { - ZbGateway.GateWayList[i].DisConnectLocalMqttClient("1"); - } - //闈瀢ifi鎯呭喌涓�,涓嶉渶瑕佸箍鎾� - System.Threading.Thread.Sleep(1000); - continue; - } - searchCount--; - - //姣忕骞挎挱鍙戠幇涓�娆$綉鍏� - int count = 2; - listReceiveIP.Clear(); - while (0 < count--) - { - //鐐瑰鐐瑰彂閫�(鍏堝彂涓�鏉″凡鏈夌殑鐐规挱锛屽洖澶嶅嚑鐜囬珮涓�鐐癸級 - for (int i = 0; i < listReceiveIP.Count; i++) - { - FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(listReceiveIP[i]), 7624), broadBytes); - } - //骞挎挱鍙戦�� - if (broadcastIpAddress.ToString() != "0.0.0.0") - { - FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); - } - System.Threading.Thread.Sleep(1000); } } catch { } @@ -190,7 +162,6 @@ HomeId = homeID, IsMainGateWay = isMainGateWay, GwId = id, - GatewayOnlineFlage = true, PubKey = pubKey }; //閫氳鍒扮綉鍏冲垪琛� @@ -216,6 +187,7 @@ var gateWay = ZbGateway.GateWayList.Find(obj => obj.GwId == zbGateWay.GwId); if (gateWay == null) { + zbGateWay.OnlineTime = DateTime.Now; ZbGateway.GateWayList.Add(zbGateWay); await zbGateWay.StartLocalMqtt(ipAddress); } @@ -223,7 +195,7 @@ { gateWay.IsVirtual = false; //灏嗚缃戝叧鏍囪瘑涓恒�愬彲鎼滅储鍒帮紝鍗筹細鍦ㄧ嚎銆� - gateWay.GatewayOnlineFlage = true; + gateWay.OnlineTime = DateTime.Now; if (gateWay.GwIP != ipAddress) { await gateWay.DisConnectLocalMqttClient("2"); @@ -368,8 +340,10 @@ } list.Clear(); oldHomeID = Shared.Common.Config.Instance.HomeId; + var tempBytes = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.HomeId); System.Array.Copy(tempBytes, 0, broadBytes, 7, 36 < tempBytes.Length ? 36 : tempBytes.Length); + //浣忓畢涓凡缁忓瓨鍦ㄧ殑缃戝叧濡傛灉灞�鍩熺綉涓嶅瓨鍦紝闇�瑕佸湪褰撳墠浣忓畢涓櫄鎷熶竴涓綉鍏矷D鐩稿悓鐨勭綉鍏� var gateWayFileList = Global.FileListByHomeId().FindAll(obj => obj.StartsWith("Gateway_")); foreach (var filePath in gateWayFileList) @@ -444,7 +418,12 @@ { return; } - udpClient.Send(bytes, bytes.Length, iPEndPoint); + int value = udpClient.Send(bytes, bytes.Length, iPEndPoint); + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "鍙戦�侀暱搴�(BeginSendTo)锛�" + value + " 鍙戦�佸唴瀹�:" + System.Text.Encoding.UTF8.GetString(bytes)); + } } catch (Exception ex) { -- Gitblit v1.8.0