From 2bbb1b72dbce5cf9bd4ac4a5b7488e3f18eaf929 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期六, 19 十二月 2020 18:37:38 +0800
Subject: [PATCH] 2020-12-19 1.IOS和Android网络切换,远程和本地控制切换优化。 2.IOS和Android后台回到前台,搜索网关,远程和本地控制切换优化.
---
HDL_ON/DAL/DriverLayer/Control.cs | 100 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 77 insertions(+), 23 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
old mode 100755
new mode 100644
index 64eb96a..2e8555f
--- 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>
/// 缃戝叧鏄惁鍦ㄧ嚎
@@ -181,30 +191,56 @@
/// </summary>
public void SearchLoaclGateway()
{
- OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585);
- new System.Threading.Thread(() =>
+ MainPage.Log($"鎼滅储鏈湴缃戝叧鍒楄〃锛岀綉鍏崇被鍨�:{DB_ResidenceData.Instance.GatewayType}");
+ if (MainPage.InternetStatus == 0)
{
- 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);
- }
- })
- { IsBackground = true }.Start();
- if (!GatewayOnline)//缃戝叧涓嶅湪绾跨殑鏃跺�欐墠鍙皾璇曡繙绋嬭繛鎺�
- {
- Ins.IsRemote = true;
- DAL.Mqtt.MqttClient.InitState();
+ Ins.GatewayOnline = false;
+ return;
}
+ else if (MainPage.InternetStatus == 1)
+ {
+ if (!Ins.IsRemote)
+ {
+ Ins.IsRemote = true;
+ DAL.Mqtt.MqttClient.InitState();
+ }
+ }
+ 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>
@@ -440,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))
{
@@ -565,7 +603,23 @@
}
break;
case SPK.LightRGBW:
- case SPK.LightCCT:
+ break;
+ case SPK.LightCCT:
+ var lightCCT = FunctionList.List.lights.Find((obj) => obj.sid == updateTemp.sid);
+ if (lightCCT != null)
+ {
+ localObj = lightCCT;
+ foreach (var attr in updateTemp.status)
+ {
+ var localAttr = lightCCT.attributes.Find((obj) => obj.key == attr.key);
+ if (localAttr != null)
+ {
+ localAttr.curValue = attr.value;
+ }
+ }
+ lightCCT.lastState = Language.StringByID(StringId.Brightness) + " : " + lightCCT.brightness + "%";
+ DimmerPage.UpdataStates(lightCCT);
+ }
break;
case SPK.CurtainSwitch:
var curtain = FunctionList.List.curtains.Find((obj) => obj.sid == updateTemp.sid);
--
Gitblit v1.8.0