JLChen
2021-01-05 f500e14c0a994487070380c50c85e0929cbc8e63
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
@@ -25,8 +25,11 @@
            curView = this;
            myLoading = new Loading ();
            myLoading.TextColor = 0xFFA9A9A9;
            myLoading.LodingBackgroundColor = SkinStyle.Current.MainColor;
            //#if __IOS__
            myLoading.LodingBackgroundColor = 0x00999999;
            //myLoading.LodingBackgroundColor = 0x20999999;
            //#else
            //            myLoading.LodingBackgroundColor = SkinStyle.Current.ViewColor;
            //#endif
@@ -36,6 +39,8 @@
                    myLoading.Hide ();
                    btnCloseLoading.RemoveFromParent ();
                    WirelessConfig (new byte [] { 1 });//close
                    //2020-07-02 关闭自动搜索线程
                    StopSearchDeviceThead ();
                    if (needRefresh) {
                        needRefresh = false;
                        SearchDeviceList ();
@@ -50,6 +55,7 @@
            curView = null;
            addedCommon.Clear ();
            BackgroundColor = SkinStyle.Current.MainColor;
            //StopSearchDeviceThead ();
            base.RemoveFromParent ();
        }
@@ -94,8 +100,8 @@
            };
            var btnSearch = new Button () {
                Width = Application.GetRealWidth (75),
                Height = Application.GetRealHeight (75),
                Width = Application.GetMinRealAverage (75),
                Height = Application.GetMinRealAverage (75),
                X = Application.GetRealWidth (520),
                Y = Application.GetRealHeight (10),
                UnSelectedImagePath = "Item/Refresh.png",
@@ -146,11 +152,11 @@
        {
            if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) {
                Console.WriteLine ("Assign OnePortMqttFR,HDL MQTT");
                Utlis.WriteLine ("Assign OnePortMqttFR,HDL MQTT");
                //RemoteSetting ();
                RemoteSettingWithHDLMQTT ();
            } else {
                Console.WriteLine ("Assign OnePortWirelessFR");
                Utlis.WriteLine ("Assign OnePortWirelessFR");
                RemoteSettingWithOldDevice ();
                //RemoteSettingWithMQTT ();
            }
@@ -195,7 +201,7 @@
                    if (common.Type == DeviceType.MusicModel)
                        continue;
                    if (common.isMixBox) {
                        Console.WriteLine ("IsMixBox");
                        Utlis.WriteLine ("IsMixBox");
                        continue;
                    }
                    countDevcie++;
@@ -243,14 +249,17 @@
                        if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR || gatewayDeicve.Type == DeviceType.OnePortMqttFR) {
                            Control.ControlBytesSend (Command.GotoConfigMode, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
                            //new Alert ("", "网关已经进入配频模式,请手动新设备进入配频模式。", "Close").Show ();
                            new Alert ("", "Searching for new devices, Please make sure all new devices are in configuration mode.", "OK").Show ();
                            new Alert ("", ErrorCode.SearchingForNewDevices, "OK").Show ();
                            this.AddChidren (myLoading);
                            //myLoading.Start ("点击屏幕关闭配频模式");
                            myLoading.Start ("Searching, Please touch the here to exit the searching mode.");
                            myLoading.Start (ErrorCode.SearchingExitTheSearchingMode);
                            //myLoading.Start ("Waiting for new device, Please touch the here to exit the waiting mode.");
                            
                            this.AddChidren (btnCloseLoading);
                            //2020-07-02 网关配频模式时,开启自动搜索线程
                            StartSearchDeviceThead ();
                        }
                    });
                });
@@ -463,7 +472,7 @@
                                            btnDelDevice.Parent.RemoveFromParent ();
                                        });
                                    } catch (Exception ex) {
                                        Console.WriteLine (ex.Message);
                                        Utlis.WriteLine (ex.Message);
                                    } finally {
                                        Application.RunOnMainThread (() => {
                                            MainPage.Loading.Hide ();
@@ -501,7 +510,7 @@
                        //            }
                        //        }
                        //    } catch (Exception ex) {
                        //        Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message);
                        //        Utlis.WriteLine ("Cinfig Read Device Loop Info " + ex.Message);
                        //    }
                        //});
                    }
@@ -523,7 +532,7 @@
                    //这里搜索设备,直到完成就退出
                    readDevice ();
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                    Utlis.WriteLine (ex.Message);
                }
                Application.RunOnMainThread (action);
            }) { IsBackground = true }.Start ();
