From 5174e95a428876018ce3372f3dbc24b2861ea472 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 20 十一月 2019 16:11:54 +0800 Subject: [PATCH] 11.20 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 108 +++++++++++++++++++---------------------------------- 1 files changed, 39 insertions(+), 69 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs old mode 100755 new mode 100644 index 50321cc..fa47ba0 --- 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 { @@ -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++) { @@ -91,44 +91,24 @@ } 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 - { - if (searchCount <= 0) - { - System.Console.WriteLine($"=====================3{System.DateTime.Now.ToString()}"); - gateWayList.Clear(); - //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 - await StartCloudMqtt(); - } - } + if (0 < gateWayList.Count) + { + searchCount = 4; + ZbGateway.IsRemote = false; } else { if (searchCount <= 0) { - System.Console.WriteLine($"=====================4{System.DateTime.Now.ToString()}"); gateWayList.Clear(); - //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 - await StartCloudMqtt(); + ZbGateway.IsRemote = true; } } + searchCount--; - #region 2绉掓悳绱竴娆$綉鍏� + #region 2绉掓悳绱竴娆$綉鍏� //姣�0.5绉掑箍鎾彂鐜颁竴娆$綉鍏筹紝鍏�2s int count = 4; new System.Threading.Thread(() => @@ -148,10 +128,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 +197,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 +212,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 +229,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 +242,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 +261,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 +276,27 @@ } 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) + { + gateWay.getGatewayBaseInfo.IsMainGateWay = true; + for (int j = i + 1; j < gateWayList.Count; j++) + { + gateWayList[j].getGatewayBaseInfo.IsMainGateWay = false; + } + break; + } } } - } - if (gateWayList.Find(obj => obj.getGatewayBaseInfo.IsMainGateWay == true) != null) - { - break; } } catch { } -- Gitblit v1.8.0