From 9137222ece9b978eb97b5598f2eee6e070bcf9d6 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 28 二月 2020 15:22:16 +0800 Subject: [PATCH] 2020-02-28 更新 --- Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs | 73 +++++++++++++++++++----------------- 1 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs b/Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs index 0013c38..2a1d2e1 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs @@ -1,8 +1,5 @@ using System; using Shared.SimpleControl.Phone; -using System.Collections.Generic; -using System.Text; -using System.Net.NetworkInformation; namespace Shared.SimpleControl { @@ -17,25 +14,37 @@ } static bool isConnectiong = false; - + static DateTime mFlagDateTime; /// <summary> /// 妫�娴�/杩炴帴杩滅▼ /// </summary> + /// <param name="status">褰撳墠缃戠粶鐘舵��</param> + /// <param name="IsReconnectRemote">鏄惁闇�瑕侀噸鏂拌繛鎺ヨ繙绋�</param> public static void CheckLinkRemote (int status, bool IsReconnectRemote = true) { - //if (isConnectiong) { - // return; - //} - //isConnectiong = true; + + //20S鍚庡己鍒堕噸缃甶sConnectiong鐘舵�侊紝闃叉isConnectiong涓�鐩翠负true鐘舵�� + if (mFlagDateTime.AddSeconds (20).Ticks <= System.DateTime.Now.Ticks) { + mFlagDateTime = DateTime.Now; + if (isConnectiong) { + Console.WriteLine ("20s銆媔sConnectiong true "); + isConnectiong = false; + } + } + + if (isConnectiong) { + return; + } + isConnectiong = true; UserConfig.Instance.internetStatus = status; #if wallon - return; + return; #endif - if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin || isConnectiong) { + if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) { + isConnectiong = false; return; } - isConnectiong = true; new System.Threading.Thread (async () => { try { if (status == 0) { @@ -65,13 +74,15 @@ obj.Split ('_') [1].ToString () == DeviceType.OnePortMqttFR.ToString ()); }); bool canRemote = false; - + + + //1.濡傛灉鏈湴娌$綉鍏虫暟鎹紝鎻愮ずWiFiOffline锛屽苟涓斿垽鏂槸鍚﹂渶瑕佹柇寮�杩滅▼ if (gateWayList == null || gateWayList.Count == 0) { Utlis.ShowAppLinkStatus (AppLinkStatus.WiFiOffline); await DisConnectRemoteAsync (); } - + //2.杩滅▼杩炴帴鎯呭喌涓嬶紝鏄惁闇�瑕佹柇寮�杩炴帴閲嶈繛 if (IsReconnectRemote) { if (CommonPage.IsRemote) { CommonPage.IsRemote = false; @@ -80,12 +91,13 @@ } } + //3.鍙戦�佷竴娆� CheckGateway鏁版嵁 if (CommonPage.IsRemote) { //await SmartHome.MqttCommon.StartCloudMqtt (); SmartHome.MqttCommon.MqttRemoteSend (new byte [] { }, 3); } - //鏈湴鏄惁瀛樺湪涓庡綋鍓嶄綇瀹呯粦瀹氱綉鍏崇殑鏁版嵁 + //4.鏈湴鏄惁瀛樺湪涓庡綋鍓嶄綇瀹呯粦瀹氱綉鍏崇殑鏁版嵁 bool HomeGatewaysExistsLocally = false; foreach (var gatewayFileName in gateWayList) { var tempStrings = gatewayFileName.Split ('_'); @@ -93,6 +105,7 @@ var common = Newtonsoft.Json.JsonConvert.DeserializeObject<GatewayBase> (gateWayString); if (common != null) { if (common.MAC.Replace (".", "") == UserConfig.Instance.GatewayMAC.Replace (".", "")) { + //4.1 鏈湴瀛樺湪涓庡綋鍓嶄綇瀹呯粦瀹氱綉鍏崇殑鏁版嵁锛屽鏋滄槸WiFi杩炴帴锛屽氨灞�鍩熺綉鎼滅储缃戝叧鏄惁鍦ㄥ悓涓�灞�鍩熺綉 HomeGatewaysExistsLocally = true; canRemote = true; if (status == 2) { @@ -113,6 +126,7 @@ canRemote = false; var mac0 = CommonPage.byteToHex16 (result [5]) + "." + CommonPage.byteToHex16 (result [6]) + "." + CommonPage.byteToHex16 (result [7]) + "." + CommonPage.byteToHex16 (result [8]) + "." + CommonPage.byteToHex16 (result [9]) + "." + CommonPage.byteToHex16 (result [10]) + "." + CommonPage.byteToHex16 (result [11]) + "." + CommonPage.byteToHex16 (result [12]); if (common.MAC == mac0) { + //4.2 缃戝叧鍦ㄥ悓涓�灞�鍩熺綉锛屾樉绀篧iFi鐘舵�侊紝鍙栨秷杩滅▼鏂紑杩滅▼杩炴帴 CommonPage.IsRemote = false; Application.RunOnMainThread (() => { MainPage.WiFiStatus = "CrabtreeAdd/WiFi.png"; @@ -133,11 +147,12 @@ - //鑳借繙绋� + //5.鑳借繙绋� if (canRemote) { if (!CommonPage.IsRemote) { if (UserConfig.Instance.CheckHomeGateways ()) { if (!string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { + // 5.1鑳借繙绋�,鏄剧ずCloudUnlink鐘舵�侊紝IsRemote璁句负true寮�濮嬭繙绋� Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); CommonPage.IsRemote = true; SmartHome.MqttCommon.IsGatewayOnline = false; @@ -148,33 +163,19 @@ } else { - //涓嶈兘杩滅▼锛屽鏋滀箣鍓嶈繙绋嬫ā寮忓垯鏂紑MQTT杩炴帴,鏄剧ず涓烘湭杩炴帴 + //6.涓嶈兘杩滅▼锛屽鏋滀箣鍓嶈繙绋嬫ā寮忓垯鏂紑MQTT杩炴帴,鏄剧ず涓烘湭杩炴帴 if (CommonPage.IsRemote) { Utlis.ShowAppLinkStatus (AppLinkStatus.WiFiOffline); CommonPage.IsRemote = false; await SmartHome.MqttCommon.DisConnectRemoteMqttClient (); } - + //鏈湴涓嶅瓨鍦ㄤ笌褰撳墠浣忓畢缁戝畾缃戝叧鐨勬暟鎹� if (!HomeGatewaysExistsLocally) { Utlis.ShowAppLinkStatus (AppLinkStatus.WiFiOffline); } } - - - //if (canRemote && !CommonPage.IsRemote) { - // if (UserConfig.Instance.CheckHomeGateways ()) { - // if (!string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { - // Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); - // Shared.SimpleControl.CommonPage.IsRemote = true; - // //await SmartHome.MqttCommon.StartCloudMqtt (); - // } - // } - //} - - - } } catch (Exception ex) { Console.WriteLine ("CheckLinkRemote : " + ex.ToString ()); @@ -188,12 +189,13 @@ } - + /// <summary> /// 鍏抽棴杩滅▼杩炴帴妯″紡锛屽苟鏂紑MQTT /// </summary> - /// <returns></returns> - static async System.Threading.Tasks.Task DisConnectRemoteAsync (){ + /// <returns></returns> + static async System.Threading.Tasks.Task DisConnectRemoteAsync () + { if (CommonPage.IsRemote) { CommonPage.IsRemote = false; @@ -205,3 +207,6 @@ + + + -- Gitblit v1.8.0