CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2023-01-06 c05a93ddb0714a310a31574aaf030e677d9a07b6
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -17,6 +17,21 @@
        {
            BackgroundColor = SkinStyle.Current.MainColor;
            inThisView = true;
            //var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret ("3782DACE9D900428");
            //if (secretKeyPack != null) {
            //    if (secretKeyPack.Code == StateCode.SUCCESS) {
            //        var pack = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceSecret> (secretKeyPack.Data.ToString ());
            //        if (pack != null) {
            //            byte [] usefullBytes = new byte [17];
            //            usefullBytes [0] = 1;
            //            byte [] ddd = System.Text.Encoding.ASCII.GetBytes (pack.deviceSecret);
            //            Array.Copy (ddd, 0, usefullBytes, 1, 16 < ddd.Length ? 16 : ddd.Length);
            //        }
            //    }
            //}
        }
        public override void RemoveFromParent ()
@@ -427,6 +442,8 @@
                        MainPage.Loading.Start ("Searching for gateway...");
                    });
                    #region 搜索设备
                    //是否需要加密检测、、为了适配多网关,搜索添加网关的时候需要关掉加密检测,然后同时发送密文,明文搜索网关 2023-01-06 16:49:30
                    CommonPage.needEncryptionDetection = false;
                    ////2020-01-14 默认明文开始搜索
                    UserConfig.Instance.IsLocalEncrypt = false;
                    UserConfig.Instance.EncryptedPasswordCorrect = true;
@@ -482,8 +499,57 @@
                            readCount = 3;
                        }
                    }
                    CommonPage.FindGateway = false;
                    //2023-01-06 16:33:09 增加同时发送密文搜索
                    CommonPage.needEncryptionDetection = true;
                    UserConfig.Instance.IsLocalEncrypt = true;
                    readCount = 3;
                    while (0 < readCount) {
                        readCount--;
                        System.IO.MemoryStream ms = new System.IO.MemoryStream ();
                        ms.WriteByte (CommonPage.RandomHigh);
                        ms.WriteByte (CommonPage.RandomLow);
                        List<Common> list = CommonPage.GateWayList;
                        int tempCount = list.Count;
                        string s = ";";
                        for (int i = 0; i < list.Count; i++) {
                            Common common = list [i];
                            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);
                        }
                        Control control = new Control ();
                        Utlis.WriteLine ("组播搜索网关,搜索地址是:" + CommonPage.EndPoint.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = CommonPage.EndPoint,
                            Command = Command.ReadGateway,
                            SubnetID = 0xFF,
                            DeviceID = 0xFF,
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        Utlis.WriteLine ("广播搜索网关,搜索地址是:" + new Net.NetWiFi ().BroadcastIpAddress.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = new System.Net.IPEndPoint (new Net.NetWiFi ().BroadcastIpAddress, 6000),
                            Command = Command.ReadGateway,
                            SubnetID = 0xFF,
                            DeviceID = 0xFF,
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        System.Threading.Thread.Sleep (800);
                        //如果数量不相等,就重置次数
                        if (tempCount != CommonPage.GateWayList.Count) {
                            readCount = 3;
                        }
                    }
                    CommonPage.FindGateway = false;
                    CommonPage.LocalPhoneFindDevice = false;
                    #endregion
                } catch (Exception ex) {
@@ -645,14 +711,14 @@
            //    //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
            //    Utlis.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            //}
            UserConfig.Instance.IsLocalEncrypt = false;
            var backBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
          
            if (backBytes == null) {
                Application.RunOnMainThread (() => {
                    new Alert ("", "No response from gateway. Please make sure the gateway is online and its firmware is up to date.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                });
                return false;
            }
            if (backBytes.Length >= 37) {