From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs |  384 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 205 insertions(+), 179 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
index c790418..ead44e9 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -15,7 +15,7 @@
         /// <summary>
         /// 鏂颁笂鎶ョ殑璁惧
         /// </summary>
-        private Dictionary<string, List<CommonDevice>> dicNewDevice = new Dictionary<string, List<CommonDevice>>();
+        private List<CommonDevice> listNewDevice = new List<CommonDevice>();
         /// <summary>
         /// 鏄剧ず璁惧绾跨▼鏄惁宸茬粡寮�鍚�
         /// </summary>
@@ -49,17 +49,13 @@
         /// </summary>
         private ZbGateway realGateway = null;
         /// <summary>
-        /// 杩涘害鏉�
+        /// 杩涘害鏉℃帶浠�
         /// </summary>
-        private FrameLayout btnProgressBar = null;
+        private ProgressRowBar btnProgressBar = null;
         /// <summary>
-        /// 杩涘害鍊兼樉绀烘枃鏈殑鏁翠綋
+        /// 缃戝叧鏄惁鍏佽鍏ョ綉鐨勬爣璇�
         /// </summary>
-        private FrameLayout frameProgress = null;
-        /// <summary>
-        /// 杩涘害鍊肩殑鏄剧ず鏂囨湰
-        /// </summary>
-        private NormalViewControl btnProgressView = null;
+        private bool gatewayCanAddDevice = false;
 
         #endregion
 
@@ -76,7 +72,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 +88,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);
@@ -107,56 +105,22 @@
             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);
-            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.BackgroundColor = 0xfffb744a;
-            btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2;
-            btnProRow.AddChidren(btnProgressBar);
+            this.btnProgressBar = new ProgressRowBar(559, 29);
+            btnProgressBar.ProgressBarGoback = false;
+            btnProgressBar.Gravity = Gravity.CenterHorizontal;
+            btnProgressBar.Y = Application.GetRealHeight(861);
+            bodyFrameLayout.AddChidren(btnProgressBar);
+            btnProgressBar.StartMode1(true);
 
-            //杩涘害鍊兼枃鏈�
-            this.frameProgress = new FrameLayout();
-            frameProgress.Width = Application.GetRealWidth(84);
-            frameProgress.Height = Application.GetRealHeight(60);
-            frameProgress.Y = Application.GetRealHeight(772);
-            bodyFrameLayout.AddChidren(frameProgress);
-            frameProgress.X = btnProRow.X + btnProgressBar.Right - frameProgress.Width / 2;
-            var btnProgressPic = new PicViewControl(84, 60);
-            btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png";
-            frameProgress.AddChidren(btnProgressPic);
-            this.btnProgressView = new NormalViewControl(84, 32, true);
-            btnProgressView.TextSize = 10;
-            btnProgressView.TextAlignment = TextAlignment.Center;
-            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
@@ -177,7 +141,7 @@
                 //鍋滄鎺ユ敹
                 this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
 
-                Application.RunOnMainThread(() =>
+                HdlThreadLogic.Current.RunMain(() =>
                 {
                     this.CloseForm();
                 });
@@ -190,56 +154,40 @@
                 this.StartTopicTimeOutThread();
                 return;
             }
-            //涓柇涓婚瓒呮椂绾跨▼
-            this.topTimeOut = -100;
 
-            lock (this.dicNewDevice)
+            var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+            CommonDevice.DeviceInfoData info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString());
+            if (info.DriveCode != 0)
             {
-                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 = HdlGatewayLogic.Current.GetGatewayId(this.realGateway);
-                //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
-                Common.LocalDevice.Current.SetDeviceInfoToMain(device, device);
-
-                //娣诲姞璁惧鐨勭紦瀛�
-                device.IsOnline = 1;
-                Common.LocalDevice.Current.AddDeviceToMemory(ref device);
- 
-                if (this.dicNewDevice.ContainsKey(device.DeviceAddr) == false)
-                {
-                    this.dicNewDevice[device.DeviceAddr] = new List<CommonDevice>();
-                }
-
-                //鍒锋柊瓒呮椂鏃堕棿
-                this.waitDeviceTimeOut = 20;
-
-                //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
-                HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
-
-                if ((device is OTADevice) == false)
-                {
-                    //涓嶉渶瑕�200绔偣鐨勯偅涓澶�
-                    this.dicNewDevice[device.DeviceAddr].Add(device);
-
-                    //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
-                    this.StartShowDeviceAddSuccessFormThread();
-                }
+                //涓嶉渶瑕佽櫄鎷熻澶�
+                return;
             }
+            //鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞�
+            var device = Common.LocalDevice.Current.NewDeviceObjectByDeviceId((DeviceType)jobject.Value<int>("Device_ID"), jobject.Value<int>("Epoint"));
+            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;
+
+            //涓嶉渶瑕�200绔偣鐨勯偅涓澶�  2020.01.13 鍙樻洿:ota涔熷姞杩涙潵
+            this.listNewDevice.Add(device);
+
+            //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
+            this.StartShowDeviceAddSuccessFormThread();
         }
 
         #endregion
