From 2029e64ec0491f7e511dc15bffaf821bfbabe2de Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 20 七月 2020 14:10:22 +0800 Subject: [PATCH] 上传一个很特别的新版本 --- ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs | 61 ++++++++++++++++++++++-------- 1 files changed, 45 insertions(+), 16 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs index 9ff57e4..88a2389 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs @@ -30,8 +30,22 @@ public static ZbGateway MainGateWay { get - { - return GateWayList.Find((obj) => { return obj.HomeId == Shared.Common.Config.Instance.HomeId && obj.IsMainGateWay; }); + { + ZbGateway mainWay = null; + for (int i = 0; i < GateWayList.Count; i++) + { + if (GateWayList[i].HomeId == Config.Instance.HomeId) + { + //2020.07.16鍙樻洿:鍒閭d箞澶�,濡傛灉浣忓畢ID涓�鏍�,鍏堢‘瀹氬氨鏄畠浜�(涓嶇劧鏈夋椂鍊欑粡甯歌繑鍥瀗ull,鏈夊彲鑳芥槸鍒锋柊涓嶅埌) + mainWay = GateWayList[i]; + if (mainWay.IsMainGateWay == true) + { + //鐒跺悗濡傛灉瀹冪‘瀹炴槸涓荤綉鍏�,鐩存帴break + break; + } + } + } + return mainWay; } } @@ -2335,7 +2349,7 @@ /// </summary> static Guid currentGuid = Guid.NewGuid(); - public async System.Threading.Tasks.Task SendAesKey() + public async Task SendAesKey() { if (PubKey != null) { @@ -2354,12 +2368,11 @@ } } - public async System.Threading.Tasks.Task StartLocalMqtt(string brokerName) + public async Task StartLocalMqtt(string brokerName) { if (localMqttIsConnecting - || !Shared.Common.Config.Instance.IsLogin - || Shared.Common.Config.Instance.HomeId == "" - || localIsConnected) + || Shared.Common.Config.Instance.HomeId == "" + || localIsConnected) { return; } @@ -2467,7 +2480,7 @@ /// 鑾峰彇褰撳墠甯愬彿鎵�鏈夌殑缃戝叧淇℃伅 /// </summary> /// <returns></returns> - static async System.Threading.Tasks.Task initGateWayBaseInfomation() + static async Task initGateWayBaseInfomation() { if (AllowRemoteCtrl == false) { @@ -2558,23 +2571,37 @@ public static IMqttClient RemoteMqttClient = new MqttFactory().CreateMqttClient(); static bool remoteIsConnected; + /// <summary> + /// 杩滅▼寮�濮嬭繛鎺ョ殑鏃堕棿鐐� + /// </summary> + private static DateTime RemoteConnectTime = DateTime.Now; /// <summary> /// 鍚姩杩滅▼Mqtt /// </summary> /// <returns>The start.</returns> /// <param name="brokerName">Broker name.</param> - public static async System.Threading.Tasks.Task StartRemoteMqtt() + public static async Task StartRemoteMqtt() { //杩藉姞锛氭病鏈夎繙绋嬭繛鎺ョ殑鏉冮檺 if (AllowRemoteCtrl == false - || remoteMqttIsConnecting - || !Shared.Common.Config.Instance.IsLogin || Shared.Common.Config.Instance.HomeId == "" || remoteIsConnected) { return; } - await System.Threading.Tasks.Task.Factory.StartNew(async () => + //濡傛灉杩滅▼杩樺湪杩炴帴涓� + if (remoteMqttIsConnecting == true) + { + //濡傛灉杩欎釜鍙橀噺涓�鐩村浜庤繛鎺ヤ腑鐨勭姸鎬�,浣嗘槸宸茬粡杩囧幓浜�10绉掍簡,杩樻槸true鐨勮瘽,璇存槑杩欓噷鏄湁鐐归棶棰樼殑,闇�瑕侀噸鏂板垱寤� + if ((DateTime.Now - RemoteConnectTime).TotalMilliseconds < 10 * 1000) + { + return; + } + } + //璁板綍璧疯繖娆¤繙绋嬭繛鎺ョ殑鏃堕棿鐐� + RemoteConnectTime = DateTime.Now; + + await Task.Factory.StartNew(async () => { try { @@ -2724,8 +2751,6 @@ AllowRemoteCtrl = false; return; } - //铏界劧涓嶇煡閬撳鎸や笅绾块偅涓�鍧楁湁娌℃湁鐢�,涓嶈繃鍏堣繖涔堝紕 - await System.Threading.Tasks.Task.Delay(1500); var responseData = jobject["ResponseData"]; if (responseData != null) @@ -2773,13 +2798,15 @@ /// <summary> /// 鏂紑鏈嶅姟鍣ㄨ繛鎺� /// </summary> - public async System.Threading.Tasks.Task DisConnectLocalMqttClient(string s) + public async Task DisConnectLocalMqttClient(string s) { try { if (localIsConnected) { localIsConnected = false; + //杩欎釜涓滆タ涔熻寮� + localMqttIsConnecting = false; DebugPrintLog($"Local涓诲姩鏂紑_{s}"); //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None); await localMqttClient.DisconnectAsync(); @@ -2794,13 +2821,15 @@ /// <summary> /// 鏂紑杩滅▼Mqtt鐨勯摼鎺� /// </summary> - public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s = "") + public static async Task DisConnectRemoteMqttClient(string s = "") { try { if (remoteIsConnected) { remoteIsConnected = false; + //杩欎釜涓滆タ涔熻寮� + remoteMqttIsConnecting = false; DebugPrintLog($"Remote涓诲姩鏂紑_{s}"); //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None); await RemoteMqttClient.DisconnectAsync(); -- Gitblit v1.8.0