From d53e6af2c5f17838fa79659614b15a2a1f383399 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 31 三月 2023 10:04:58 +0800
Subject: [PATCH] 1

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs |   68 +++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
index 570c048..3d0bab8 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
+++ b/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鍜宻id鍒楄〃
@@ -1414,4 +1472,10 @@
         //}
 
     }
+
+
+    public class DeviceSecret
+    {
+        public string deviceSecret;
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0