@@ -270,21 +218,38 @@
                 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++)
                 {
-                    foreach (var listDevice in this.dicNewDevice.Values)
+                    var device = this.listNewDevice[i];
+                    if (device.DeviceAddr != this.listNewDevice[0].DeviceAddr)
                     {
-                        //閲嶆柊鍙樻洿UI
-                        foreach (var device in listDevice)
-                        {
-                            device.IconPath = string.Empty;
-                            device.ReSave();
-                        }
-                        //鏄剧ず璁惧淇℃伅鐢婚潰
-                        this.ShowDeviceAddSuccessForm(listDevice);
-                        break;
+                        continue;
                     }
+                    listDevice.Add(device);
+                    //閲嶆柊鍙樻洿UI
+                    if (device is OTADevice)
+                    {
+                        continue;
+                    }
+                    device.IconPath = string.Empty;
+                    device.ReSave();
+
+                    //璁剧疆璁惧鍔熻兘绫诲瀷 (涓嶈兘鍦ㄦ帴鏀跺洖璺殑鍦版柟鍐欏叆,涓嶇劧缃戝叧鍙兘浼氳秴璐熻嵎)
+                    Common.LocalDevice.Current.RefreshDeviceFunctionType(device, device, true);
+                    System.Threading.Thread.Sleep(200);
+                    //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
+                    if (HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device) == true)
+                    {
+                        System.Threading.Thread.Sleep(200);
+                    }
+                }
+
+                //鐩墠灏卞紕涓�涓�
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //鏄剧ず璁惧淇℃伅鐢婚潰
+                    this.ShowDeviceAddSuccessForm(listDevice);
                 });
             });
         }
@@ -319,23 +284,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(() =>
             {
@@ -344,14 +309,20 @@
                 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(() =>
+                    HdlThreadLogic.Current.RunMain(() =>
                     {
                         if (btnRound != null)
                         {
@@ -379,15 +350,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);
+                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());
@@ -398,13 +388,13 @@
                     HdlLogLogic.Current.WriteLog(-1, resultData);
                     return 2;
                 }
-                this.topTimeOut = topMaxTime;
                 //璁剧疆杩涘害鍊�
-                this.SetDeviceProgressValue(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());
@@ -415,13 +405,13 @@
                     HdlLogLogic.Current.WriteLog(-1, resultData);
                     return 2;
                 }
-                this.topTimeOut = topMaxTime;
                 //璁剧疆杩涘害鍊�
-                this.SetDeviceProgressValue(3);
+                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());
@@ -432,13 +422,13 @@
                     HdlLogLogic.Current.WriteLog(-1, resultData);
                     return 2;
                 }
-                this.topTimeOut = topMaxTime;
                 //璁剧疆杩涘害鍊�
-                this.SetDeviceProgressValue(4);
+                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());
@@ -449,43 +439,27 @@
                     HdlLogLogic.Current.WriteLog(-1, resultData);
                     return 2;
                 }
-                this.topTimeOut = topMaxTime;
                 //璁剧疆杩涘害鍊�
-                this.SetDeviceProgressValue(5);
+                this.btnProgressBar.SetValue(5, 6);
                 return 2;
             }
             else if (topic == gatewayId + "/DeviceInComingRespon")
             {
+                this.topTimeOut = topMaxTime;
+
+                //璁惧鍏ョ綉鏃�,鏈夋椂鍊欑綉鍏充細涓婃姤铏氭嫙璁惧
+                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 0;
+                }
                 //缃戝叧鏈�缁堜笂鎶ヨ妭鐐硅澶囦俊鎭�
-                this.SetDeviceProgressValue(6);
+                this.btnProgressBar.SetValue(6, 6);
                 return 1;
             }
             return 0;
-        }
-
-        /// <summary>
-        /// 璁剧疆璁惧鐨勮繘搴﹀��
-        /// </summary>
-        /// <param name="value"></param>
-        private void SetDeviceProgressValue(decimal value)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                //杩涘害鏉�
-                decimal result = value / 6;
-                int width = (int)(result * Application.GetRealWidth(559));
-                if (btnProgressBar.Width >= width)
-                {
-                    //鏈変簺璁惧浼氫笂鎶ヤ袱娆�,杩欓噷涓嶈兘璁╁畠鐨勮繘搴︽潯寰�鍥炶蛋
-                    return;
-                }
-                btnProgressBar.Width = width;
-
-                //鏂囨湰鏄剧ず
-                btnProgressView.Text = ((int)(result * 100)) + "%";
-                //鏂囨湰鏄剧ず鐨勯偅涓浘鐗囨绉诲姩
-                frameProgress.X = Application.GetRealWidth(262) + btnProgressBar.Right - frameProgress.Width / 2;
-            });
         }
 
         /// <summary>
@@ -506,15 +480,42 @@
                     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));
-                    Application.RunOnMainThread(() =>
+                    HdlThreadLogic.Current.RunMain(() =>
                     {
                         //鍏抽棴鐣岄潰
                         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);
                 }
             });
         }
@@ -528,15 +529,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 +559,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