1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
@@ -32,6 +32,10 @@
                    myLoading.Hide ();
                    btnCloseLoading.RemoveFromParent ();
                    WirelessConfig (new byte [] { 1 });//close
                    if (CommonPage.newDevice > 0) {
                        CommonPage.newDevice = 0;
                        SearchDeviceList ();
                    }
                });
            };
@@ -143,18 +147,25 @@
            MainPage.Loading.Start ("Configuring device...");
            System.Threading.Tasks.Task.Run (() => {
                try {
                    var currentRegionIdBytes = new byte [] {
                        (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256),
                        (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256),
                        (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256),
                        (byte)(UserConfig.Instance.CurrentRegion.RegionID%256),
                    };
                    //2022-01-12 修复计算溢出问题
                    byte regionID1 = (byte)((UserConfig.Instance.CurrentRegion.RegionID >> (6 * 4)) & 0xFF);
                    byte regionID2 = (byte)((UserConfig.Instance.CurrentRegion.RegionID >> (4 * 4)) & 0xFF);
                    byte regionID3 = (byte)((UserConfig.Instance.CurrentRegion.RegionID >> (2 * 4)) & 0xFF);
                    byte regionID4 = (byte)((UserConfig.Instance.CurrentRegion.RegionID) & 0xFF);
                    var currentRegionIdBytes = new byte [] {regionID1, regionID2, regionID3, regionID4};
                    //var currentRegionIdBytes = new byte [] {
                    //    (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256),
                    //    (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256),
                    //    (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256),
                    //    (byte)(UserConfig.Instance.CurrentRegion.RegionID%256),
                    //};
                    gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
                    serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
                    gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName;
                    gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace(".","");//UserConfig.Instance.CurrentRegion.RegionName;
                    gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName;
                    gatewayDeicve.Remote_UserName = "Admin";
                    gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.MasterID;
                    byte [] ggn = new byte [20];
@@ -176,7 +187,7 @@
                    byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
                    gatewayBytes [0] = 2;//远程标示
                    Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
                    Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
@@ -265,7 +276,7 @@
                                Application.RunOnMainThread (() => {
                                    new Alert ("", "Communication abnormality,gateway failed to bind residence.Please try again.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                    if (MainPage.LoginUser.AccountString == "464027401@qq.com") {
                                        new Alert ("22:"+respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                        new Alert ("22:" + respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                    }
                                });
                            }
@@ -368,7 +379,8 @@
                    th = null;
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                        if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR) {
                        if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR && CommonPage.newDevice==0) {
                            CommonPage.newDevice = 0;
                            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 ();
@@ -612,23 +624,24 @@
                    //}
                    if (config) {
                        System.Threading.Tasks.Task.Factory.StartNew (() => {
                            try {
                                byte bigClass = common.BigClass;
                                byte minClass = common.MinClass;
                                int count = common.LoopCount;
                                for (int k = 1, j = 0; k <= count; k++) {
                                    if (Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID, new byte [] { bigClass, minClass, (byte)k }) == null) {
                                        j++;
                                        //连续两次读取不到数据则跳出该循环
                                        if (j == 2 && k == 2)
                                            break;
                                    }
                                }
                            } catch (Exception ex) {
                                Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message);
                            }
                        });
                        CommonPage.newDevice++;
                        //System.Threading.Tasks.Task.Factory.StartNew (() => {
                        //    try {
                        //        byte bigClass = common.BigClass;
                        //        byte minClass = common.MinClass;
                        //        int count = common.LoopCount;
                        //        for (int k = 1, j = 0; k <= count; k++) {
                        //            if (Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID, new byte [] { bigClass, minClass, (byte)k }) == null) {
                        //                j++;
                        //                //连续两次读取不到数据则跳出该循环
                        //                if (j == 2 && k == 2)
                        //                    break;
                        //            }
                        //        }
                        //    } catch (Exception ex) {
                        //        Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message);
                        //    }
                        //});
                    }
                    #endregion