From e327510c7329aa9a95e62a460ec659ea0c9563ad Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期六, 19 十二月 2020 19:05:47 +0800 Subject: [PATCH] Merge branch 'CJL' into NewFilePath --- HDL_ON/DAL/DriverLayer/Control.cs | 75 +++++++++++++++++++++++++++---------- 1 files changed, 55 insertions(+), 20 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index 13b5269..2e8555f 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -25,6 +25,8 @@ public class Control { + + static Control _control; public static Control Ins { @@ -58,6 +60,14 @@ return t.ToString(); } + /// <summary> + /// 鏄惁鎼滅储鏈湴缃戝叧鎴愬姛 + /// </summary> + public bool IsSearchLocalGatewaySuccessful = false; + + /// <summary> + /// + /// </summary> bool _gatewayOnline = false; /// <summary> /// 缃戝叧鏄惁鍦ㄧ嚎 @@ -183,31 +193,54 @@ { MainPage.Log($"鎼滅储鏈湴缃戝叧鍒楄〃锛岀綉鍏崇被鍨�:{DB_ResidenceData.Instance.GatewayType}"); if (MainPage.InternetStatus == 0) - return; - OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585); - new System.Threading.Thread(() => { - for (int i = 0; i < 5; i++) - { - if (GatewayOnline) - break; - if (DB_ResidenceData.Instance.GatewayType == 0) - { - new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); - } - else if (DB_ResidenceData.Instance.GatewayType == 1) - { - new Control_Udp().SearchLocalGateway(); - } - System.Threading.Thread.Sleep(500); - } - if (!GatewayOnline)//缃戝叧涓嶅湪绾跨殑鏃跺�欐墠鍙皾璇曡繙绋嬭繛鎺� + Ins.GatewayOnline = false; + return; + } + else if (MainPage.InternetStatus == 1) + { + if (!Ins.IsRemote) { Ins.IsRemote = true; DAL.Mqtt.MqttClient.InitState(); } - }) - { IsBackground = true }.Start(); + } + else if (MainPage.InternetStatus == 2) + { + OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585); + //閲嶇疆鎼滅储缃戝叧鏍囧織 + IsSearchLocalGatewaySuccessful = false; + + new System.Threading.Thread(() => + { + for (int i = 0; i < 5; i++) + { + if (IsSearchLocalGatewaySuccessful) + break; + if (DB_ResidenceData.Instance.GatewayType == 0) + { + new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); + } + else if (DB_ResidenceData.Instance.GatewayType == 1) + { + new Control_Udp().SearchLocalGateway(); + } + System.Threading.Thread.Sleep(500); + } + + if (!IsSearchLocalGatewaySuccessful) + { + //鏈湴鎼滅储涓嶅埌缃戝叧 + if (!Ins.IsRemote) + { + Ins.IsRemote = true; + DAL.Mqtt.MqttClient.InitState(); + } + } + }) + { IsBackground = true }.Start(); + } + } /// <summary> @@ -443,6 +476,8 @@ var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); if (device.device_mac == DB_ResidenceData.Instance.residenceGatewayMAC) { + //鏈湴鎼滅储缃戝叧鎴愬姛 + Control.Ins.IsSearchLocalGatewaySuccessful = true; Ins.GatewayOnline = true; if (!string.IsNullOrEmpty(device.gatewayId)) { -- Gitblit v1.8.0