From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 42 ++++++++++++++++++++++++++++++++++++------ 1 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index b9fc01d..d5f60c1 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -69,6 +69,7 @@ new System.Threading.Thread(() => { var broadBytes = new byte[44]; + var waitCount = 0; while (true) { @@ -110,6 +111,7 @@ if (listReceiveIP.Count > 0) { + waitCount = 0; //灞�鍩熺綉鑳藉骞挎挱寰楀埌缃戝叧 ZbGateway.IsRemote = false; //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� @@ -117,6 +119,13 @@ } else { + waitCount++; + if (waitCount >= 2) + { + //涓ゆ閮芥悳涓嶅埌,鎵嶆爣璁颁负杩滅▼ + continue; + } + waitCount = 0; //灞�鍩熺綉骞挎挱涓嶅埌缃戝叧 ZbGateway.IsRemote = true; //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� @@ -152,7 +161,7 @@ } var ipEndPoint = new System.Net.IPEndPoint(IPAddress.Any, 0); var bytes = FindGateWaySocket.udpClient.Receive(ref ipEndPoint); - if (bytes[43] == 0xA2) + if (bytes.Length > 43 && bytes[43] == 0xA2) { //骞挎挱鍥炲缃戝叧鐨勫熀鏈俊鎭鐞� var ipAddress = $"{bytes[3]}.{bytes[4]}.{bytes[5]}.{bytes[6]}"; @@ -400,13 +409,29 @@ /// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳� /// </summary> /// <param name="port"></param> - public static void Start() + public static bool Start() { - if (udpClient!=null) + if (udpClient != null) { - return; + return true; } - udpClient = new UdpClient { EnableBroadcast = true }; + + //鑾峰彇鎵嬫満鐨剋ifi鍦板潃 +#if Android + var netwifi = new Shared.Net.NetWiFi(); + string phoneIp = netwifi.GetIPAddress(); +#endif +#if iOS + string phoneIp = Shared.Net.NetWiFi.GetIPAddress(); +#endif + //"127.0.0.1"鏄簳灞傚簱閲岄潰璁剧疆鐨勫垵濮嬮粯璁ゅ�� + if (phoneIp != "127.0.0.1") + { + udpClient = new UdpClient(new IPEndPoint(IPAddress.Parse(phoneIp), 7624)); + udpClient.EnableBroadcast = true; + return true; + } + return false; } /// <summary> @@ -432,8 +457,13 @@ { try { - if (udpClient == null) + if (Start() == false) { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "udp New涓嶈捣鏉�"); + } return; } int value = udpClient.Send(bytes, bytes.Length, iPEndPoint); -- Gitblit v1.8.0