From 98c998ca98ee014266f65a517d672df0cd97f244 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期三, 25 三月 2020 17:51:18 +0800
Subject: [PATCH] 2020-03-25-1
---
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs | 238 +++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 159 insertions(+), 79 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
index aca18a0..4102a31 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -21,9 +21,9 @@
/// </summary>
private bool isDeviceThreadStart = false;
/// <summary>
- /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱)
+ /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱櫨姣)
/// </summary>
- private int waitDeviceTimeOut = 3;
+ private int waitDeviceTimeOut = 20;
/// <summary>
/// 涓婚瓒呮椂鐨勭嚎绋嬫槸鍚﹀紑鍚�
/// </summary>
@@ -31,7 +31,11 @@
/// <summary>
/// 涓婚闂寸殑瓒呮椂鏃堕棿 -100:涓柇绾跨▼(鍗曚綅锛氱)
/// </summary>
- private int topTimeOut = 60;
+ private int topTimeOut = 120;
+ /// <summary>
+ /// 瓒呮椂鏈�澶ф椂闂�
+ /// </summary>
+ private int topMaxTime = 120;
/// <summary>
/// 鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨�
/// </summary>
@@ -40,6 +44,10 @@
/// 缃戝叧ID
/// </summary>
private string gatewayId = string.Empty;
+ /// <summary>
+ /// 鐪熷疄缃戝叧
+ /// </summary>
+ private ZbGateway realGateway = null;
/// <summary>
/// 杩涘害鏉�
/// </summary>
@@ -52,6 +60,10 @@
/// 杩涘害鍊肩殑鏄剧ず鏂囨湰
/// </summary>
private NormalViewControl btnProgressView = null;
+ /// <summary>
+ /// 缃戝叧鏄惁鍏佽鍏ョ綉鐨勬爣璇�
+ /// </summary>
+ private bool gatewayCanAddDevice = false;
#endregion
@@ -60,24 +72,25 @@
/// <summary>
/// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
/// </summary>
- /// <param name="i_formId">鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨�</param>
- public void ShowForm(string i_formId)
- {
- this.targetFormId = i_formId;
-
- //璁剧疆鏍囬淇℃伅
- base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice));
-
- this.gatewayId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
-
- //鍒濆鍖栦腑閮ㄦ帶浠�
- this.InitMiddleFrame();
- }
-
- /// <summary>
- /// 鍒濆鍖栦腑閮ㄦ帶浠�
- /// </summary>
- private void InitMiddleFrame()
+ /// <param name="i_formId">鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨�</param>
+ public void ShowForm(string i_formId)
+ {
+ this.targetFormId = i_formId;
+
+ //璁剧疆鏍囬淇℃伅
+ base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice));
+
+ this.gatewayId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
+ HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId);
+
+ //鍒濆鍖栦腑閮ㄦ帶浠�
+ this.InitMiddleFrame();
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栦腑閮ㄦ帶浠�
+ /// </summary>
+ private void InitMiddleFrame()
{
//娓呯┖bodyFrame
this.ClearBodyFrame();
@@ -98,18 +111,17 @@
bodyFrameLayout.AddChidren(btnSearch);
//杩涘害鏉�
- var btnProRow = new FrameLayout();
- btnProRow.Gravity = Gravity.CenterHorizontal;
- btnProRow.Y = Application.GetRealHeight(861);
- btnProRow.Width = Application.GetRealWidth(559);
- btnProRow.Height = Application.GetRealHeight(29);
+ var btnProRow = new FrameLayout();
+ btnProRow.Gravity = Gravity.CenterHorizontal;
+ btnProRow.Y = Application.GetRealHeight(861);
+ btnProRow.Width = Application.GetRealWidth(559);
+ btnProRow.Height = Application.GetRealHeight(29);
btnProRow.BackgroundColor = 0xffe6e6e6;
btnProRow.Radius = (uint)Application.GetRealHeight(29) / 2;
- bodyFrameLayout.AddChidren(btnProRow);
- this.btnProgressBar = new FrameLayout();
- btnProgressBar.Width = 0;
- btnProgressBar.Height = btnProRow.Height;
- btnProgressBar.Radius = btnProRow.Radius;
+ bodyFrameLayout.AddChidren(btnProRow);
+ this.btnProgressBar = new FrameLayout();
+ btnProgressBar.Width = 0;
+ btnProgressBar.Height = btnProRow.Height;
btnProgressBar.BackgroundColor = 0xfffb744a;
btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2;
btnProRow.AddChidren(btnProgressBar);
@@ -130,26 +142,13 @@
btnProgressView.Text = "0%";
frameProgress.AddChidren(btnProgressView);
- HdlThreadLogic.Current.RunThread(() =>
- {
- //钃濇墠鍒氳鏈夋椂鍊欑綉鍏充細鏀朵笉鍒板叆缃戠殑鍛戒护,鎵�浠ュ彂涓夋
- for (int i = 0; i < 3; i++)
- {
- if (this.Parent == null)
- {
- return;
- }
- //璁╃綉鍏冲厑璁稿叆缃�
- GatewayResourse.NowSelectGateway.AddNewDeviceToGateway(255);
- System.Threading.Thread.Sleep(1000);
- }
- });
+ //鍏佽璁惧鍏ョ綉
+ this.StartDeviceCanAddToGateway(false);
//娣诲姞鐩戣璁惧鏂颁笂鎶ョ殑浜嬩欢
- GatewayResourse.NowSelectGateway.GwResDataAction += this.AdjustGatewayResultData;
-
- //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼
- this.StartConcetionAnimeteThread();
+ this.realGateway.GwResDataAction += this.AdjustGatewayResultData;
+ //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼
+ this.StartConcetionAnimeteThread();
}
#endregion
@@ -168,7 +167,7 @@
if (result == -1)
{
//鍋滄鎺ユ敹
- GatewayResourse.NowSelectGateway.GwResDataAction -= this.AdjustGatewayResultData;
+ this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
Application.RunOnMainThread(() =>
{
@@ -183,8 +182,6 @@
this.StartTopicTimeOutThread();
return;
}
- //涓柇涓婚瓒呮椂绾跨▼
- this.topTimeOut = -100;
lock (this.dicNewDevice)
{
@@ -205,7 +202,7 @@
//缁欐柊璁惧璁剧疆涓婚敭灞炴��
Common.LocalDevice.Current.SetNewDeviceMainKeys(device, jobject);
- device.CurrentGateWayId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
+ device.CurrentGateWayId = HdlGatewayLogic.Current.GetGatewayId(this.realGateway);
//灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
Common.LocalDevice.Current.SetDeviceInfoToMain(device, device);
@@ -219,19 +216,16 @@
}
//鍒锋柊瓒呮椂鏃堕棿
- this.waitDeviceTimeOut = 3;
+ this.waitDeviceTimeOut = 20;
//鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
- if ((device is OTADevice) == false)
- {
- //涓嶉渶瑕�200绔偣鐨勯偅涓澶�
- this.dicNewDevice[device.DeviceAddr].Add(device);
+ //涓嶉渶瑕�200绔偣鐨勯偅涓澶� 2020.01.13 鍙樻洿:ota涔熷姞杩涙潵
+ this.dicNewDevice[device.DeviceAddr].Add(device);
- //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
- this.StartShowDeviceAddSuccessFormThread();
- }
+ //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
+ this.StartShowDeviceAddSuccessFormThread();
}
}
@@ -256,12 +250,12 @@
while (this.waitDeviceTimeOut >= 0)
{
//绛夊緟涓嬩竴涓洖璺�
- System.Threading.Thread.Sleep(1000);
+ System.Threading.Thread.Sleep(100);
this.waitDeviceTimeOut--;
}
//鍋滄鎺ユ敹
- GatewayResourse.NowSelectGateway.GwResDataAction -= this.AdjustGatewayResultData;
- System.Threading.Thread.Sleep(500);
+ this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
+ System.Threading.Thread.Sleep(200);
//鐩墠灏卞紕涓�涓�
Application.RunOnMainThread(() =>
@@ -271,6 +265,10 @@
//閲嶆柊鍙樻洿UI
foreach (var device in listDevice)
{
+ if (device is OTADevice)
+ {
+ continue;
+ }
device.IconPath = string.Empty;
device.ReSave();
}
@@ -333,9 +331,23 @@
HdlThreadLogic.Current.RunThread(() =>
{
int index = 1;
+ int timeCount = 0;
while (this.Parent != null)
{
System.Threading.Thread.Sleep(500);
+
+ //缃戝叧鍏佽璁惧鍏ョ綉鍚庢墠寮�濮嬭鏃�
+ if (this.gatewayCanAddDevice == true)
+ {
+ timeCount++;
+ if (timeCount >= 360)
+ {
+ this.gatewayCanAddDevice = false;
+ //鍐嶆鍙戦�佸厑璁歌澶囧叆缃�
+ this.StartDeviceCanAddToGateway(true);
+ timeCount = 0;
+ }
+ }
Application.RunOnMainThread(() =>
{
if (btnRound != null)
@@ -364,15 +376,34 @@
/// <returns></returns>
private int CheckIsDeviceComming(string topic, string resultData)
{
- if (topic == gatewayId + "/Device/DeviceAnnounce_Respon")
+ if (topic == gatewayId + "/Device/SearchNewDevice")
{
- this.topTimeOut = 60;
+ //缃戝叧鍥炲璁惧宸茬粡鍙互鍏ョ綉
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchNewDeviceResult>(jobject["Data"].ToString());
+ if (info.time > 0)
+ {
+ this.gatewayCanAddDevice = true;
+ }
+ return 0;
+ }
+ else if (topic == gatewayId + "/Device/DeviceAnnounce_Respon")
+ {
+ this.topTimeOut = topMaxTime;
+
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceAnnounceInfo>(jobject["Data"].ToString());
+ if (info.IsNew == 6 || info.IsNew == 7)
+ {
+ return 0;
+ }
//缃戝叧鍛婄煡瀹㈡埛绔湁璁惧澹版槑
this.SetDeviceProgressValue(1);
return 2;
}
else if (topic == gatewayId + "/Device/DeviceGetActiveEP_Respon")
{
+ this.topTimeOut = topMaxTime;
//缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囨椿鍔ㄧ鐐逛俊鎭�
var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -383,13 +414,13 @@
HdlLogLogic.Current.WriteLog(-1, resultData);
return 2;
}
- this.topTimeOut = 60;
//璁剧疆杩涘害鍊�
this.SetDeviceProgressValue(2);
return 2;
}
else if (topic == gatewayId + "/Device/DeviceGetActiveEPSimpleDesc_Respon")
{
+ this.topTimeOut = topMaxTime;
//缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囨墍鏈夋椿鍔ㄧ鐐圭畝鍗曟弿杩扮淇℃伅
var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -400,30 +431,30 @@
HdlLogLogic.Current.WriteLog(-1, resultData);
return 2;
}
- this.topTimeOut = 60;
//璁剧疆杩涘害鍊�
this.SetDeviceProgressValue(3);
return 2;
}
else if (topic == gatewayId + "/Device/DeviceGetDefaultBind_Respon")
{
+ this.topTimeOut = topMaxTime;
//缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囬粯璁ょ粦瀹氳〃淇℃伅
var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
if (info.Result != 0)
{
//鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃�
- this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
- //HdlLogLogic.Current.WriteLog(-1, resultData);
+ //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
+ HdlLogLogic.Current.WriteLog(-1, resultData);
return 2;
}
- this.topTimeOut = 60;
//璁剧疆杩涘害鍊�
this.SetDeviceProgressValue(4);
return 2;
}
else if (topic == gatewayId + "/Device/DeviceAutoBindZBCoord_Respon")
{
+ this.topTimeOut = topMaxTime;
//缃戝叧鍛婄煡瀹㈡埛绔澶囪嚜鍔ㄧ粦瀹氬崗璋冨櫒淇℃伅
var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -434,13 +465,13 @@
HdlLogLogic.Current.WriteLog(-1, resultData);
return 2;
}
- this.topTimeOut = 60;
//璁剧疆杩涘害鍊�
this.SetDeviceProgressValue(5);
return 2;
}
else if (topic == gatewayId + "/DeviceInComingRespon")
{
+ this.topTimeOut = topMaxTime;
//缃戝叧鏈�缁堜笂鎶ヨ妭鐐硅澶囦俊鎭�
this.SetDeviceProgressValue(6);
return 1;
@@ -491,7 +522,7 @@
System.Threading.Thread.Sleep(1000);
this.topTimeOut--;
}
- if (this.topTimeOut < 0 && this.topTimeOut >= -10)
+ if (this.topTimeOut < 0)
{
//鍝嶅簲瓒呮椂,璇烽噸鏂板叆缃�
this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork));
@@ -506,23 +537,50 @@
#endregion
+ #region 鈻� 鍏佽璁惧鍏ョ綉_______________________
+
+ /// <summary>
+ /// 鍏佽璁惧鍏ョ綉
+ /// </summary>
+ /// <param name="close"></param>
+ private void StartDeviceCanAddToGateway(bool close)
+ {
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ if (close == true)
+ {
+ //鍏抽棴鍏ョ綉妯″紡
+ this.realGateway.AddNewDeviceToGateway(0);
+ System.Threading.Thread.Sleep(2000);
+ }
+ while (gatewayCanAddDevice == false && this.Parent != null)
+ {
+ //璁╃綉鍏冲厑璁稿叆缃�
+ this.realGateway.AddNewDeviceToGateway(180);
+ System.Threading.Thread.Sleep(6000);
+ }
+ });
+ }
+
+ #endregion
+
#region 鈻� 鐢婚潰鍏抽棴___________________________
/// <summary>
/// 鐢婚潰鍏抽棴
- /// </summary>
- public override void CloseForm()
- {
- base.CloseForm();
+ /// </summary>
+ public override void CloseFormBefore()
+ {
//鍋滄鎺ユ敹
- GatewayResourse.NowSelectGateway.GwResDataAction -= this.AdjustGatewayResultData;
+ this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
HdlThreadLogic.Current.RunThread(() =>
{
System.Threading.Thread.Sleep(1200);
//鍏抽棴鍏ョ綉妯″紡
- GatewayResourse.NowSelectGateway.AddNewDeviceToGateway(0);
+ this.realGateway.AddNewDeviceToGateway(0);
});
+ base.CloseFormBefore();
}
#endregion
@@ -540,6 +598,28 @@
public int Result = -1;
}
+ /// <summary>
+ /// 缃戝叧鍛婄煡瀹㈡埛绔湁璁惧澹版槑
+ /// </summary>
+ private class DeviceAnnounceInfo
+ {
+ /// <summary>
+ /// 钃濇墠鍒氳 6鍜�7 杩欎袱涓槸璁惧閲嶅惎涓婃姤鐨勶紝鐩墠鏆傛椂涓嶈兘鏄剧ず鍒板叆缃戞楠ら偅閲岀殑
+ /// </summary>
+ public int IsNew = -1;
+ }
+
+ /// <summary>
+ /// 缃戝叧鍥炲鍏佽璁惧鍏ョ綉
+ /// </summary>
+ private class SearchNewDeviceResult
+ {
+ /// <summary>
+ /// 鍏佽璁惧鍏ョ綉鐨勬椂闂�
+ /// </summary>
+ public int time = 0;
+ }
+
#endregion
}
}
--
Gitblit v1.8.0