From 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期二, 21 七月 2020 09:46:53 +0800 Subject: [PATCH] 请合并最新多功能面板代码 --- ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs | 570 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 570 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs new file mode 100755 index 0000000..d456bd7 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs @@ -0,0 +1,570 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.Device +{ + /// <summary> + /// 鎼滅储璁惧鐨勭晫闈� + /// </summary> + public class DeviceSearchForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鏂颁笂鎶ョ殑璁惧 + /// </summary> + private List<CommonDevice> listNewDevice = new List<CommonDevice>(); + /// <summary> + /// 鏄剧ず璁惧绾跨▼鏄惁宸茬粡寮�鍚� + /// </summary> + private bool isDeviceThreadStart = false; + /// <summary> + /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱櫨姣) + /// </summary> + private int waitDeviceTimeOut = 20; + /// <summary> + /// 涓婚瓒呮椂鐨勭嚎绋嬫槸鍚﹀紑鍚� + /// </summary> + private bool isTopicTimeOutThreadStart = false; + /// <summary> + /// 涓婚闂寸殑瓒呮椂鏃堕棿 -100:涓柇绾跨▼(鍗曚綅锛氱) + /// </summary> + private int topTimeOut = 120; + /// <summary> + /// 瓒呮椂鏈�澶ф椂闂� + /// </summary> + private int topMaxTime = 120; + /// <summary> + /// 鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨� + /// </summary> + private string targetFormId = string.Empty; + /// <summary> + /// 缃戝叧ID + /// </summary> + private string gatewayId = string.Empty; + /// <summary> + /// 鐪熷疄缃戝叧 + /// </summary> + private ZbGateway realGateway = null; + /// <summary> + /// 杩涘害鏉℃帶浠� + /// </summary> + private ProgressRowBar btnProgressBar = null; + /// <summary> + /// 缃戝叧鏄惁鍏佽鍏ョ綉鐨勬爣璇� + /// </summary> + private bool gatewayCanAddDevice = false; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <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 = GatewayResourse.NowSelectGatewayId; + HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId); + + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄦ帶浠� + /// </summary> + private void InitMiddleFrame() + { + //娓呯┖bodyFrame + this.ClearBodyFrame(); + + //鍥剧墖 + 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); + btnSearch.TextAlignment = TextAlignment.Center; + btnSearch.TextID = R.MyInternationalizationString.uDeviceSearching; + btnSearch.Y = Application.GetRealHeight(1037); + btnSearch.TextColor = UserCenterColor.Current.TextGrayColor3; + bodyFrameLayout.AddChidren(btnSearch); + + //杩涘害鏉� + this.btnProgressBar = new ProgressRowBar(559, 29); + btnProgressBar.ProgressBarGoback = false; + btnProgressBar.Gravity = Gravity.CenterHorizontal; + btnProgressBar.Y = Application.GetRealHeight(861); + bodyFrameLayout.AddChidren(btnProgressBar); + btnProgressBar.StartMode1(true); + + if (this.realGateway != null) + { + //鍏佽璁惧鍏ョ綉 + this.StartDeviceCanAddToGateway(false); + //娣诲姞鐩戣璁惧鏂颁笂鎶ョ殑浜嬩欢 + this.realGateway.GwResDataAction += this.AdjustGatewayResultData; + } + //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼ + this.StartConcetionAnimeteThread(framePic); + } + + #endregion + + #region 鈻� 鏂拌澶囧叆缃戞帴鏀禵____________________ + + /// <summary> + /// 澶勭悊缃戝叧涓婚涓婃姤 + /// </summary> + /// <param name="topic">涓婚</param> + /// <param name="resultData">涓婃姤鏁版嵁</param> + private void AdjustGatewayResultData(string topic, string resultData) + { + //妫�娴嬩富棰�(-1:寮傚父 0:涓嶆槸鐩稿叧鐨勪富棰� 1:璁惧鏈�鍚庣殑涓婚涓婃姤 2:璁惧鏈�缁堜笂鎶ヤ箣鍓嶇殑涓婚) + var result = this.CheckIsDeviceComming(topic, resultData); + if (result == -1) + { + //鍋滄鎺ユ敹 + this.realGateway.GwResDataAction -= this.AdjustGatewayResultData; + + Application.RunOnMainThread(() => + { + this.CloseForm(); + }); + return; + } + else if (result == 0) { return; } + else if (result == 2) + { + //寮�鍚富棰橀棿闅旇秴鏃剁嚎绋� + this.StartTopicTimeOutThread(); + return; + } + + var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData); + CommonDevice.DeviceInfoData info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString()); + if (info.DriveCode != 0) + { + //涓嶉渶瑕佽櫄鎷熻澶� + return; + } + //鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞� + var device = Common.LocalDevice.Current.NewDeviceObjectByDeviceId((DeviceType)jobject.Value<int>("Device_ID")); + if (device == null) + { + return; + } + device.DeviceInfo = info; + + //缁欐柊璁惧璁剧疆涓婚敭灞炴�� + Common.LocalDevice.Current.SetNewDeviceMainKeys(device, jobject); + device.CurrentGateWayId = this.realGateway.GwId; + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + Common.LocalDevice.Current.SetDeviceInfoToMain(device, device); + + //娣诲姞璁惧鐨勭紦瀛� + device.IsOnline = 1; + Common.LocalDevice.Current.AddDeviceToMemory(ref device); + + //鍒锋柊瓒呮椂鏃堕棿 + this.waitDeviceTimeOut = 20; + + //鑾峰彇璁惧鐨勫浐瀹氬睘鎬� + HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device); + + //涓嶉渶瑕�200绔偣鐨勯偅涓澶� 2020.01.13 鍙樻洿:ota涔熷姞杩涙潵 + this.listNewDevice.Add(device); + + //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�) + this.StartShowDeviceAddSuccessFormThread(); + } + + #endregion + + #region 鈻� 鏄剧ず璁惧淇℃伅鐢婚潰___________________ + + /// <summary> + /// 寮�鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼ + /// </summary> + private void StartShowDeviceAddSuccessFormThread() + { + if (this.isDeviceThreadStart == true) + { + //绾跨▼宸茬粡寮�鍚� + return; + } + this.isDeviceThreadStart = true; + + HdlThreadLogic.Current.RunThread(() => + { + while (this.waitDeviceTimeOut >= 0) + { + //绛夊緟涓嬩竴涓洖璺� + System.Threading.Thread.Sleep(100); + this.waitDeviceTimeOut--; + } + //鍋滄鎺ユ敹 + this.realGateway.GwResDataAction -= this.AdjustGatewayResultData; + System.Threading.Thread.Sleep(200); + + //鐩墠灏卞紕涓�涓� + Application.RunOnMainThread(() => + { + var listDevice = new List<CommonDevice>(); + for (int i = 0; i < this.listNewDevice.Count; i++) + { + var device = this.listNewDevice[i]; + if (device.DeviceAddr != this.listNewDevice[0].DeviceAddr) + { + continue; + } + listDevice.Add(device); + //閲嶆柊鍙樻洿UI + if (device is OTADevice) + { + continue; + } + device.IconPath = string.Empty; + device.ReSave(); + } + //鏄剧ず璁惧淇℃伅鐢婚潰 + this.ShowDeviceAddSuccessForm(listDevice); + }); + }); + } + + /// <summary> + /// 鏄剧ず璁惧淇℃伅鐢婚潰 + /// </summary> + /// <param name="listMacDevice">鏂拌澶囧垪琛�</param> + private void ShowDeviceAddSuccessForm(List<CommonDevice> listMacDevice) + { + if (this.Parent == null) + { + return; + } + //鍏抽棴鑷韩 + this.CloseForm(); + if (this.targetFormId != string.Empty) + { + //鍐嶅叧闂澶囧叆缃戞寚瀵肩晫闈� + this.CloseFormByFormName(this.targetFormId); + } + + //娣诲姞璁惧 + var form = new DeviceAddSuccessForm(); + form.AddForm(listMacDevice[0].DeviceAddr); + } + + #endregion + + #region 鈻� 鍋囨兂鍔ㄧ敾___________________________ + + /// <summary> + /// 寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼ + /// </summary> + private void StartConcetionAnimeteThread(FrameLayout framePic) + { + int iconSize = this.GetPictrueRealSize(23); + + var listPoint = new List<int>(); + for (int i = 0; i < 9; i++) + { + //X杞�+Index*(鍥炬爣澶у皬+闂磋窛) + 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 = this.GetPictrueRealSize(225); + framePic.AddChidren(btnRound); + + 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) + { + btnRound.X = listPoint[index]; + index++; + if (index == listPoint.Count) + { + index = 0; + } + } + }); + } + }); + } + + #endregion + + #region 鈻� 妫�娴嬩富棰榑__________________________ + + /// <summary> + /// 妫�娴嬩富棰�(-1:寮傚父 0:涓嶆槸鐩稿叧鐨勪富棰� 1:璁惧鏈�鍚庣殑涓婚涓婃姤 2:璁惧鏈�缁堜笂鎶ヤ箣鍓嶇殑涓婚) + /// </summary> + /// <param name="topic"></param> + /// <param name="resultData"></param> + /// <returns></returns> + private int CheckIsDeviceComming(string topic, string resultData) + { + 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.btnProgressBar.SetValue(1, 6); + 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()); + if (info.Result != 0) + { + //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃� + //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork)); + HdlLogLogic.Current.WriteLog(-1, resultData); + return 2; + } + //璁剧疆杩涘害鍊� + this.btnProgressBar.SetValue(2, 6); + 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()); + if (info.Result != 0) + { + //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃� + //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork)); + HdlLogLogic.Current.WriteLog(-1, resultData); + return 2; + } + //璁剧疆杩涘害鍊� + this.btnProgressBar.SetValue(3, 6); + 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); + return 2; + } + //璁剧疆杩涘害鍊� + this.btnProgressBar.SetValue(4, 6); + 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()); + if (info.Result != 0) + { + //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃� + //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork)); + HdlLogLogic.Current.WriteLog(-1, resultData); + return 2; + } + //璁剧疆杩涘害鍊� + this.btnProgressBar.SetValue(5, 6); + return 2; + } + else if (topic == gatewayId + "/DeviceInComingRespon") + { + this.topTimeOut = topMaxTime; + //缃戝叧鏈�缁堜笂鎶ヨ妭鐐硅澶囦俊鎭� + this.btnProgressBar.SetValue(6, 6); + return 1; + } + return 0; + } + + /// <summary> + /// 寮�鍚富棰橀棿鐨勮秴鏃剁嚎绋� + /// </summary> + private void StartTopicTimeOutThread() + { + if (this.isTopicTimeOutThreadStart == true) + { + return; + } + this.isTopicTimeOutThreadStart = true; + HdlThreadLogic.Current.RunThread(() => + { + while (this.Parent != null && this.topTimeOut >= 0) + { + //绛夊緟涓嬩竴涓富棰� + System.Threading.Thread.Sleep(1000); + this.topTimeOut--; + } + if (this.topTimeOut < 0) + { + //鍝嶅簲瓒呮椂,璇烽噸鏂板叆缃� + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork)); + Application.RunOnMainThread(() => + { + //鍏抽棴鐣岄潰 + this.CloseForm(); + }); + } + }); + } + + #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 CloseFormBefore() + { + if (this.realGateway != null) + { + //鍋滄鎺ユ敹 + this.realGateway.GwResDataAction -= this.AdjustGatewayResultData; + + HdlThreadLogic.Current.RunThread(() => + { + System.Threading.Thread.Sleep(1200); + //鍏抽棴鍏ョ綉妯″紡 + this.realGateway.AddNewDeviceToGateway(0); + }); + } + base.CloseFormBefore(); + } + + #endregion + + #region 鈻� 缁撴瀯浣揰____________________________ + + /// <summary> + /// 缃戝叧鎺ㄩ�佺殑璁惧缁撴灉淇℃伅 + /// </summary> + private class DeviceResultInfo + { + /// <summary> + /// 缁撴灉(0:鎴愬姛,浠ュ閮芥槸澶辫触) + /// </summary> + 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