From 7b60238359b94125d591678eff105ae2bf47843f Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 15 十一月 2019 13:16:21 +0800
Subject: [PATCH] 2019.11.15
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 680 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 552 insertions(+), 128 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index 30dbd10..168cc2b 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -15,11 +15,11 @@
#region 鈻� 鍙橀噺澹版槑___________________________
/// <summary>
- /// 澶囦唤涓氬姟鐨勯�昏緫
+ /// 缃戝叧涓氬姟鐨勯�昏緫绫�
/// </summary>
private static HdlGatewayLogic m_Current = null;
/// <summary>
- /// 澶囦唤涓氬姟鐨勯�昏緫
+ /// 缃戝叧涓氬姟鐨勯�昏緫绫�
/// </summary>
public static HdlGatewayLogic Current
{
@@ -179,20 +179,34 @@
#region 鈻� 娣诲姞缃戝叧___________________________
/// <summary>
- /// 娣诲姞鏂扮綉鍏�(浠呴檺杩藉姞鏂扮殑缃戝叧 1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
+ /// 娣诲姞鏂扮綉鍏�(浠呴檺杩藉姞鏂扮殑缃戝叧)
/// </summary>
/// <param name="zbGateway">缃戝叧</param>
/// <param name="mode">鏄惁鏄剧ず閿欒</param>
- public async Task<int> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
+ public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
{
//鎵ц娣诲姞缃戝叧鍒板唴瀛�
var result = await this.DoAddGatewayToMemory(zbGateway, mode);
+ //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
+ if (result == 0)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //缃戝叧缁戝畾鍦ㄥ綋鍓嶈处鍙蜂笅鐨勫叾浠栦綇瀹呴噷\r\n璇疯В闄ょ粦瀹氬悗鍐嶈瘯
+ string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
+ if (msg.Contains("{0}") == true)
+ {
+ msg = string.Format(msg, "\r\n");
+ }
+ this.ShowTipMsg(msg);
+ }
+ return false;
+ }
if (result != 1)
{
- return result;
+ return false;
}
-
- return 1;
+ return true;
}
/// <summary>
@@ -391,7 +405,7 @@
/// 閲嶆柊缁戝畾缃戝叧(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
/// </summary>
/// <param name="zbGateway">缃戝叧</param>
- public async Task<int> ReBindNewGateway(ZbGateway zbGateway)
+ public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
{
if (zbGateway == null)
{
@@ -424,9 +438,19 @@
HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
}
- //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
- ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
-
+ if (btnMsg == null)
+ {
+ //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
+ ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
+ }
+ else
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
+ btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
+ });
+ }
await System.Threading.Tasks.Task.Delay(8000);
//鑾峰彇缃戝叧鐨勪俊鎭�
@@ -538,8 +562,104 @@
HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath);
return true;
- }
-
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧鍒囨崲___________________________
+
+ /// <summary>
+ /// 鎵ц鍒囨崲缃戝叧鎿嶄綔
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ public async Task<bool> DoSwitchGateway(string gatewayId)
+ {
+ var zbGateway = this.GetLocalGateway(gatewayId);
+ if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
+ {
+ //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
+ var result = await this.GetOnlineGatewayInfo(gatewayId);
+ if (result == false)
+ {
+ return false;
+ }
+ }
+ //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
+ this.SaveGatewayIdToLocation(gatewayId);
+ return true;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍦ㄧ嚎缃戝叧淇℃伅
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ /// <returns></returns>
+ private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
+ {
+ //鏄剧ず杩涘害鏉�
+ ProgressBar.Show();
+
+ //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
+ ZbGateway realWay = null;
+ bool getGatewayInfo = true;
+ if (this.GetRealGateway(ref realWay, gatewayId) == true)
+ {
+ //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
+ if (this.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
+ {
+ int result2 = await this.ReBindNewGateway(realWay);
+ if (result2 == 0)
+ {
+ //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇�
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ }
+ else if (result2 == -1)
+ {
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ return false;
+ }
+ //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭�
+ getGatewayInfo = false;
+ }
+ }
+
+ if (getGatewayInfo == true)
+ {
+ //鑾峰彇缃戝叧淇℃伅
+ var info = await this.GetGatewayNewInfoAsync(realWay);
+ if (info == null)
+ {
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ return false;
+ }
+ }
+
+ //鑾峰彇鍏ㄩ儴璁惧
+ bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ if (result == false)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// 淇濆瓨閫夋嫨鐨勭綉鍏矷D鍒版湰鍦�
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ public void SaveGatewayIdToLocation(string gatewayId)
+ {
+ GatewayResourse.AppOldSelectGatewayId = gatewayId;
+ byte[] data = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
+ Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
+ }
+
#endregion
#region 鈻� 鍒犻櫎缃戝叧___________________________
@@ -678,8 +798,8 @@
if (waitTime == true)
{
- //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟3绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage)
- System.Threading.Thread.Sleep(3000);
+ //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟2绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage)
+ System.Threading.Thread.Sleep(2000);
//妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
if (this.CheckHadGatewayInWifi(listRealWay) == false)
{
@@ -907,6 +1027,198 @@
#endregion
+ #region 鈻� 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬揰________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬�(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public int GetGatewayChannelId(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return -1;
+ }
+ ChannelIdInfo data = null;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ data = Newtonsoft.Json.JsonConvert.DeserializeObject<ChannelIdInfo>(jobject["Data"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 8 } };
+ realWay.Send("ZbGw/GetChannel", jObject.ToString());
+
+ int TimeOut = 0;
+ while (data == null && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (data == null)
+ {
+ //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ return -1;
+ }
+
+ return data.Channel;
+ }
+
+ /// <summary>
+ /// 缃戝叧淇¢亾淇℃伅
+ /// </summary>
+ private class ChannelIdInfo
+ {
+ /// <summary>
+ /// 缃戝叧淇¢亾
+ /// </summary>
+ public int Channel = -1;
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍗忚皟鍣∕AC______________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣∕AC鍦板潃(浼氭湁绛夊緟寤惰繜,杩斿洖null浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public string GetGatewayCoordinatorMac(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return null;
+ }
+ CoordinatorMacInfo data = null;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ data = Newtonsoft.Json.JsonConvert.DeserializeObject<CoordinatorMacInfo>(jobject["Data"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 13 } };
+ realWay.Send("ZbGw/GetMac", jObject.ToString());
+
+ int TimeOut = 0;
+ while (data == null && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (data == null)
+ {
+ //鑾峰彇鍗忚皟鍣∕ac澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ return null;
+ }
+
+ return data.MacAddr;
+ }
+
+ /// <summary>
+ /// 缃戝叧鍗忚皟鍣∕ac淇℃伅
+ /// </summary>
+ private class CoordinatorMacInfo
+ {
+ /// <summary>
+ /// 璋冨櫒Mac
+ /// </summary>
+ public string MacAddr = string.Empty;
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍗忚皟鍣≒anID____________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣≒anID(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public int GetGatewayPanId(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return -1;
+ }
+ PanIdInfo data = null;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/" + "ZbGw/GetPanId_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ data = Newtonsoft.Json.JsonConvert.DeserializeObject<PanIdInfo>(jobject["Data"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 12 } };
+ realWay.Send("ZbGw/GetPanId", jObject.ToString());
+
+ int TimeOut = 0;
+ while (data == null && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (data == null)
+ {
+ //鑾峰彇鍗忚皟鍣≒anID澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ return -1;
+ }
+
+ return data.PANID;
+ }
+
+ /// <summary>
+ /// 缃戝叧PanId淇℃伅
+ /// </summary>
+ private class PanIdInfo
+ {
+ /// <summary>
+ /// PanId
+ /// </summary>
+ public int PANID = -1;
+ }
+
+ #endregion
+
#region 鈻� 鑾峰彇缃戝叧GwInfo閲岄潰鐨勫睘鎬__________
/// <summary>
@@ -938,44 +1250,6 @@
{
//鑾峰彇鏈湴鐨勫睘鎬�
objValue = localWay.getGwInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGwInfo, null);
- }
-
- if (objValue == null)
- {
- return defult;
- }
- return objValue;
- }
-
- /// <summary>
- /// 鑾峰彇缃戝叧GatewayBaseInfo閲岄潰鐨勫睘鎬�
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <param name="attributeName">GatewayBaseInfo閲岄潰灞炴�х殑鍚嶅瓧</param>
- /// <param name="defult">濡傛灉鑾峰彇涓嶅埌鏃讹紝璁剧疆鐨勯粯璁ゅ��</param>
- /// <returns></returns>
- public object GetGatewayBaseInfoAttribute(ZbGateway zbGateway, string attributeName, string defult = "")
- {
- string gwID = this.GetGatewayId(zbGateway);
- var localWay = this.GetLocalGateway(gwID);
-
- object objValue = null;
- if (localWay == null || localWay.getGatewayBaseInfo == null)
- {
- //鏈湴娌℃湁璁板綍鏈夎繖涓笢瑗�,鍒欑洿鎺ヨ繑鍥炲弬鏁扮殑鏁版嵁
- if (zbGateway.getGatewayBaseInfo != null)
- {
- objValue = zbGateway.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, zbGateway.getGatewayBaseInfo, null);
- }
- else
- {
- return defult;
- }
- }
- else
- {
- //鑾峰彇鏈湴灞炴��
- objValue = localWay.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGatewayBaseInfo, null);
}
if (objValue == null)
@@ -1053,38 +1327,60 @@
}
/// <summary>
- /// 鑾峰彇缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛�
+ /// 璁剧疆缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛�
/// </summary>
+ /// <param name="button"></param>
/// <param name="zbGateway"></param>
/// <returns></returns>
- public string GetGatewayImageText(ZbGateway zbGateway)
+ public void SetGatewayImageText(Button button, ZbGateway zbGateway)
{
+ //鍒濆鍊�:鏃犳硶璇嗗埆鐨勭綉鍏宠澶�
+ button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
+
string gwId = this.GetGatewayId(zbGateway);
- int imageType = -1;
if (this.dicGateway.ContainsKey(gwId) == false || this.dicGateway[gwId].getGwInfo == null)
{
//濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇
- var result = this.GetGatewayNewInfo(zbGateway, ShowErrorMode.NO);
- if (result == null)
+ if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
{
- //鏃犳硶璇嗗埆鐨勭綉鍏宠澶�
- return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
+ string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
+ if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ {
+ //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
+ button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ }
}
- imageType = result.LinuxImageType;
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(async () =>
+ {
+ var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
+ if (result != null)
+ {
+ zbGateway.getGwInfo = result;
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
+ if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ {
+ //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
+ button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ }
+ });
+ }
+ });
+ }
}
else
{
- imageType = Convert.ToInt32(this.GetGwInfoAttribute(this.dicGateway[gwId], "LinuxImageType"));
+ string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
+ if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ {
+ //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
+ button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ }
}
- string keyName = Common.LocalDevice.deviceModelIdName + imageType;
- if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
- {
- //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
- return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]);
- }
-
- //鏃犳硶璇嗗埆鐨勭綉鍏宠澶�
- return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
}
#endregion
@@ -1160,12 +1456,11 @@
{
bool bolBreak = false;
ZbGatewayData.GetGwData result = null;
- new System.Threading.Thread(async () =>
+ HdlThreadLogic.Current.RunThread(async () =>
{
result = await this.GetGatewayNewInfoAsync(zbGateway, mode);
bolBreak = true;
- })
- { IsBackground = true }.Start();
+ });
while (bolBreak == false)
{
@@ -1315,7 +1610,7 @@
#region 鈻� 涓荤綉鍏冲垽瀹歘________________________
/// <summary>
- /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� -1:杩滅▼妯″紡,涓嶅瓨鍦ㄥ暐涓荤綉鍏崇殑璇存硶)
+ /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
/// </summary>
/// <param name="zbGateway">缃戝叧瀵硅薄</param>
/// <returns></returns>
@@ -1326,7 +1621,7 @@
}
/// <summary>
- /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� -1:杩滅▼妯″紡,涓嶅瓨鍦ㄥ暐涓荤綉鍏崇殑璇存硶)
+ /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
/// </summary>
/// <param name="waiID">缃戝叧id</param>
/// <returns></returns>
@@ -1337,7 +1632,7 @@
{
return 0;
}
- return zbGateway.IsMainGateWay == true ? 1 : 0;
+ return zbGateway.IsMainGateWay == true ? 1 : 2;
}
#endregion
@@ -1345,7 +1640,7 @@
#region 鈻� 璁剧疆缃戝叧鍥剧墖_______________________
/// <summary>
- /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗囷紝瑙勬牸锛�915X492
+ /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗�
/// </summary>
/// <param name="button"></param>
/// <param name="zbGateway"></param>
@@ -1355,31 +1650,35 @@
var localWay = this.GetLocalGateway(gwID);
if (localWay == null || localWay.getGwInfo == null)
{
- //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
- new System.Threading.Thread(async () =>
+ if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
{
- var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
- if (result != null)
+ button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.getGwInfo.LinuxImageType + ".png";
+ }
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(async () =>
{
- Application.RunOnMainThread(() =>
+ var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
+ if (result != null)
{
- if (button != null)
+ zbGateway.getGwInfo = result;
+ HdlThreadLogic.Current.RunMain(() =>
{
button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
- }
- });
- }
- })
- { IsBackground = true }.Start();
+ });
+ }
+ });
+ }
}
else
{
- button.UnSelectedImagePath = "Gateway/RealGateway" + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString() + ".png";
+ button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.getGwInfo.LinuxImageType + ".png";
}
}
/// <summary>
- /// 璁剧疆缃戝叧鍥炬爣锛岃鏍硷細110X110
+ /// 璁剧疆缃戝叧鍥炬爣
/// </summary>
/// <param name="button"></param>
/// <param name="zbGateway"></param>
@@ -1389,29 +1688,30 @@
var localWay = this.GetLocalGateway(gwID);
if (localWay == null || localWay.getGwInfo == null)
{
- //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
- new System.Threading.Thread(async () =>
+ if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
{
- var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
- if (result != null)
+ button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.getGwInfo.LinuxImageType + ".png";
+ }
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(async () =>
{
- Application.RunOnMainThread(() =>
+ var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
+ if (result != null)
{
- if (button != null)
+ zbGateway.getGwInfo = result;
+ HdlThreadLogic.Current.RunMain(() =>
{
button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
- button.SelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + "Selected.png";
- }
- });
- }
- })
- { IsBackground = true }.Start();
+ });
+ }
+ });
+ }
}
else
{
- string linType = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
- button.UnSelectedImagePath = "Gateway/GatewayIcon" + linType + ".png";
- button.SelectedImagePath = "Gateway/GatewayIcon" + linType + "Selected.png";
+ button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.getGwInfo.LinuxImageType + ".png";
}
}
@@ -1446,13 +1746,13 @@
#endregion
- #region 鈻� 娴嬭瘯缃戝叧___________________________
+ #region 鈻� 缃戝叧瀹氫綅___________________________
/// <summary>
- /// 鍙戦�佹祴璇曟寚浠ゅ埌璁惧(缃戝叧LED闂儊璇嗗埆)
+ /// 鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆)
/// </summary>
/// <param name="zbGateway"></param>
- public void SetTestCommand(ZbGateway zbGateway)
+ public void SetFixedPositionCommand(ZbGateway zbGateway)
{
ZbGateway realWay = null;
if (this.GetRealGateway(ref realWay, zbGateway) == false)
@@ -1575,7 +1875,7 @@
return;
}
- new System.Threading.Thread(() =>
+ HdlThreadLogic.Current.RunThread(() =>
{
var dicStatu = this.GetNowOnlineStatuBeforeCheck();
//绛変釜3绉掞紝鍑嗗涓�涓�
@@ -1604,8 +1904,7 @@
}
//灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
this.PushGatewayOnlineStatuToForm(dicStatu);
- })
- { IsBackground = true }.Start();
+ });
}
#endregion
@@ -1623,7 +1922,7 @@
return;
}
- new System.Threading.Thread(() =>
+ HdlThreadLogic.Current.RunThread(() =>
{
//鍏堣幏鍙栫幇鍦ㄥ叏閮ㄧ殑缃戝叧锛屽垵鏈熷�よ缃负涓嶅湪绾�
var dicStatu = this.GetNowOnlineStatuBeforeCheck();
@@ -1665,8 +1964,7 @@
string msg = Language.StringByID(R.MyInternationalizationString.uRemoteTimeOutAndNotGatewaiOnline);
//this.ShowTipMsg(msg);
}
- })
- { IsBackground = true }.Start();
+ });
}
#endregion
@@ -1791,7 +2089,7 @@
}
bool canBreak = false;
- new System.Threading.Thread(async () =>
+ HdlThreadLogic.Current.RunThread(async () =>
{
List<string> list = new List<string>() { "NotSetAgain" };
@@ -1817,8 +2115,7 @@
}
dicDbGateway = dic;
canBreak = true;
- })
- { IsBackground = true }.Start();
+ });
int count = 0;
while (canBreak == false)
@@ -1833,6 +2130,74 @@
}
return dicDbGateway;
+ }
+
+ #endregion
+
+ #region 鈻� 璁剧疆缃戝叧缁忕含搴____________________
+
+ /// <summary>
+ /// 璁剧疆缃戝叧缁忕含搴�
+ /// </summary>
+ /// <param name="gateway">缃戝叧瀵硅薄</param>
+ /// <param name="Longitude">缁忓害</param>
+ /// <param name="Latitude">缁村害</param>
+ /// <returns></returns>
+ public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, gateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ return false;
+ }
+
+ int result = -1;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
+ }
+ };
+ realWay.Actions += action;
+ //涓や綅灏忔暟
+ Longitude = Math.Round(Longitude, 2);
+ Latitude = Math.Round(Latitude, 2);
+
+ int intLongitude = Convert.ToInt32(Longitude.ToString().Replace(".", string.Empty));
+ int intLatitude = Convert.ToInt32(Latitude.ToString().Replace(".", string.Empty));
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
+ jObject.Add("Data", data);
+ realWay.Send("Logic/SetSite", jObject.ToString());
+
+ int TimeOut = 0;
+ while (result == -1 && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (result != 0)
+ {
+ //璁剧疆缃戝叧缁忕含搴﹀け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
+ if (result == -1)
+ {
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ }
+ this.ShowTipMsg(msg);
+ return false;
+ }
+
+ return true;
}
#endregion
@@ -1887,7 +2252,7 @@
/// </summary>
public void ResetComandToBindBackupGateway()
{
- new System.Threading.Thread(async () =>
+ HdlThreadLogic.Current.RunThread(async () =>
{
var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
if (fileData == null)
@@ -1936,8 +2301,7 @@
var byteData = System.Text.Encoding.UTF8.GetBytes(strData);
Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile, byteData);
}
- })
- { IsBackground = true }.Start();
+ });
}
#endregion
@@ -1992,6 +2356,7 @@
{
//鑾峰彇浠庝簯绔偅閲屽緱鏉ョ殑鍏ㄩ儴鏂囦欢
var listBackFile = HdlAutoBackupLogic.GetFileFromDirectory(UserCenterLogic.CombinePath(backDirectory));
+ listBackFile.Sort();
//娣诲姞闄勫姞鎯呮姤:杩樺師璁惧閰嶇疆
ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uRecoverDeviceSettion));
ProgressBar.SetMaxValue(listBackFile.Count);
@@ -2000,7 +2365,7 @@
var listSaveFile = new HashSet<string>();
foreach (string fileName in listBackFile)
{
- if (fileName.Length < 10 || fileName.StartsWith(Common.LocalDevice.deviceFirstName) == false)
+ if (fileName.Length < 10 || fileName.StartsWith("Device_") == false)
{
//涓嶆槸璁惧澶囦唤鏂囦欢
continue;
@@ -2060,7 +2425,7 @@
if (deleteFile.Length > 12)
{
string deviceFileName = deleteFile.Substring(5);
- if (deviceFileName.StartsWith(Common.LocalDevice.deviceFirstName) == false)
+ if (deviceFileName.StartsWith("Device_") == false)
{
//涓嶆槸璁惧鏂囦欢
continue;
@@ -2119,19 +2484,19 @@
else if (backType == GatewayBackupEnum.APir鐏厜閰嶇疆)
{
var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlPirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
+ result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
}
else if (backType == GatewayBackupEnum.A骞叉帴鐐归鑹茶皟鑺�)
{
var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.KeyColorData>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlPanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
+ result = await HdlDevicePanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
}
else if (backType == GatewayBackupEnum.A骞叉帴鐐逛寒搴﹁皟鑺�)
{
var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
int directionsLevel = Convert.ToInt32(recoverData["directionsLevel"]);
int backlightLevel = Convert.ToInt32(recoverData["backlightLevel"]);
- result = await HdlPanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
+ result = await HdlDevicePanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
}
else if (backType == GatewayBackupEnum.A骞叉帴鐐硅妭鑳芥ā寮�)
{
@@ -2139,12 +2504,71 @@
bool modeEnable = Convert.ToBoolean(recoverData["modeEnable"]);
int modeTime = Convert.ToInt32(recoverData["modeTime"]);
int level = Convert.ToInt32(recoverData["level"]);
- result = await HdlPanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
+ result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
}
else if (backType == GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�)
{
var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlPanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
+ result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
+ }
+ else if (backType == GatewayBackupEnum.A绐楀笜鏂瑰悜)
+ {
+ var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData));
+ result = await HdlDeviceCurtainLogic.Current.SetCurtainDirection((Rollershade)device, statu);
+ }
+ else if (backType == GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗)
+ {
+ var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData));
+ result = await HdlDeviceCurtainLogic.Current.SetHandPullControl((Rollershade)device, statu);
+ }
+ else if (backType == GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅)
+ {
+ var curtainDevice = (Rollershade)device;
+ var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
+ int upLimit = Convert.ToInt32(recoverData["upLimit"]);
+ int downLimit = Convert.ToInt32(recoverData["downLimit"]);
+ //鍏堥噸缃獥甯�
+ result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
+ if (result == false) { return -1; }
+ await Task.Delay(5000);
+ //閲嶇疆涓婇檺浣�
+ result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.UpLimit);
+ if (result == false) { return -1; }
+ //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
+ curtainDevice.WcdGoToTiltValue(upLimit);
+ await Task.Delay(3000);
+ //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
+ result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit, -1, -1);
+ if (result == false) { return -1; }
+
+ await Task.Delay(2000);
+ //閲嶇疆涓嬮檺浣�
+ result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.DownLimit);
+ if (result == false) { return -1; }
+ //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
+ curtainDevice.WcdGoToTiltValue(downLimit);
+ await Task.Delay(3000);
+ //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
+ result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit, -1, -1);
+ }
+ else if (backType == GatewayBackupEnum.A绌鸿皟鑷畾涔夋ā寮�)
+ {
+ var data = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
+ result = await HdlDeviceAirConditionerLogic.Current.SetAcModeSupport((AC)device, data);
+ if (result == true)
+ {
+ //杞崲涓轰簩杩涘埗
+ var value = Convert.ToString(data, 2).PadLeft(16, '0');
+ //杩欎簲涓缃槸鏀惧湪鍚庨潰鐨�
+ var fixValue = value.Substring(0, value.Length - 5);
+ var reportValue = value.Substring(fixValue.Length);
+ //鏇存敼缂撳瓨
+ for (int i = 0; i < reportValue.Length; i++)
+ {
+ ((AC)device).listSupportMode[i] = Convert.ToInt32(reportValue[i]);
+ }
+ device.ReSave();
+ }
}
return result == true ? 1 : -1;
}
--
Gitblit v1.8.0