From 5da99fed2eb0d08b6338064da5f998891252c7b8 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期一, 18 五月 2020 16:39:59 +0800 Subject: [PATCH] 2020-05-18-2 --- ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs | 164 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 118 insertions(+), 46 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs index a32c91a..c399fee 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs @@ -60,6 +60,10 @@ /// 杩涘害鍊肩殑鏄剧ず鏂囨湰 /// </summary> private NormalViewControl btnProgressView = null; + /// <summary> + /// 缃戝叧鏄惁鍏佽鍏ョ綉鐨勬爣璇� + /// </summary> + private bool gatewayCanAddDevice = false; #endregion @@ -76,7 +80,7 @@ //璁剧疆鏍囬淇℃伅 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice)); - this.gatewayId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway); + this.gatewayId = GatewayResourse.NowSelectGatewayId; HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId); //鍒濆鍖栦腑閮ㄦ帶浠� @@ -92,11 +96,13 @@ this.ClearBodyFrame(); //鍥剧墖 - var btnPic = new PicViewControl(878, 478); - btnPic.Y = Application.GetMinRealAverage(251); - btnPic.Gravity = Gravity.CenterHorizontal; - btnPic.UnSelectedImagePath = "Instruct/DeviceSearch.png"; - bodyFrameLayout.AddChidren(btnPic); + var framePic = new FrameLayout(); + framePic.Width = this.GetPictrueRealSize(878); + framePic.Height = this.GetPictrueRealSize(478); + framePic.Y = Application.GetRealHeight(251); + framePic.Gravity = Gravity.CenterHorizontal; + framePic.BackgroundImagePath = "Instruct/DeviceSearch.png"; + bodyFrameLayout.AddChidren(framePic); //姝e湪鎼滅储璁惧锛岃绋嶅�欌�� var btnSearch = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false); @@ -138,25 +144,15 @@ btnProgressView.Text = "0%"; frameProgress.AddChidren(btnProgressView); - HdlThreadLogic.Current.RunThread(() => + if (this.realGateway != null) { - //钃濇墠鍒氳鏈夋椂鍊欑綉鍏充細鏀朵笉鍒板叆缃戠殑鍛戒护,鎵�浠ュ彂涓夋 - for (int i = 0; i < 3; i++) - { - if (this.Parent == null) - { - return; - } - //璁╃綉鍏冲厑璁稿叆缃� - this.realGateway.AddNewDeviceToGateway(180); - System.Threading.Thread.Sleep(1000); - } - }); - - //娣诲姞鐩戣璁惧鏂颁笂鎶ョ殑浜嬩欢 - this.realGateway.GwResDataAction += this.AdjustGatewayResultData; + //鍏佽璁惧鍏ョ綉 + this.StartDeviceCanAddToGateway(false); + //娣诲姞鐩戣璁惧鏂颁笂鎶ョ殑浜嬩欢 + this.realGateway.GwResDataAction += this.AdjustGatewayResultData; + } //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼ - this.StartConcetionAnimeteThread(); + this.StartConcetionAnimeteThread(framePic); } #endregion @@ -318,23 +314,23 @@ /// <summary> /// 寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼ /// </summary> - private void StartConcetionAnimeteThread() + private void StartConcetionAnimeteThread(FrameLayout framePic) { - int iconSize = Application.GetMinRealAverage(23); + int iconSize = this.GetPictrueRealSize(23); var listPoint = new List<int>(); for (int i = 0; i < 9; i++) { //X杞�+Index*(鍥炬爣澶у皬+闂磋窛) - listPoint.Add(Application.GetMinRealAverage(394) + i * (iconSize + Application.GetMinRealAverage(10))); + listPoint.Add(this.GetPictrueRealSize(300) + i * (iconSize + this.GetPictrueRealSize(10))); } var btnRound = new PicViewControl(iconSize, iconSize, false); btnRound.Radius = (uint)iconSize / 2; btnRound.BackgroundColor = UserCenterColor.Current.ConcetionRoundColor; btnRound.X = listPoint[0]; - btnRound.Y = Application.GetMinRealAverage(475); - bodyFrameLayout.AddChidren(btnRound); + btnRound.Y = this.GetPictrueRealSize(225); + framePic.AddChidren(btnRound); HdlThreadLogic.Current.RunThread(() => { @@ -343,12 +339,18 @@ while (this.Parent != null) { System.Threading.Thread.Sleep(500); - timeCount++; - if (timeCount >= 240) + + //缃戝叧鍏佽璁惧鍏ョ綉鍚庢墠寮�濮嬭鏃� + if (this.gatewayCanAddDevice == true) { - //120绉掑悗,鍐嶆鍙戦�佺綉鍏宠澶囧叆缃戝懡浠� - this.realGateway.AddNewDeviceToGateway(180); - timeCount = 0; + timeCount++; + if (timeCount >= 360) + { + this.gatewayCanAddDevice = false; + //鍐嶆鍙戦�佸厑璁歌澶囧叆缃� + this.StartDeviceCanAddToGateway(true); + timeCount = 0; + } } Application.RunOnMainThread(() => { @@ -378,15 +380,34 @@ /// <returns></returns> private int CheckIsDeviceComming(string topic, string resultData) { - if (topic == gatewayId + "/Device/DeviceAnnounce_Respon") + if (topic == gatewayId + "/Device/SearchNewDevice") + { + //缃戝叧鍥炲璁惧宸茬粡鍙互鍏ョ綉 + 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()); @@ -397,13 +418,13 @@ HdlLogLogic.Current.WriteLog(-1, resultData); return 2; } - this.topTimeOut = topMaxTime; //璁剧疆杩涘害鍊� 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()); @@ -414,13 +435,13 @@ HdlLogLogic.Current.WriteLog(-1, resultData); return 2; } - this.topTimeOut = topMaxTime; //璁剧疆杩涘害鍊� 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()); @@ -431,13 +452,13 @@ HdlLogLogic.Current.WriteLog(-1, resultData); return 2; } - this.topTimeOut = topMaxTime; //璁剧疆杩涘害鍊� 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()); @@ -448,7 +469,6 @@ HdlLogLogic.Current.WriteLog(-1, resultData); return 2; } - this.topTimeOut = topMaxTime; //璁剧疆杩涘害鍊� this.SetDeviceProgressValue(5); return 2; @@ -521,6 +541,33 @@ #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> @@ -528,15 +575,18 @@ /// </summary> public override void CloseFormBefore() { - //鍋滄鎺ユ敹 - this.realGateway.GwResDataAction -= this.AdjustGatewayResultData; - - HdlThreadLogic.Current.RunThread(() => + if (this.realGateway != null) { - System.Threading.Thread.Sleep(1200); - //鍏抽棴鍏ョ綉妯″紡 - this.realGateway.AddNewDeviceToGateway(0); - }); + //鍋滄鎺ユ敹 + this.realGateway.GwResDataAction -= this.AdjustGatewayResultData; + + HdlThreadLogic.Current.RunThread(() => + { + System.Threading.Thread.Sleep(1200); + //鍏抽棴鍏ョ綉妯″紡 + this.realGateway.AddNewDeviceToGateway(0); + }); + } base.CloseFormBefore(); } @@ -555,6 +605,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