From b9cb076fe6127160c96c35bf9c8cebcffe1d5ccd Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期五, 10 一月 2020 17:35:23 +0800 Subject: [PATCH] 2020.1.10 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 111 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 74 insertions(+), 37 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs index 0993102..5fafb97 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs @@ -142,8 +142,10 @@ List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId); foreach (var device in list) { - //鍒犻櫎璁惧锛屼笉鍒犻櫎鎴块棿淇℃伅 - Common.LocalDevice.Current.DeleteMemmoryDevice(device, false); + //鍒犻櫎涓�鑸澶� + Common.LocalDevice.Current.DeleteMemmoryDevice(device, true); + //鍒犻櫎Ota璁惧 + Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr); } //鍒犻櫎缃戝叧鏂囦欢 this.DeleteGatewayFile(gatewayId); @@ -178,10 +180,18 @@ /// <returns></returns> private ZbGateway GetGatewayFromFile(string file) { - byte[] filebyte = Global.ReadFileByHomeId(file); - string strvalue = System.Text.Encoding.UTF8.GetString(filebyte); - var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue); - return gateway; + try + { + byte[] filebyte = Global.ReadFileByHomeId(file); + string strvalue = System.Text.Encoding.UTF8.GetString(filebyte); + var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue); + return gateway; + } + catch (Exception ex) + { + HdlLogLogic.Current.WriteLog(ex); + return null; + } } #endregion @@ -212,11 +222,13 @@ } return false; } - if (result != 1) + if (result == -1) { return false; } - return true; + //璁剧疆缃戝叧鐨勭粡绾害 + bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude); + return falge; } /// <summary> @@ -415,6 +427,7 @@ /// 閲嶆柊缁戝畾缃戝叧(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�) /// </summary> /// <param name="zbGateway">缃戝叧</param> + /// <param name="btnMsg">娑堟伅鎺т欢</param> public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) { if (zbGateway == null) @@ -422,6 +435,12 @@ //閿欒:缃戝叧瀵硅薄涓㈠け string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); this.ShowTipMsg(msg); + return -1; + } + //璁剧疆缃戝叧鐨勭粡绾害 + bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude); + if (falge == false) + { return -1; } @@ -641,10 +660,10 @@ } //鑾峰彇鍏ㄩ儴璁惧 - bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay); + int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay); //鍏抽棴杩涘害鏉� ProgressBar.Close(); - if (result == false) + if (result == -1) { return false; } @@ -742,6 +761,8 @@ { //鍒犻櫎璁惧鏂囦欢 Common.LocalDevice.Current.DeleteMemmoryDevice(device, true); + //鍒犻櫎Ota璁惧 + Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr); } //濡傛灉鏄富缃戝叧 if (this.IsMainGateway(zbGatewayID) == 1) @@ -1832,7 +1853,15 @@ return; } var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 85 } }; - realWay.Send("GwLinuxLocate_Respon", jObject.ToString()); + if (this.IsGatewayExist(zbGateway) == true) + { + realWay.Send("GwLinuxLocate_Respon", jObject.ToString()); + } + else + { + //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺� + realWay.SendLocation("GwLinuxLocate_Respon", System.Text.Encoding.UTF8.GetBytes(jObject.ToString())); + } } #endregion @@ -2121,7 +2150,7 @@ bool canBreak = false; HdlThreadLogic.Current.RunThread(async () => { - List<string> list = new List<string>() { "NotSetAgain" }; + List<string> list = new List<string>() { "NotSetAgain", "NotCheck" }; //璁剧疆璁块棶鎺ュ彛鐨勫弬鏁� var pra = new GetGatewayPra(); @@ -2205,7 +2234,15 @@ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } }; var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } }; jObject.Add("Data", data); - realWay.Send("Logic/SetSite", jObject.ToString()); + if (this.IsGatewayExist(gateway) == true) + { + realWay.Send("Logic/SetSite", jObject.ToString()); + } + else + { + //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺� + realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString())); + } int TimeOut = 0; while (result == -1 && TimeOut < 30) @@ -2347,27 +2384,27 @@ /// <returns></returns> public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData) { - //ZbGateway realWay = null; - //if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false) - //{ - // //娌℃湁鎵惧埌鐪熷疄鐗╃悊缃戝叧 - // return false; - //} - //string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0'); - ////鍒涘缓鏂囦欢瀵硅薄 - //var result = await realWay.CreateFileAsync(fileName); - //if (result == null || result.Result != 0) - //{ - // return false; - //} - ////鍙戦�佹暟鎹祦 - //var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData); - //var byteData = System.Text.Encoding.UTF8.GetBytes(data); - //var result2 = await realWay.SendFileAsync(byteData); - //if (result2 == null || result2.Result != 0) - //{ - // return false; - //} + ZbGateway realWay = null; + if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false) + { + //娌℃湁鎵惧埌鐪熷疄鐗╃悊缃戝叧 + return false; + } + string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0'); + //鍒涘缓鏂囦欢瀵硅薄 + var result = await realWay.CreateFileAsync(fileName); + if (result == null || result.Result != 0) + { + return false; + } + //鍙戦�佹暟鎹祦 + var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData); + var byteData = System.Text.Encoding.UTF8.GetBytes(data); + var result2 = await realWay.SendFileAsync(byteData); + if (result2 == null || result2.Result != 0) + { + return false; + } return true; } @@ -2514,7 +2551,7 @@ else if (backType == GatewayBackupEnum.APir鐏厜閰嶇疆) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData)); - result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData); + result = await HdlDevicePirSensorLogic.Current.SetPirSensorSettion((IASZone)device, recoverData); } else if (backType == GatewayBackupEnum.A骞叉帴鐐归鑹茶皟鑺�) { @@ -2536,10 +2573,10 @@ int level = Convert.ToInt32(recoverData["level"]); result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level); } - else if (backType == GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�) + else if (backType == GatewayBackupEnum.A骞叉帴鐐圭涓夌骇鍒鏈夊睘鎬�) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData)); - result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData); + result = await HdlDevicePanelLogic.Current.EditorDryContactThirdFunction((Panel)device, recoverData); } else if (backType == GatewayBackupEnum.A绐楀笜鏂瑰悜) { -- Gitblit v1.8.0