From 160785587667cc0d927f85e44c139ec9dde13a9e Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 25 十一月 2019 14:30:13 +0800 Subject: [PATCH] 原来的 IOS 工程舍弃(注:没有合并其他组员的代码) --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 146 +++++++++++++++++++++--------------------------- 1 files changed, 65 insertions(+), 81 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index 50321cc..f4c69b6 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -6,7 +6,7 @@ using Shared.Common; using ZigBee.Device; -using static ZigBee.Device.ZbGateway; + namespace ZigBee.Common { @@ -34,7 +34,7 @@ new System.Threading.Thread(async () => { var gateWayList = new List<ZbGateway> { }; - var searchCount = 0; + var searchCount = 6; var oldHomeID = string.Empty; var broadBytes = new byte[44];// byteHomeId[0] ,//H broadBytes[0] = 0xfe; @@ -59,9 +59,9 @@ { //鍥犱负閭d竴鐬棿锛屾湁鍙兘mqtt浼氬姞鍥炴潵,鎵�浠ュ厛鍔犵紦瀛� var list = new List<ZbGateway>(); - list.AddRange(GateWayList); + list.AddRange(ZbGateway.GateWayList); //鐒跺悗娓呯┖鎺� - GateWayList.Clear(); + ZbGateway.GateWayList.Clear(); //鏈�鍚庡啀鏂紑mqtt杩炴帴 for (int i = 0; i < list.Count; i++) { @@ -90,49 +90,37 @@ } } - var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; - System.Console.WriteLine($"Wifi{Shared.Application.IsWifi}"); - if (Shared.Application.IsWifi) - { - if (0 < gateWayList.Count) - { - searchCount = 4; - - //鍏抽棴杩滅▼鏈嶅姟鍣� - if (RemoteMqttClient != null && RemoteMqttClient.IsConnected == true) - { - await RemoteMqttClient?.DisconnectAsync(); - System.Console.WriteLine($"鏀跺埌缃戝叧杩滅▼杩炴帴涓诲姩鏂紑_{System.DateTime.Now.ToString()}"); - } - } - else + var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; + + + if (Shared.Application.IsWifi) + { + if (0 < gateWayList.Count) { - if (searchCount <= 0) + searchCount = 6; + ZbGateway.IsRemote = false; + } + else + { + if (searchCount < 0) { - System.Console.WriteLine($"=====================3{System.DateTime.Now.ToString()}"); - gateWayList.Clear(); - //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 - await StartCloudMqtt(); - } - } - } - else - { - if (searchCount <= 0) - { - System.Console.WriteLine($"=====================4{System.DateTime.Now.ToString()}"); - gateWayList.Clear(); - //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 - await StartCloudMqtt(); - } - } + ZbGateway.IsRemote = true; + } + } + } + else + { + ZbGateway.IsRemote = true; + } + searchCount--; - #region 2绉掓悳绱竴娆$綉鍏� - //姣�0.5绉掑箍鎾彂鐜颁竴娆$綉鍏筹紝鍏�2s - int count = 4; + #region 1绉掓悳绱竴娆$綉鍏� + //姣�0.5绉掑箍鎾彂鐜颁竴娆$綉鍏筹紝鍏�1s + int count = 2; new System.Threading.Thread(() => - { + { + gateWayList.Clear(); while (0 < count--) { try @@ -148,10 +136,7 @@ FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); } } - catch (Exception e) - { - System.Console.WriteLine("===" + e.Message); - } + catch { } System.Threading.Thread.Sleep(500); } }) @@ -220,11 +205,11 @@ } } //缃戝叧鍒楄〃瀛樺偍澶勭悊 - var gateWay = GateWayList.Find(obj => obj.getGatewayBaseInfo != null && obj.getGatewayBaseInfo.gwID == zbGateWay.getGatewayBaseInfo.gwID); + var gateWay = ZbGateway.GateWayList.Find(obj => obj.getGatewayBaseInfo != null && obj.getGatewayBaseInfo.gwID == zbGateWay.getGatewayBaseInfo.gwID); if (gateWay == null) { await zbGateWay.StartLocalMqtt(ipAddress); - GateWayList.Add(zbGateWay); + ZbGateway.GateWayList.Add(zbGateWay); NewGateWayAction?.Invoke(zbGateWay); } else @@ -235,10 +220,10 @@ if (gateWay.getGatewayBaseInfo.IpAddress != ipAddress) { gateWay.DisConnect("2"); - GateWayList.Remove(gateWay); + ZbGateway.GateWayList.Remove(gateWay); gateWay = zbGateWay; await zbGateWay.StartLocalMqtt(ipAddress); - GateWayList.Add(gateWay); + ZbGateway.GateWayList.Add(gateWay); } else { @@ -252,9 +237,9 @@ //涓荤綉鍏宠缃� if (isMainGateWay && oldHomeID == gateWay.getGatewayBaseInfo.HomeId) { - for (int i = 0; i < GateWayList.Count; i++) + for (int i = 0; i < ZbGateway.GateWayList.Count; i++) { - var gw = GateWayList[i]; + var gw = ZbGateway.GateWayList[i]; //缃戝叧ID涓嶆槸褰撳墠鐨勭綉鍏筹紝鍒欐妸缃戝叧鍒楄〃涓叾浠栫綉鍏虫爣璁颁负涓嶆槸涓荤綉鍏� if (gw.getGatewayBaseInfo.gwID != id && oldHomeID == gw.getGatewayBaseInfo.HomeId) { @@ -265,22 +250,14 @@ gateWay.getGatewayBaseInfo.IsMainGateWay = true; } } - } } - catch (Exception ex) - { - var mess = ex.Message; - } + catch { } } -#endregion + #endregion } - catch (Exception ex) - { - var mess = ex.Message; - } + catch { } System.Threading.Thread.Sleep(500); - } }) { IsBackground = true }.Start(); @@ -292,12 +269,14 @@ { try { + //瀹氭椂妫�娴嬭繙绋嬭繛鎺ユ儏鍐� + await ZbGateway.StartCloudMqtt(); if (!ZbGateway.IsRemote) { System.Threading.Thread.Sleep(500); continue; } - var gateWayList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId); + var gateWayList =ZbGateway.GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId); if (gateWayList.Count == 1) { @@ -305,28 +284,33 @@ } else { - for (int i = 0; i < gateWayList.Count; i++) + if (gateWayList.Find((obj) => obj.getGatewayBaseInfo.IsMainGateWay) == null) { - var gateWay = gateWayList[i]; - var info = await gateWay.GetZbGwInfoAsync(); - if (info == null || info.getGwData == null) + for (int i = 0; i < gateWayList.Count; i++) { - continue; - } - if (info.getGwData.IsDominant == 1) - { - gateWay.getGatewayBaseInfo.IsMainGateWay = true; - for (int j = i + 1; j < gateWayList.Count; j++) + var gateWay = gateWayList[i]; + var info = await gateWay.GetZbGwInfoAsync(); + if (info == null || info.getGwData == null) { - gateWayList[j].getGatewayBaseInfo.IsMainGateWay = false; - } - break; + continue; + } + if (info.getGwData.IsDominant == 1) + { + for (int j = 0; j < gateWayList.Count; j++) + { + if (gateWayList[i].getGatewayBaseInfo.gwID == info.getGwData.GwId) + { + gateWayList[i].getGatewayBaseInfo.IsMainGateWay = true; + } + else + { + gateWayList[i].getGatewayBaseInfo.IsMainGateWay = false; + } + } + break; + } } } - } - if (gateWayList.Find(obj => obj.getGatewayBaseInfo.IsMainGateWay == true) != null) - { - break; } } catch { } -- Gitblit v1.8.0