From 59e396f6a6a96e7fa2a2986a471fbe577af73191 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 13 七月 2023 17:14:57 +0800
Subject: [PATCH] 安卓优化
---
HDL_ON/DAL/DriverLayer/Control.cs | 130 +++++++++++++++++++++++++++++++++---------
1 files changed, 101 insertions(+), 29 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 29e90a2..e60e1ae 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -124,6 +124,10 @@
HomePage.LoadEvent_CheckLinkStatus();
}
}
+ else
+ {
+ MainPage.Log($"鐘舵�佷竴鑷达紝涓嶆洿鏂版暟鎹�(鏈湴)");
+ }
}
}
bool _GatewayOnline_Cloud = false;
@@ -138,45 +142,55 @@
}
set
{
- if (_GatewayOnline_Cloud != value)
+ try
{
- _GatewayOnline_Cloud = value;
- if (GatewayOnline_Local)
+ if (_GatewayOnline_Cloud != value)
{
- return;
- }
- if (value)
- {
- if (DB_ResidenceData.Instance.HomeGateway == null)
+ _GatewayOnline_Cloud = value;
+ if (GatewayOnline_Local)
{
return;
}
- if (!DB_ResidenceData.Instance.HomeGateway.gatewayStatus)//杩滅▼鎯呭喌涓嬶紝缃戝叧鏈摼鎺ユ湇鍔″櫒涓嶈兘淇敼涓婚〉缃戝叧鐘舵��
+ if (value)
{
+ if (DB_ResidenceData.Instance.HomeGateway == null)
+ {
+ return;
+ }
+ if (!DB_ResidenceData.Instance.HomeGateway.gatewayStatus)//杩滅▼鎯呭喌涓嬶紝缃戝叧鏈摼鎺ユ湇鍔″櫒涓嶈兘淇敼涓婚〉缃戝叧鐘舵��
+ {
+ new System.Threading.Thread(() =>
+ {
+ System.Threading.Thread.Sleep(3000);
+ var pm = new DAL.Server.HttpServerRequest();
+ pm.GetGatewayInfo();
+ })
+ { IsBackground = true }.Start();
+ return;
+ }
+ //淇敼涓婚〉杩炴帴鐘舵��
+ HomePage.LoadEvent_CheckLinkStatus();
+ MainPage.Log($"缃戝叧浜戠鍦ㄧ嚎锛屽埛鏂拌澶囩姸鎬�");
new System.Threading.Thread(() =>
{
- System.Threading.Thread.Sleep(3000);
- var pm = new DAL.Server.HttpServerRequest();
- pm.GetGatewayInfo();
+ System.Threading.Thread.Sleep(1000);
+ FunctionList.List.ReadAllFunctionStatus();
})
- { IsBackground = true }.Start();
- return;
+ { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start();
}
- //淇敼涓婚〉杩炴帴鐘舵��
- HomePage.LoadEvent_CheckLinkStatus();
- MainPage.Log($"缃戝叧浜戠鍦ㄧ嚎锛屽埛鏂拌澶囩姸鎬�");
- new System.Threading.Thread(() =>
+ else
{
- System.Threading.Thread.Sleep(1000);
- FunctionList.List.ReadAllFunctionStatus();
- })
- { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start();
+ //淇敼涓婚〉杩炴帴鐘舵��
+ HomePage.LoadEvent_CheckLinkStatus();
+ }
}
else
{
- //淇敼涓婚〉杩炴帴鐘舵��
- HomePage.LoadEvent_CheckLinkStatus();
+ MainPage.Log($"鐘舵�佷竴鑷达紝涓嶆洿鏂版暟鎹�(浜戠)");
}
+ }catch(Exception ex)
+ {
+ MainPage.Log($"Set GatewayCloudOnline Error:{ex.Message}");
}
}
}
@@ -251,7 +265,8 @@
public void SearchLoaclGateway()
{
//2021-01-15 : 浣忓畢娌℃湁缁戝畾缃戝叧鐨勬椂鍊欎笉鐢ㄦ悳绱紝骞朵笖涓嶈兘閾炬帴mqtt
- if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId))
+ if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId) ||
+ !UserInfo.Current.IsLogin)
{
return;
}
@@ -270,6 +285,7 @@
}
else if (MainPage.InternetStatus == 2)
{
+ DAL.Mqtt.MqttClient.InitState();
OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585);
//閲嶇疆鎼滅储缃戝叧鏍囧織
IsSearchLocalGatewaySuccessful = false;
@@ -296,7 +312,6 @@
System.Threading.Thread.Sleep(500);
}
- DAL.Mqtt.MqttClient.InitState();
})
{ IsBackground = true }.Start();
}
@@ -458,7 +473,6 @@
return true;
}
-
//MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}");
///绗笁鏂规秱楦﹁澶囩粺涓�浣跨敤杩滅▼鎺у埗
@@ -510,6 +524,7 @@
var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, resend);
MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+ Ins.myTcpClient.SendMessage(sendBytes);
}
}
//杩滅▼閫氳
@@ -934,6 +949,10 @@
/// <returns></returns>
public void ConvertReceiveData(byte[] receiveBytes, string ip)
{
+ if (!UserInfo.Current.IsLogin)
+ {
+ return;
+ }
var reString = Encoding.UTF8.GetString(receiveBytes);
AnalysisReceiveData(reString, receiveBytes, ip);
}
@@ -945,6 +964,7 @@
/// <returns></returns>
public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes, string sIp = null)
{
+
LocalCommunicationData receiveObj = new LocalCommunicationData();
@@ -1082,7 +1102,8 @@
}
}
else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
- receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
+ receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
+ receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" ||
receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
{
@@ -1175,11 +1196,62 @@
}
+
/// <summary>
/// 鏇存柊璁惧鐘舵��
/// A鍗忚鏁版嵁
/// </summary>
- /// <param name="updateBytes"></param>
+ public void UpdataGroupControlStatus(string revString, byte[] usefulBytes, bool isCloudData = false)
+ {
+ var temp = JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
+ if (temp != null)
+ {
+ Control_Udp.ReceiveRepeatManager(temp.id, usefulBytes);
+ var allLocalFuntion = FunctionList.List.groupControls;
+ foreach (var updateTemp in temp.objects)
+ {
+ try
+ {
+ var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid);
+ if (localFunction == null)
+ {
+ continue;
+ }
+ MainPage.Log($"鏀跺埌鏁版嵁:{revString}");
+ foreach (var attr in updateTemp.status)
+ {
+ localFunction.time_stamp = temp.time_stamp;
+ localFunction.SetAttrState(attr.key, attr.value);
+
+ }
+
+ //鏇存柊鐣岄潰鐘舵��
+ switch (localFunction.spk)
+ {
+ case SPK.ElectricEnergy:
+ EnergyMainPage.UpdataStatus(localFunction);
+ break;
+ }
+
+ HomePage.UpdataFunctionStates(localFunction);
+ RoomPage.UpdataStates(localFunction);
+ FunctionPage.UpdataStates(localFunction);
+ ClassificationPage.UpdataInfo(localFunction);
+
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"A鍗忚鏇存柊鐘舵�佸紓甯�:{ex.Message}");
+ }
+ }
+ }
+ }
+
+
+ /// <summary>
+ /// 鏇存柊璁惧鐘舵��
+ /// A鍗忚鏁版嵁
+ /// </summary>
public void UpdataFunctionStatus(string revString, byte[] usefulBytes, bool isCloudData = false)
{
////test 浜戠杩炴帴鎴愬姛鏃讹紝涓嶉�傜敤鏈湴鏁版嵁鏇存柊
--
Gitblit v1.8.0