From 5727cf0b9b54da0a191dd1e23cb5abf21320fbff Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 25 十一月 2019 10:34:17 +0800 Subject: [PATCH] IOS使用新的项目名称 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 121 +++++++++++++++++---------------------- 1 files changed, 53 insertions(+), 68 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 90927c1..fa47ba0 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -3,15 +3,16 @@ using System.Net; using System.Net.Sockets; using System.Text; + using Shared.Common; using ZigBee.Device; -using static ZigBee.Device.ZbGateway; + namespace ZigBee.Common { public static class Application { - static bool isInited; + public static bool isInited; static bool isEncry; /// <summary> /// 鏄惁姝e湪鎼滅储缃戝叧 @@ -29,10 +30,11 @@ return; } isInited = true; + new System.Threading.Thread(async () => { var gateWayList = new List<ZbGateway> { }; - var searchCount = 2; + var searchCount = 0; var oldHomeID = string.Empty; var broadBytes = new byte[44];// byteHomeId[0] ,//H broadBytes[0] = 0xfe; @@ -57,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,31 +92,23 @@ var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; - //缃戝叧閫氳澶勭悊 - if (0 < gateWayList.Count) { - searchCount = 2; - gateWayList.Clear(); - var aa = GateWayList; - - //鍏抽棴杩滅▼鏈嶅姟鍣� - if (RemoteMqttClient!=null&& RemoteMqttClient.IsConnected==true) - { - await RemoteMqttClient?.DisconnectAsync(); - System.Console .WriteLine ($"鏀跺埌缃戝叧杩滅▼杩炴帴涓诲姩鏂紑_{System.DateTime.Now.ToString()}"); - } + searchCount = 4; + ZbGateway.IsRemote = false; } else - { - if (searchCount <= 0) - { - //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 - await StartCloudMqtt(); + { + if (searchCount <= 0) + { + gateWayList.Clear(); + ZbGateway.IsRemote = true; } } + searchCount--; + #region 2绉掓悳绱竴娆$綉鍏� //姣�0.5绉掑箍鎾彂鐜颁竴娆$綉鍏筹紝鍏�2s int count = 4; new System.Threading.Thread(() => @@ -124,7 +118,8 @@ try { //鐐瑰鐐瑰彂閫�(鍏堝彂涓�鏉″凡鏈夌殑鐐规挱锛屽洖澶嶅嚑鐜囬珮涓�鐐癸級 - for (int i = 0; i < gateWayList.Count;i++){ + for (int i = 0; i < gateWayList.Count; i++) + { FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(gateWayList[i].getGatewayBaseInfo.IpAddress), 7624), broadBytes); } //骞挎挱鍙戦�� @@ -133,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); } }) @@ -171,7 +163,6 @@ var pubKeyLengthByte1 = bytes[49 + gwNameLength + 1 + gwIdLength + 2]; int pubKeyLength = ((pubKeyLengthByte1 & 0xff) << 8 | (pubKeyLengthByte0 & 0xff)); var pubKey = Encoding.UTF8.GetString(bytes, 49 + gwNameLength + 1 + gwIdLength + 2 + 1, pubKeyLength); - var zbGateWay = new ZbGateway { getGatewayBaseInfo = new ZbGateway.GatewayBaseInfo @@ -192,25 +183,25 @@ //缃戝叧鍖归厤褰撳墠浣忓畢涓埌缃戝叧 if (Shared.Common.Config.Instance.HomeId == homeID) { - gateWayList.Add(zbGateWay); + gateWayList.Add(zbGateWay); } //UI鐣岄潰姝e湪鎼滅储锛屼笉蹇呴厤褰撳墠浣忓畢鍒板埌缃戝叧姝ゆ椂涔熼�氳 else if (IsSearchingGateway) { - gateWayList.Add(zbGateWay); + gateWayList.Add(zbGateWay); } //缃戝叧涓埌浣忓畢ID涓虹┖姝ゆ椂涔熼�氳 else if (homeID == string.Empty) { - gateWayList.Add(zbGateWay); + gateWayList.Add(zbGateWay); } } //缃戝叧鍒楄〃瀛樺偍澶勭悊 - 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); + await zbGateWay.StartLocalMqtt(ipAddress); + ZbGateway.GateWayList.Add(zbGateWay); NewGateWayAction?.Invoke(zbGateWay); } else @@ -221,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); + await zbGateWay.StartLocalMqtt(ipAddress); + ZbGateway.GateWayList.Add(gateWay); } else { @@ -232,15 +223,15 @@ gateWay.getGatewayBaseInfo.Time = time; gateWay.getGatewayBaseInfo.GwName = gwName; gateWay.getGatewayBaseInfo.HomeId = homeID; - await gateWay.StartLocalMqtt(ipAddress); + await gateWay.StartLocalMqtt(ipAddress); } //涓荤綉鍏宠缃� 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) { @@ -251,21 +242,14 @@ gateWay.getGatewayBaseInfo.IsMainGateWay = true; } } - } } - catch (Exception ex) - { - var mess = ex.Message; - } + catch { } } + #endregion } - catch (Exception ex) - { - var mess = ex.Message; - } + catch { } System.Threading.Thread.Sleep(500); - } }) { IsBackground = true }.Start(); @@ -277,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) { @@ -290,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