@@ -568,7 +577,7 @@
                    ms.WriteByte (common.SubnetID);
                    ms.WriteByte (common.DeviceID);
                }
                Console.WriteLine ("搜索非网关设备,网络地址是:" + CommonPage.EndPoint.ToString ());
                Utlis.WriteLine ("搜索非网关设备,网络地址是:" + CommonPage.EndPoint.ToString ());
                var control = new Control ();
                control.Send (new Target () {
                    IPEndPoint = CommonPage.EndPoint,
@@ -707,7 +716,7 @@
                        BindGatewaysNew ();
                    }
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                    Utlis.WriteLine (ex.Message);
                    Application.RunOnMainThread (() => {
                        new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    });
@@ -754,7 +763,7 @@
                    }
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                    Utlis.WriteLine (ex.Message);
                    Application.RunOnMainThread (() => {
                        //修改网关连接模式失败
                        new Alert ("", "Failed to modify gateway connection mode!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
@@ -1096,6 +1105,88 @@
        }
        #region 2020-07-02
        /// <summary>
        /// 定时搜索设备线程
        /// </summary>
        Thread searchDeviceThead;
        bool bStartSearch;
        /// <summary>
        /// 2020-07-02
        /// 网关配频模式时,开启自动搜索线程
        /// </summary>
        void StartSearchDeviceThead ()
        {
            StopSearchDeviceThead ();
            CommonPage.LocalPhoneFindDevice = true;
            CommonPage.FindGatewayChilren = true;
            CommonPage.RandomHigh = (byte)new Random ().Next (255);
            CommonPage.RandomLow = (byte)new Random ().Next (255);
            bStartSearch = true;
            searchDeviceThead = new Thread ((obj) => {
                while (bStartSearch) {
                    try {
                        //定时4S
                        Thread.Sleep (4000);
                        var ms = new System.IO.MemoryStream ();
                        ms.WriteByte (CommonPage.RandomHigh);
                        ms.WriteByte (CommonPage.RandomLow);
                        var list = CommonPage.DeviceList;
                        int tempCount = list.Count;
                        string s = ";";
                        for (int i = 0; i < list.Count; i++) {
                            Common common = list [i];
                            if (common.SubnetID != gatewayDeicve.SubnetID)
                                continue;
                            if (s.Contains (";" + common.SubnetID.ToString () + ":" + common.DeviceID.ToString ()))
                                continue;
                            s += common.SubnetID.ToString () + ":" + common.DeviceID.ToString () + ";";
                            ms.WriteByte (common.SubnetID);
                            ms.WriteByte (common.DeviceID);
                        }
                        Utlis.WriteLine ("SearchDeviceThead搜索非网关设备,网络地址是:" + CommonPage.EndPoint.ToString ());
                        var control = new Control ();
                        control.Send (new Target () {
                            IPEndPoint = CommonPage.EndPoint,
                            Command = Command.ReadDeviceModul,
                            SubnetID = gatewayDeicve.SubnetID,
                            DeviceID = 0xFF,
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        ms.Close ();
                    } catch {
                    }
                }
            });
            searchDeviceThead.Start ();
            Utlis.WriteLine ("----StartSearchDeviceThead----");
        }
        /// <summary>
        /// 暂停搜索设备线程
        /// </summary>
        void StopSearchDeviceThead ()
        {
            CommonPage.LocalPhoneFindDevice = false;
            CommonPage.FindGatewayChilren = false;
            bStartSearch = false;
            if (searchDeviceThead != null)
                searchDeviceThead.Abort ();
            Utlis.WriteLine ("----StopSearchDeviceThead----");
        }
        #endregion
        ///// <summary>
        ///// 查询当前住宅 网关列表
        ///// </summary>
@@ -1220,7 +1311,7 @@
        //            }
        //        } catch (Exception ex) {
        //            Console.WriteLine (ex.Message);
        //            Utlis.WriteLine (ex.Message);
        //            Application.RunOnMainThread (() => {
        //                new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
        //            });
@@ -1235,7 +1326,7 @@
        //    //Room.InitAllRoom ();
        //}
        ///// <summary>
        ///// 修改URL