CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2023-01-06 c05a93ddb0714a310a31574aaf030e677d9a07b6
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
@@ -316,7 +316,7 @@
                    //}
                    EventHandler<MouseEventArgs> eHandler = (sender, e) => {
                        Dialog dialog = new Dialog ();
                        Dialog dialog = new Dialog ();//修改设备备注
                        FrameLayout dialogBodyView = new FrameLayout () {
                            BackgroundColor = SkinStyle.Current.DialogColor,
                            Width = Application.GetRealWidth (494),
@@ -415,9 +415,16 @@
                            //CommonPage.UpdateRemark (common.SubnetID, common.DeviceID, btnChangeName.Text.Trim ());
                            byte [] updateBytes = new byte [20];
                            byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (btnChangeName.Text.Trim ());
                            string changeName = btnChangeName.Text.Trim ();
                            byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (changeName);
                            Array.Copy (remakeBytes, 0, updateBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
                            Control.ControlBytesSend (Command.Write_DeviceRamarkCMD, common.SubnetID, common.DeviceID, updateBytes);
                            //修改云端备注
                            new Thread (() => {
                                var http = new HttpServerRequest ();
                                http.EditDeviceName (common.DeviceID.ToString(), UserConfig.Instance.CurrentRegion.Id,changeName);
                            }) { IsBackground = true }.Start ();
                            btnDeviceName.Text = btnChangeName.Text;
@@ -761,6 +768,8 @@
                            if (SetGateWayMqttUrlAddress ()) {
                                //4.写配置成功后下一步操作
                                GatewaySettingSucceeded ();
                                //追加判断网关上网秘钥是否写入成功 2022年12月28日14:16:14
                                ApplyServerKey ();
                            }
                        }
                    }
@@ -961,6 +970,55 @@
            UploadOidAndSidList ();
        }
        /// <summary>
        /// 读取网关上网秘钥,如果秘钥有问题则重新写入
        /// </summary>
        void ApplyServerKey ()
        {
            if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) {
                var result = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { 0});
                if (result != null && result.Length > 1) {
                    if (result [1] == 0xF5) {
                        var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret (gatewayDeicve.MAC.Replace(".",""));
                        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);
                                    var result2 = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, usefullBytes);
                                    //byte [] restartArray = new byte [12];
                                    //string [] macArray = gatewayDeicve.MAC.Split (".");
                                    //for(int i = 0; i < macArray.Length; i++) {
                                    //    restartArray [i + 2] = Convert.ToByte (macArray [i], 16);
                                    //}
                                    //restartArray [10] = gatewayDeicve.SubnetID;
                                    //restartArray [11] = gatewayDeicve.DeviceID;
                                    //var result3 = Control.ControlBytesSendHasReturn (Command.RestartTheGateway, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, restartArray);
                                    //Application.RunOnMainThread (() => {
                                    //    new Alert ("", "The Internet access key was successfully written, and the gateway is being restarted!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                    //});
                                }
                            }
                        } else {
                            Application.RunOnMainThread (() => {
                                new Alert ("", "Failed to generate Internet access key!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            });
                        }
                    }
                } else {
                    //Application.RunOnMainThread (() => {
                    //    new Alert ("", "Failed to read the Internet access key!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    //});
                }
            }
        }
        /// <summary>
        /// 上传oid和sid列表
@@ -1414,4 +1472,10 @@
        //}
    }
    public class DeviceSecret
    {
        public string deviceSecret;
    }
}