From 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期二, 21 七月 2020 09:46:53 +0800 Subject: [PATCH] 请合并最新多功能面板代码 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 93 +++++++++++++++++++++++++++------------------- 1 files changed, 54 insertions(+), 39 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index 367c79d..002e5a4 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -13,7 +13,6 @@ public static class Application { public static bool isInited; - static bool isEncry; /// <summary> /// 鏄惁姝e湪鎼滅储缃戝叧 /// </summary> @@ -33,7 +32,10 @@ { return; } - isInited = true; + isInited = true; + + //鍒濆鍖朣ocket + FindGateWaySocket.Start(); new System.Threading.Thread(async () => { @@ -84,19 +86,18 @@ if (paths.Length < 3) continue; - var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.getGatewayBaseInfo != null) && (obj.getGatewayBaseInfo.gwID == paths[2])); + var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == paths[2])); if (gateWay == null) { gateWay = new ZbGateway { IsVirtual = true }; - gateWay.getGatewayBaseInfo.gwID = paths[2]; - gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; + gateWay.GwId = paths[2]; + gateWay.HomeId = Shared.Common.Config.Instance.HomeId; ZbGateway.GateWayList.Add(gateWay); } } } var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; - if (Shared.Application.IsWifi) { @@ -144,7 +145,7 @@ //鐐瑰鐐瑰彂閫�(鍏堝彂涓�鏉″凡鏈夌殑鐐规挱锛屽洖澶嶅嚑鐜囬珮涓�鐐癸級 for (int i = 0; i < gateWayList.Count; i++) { - FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(gateWayList[i].getGatewayBaseInfo.IpAddress), 7624), broadBytes); + FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(gateWayList[i].GwIP), 7624), broadBytes); } //骞挎挱鍙戦�� if (broadcastIpAddress.ToString() != "0.0.0.0") @@ -152,11 +153,7 @@ FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); } } - catch - { - //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴 - FindGateWaySocket.Stop(); - } + catch{} System.Threading.Thread.Sleep(500); } }) @@ -174,7 +171,6 @@ var bytes = new byte[1024]; var len = FindGateWaySocket.busSocket.Receive(bytes, bytes.Length, System.Net.Sockets.SocketFlags.None); - if (bytes[43] == 0xA2) { //骞挎挱鍥炲缃戝叧鐨勫熀鏈俊鎭鐞� @@ -193,19 +189,16 @@ var pubKey = Encoding.UTF8.GetString(bytes, 49 + gwNameLength + 1 + gwIdLength + 2 + 1, pubKeyLength); var zbGateWay = new ZbGateway { - getGatewayBaseInfo = new ZbGateway.GatewayBaseInfo - { - IpAddress = ipAddress, - GwName = gwName, - HomeId = homeID, - IsMainGateWay = isMainGateWay, - gwID = id, - }, + GwIP = ipAddress, + GwName = gwName, + HomeId = homeID, + IsMainGateWay = isMainGateWay, + GwId = id, GatewayOnlineFlage = true, PubKey = pubKey }; //閫氳鍒扮綉鍏冲垪琛� - if (gateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == zbGateWay.getGatewayBaseInfo.gwID) == null) + if (gateWayList.Find(obj => obj.GwId == zbGateWay.GwId) == null) { //缃戝叧鍖归厤褰撳墠浣忓畢涓埌缃戝叧 if (Shared.Common.Config.Instance.HomeId == homeID) @@ -224,7 +217,7 @@ //} } //缃戝叧鍒楄〃瀛樺偍澶勭悊 - var gateWay = ZbGateway.GateWayList.Find(obj => obj.getGatewayBaseInfo != null && obj.getGatewayBaseInfo.gwID == zbGateWay.getGatewayBaseInfo.gwID); + var gateWay = ZbGateway.GateWayList.Find(obj => obj.GwId == zbGateWay.GwId); if (gateWay == null) { ZbGateway.GateWayList.Add(zbGateWay); @@ -236,7 +229,7 @@ gateWay.IsVirtual = false; //灏嗚缃戝叧鏍囪瘑涓恒�愬彲鎼滅储鍒帮紝鍗筹細鍦ㄧ嚎銆� gateWay.GatewayOnlineFlage = true; - if (gateWay.getGatewayBaseInfo.IpAddress != ipAddress) + if (gateWay.GwIP != ipAddress) { await gateWay.DisConnectLocalMqttClient("2"); ZbGateway.GateWayList.Remove(gateWay); @@ -247,25 +240,25 @@ else { gateWay.PubKey = pubKey; - gateWay.getGatewayBaseInfo.GwName = gwName; - gateWay.getGatewayBaseInfo.HomeId = homeID; + gateWay.GwName = gwName; + gateWay.HomeId = homeID; await gateWay.StartLocalMqtt(ipAddress); } //涓荤綉鍏宠缃� - if (isMainGateWay && oldHomeID == gateWay.getGatewayBaseInfo.HomeId) + if (isMainGateWay && oldHomeID == gateWay.HomeId) { for (int i = 0; i < ZbGateway.GateWayList.Count; i++) { var gw = ZbGateway.GateWayList[i]; //缃戝叧ID涓嶆槸褰撳墠鐨勭綉鍏筹紝鍒欐妸缃戝叧鍒楄〃涓叾浠栫綉鍏虫爣璁颁负涓嶆槸涓荤綉鍏� - if (gw.getGatewayBaseInfo.gwID != id && oldHomeID == gw.getGatewayBaseInfo.HomeId) + if (gw.GwId != id && oldHomeID == gw.HomeId) { - gw.getGatewayBaseInfo.IsMainGateWay = false; + gw.IsMainGateWay = false; } } //鏍囪褰撳墠缃戝叧鏄富缃戝叧 - gateWay.getGatewayBaseInfo.IsMainGateWay = true; + gateWay.IsMainGateWay = true; } } @@ -285,12 +278,17 @@ } } } + else + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + var data33 = Encoding.UTF8.GetString(bytes).Replace("锟�)", string.Empty).TrimStart('\0').TrimEnd('\0'); + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, data33); + } + } } - catch - { - //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴 - FindGateWaySocket.Stop(); - } + catch{} } #endregion } @@ -391,10 +389,20 @@ { try { - Start(7624); - busSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, iPEndPoint, new AsyncCallback(asyncEndSend), null); + if (IsRunning) + { + busSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, iPEndPoint, new AsyncCallback(asyncEndSend), null); + } + } - catch { } + catch (Exception ex) + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "鍙戦�佸紓甯�(BeginSendTo)\r\n" + ex.Message); + } + } } /// <summary> @@ -407,7 +415,14 @@ { int bytesSent = busSocket.EndSendTo(iar); } - catch { } + catch(Exception ex) + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "寮傛鍙戦�佺粨鏉熷紓甯�(asyncEndSend)\r\n" + ex.Message); + } + } } } } -- Gitblit v1.8.0