From 1018d2975dc7facf691307f7504b90f84e07a54b Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 26 七月 2023 11:00:20 +0800 Subject: [PATCH] 迁移更新 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs | 146 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 126 insertions(+), 20 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs index 7bc371f..10cf576 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs @@ -19,7 +19,8 @@ private bool finish = false; #if DEBUG - private string SeverAddr = "https://test-gz.hdlcontrol.com"; + //private string SeverAddr = "https://test-gz.hdlcontrol.com"; + private string SeverAddr = "https://bahrain-gateway.hdlcontrol.com"; #else private string SeverAddr = "https://bahrain-gateway.hdlcontrol.com"; #endif @@ -188,16 +189,16 @@ - Account2New ("12345678"); - Home2New (); - //杩佺Щ浜戠鍏朵粬澶囦唤 - var moveCloudDataResult = MoveCloudBackup (); - Application.RunOnMainThread (() => { - btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}"; - btnTipMsg.TextColor = SkinStyle.Current.DelColor; - loading.Hide (); - return; - }); + //Account2New ("12345678"); + //Home2New (); + ////杩佺Щ浜戠鍏朵粬澶囦唤 + //var moveCloudDataResult = MoveCloudBackup (); + //Application.RunOnMainThread (() => { + // btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}"; + // btnTipMsg.TextColor = SkinStyle.Current.DelColor; + // loading.Hide (); + // return; + //}); #endif if (etPwd.Text.Trim() == "") { @@ -688,8 +689,6 @@ GatewayBase common = null; string gateWayString = ""; if (gateWayList.Count > 0) { - - foreach (var gatewayFileName in gateWayList) { var tempStrings = gatewayFileName.Split ('_'); if (tempStrings [1].ToString () == DeviceType.OnePortBus.ToString () || tempStrings [1].ToString () == DeviceType.RCU.ToString () || @@ -898,6 +897,8 @@ //鑾峰彇涓婄綉绉橀挜 var netKet = GetInternetAccessKey (common.MAC.Replace (".", "")); + + if (!string.IsNullOrEmpty (netKet)) { Application.RunOnMainThread (() => { btnTipMsg.Text = "The Internet access key was obtained successfully. It is being written."; @@ -928,6 +929,110 @@ return; }); } + +#if DEBUG + System.Threading.Thread.Sleep (5000); +#endif + + CommonPage.FindGateway = true; + try { + #region 鎼滅储璁惧 + CommonPage.LocalPhoneFindDevice = true; + CommonPage.RandomHigh = (byte)new Random ().Next (255); + CommonPage.RandomLow = (byte)new Random ().Next (255); + CommonPage.GateWayList.Clear (); + CommonPage.FindGateway = true; + //濡傛灉涓ゆ閮芥病鏈夋暟鎹弽棣堬紝灏变笉璇诲彇 + int readCount = 2; + 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 common2 = list [i]; + if (s.Contains (";" + common2.SubnetID.ToString () + ":" + common2.DeviceID.ToString ())) + continue; + s += common2.SubnetID.ToString () + ":" + common2.DeviceID.ToString () + ";"; + ms.WriteByte (common2.SubnetID); + ms.WriteByte (common2.DeviceID); + } + Control control = new Control (); + + Console.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); + + Console.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 = 2; + } + } + CommonPage.FindGateway = false; + + CommonPage.LocalPhoneFindDevice = false; + #endregion + } catch (Exception ex) { + Console.WriteLine (ex.ToString ()); + } finally { + if (CommonPage.GateWayList.Count > 0) { + foreach (var gateway1 in CommonPage.GateWayList) { + var bingResidenceIdBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { }); + if (bingResidenceIdBytes == null) { + continue; + } + int bingResideceId = 0; + for (int i = 0; i < bingResidenceIdBytes.Length; i++) { + bingResideceId += (int)(bingResidenceIdBytes [i] * Math.Pow (256, 3 - i)); + } + if (bingResideceId != UserConfig.Instance.CurrentRegion.RegionID && bingResideceId != 0) { + } else { + //鍐欏叆涓婄綉绉橀挜 + writeSecretKeyResult = WriteSecretKey (gateway1.SubnetID, gateway1.DeviceID, secretkeySendBytes); + if (writeSecretKeyResult) { + Application.RunOnMainThread (() => { + btnTipMsg.Text = "The Internet access key was written successfully."; + }); + } else { + Application.RunOnMainThread (() => { + btnTipMsg.Text = "Failed to write Internet secret key."; + btnTipMsg.TextColor = SkinStyle.Current.DelColor; + }); + } +#if DEBUG + System.Threading.Thread.Sleep (5000); +#endif + + } + } + } + } + + + + + + } else { Application.RunOnMainThread (() => { btnTipMsg.Text = "Failed to obtain the Internet secret key. Please try again."; @@ -937,7 +1042,6 @@ } //鍐欏叆mqtt鍩熷悕淇℃伅 SetGateWayMqttUrlAddress (common.SubnetID, common.DeviceID); - //杩佺Щ缃戝叧 var moveGatewayResult = Gateway2New (common.MAC.Replace (".", ""), newHomeId, common.SubnetID); @@ -956,12 +1060,14 @@ } //杩佺Щ浜戠鍏朵粬澶囦唤 var moveCloudDataResult = MoveCloudBackup (); - Application.RunOnMainThread (() => { - btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}"; - btnTipMsg.TextColor = SkinStyle.Current.DelColor; - loading.Hide (); - return; - }); + if (moveCloudDataResult != "0") { + Application.RunOnMainThread (() => { + btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}"; + btnTipMsg.TextColor = SkinStyle.Current.DelColor; + loading.Hide (); + return; + }); + } //鍒涘缓杩佺Щ澶囦唤鏂囦欢澶� var backId = moveFolder2New (newHomeId); //杩佺Щ澶囦唤鏂囦欢 -- Gitblit v1.8.0