From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期一, 11 一月 2021 16:11:20 +0800 Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs | 367 ++++++++++++++++++++++++++++++++------------------- 1 files changed, 230 insertions(+), 137 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs index 46bbfd3..2f278d8 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs @@ -25,8 +25,11 @@ curView = this; myLoading = new Loading (); + myLoading.TextColor = 0xFFA9A9A9; + myLoading.LodingBackgroundColor = SkinStyle.Current.MainColor; + //#if __IOS__ - myLoading.LodingBackgroundColor = 0x00999999; + //myLoading.LodingBackgroundColor = 0x20999999; //#else // myLoading.LodingBackgroundColor = SkinStyle.Current.ViewColor; //#endif @@ -36,6 +39,8 @@ myLoading.Hide (); btnCloseLoading.RemoveFromParent (); WirelessConfig (new byte [] { 1 });//close + //2020-07-02 鍏抽棴鑷姩鎼滅储绾跨▼ + StopSearchDeviceThead (); if (needRefresh) { needRefresh = false; SearchDeviceList (); @@ -50,6 +55,7 @@ curView = null; addedCommon.Clear (); BackgroundColor = SkinStyle.Current.MainColor; + //StopSearchDeviceThead (); base.RemoveFromParent (); } @@ -94,8 +100,8 @@ }; var btnSearch = new Button () { - Width = Application.GetRealWidth (75), - Height = Application.GetRealHeight (75), + Width = Application.GetMinRealAverage (75), + Height = Application.GetMinRealAverage (75), X = Application.GetRealWidth (520), Y = Application.GetRealHeight (10), UnSelectedImagePath = "Item/Refresh.png", @@ -146,11 +152,11 @@ { if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) { - Console.WriteLine ("Assign OnePortMqttFR锛孒DL MQTT"); + Utlis.WriteLine ("Assign OnePortMqttFR锛孒DL MQTT"); //RemoteSetting (); RemoteSettingWithHDLMQTT (); } else { - Console.WriteLine ("Assign OnePortWirelessFR"); + Utlis.WriteLine ("Assign OnePortWirelessFR"); RemoteSettingWithOldDevice (); //RemoteSettingWithMQTT (); } @@ -195,7 +201,7 @@ if (common.Type == DeviceType.MusicModel) continue; if (common.isMixBox) { - Console.WriteLine ("IsMixBox"); + Utlis.WriteLine ("IsMixBox"); continue; } countDevcie++; @@ -243,14 +249,17 @@ if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR || gatewayDeicve.Type == DeviceType.OnePortMqttFR) { 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 (); + new Alert ("", ErrorCode.SearchingForNewDevices, "OK").Show (); this.AddChidren (myLoading); //myLoading.Start ("鐐瑰嚮灞忓箷鍏抽棴閰嶉妯″紡"); - myLoading.Start ("Searching, Please touch the here to exit the searching mode."); + myLoading.Start (ErrorCode.SearchingExitTheSearchingMode); //myLoading.Start ("Waiting for new device, Please touch the here to exit the waiting mode."); this.AddChidren (btnCloseLoading); + + //2020-07-02 缃戝叧閰嶉妯″紡鏃讹紝寮�鍚嚜鍔ㄦ悳绱㈢嚎绋� + StartSearchDeviceThead (); } }); }); @@ -463,7 +472,7 @@ btnDelDevice.Parent.RemoveFromParent (); }); } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -501,7 +510,7 @@ // } // } // } catch (Exception ex) { - // Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message); + // Utlis.WriteLine ("Cinfig Read Device Loop Info " + ex.Message); // } //}); } @@ -523,7 +532,7 @@ //杩欓噷鎼滅储璁惧锛岀洿鍒板畬鎴愬氨閫�鍑� readDevice (); } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } Application.RunOnMainThread (action); }) { IsBackground = true }.Start (); @@ -568,7 +577,7 @@ ms.WriteByte (common.SubnetID); ms.WriteByte (common.DeviceID); } - Console.WriteLine ("鎼滅储闈炵綉鍏宠澶囷紝缃戠粶鍦板潃鏄�:" + CommonPage.EndPoint.ToString ()); + Utlis.WriteLine ("鎼滅储闈炵綉鍏宠澶囷紝缃戠粶鍦板潃鏄�:" + CommonPage.EndPoint.ToString ()); var control = new Control (); control.Send (new Target () { IPEndPoint = CommonPage.EndPoint, @@ -704,10 +713,10 @@ return; } } - BindGatewaysNew (); + GotoHomePage (); } } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); @@ -736,55 +745,25 @@ System.Threading.Tasks.Task.Run (() => { try { - //璇诲彇涓�绔彛浜ゆ崲鏈恒�佹棤绾跨綉鍏崇殑閰嶇疆淇℃伅 - gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, 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_UserName = "Admin"; - gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; - //gatewayDeicve.Remote_Password = "85521566"; - byte [] ggn = new byte [20]; - byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); - gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1); - Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length); - - byte [] gpn = new byte [20]; - byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName); - Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length); - - byte [] gun = new byte [8]; - byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName); - Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length); - - byte [] gpw = new byte [8]; - byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password); - Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length); - - - gatewayBytes [0] = TYPEHdlMQTT;//HDL MQTT - Array.Copy (ggn, 0, gatewayBytes, 1, 20); - Array.Copy (gpn, 0, gatewayBytes, 21, 20); - Array.Copy (gun, 0, gatewayBytes, 41, 8); - Array.Copy (gpw, 0, gatewayBytes, 49, 8); - //1.淇敼鐢ㄦ埛鍚嶄俊鎭� - Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes); - ////2.璇诲彇涓�娆$鐞嗕俊鎭� - //byte [] adminBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayAdminInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); - ////3.淇敼绠$悊淇℃伅 - //if (SetGateWayAdminInfo (adminBytes)) { - // //4.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣� - // GatewaySettingSucceeded (); + ////璇诲彇涓�绔彛浜ゆ崲鏈恒�佹棤绾跨綉鍏崇殑閰嶇疆淇℃伅 + //gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); + //if (gatewayBytes == null) { + // //璇诲彇涓�绔彛浜ゆ崲鏈恒�佹棤绾跨綉鍏崇殑閰嶇疆淇℃伅澶辫触 + // new Alert ("", "Read gateway configuration failed!", "Close").Show (); + // return; //} - - //2.淇敼绠$悊淇℃伅 - if (SetGateWayAdminInfo ()) { - //3.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣� - GatewaySettingSucceeded (); + + //1.淇敼鐢ㄦ埛鍚嶄俊鎭� 鍜屼慨鏀硅繛鎺ユā寮� + if (SetGateWayModelInfo()) { + //2.淇敼绠$悊淇℃伅 + if (SetGateWayAdminInfo ()) { + //3.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣� + GatewaySettingSucceeded (); + } } } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); Application.RunOnMainThread (() => { //淇敼缃戝叧杩炴帴妯″紡澶辫触 new Alert ("", "Failed to modify gateway connection mode!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); @@ -798,6 +777,40 @@ } }); //Room.InitAllRoom (); + } + + bool SetGateWayModelInfo () { + byte [] gatewayBytes = new byte [60]; + gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName; + gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName; + gatewayDeicve.Remote_UserName = "Admin"; + gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; + //gatewayDeicve.Remote_Password = "85521566"; + byte [] ggn = new byte [20]; + byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); + gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1); + Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length); + + byte [] gpn = new byte [20]; + byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName); + Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length); + + byte [] gun = new byte [8]; + byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName); + Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length); + + byte [] gpw = new byte [8]; + byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password); + Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length); + + + gatewayBytes [0] = TYPEHdlMQTT;//HDL MQTT + Array.Copy (ggn, 0, gatewayBytes, 1, 20); + Array.Copy (gpn, 0, gatewayBytes, 21, 20); + Array.Copy (gun, 0, gatewayBytes, 41, 8); + Array.Copy (gpw, 0, gatewayBytes, 49, 8); + byte [] backBytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes); + return CheckIsSuccessfulWithBytes (backBytes, "Failed to modify gateway connection mode."); } /// <summary> @@ -901,75 +914,73 @@ } } - BindGatewaysNew (); - + GotoHomePage (); } - /// <summary> - /// Gateway setting succeeded锛宒ata up.Please wait... - /// 缁戝畾Mac(鍗板害鐗�) - /// </summary> - void BindGatewaysNew () - { - Application.RunOnMainThread (() => { - MainPage.Loading.Start ("Gateway setting succeeded锛宒ata up. Please wait..."); - }); - IO.FileUtils.SaveEquipmentMessage (gatewayDeicve); - var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); + ///// <summary> + ///// Gateway setting succeeded锛宒ata up.Please wait... + ///// 缁戝畾Mac(鍗板害鐗�) + ///// </summary> + //void BindGatewaysNew () + //{ + // //Application.RunOnMainThread (() => { + // // MainPage.Loading.Start ("Gateway setting succeeded锛宒ata up. Please wait..."); + // //}); + // //IO.FileUtils.SaveEquipmentMessage (gatewayDeicve); + // //var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); - //璧版柊鏇存柊缁戝畾鎺ュ彛 - var mBindMacObj = new BindMacObj () { - LoginAccessToken = MainPage.LoginUser.LoginTokenString, - HomeId = UserConfig.Instance.CurrentRegion.Id, - MAC = gatewayMAC + // ////璧版柊鏇存柊缁戝畾鎺ュ彛 + // //var mBindMacObj = new BindMacObj () { + // // LoginAccessToken = MainPage.LoginUser.LoginTokenString, + // // HomeId = UserConfig.Instance.CurrentRegion.Id, + // // MAC = gatewayMAC - }; - - string urlHead = MainPage.RequestHttpsHost; - if (mBindMacObj.IsOtherAccountCtrl) { - urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; - mBindMacObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; - } + // //}; + + // //string urlHead = MainPage.RequestHttpsHost; + // //if (mBindMacObj.IsOtherAccountCtrl) { + // // urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + // // mBindMacObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + // //} - var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mBindMacObj); + // //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mBindMacObj); - //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); - var respone = MainPage.RequestHttps (API.BindMac, requestJson, urlHead); - if (respone.StateCode.ToUpper () != "SUCCESS") { - GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11 - Application.RunOnMainThread (() => { - new Alert ("", $"Failed to bind Mac address! {ErrorCode.Reason }{respone.StateCode}", Language.StringByID (R.MyInternationalizationString.Close)).Show (); - if (MainPage.LoginUser.AccountString == "464027401@qq.com") { - new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); - } - }); - return; - } - //GetNowHomeGateway (); - AddMacToUserConfig (gatewayMAC); + // ////var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); + // //var respone = MainPage.RequestHttps (API.BindMac, requestJson, urlHead); + // //if (respone.StateCode.ToUpper () != StateCode.SUCCESS) { + // // GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11 + // // Application.RunOnMainThread (() => { + // // new Alert ("", $"Failed to bind Mac address! {ErrorCode.Reason }{respone.StateCode}", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // // if (MainPage.LoginUser.AccountString == "464027401@qq.com") { + // // new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // // } + // // }); + // // return; + // //} + // //GetNowHomeGateway (); - } + // var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); + // AddMacToUserConfig (gatewayMAC); + + //} /// <summary> - /// 淇敼鍒囨崲鏈湴浣忓畢 缃戝叧 + /// 璺宠浆涓婚〉闈� /// </summary> - void AddMacToUserConfig (string gatewayMAC) + void GotoHomePage () { - - UserConfig.Instance.GatewayMAC = gatewayMAC; - UserConfig.Instance.SaveUserConfig (); MainPage.LoginUser.LastTime = DateTime.Now; Application.RunOnMainThread (() => { - bodyView.RemoveAll (); + this.RemoveFromParent (); + //MainPage.WiFiStatus = "CrabtreeAdd/WiFi.png"; UserMiddle.Init (true); + MainPage.WiFiStatus = "CrabtreeAdd/WiFi.png"; + UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; }); - } - - ///// <summary> @@ -1009,7 +1020,7 @@ // //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); // var respone = MainPage.RequestHttps (API.UpdateMac, requestJson, urlHead); - // if (respone.StateCode.ToUpper () != "SUCCESS") { + // if (respone.StateCode.ToUpper () != StateCode.SUCCESS) { // GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11 // Application.RunOnMainThread (() => { // new Alert ("", "Failed to update Mac address, gateway binding failed!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); @@ -1040,7 +1051,7 @@ // //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); // var respone = MainPage.RequestHttps (API.BindGatewayToHome, requestJson, urlHead); - // if (respone.StateCode.ToUpper () != "SUCCESS" && respone.StateCode != "BindGatewaysExists") { + // if (respone.StateCode.ToUpper () != StateCode.SUCCESS && respone.StateCode != "BindGatewaysExists") { // GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11 // Application.RunOnMainThread (() => { // new Alert ("", "Failed to bind Mac address, gateway binding failed!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); @@ -1057,35 +1068,117 @@ //} - /// <summary> - /// 缁戝畾澶辫触涔嬪悗锛屾煡璇㈠埛鏂颁竴娆″綋鍓嶄綇瀹� 缃戝叧鍒楄〃 - /// 2020-01-11 - /// </summary> - void GetNowHomeGatewayAfterBindMacFailed () - { + ///// <summary> + ///// 缁戝畾澶辫触涔嬪悗锛屾煡璇㈠埛鏂颁竴娆″綋鍓嶄綇瀹� 缃戝叧鍒楄〃 + ///// 2020-01-11 + ///// </summary> + //void GetNowHomeGatewayAfterBindMacFailed () + //{ - var requestObj3 = new GetSingleHomeGatewayPaggerObj (); - requestObj3.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString; - requestObj3.ReqDto.HomeId = UserConfig.Instance.CurrentRegion.Id; - requestObj3.ReqDto.PageSetting.Page = 1; - requestObj3.ReqDto.PageSetting.PageSize = 10; - string urlHead = MainPage.RequestHttpsHost; - if (requestObj3.IsOtherAccountCtrl) { - urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; - requestObj3.ReqDto.LoginAccessToken = UserConfig.Instance.MasterAccountToken; - } + // var requestObj3 = new GetSingleHomeGatewayPaggerObj (); + // requestObj3.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString; + // requestObj3.ReqDto.HomeId = UserConfig.Instance.CurrentRegion.Id; + // requestObj3.ReqDto.PageSetting.Page = 1; + // requestObj3.ReqDto.PageSetting.PageSize = 10; + // string urlHead = MainPage.RequestHttpsHost; + // if (requestObj3.IsOtherAccountCtrl) { + // urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + // requestObj3.ReqDto.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + // } - var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); - var revertObj3 = MainPage.RequestHttps (API.GetSingleHomeGatewayPagger, requestJson3, urlHead); - if (revertObj3.StateCode.ToUpper () == "SUCCESS") { - var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult> (revertObj3.ResponseData.ToString ()); - //2020-01-11 - UserConfig.Instance.SetNowHomeGateways (infoResult.PageData); + // var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); + // var revertObj3 = MainPage.RequestHttps (API.GetSingleHomeGatewayPagger, requestJson3, urlHead); + // if (revertObj3.StateCode.ToUpper () == StateCode.SUCCESS) { + // var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult> (revertObj3.ResponseData.ToString ()); + // //2020-01-11 + // UserConfig.Instance.SetNowHomeGateways (infoResult.PageData); - } + // } + + //} + + #region 2020-07-02 + /// <summary> + /// 瀹氭椂鎼滅储璁惧绾跨▼ + /// </summary> + Thread searchDeviceThead; + bool bStartSearch; + + /// <summary> + /// 2020-07-02 + /// 缃戝叧閰嶉妯″紡鏃讹紝寮�鍚嚜鍔ㄦ悳绱㈢嚎绋� + /// </summary> + void StartSearchDeviceThead () + { + StopSearchDeviceThead (); + CommonPage.LocalPhoneFindDevice = true; + CommonPage.FindGatewayChilren = true; + CommonPage.RandomHigh = (byte)new Random ().Next (255); + CommonPage.RandomLow = (byte)new Random ().Next (255); + + bStartSearch = true; + searchDeviceThead = new Thread ((obj) => { + while (bStartSearch) { + try { + //瀹氭椂4S + Thread.Sleep (4000); + + var ms = new System.IO.MemoryStream (); + ms.WriteByte (CommonPage.RandomHigh); + ms.WriteByte (CommonPage.RandomLow); + + var list = CommonPage.DeviceList; + int tempCount = list.Count; + string s = ";"; + for (int i = 0; i < list.Count; i++) { + Common common = list [i]; + if (common.SubnetID != gatewayDeicve.SubnetID) + continue; + 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); + } + Utlis.WriteLine ("SearchDeviceThead鎼滅储闈炵綉鍏宠澶囷紝缃戠粶鍦板潃鏄�:" + CommonPage.EndPoint.ToString ()); + var control = new Control (); + control.Send (new Target () { + IPEndPoint = CommonPage.EndPoint, + Command = Command.ReadDeviceModul, + SubnetID = gatewayDeicve.SubnetID, + DeviceID = 0xFF, + AddData = ms.ToArray () + }, SendCount.Zero, false); + + ms.Close (); + + } catch { + + } + } + }); + searchDeviceThead.Start (); + + + Utlis.WriteLine ("----StartSearchDeviceThead----"); + } + + /// <summary> + /// 鏆傚仠鎼滅储璁惧绾跨▼ + /// </summary> + void StopSearchDeviceThead () + { + CommonPage.LocalPhoneFindDevice = false; + CommonPage.FindGatewayChilren = false; + bStartSearch = false; + if (searchDeviceThead != null) + searchDeviceThead.Abort (); + + Utlis.WriteLine ("----StopSearchDeviceThead----"); } + #endregion ///// <summary> ///// 鏌ヨ褰撳墠浣忓畢 缃戝叧鍒楄〃 @@ -1108,7 +1201,7 @@ // //var requestObj3 = new GatewayByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.Id }; // var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); // var revertObj3 = MainPage.RequestHttps (API.GetSingleHomeGatewayPagger, requestJson3, urlHead); - // if (revertObj3.StateCode.ToUpper () == "SUCCESS") { + // if (revertObj3.StateCode.ToUpper () == StateCode.SUCCESS) { // var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult> (revertObj3.ResponseData.ToString ()); // var responseGatewayDataObj = infoResult.PageData; // if (responseGatewayDataObj != null && responseGatewayDataObj.Count > 0) { @@ -1211,7 +1304,7 @@ // } // } catch (Exception ex) { - // Console.WriteLine (ex.Message); + // Utlis.WriteLine (ex.Message); // Application.RunOnMainThread (() => { // new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); // }); @@ -1226,7 +1319,7 @@ // //Room.InitAllRoom (); //} - + ///// <summary> ///// 淇敼URL -- Gitblit v1.8.0