From f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期一, 30 十二月 2019 13:32:33 +0800 Subject: [PATCH] 2019-12-30-1 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 617 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 493 insertions(+), 124 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs index 97e642b..ea5c735 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs @@ -15,11 +15,11 @@ #region 鈻� 鍙橀噺澹版槑___________________________ /// <summary> - /// 澶囦唤涓氬姟鐨勯�昏緫 + /// 缃戝叧涓氬姟鐨勯�昏緫绫� /// </summary> private static HdlGatewayLogic m_Current = null; /// <summary> - /// 澶囦唤涓氬姟鐨勯�昏緫 + /// 缃戝叧涓氬姟鐨勯�昏緫绫� /// </summary> public static HdlGatewayLogic Current { @@ -117,10 +117,20 @@ { return; } + + List<string> listBackupGwId = new List<string>(); + var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile); + if (fileData != null) + { + //鏂板锛氳櫧鐒舵鐜囦綆锛屼絾鏄‘瀹炲彂鐢熶簡銆傚鏋滄湁缃戠粶鏃讹紝App閲嶆柊缁戝畾璁板綍鐨勭綉鍏冲け璐ョ殑璇� + //涓嶅簲璇ュ垹闄ゅ畠 + listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData)); + } + List<string> listDelete = new List<string>(); foreach (var gatewayId in this.dicGateway.Keys) { - if (result.ContainsKey(gatewayId) == false) + if (result.ContainsKey(gatewayId) == false && listBackupGwId.Contains(gatewayId) == false) { //鏈湴瀛樺湪浜戠涓嶅瓨鍦ㄧ殑缃戝叧锛屽垯鍒犻櫎 listDelete.Add(gatewayId); @@ -179,20 +189,34 @@ #region 鈻� 娣诲姞缃戝叧___________________________ /// <summary> - /// 娣诲姞鏂扮綉鍏�(浠呴檺杩藉姞鏂扮殑缃戝叧 1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�) + /// 娣诲姞鏂扮綉鍏�(浠呴檺杩藉姞鏂扮殑缃戝叧) /// </summary> /// <param name="zbGateway">缃戝叧</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> - public async Task<int> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) + public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) { //鎵ц娣诲姞缃戝叧鍒板唴瀛� var result = await this.DoAddGatewayToMemory(zbGateway, mode); + //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰 + if (result == 0) + { + if (mode == ShowErrorMode.YES) + { + //缃戝叧缁戝畾鍦ㄥ綋鍓嶈处鍙蜂笅鐨勫叾浠栦綇瀹呴噷\r\n璇疯В闄ょ粦瀹氬悗鍐嶈瘯 + string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg); + if (msg.Contains("{0}") == true) + { + msg = string.Format(msg, "\r\n"); + } + this.ShowTipMsg(msg); + } + return false; + } if (result != 1) { - return result; + return false; } - - return 1; + return true; } /// <summary> @@ -693,7 +717,7 @@ //绉婚櫎 ZbGateway.GateWayList.RemoveAll((obj) => this.GetGatewayId(obj) == zbGatewayID); //鏂紑mqtt杩炴帴 - realWay.DisConnect("GD"); + realWay.DisConnectLocalMqttClient("GD"); return true; } @@ -1013,6 +1037,268 @@ #endregion + #region 鈻� 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬揰________________ + + /// <summary> + /// 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬�(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒) + /// </summary> + /// <param name="zbGateway"></param> + /// <returns></returns> + public int GetGatewayChannelId(ZbGateway zbGateway) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, zbGateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); + return -1; + } + int data = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + data = Convert.ToInt32(jobject["Data"]["Channel"].ToString()); + } + }; + realWay.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 8 } }; + realWay.Send("ZbGw/GetChannel", jObject.ToString()); + + int TimeOut = 0; + while (data == -1 && TimeOut < 30) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (data == -1) + { + //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail); + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + this.ShowTipMsg(msg); + } + + return data; + } + + #endregion + + #region 鈻� 鑾峰彇鍗忚皟鍣∕AC______________________ + + /// <summary> + /// 鑾峰彇鍗忚皟鍣∕AC鍦板潃(浼氭湁绛夊緟寤惰繜,杩斿洖null浠h〃閿欒) + /// </summary> + /// <param name="zbGateway"></param> + /// <returns></returns> + public string GetGatewayCoordinatorMac(ZbGateway zbGateway) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, zbGateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); + return null; + } + string data = null; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + data = jobject["Data"]["MacAddr"].ToString(); + } + }; + realWay.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 13 } }; + realWay.Send("ZbGw/GetMac", jObject.ToString()); + + int TimeOut = 0; + while (data == null && TimeOut < 30) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (data == null) + { + //鑾峰彇鍗忚皟鍣∕ac澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail); + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + this.ShowTipMsg(msg); + } + + return data; + } + + #endregion + + #region 鈻� 鑾峰彇鍗忚皟鍣≒anID____________________ + + /// <summary> + /// 鑾峰彇鍗忚皟鍣≒anID(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒) + /// </summary> + /// <param name="zbGateway"></param> + /// <returns></returns> + public int GetGatewayPanId(ZbGateway zbGateway) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, zbGateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); + return -1; + } + int panId = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "ZbGw/GetPanId_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString()); + } + }; + realWay.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 12 } }; + realWay.Send("ZbGw/GetPanId", jObject.ToString()); + + int TimeOut = 0; + while (panId == -1 && TimeOut < 30) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (panId == -1) + { + //鑾峰彇鍗忚皟鍣≒anID澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail); + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + this.ShowTipMsg(msg); + } + + return panId; + } + + #endregion + + #region 鈻� 缃戝叧鑷姩澶囦唤璁剧疆___________________ + + /// <summary> + /// 鑾峰彇缃戝叧鑷姩澶囦唤璁剧疆(-1:寮傚父 0:鍏抽棴 1:鎵撳紑) + /// </summary> + /// <param name="zbGateway"></param> + /// <returns></returns> + public int GetGatewayAutoBackupStatu(ZbGateway zbGateway) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, zbGateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); + return -1; + } + int statu = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/GatewayAutoBackup_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + statu = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString()); + } + }; + realWay.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", 1 } }; + jObject.Add("Data", data); + realWay.Send("GatewayAutoBackup", jObject.ToString()); + + int TimeOut = 0; + while (statu == -1 && TimeOut < 60) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (statu == -1) + { + //鑾峰彇缃戝叧鑷姩澶囦唤璁剧疆澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayAutoBackupStatuFail); + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + this.ShowTipMsg(msg); + } + + return statu; + } + + /// <summary> + /// 璁剧疆缃戝叧鑷姩澶囦唤璁剧疆 + /// </summary> + /// <param name="zbGateway"></param> + /// <param name="statu"></param> + /// <returns></returns> + public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, zbGateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); + return false; + } + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/GatewayAutoBackup_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString()); + } + }; + realWay.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", statu == true ? 2 : 3 } }; + jObject.Add("Data", data); + realWay.Send("GatewayAutoBackup", jObject.ToString()); + + int TimeOut = 0; + while (result == -1 && TimeOut < 60) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (result == -1) + { + //璁剧疆缃戝叧鑷姩澶囦唤澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewayAutoBackupStatuFail); + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + this.ShowTipMsg(msg); + return false; + } + + return true; + } + + #endregion + #region 鈻� 鑾峰彇缃戝叧GwInfo閲岄潰鐨勫睘鎬__________ /// <summary> @@ -1044,44 +1330,6 @@ { //鑾峰彇鏈湴鐨勫睘鎬� objValue = localWay.getGwInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGwInfo, null); - } - - if (objValue == null) - { - return defult; - } - return objValue; - } - - /// <summary> - /// 鑾峰彇缃戝叧GatewayBaseInfo閲岄潰鐨勫睘鎬� - /// </summary> - /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <param name="attributeName">GatewayBaseInfo閲岄潰灞炴�х殑鍚嶅瓧</param> - /// <param name="defult">濡傛灉鑾峰彇涓嶅埌鏃讹紝璁剧疆鐨勯粯璁ゅ��</param> - /// <returns></returns> - public object GetGatewayBaseInfoAttribute(ZbGateway zbGateway, string attributeName, string defult = "") - { - string gwID = this.GetGatewayId(zbGateway); - var localWay = this.GetLocalGateway(gwID); - - object objValue = null; - if (localWay == null || localWay.getGatewayBaseInfo == null) - { - //鏈湴娌℃湁璁板綍鏈夎繖涓笢瑗�,鍒欑洿鎺ヨ繑鍥炲弬鏁扮殑鏁版嵁 - if (zbGateway.getGatewayBaseInfo != null) - { - objValue = zbGateway.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, zbGateway.getGatewayBaseInfo, null); - } - else - { - return defult; - } - } - else - { - //鑾峰彇鏈湴灞炴�� - objValue = localWay.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGatewayBaseInfo, null); } if (objValue == null) @@ -1318,7 +1566,7 @@ //鏈�鍚庡啀鏂紑mqtt杩炴帴 for (int i = 0; i < list.Count; i++) { - list[i].DisConnect("G"); + list[i].DisConnectLocalMqttClient("G"); } list.Clear(); } @@ -1595,50 +1843,6 @@ realWay.Send("GwLinuxLocate_Respon", jObject.ToString()); } - #endregion - - #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// 寮瑰嚭缃戝叧涓嶅湪绾跨殑 - /// </summary> - private void ShowGatewayNotOnlineMsg() - { - Application.RunOnMainThread(() => - { - //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁� - string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork); - var control = new ShowMsgControl(ShowMsgType.Tip, msg); - control.Show(); - }); - } - - /// <summary> - /// 鏄剧ず閿欒淇℃伅绐楀彛 - /// </summary> - /// <param name="msg"></param> - private void ShowErrorMsg(string msg) - { - Application.RunOnMainThread(() => - { - var contr = new ShowMsgControl(ShowMsgType.Error, msg); - contr.Show(); - }); - } - - /// <summary> - /// 鏄剧ずTip淇℃伅绐楀彛 - /// </summary> - /// <param name="msg"></param> - private void ShowTipMsg(string msg) - { - Application.RunOnMainThread(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, msg); - contr.Show(); - }); - } - #endregion #region 鈻� 缃戝叧鐩戣___________________________ @@ -1842,17 +2046,19 @@ { return; } - //鑾峰彇褰撳墠鎺ュ彈鍦ㄧ嚎鐘舵�佹帹閫佺殑鐣岄潰 - var listForm = new List<CommonFormBase>(); - listForm.AddRange(UserCenterResourse.listGatewayOnlinePushForm); - if (listForm.Count > 0) + //淇濆瓨褰撳墠婵�娲荤殑鐣岄潰ID + var listId = new List<string>(); + listId.AddRange(UserCenterResourse.listActionFormId); + for (int i = 0; i < listId.Count; i++) { - for (int i = 0; i < listChange.Count; i++) + if (UserCenterResourse.DicActionForm.ContainsKey(listId[i]) == false) { - foreach (var form in listForm) - { - form?.GatewayOnlinePush(listChange[i], listChangeStatu[i]); - } + continue; + } + //缃戝叧鍦ㄧ嚎鎺ㄩ�� + for (int j = 0; j < listChange.Count; j++) + { + UserCenterResourse.DicActionForm[listId[i]]?.GatewayOnlinePush(listChange[j], listChangeStatu[j]); } } } @@ -1962,6 +2168,74 @@ } return dicDbGateway; + } + + #endregion + + #region 鈻� 璁剧疆缃戝叧缁忕含搴____________________ + + /// <summary> + /// 璁剧疆缃戝叧缁忕含搴� + /// </summary> + /// <param name="gateway">缃戝叧瀵硅薄</param> + /// <param name="Longitude">缁忓害</param> + /// <param name="Latitude">缁村害</param> + /// <returns></returns> + public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude) + { + ZbGateway realWay = null; + if (this.GetRealGateway(ref realWay, gateway) == false) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); + this.ShowTipMsg(msg); + return false; + } + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "Logic/SetSite_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Result"].ToString()); + } + }; + realWay.Actions += action; + //涓や綅灏忔暟 + Longitude = Math.Round(Longitude, 2); + Latitude = Math.Round(Latitude, 2); + + int intLongitude = Convert.ToInt32(Longitude.ToString().Replace(".", string.Empty)); + int intLatitude = Convert.ToInt32(Latitude.ToString().Replace(".", string.Empty)); + + 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()); + + int TimeOut = 0; + while (result == -1 && TimeOut < 30) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= action; + if (result != 0) + { + //璁剧疆缃戝叧缁忕含搴﹀け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail); + if (result == -1) + { + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + } + this.ShowTipMsg(msg); + return false; + } + + return true; } #endregion @@ -2081,27 +2355,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; } @@ -2120,6 +2394,7 @@ { //鑾峰彇浠庝簯绔偅閲屽緱鏉ョ殑鍏ㄩ儴鏂囦欢 var listBackFile = HdlAutoBackupLogic.GetFileFromDirectory(UserCenterLogic.CombinePath(backDirectory)); + listBackFile.Sort(); //娣诲姞闄勫姞鎯呮姤:杩樺師璁惧閰嶇疆 ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uRecoverDeviceSettion)); ProgressBar.SetMaxValue(listBackFile.Count); @@ -2128,7 +2403,7 @@ var listSaveFile = new HashSet<string>(); foreach (string fileName in listBackFile) { - if (fileName.Length < 10 || fileName.StartsWith(Common.LocalDevice.deviceFirstName) == false) + if (fileName.Length < 10 || fileName.StartsWith("Device_") == false) { //涓嶆槸璁惧澶囦唤鏂囦欢 continue; @@ -2188,7 +2463,7 @@ if (deleteFile.Length > 12) { string deviceFileName = deleteFile.Substring(5); - if (deviceFileName.StartsWith(Common.LocalDevice.deviceFirstName) == false) + if (deviceFileName.StartsWith("Device_") == false) { //涓嶆槸璁惧鏂囦欢 continue; @@ -2276,16 +2551,110 @@ } else if (backType == GatewayBackupEnum.A绐楀笜鏂瑰悜) { + var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData)); + result = await HdlDeviceCurtainLogic.Current.SetCurtainDirection((Rollershade)device, statu); } else if (backType == GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗) { + var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData)); + result = await HdlDeviceCurtainLogic.Current.SetHandPullControl((Rollershade)device, statu); } else if (backType == GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅) { + var curtainDevice = (Rollershade)device; + var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData)); + int upLimit = Convert.ToInt32(recoverData["upLimit"]); + int downLimit = Convert.ToInt32(recoverData["downLimit"]); + //鍏堥噸缃獥甯� + result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice); + if (result == false) { return -1; } + await Task.Delay(5000); + //閲嶇疆涓婇檺浣� + result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.UpLimit); + if (result == false) { return -1; } + //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣� + curtainDevice.WcdGoToTiltValue(upLimit); + await Task.Delay(3000); + //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣 + result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit, -1, -1); + if (result == false) { return -1; } + + await Task.Delay(2000); + //閲嶇疆涓嬮檺浣� + result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.DownLimit); + if (result == false) { return -1; } + //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣� + curtainDevice.WcdGoToTiltValue(downLimit); + await Task.Delay(3000); + //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣 + result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit, -1, -1); + } + else if (backType == GatewayBackupEnum.A绌鸿皟鑷畾涔夋ā寮�) + { + var data = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData)); + result = await HdlDeviceAirConditionerLogic.Current.SetAcModeSupport((AC)device, data); + if (result == true) + { + //杞崲涓轰簩杩涘埗 + var value = Convert.ToString(data, 2).PadLeft(16, '0'); + //杩欎簲涓缃槸鏀惧湪鍚庨潰鐨� + var fixValue = value.Substring(0, value.Length - 5); + var reportValue = value.Substring(fixValue.Length); + //鏇存敼缂撳瓨 + for (int i = 0; i < reportValue.Length; i++) + { + ((AC)device).listSupportMode[i] = Convert.ToInt32(reportValue[i]); + } + device.ReSave(); + } } return result == true ? 1 : -1; } #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 寮瑰嚭缃戝叧涓嶅湪绾跨殑 + /// </summary> + private void ShowGatewayNotOnlineMsg() + { + Application.RunOnMainThread(() => + { + //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁� + string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork); + var control = new ShowMsgControl(ShowMsgType.Tip, msg); + control.Show(); + }); + } + + /// <summary> + /// 鏄剧ず閿欒淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowErrorMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Error, msg); + contr.Show(); + }); + } + + /// <summary> + /// 鏄剧ずTip淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowTipMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + contr.Show(); + }); + } + + #endregion } } -- Gitblit v1.8.0