From 88ce6b0697ccf6ce467545bb1125aefdf5b7130b Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 18 十一月 2019 11:29:04 +0800 Subject: [PATCH] 合并了全部的代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 200 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 135 insertions(+), 65 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs index 168cc2b..e5d7071 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs @@ -1043,14 +1043,14 @@ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); return -1; } - ChannelIdInfo data = null; + 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 = Newtonsoft.Json.JsonConvert.DeserializeObject<ChannelIdInfo>(jobject["Data"].ToString()); + data = Convert.ToInt32(jobject["Data"]["Channel"].ToString()); } }; realWay.Actions += action; @@ -1059,34 +1059,22 @@ realWay.Send("ZbGw/GetChannel", jObject.ToString()); int TimeOut = 0; - while (data == null && TimeOut < 30) + while (data == -1 && TimeOut < 30) { System.Threading.Thread.Sleep(100); TimeOut++; } realWay.Actions -= action; - if (data == null) + if (data == -1) { //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐� string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail); msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); this.ShowTipMsg(msg); - return -1; } - return data.Channel; - } - - /// <summary> - /// 缃戝叧淇¢亾淇℃伅 - /// </summary> - private class ChannelIdInfo - { - /// <summary> - /// 缃戝叧淇¢亾 - /// </summary> - public int Channel = -1; + return data; } #endregion @@ -1107,14 +1095,14 @@ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); return null; } - CoordinatorMacInfo data = 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 = Newtonsoft.Json.JsonConvert.DeserializeObject<CoordinatorMacInfo>(jobject["Data"].ToString()); + data = jobject["Data"]["MacAddr"].ToString(); } }; realWay.Actions += action; @@ -1136,21 +1124,9 @@ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail); msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); this.ShowTipMsg(msg); - return null; } - return data.MacAddr; - } - - /// <summary> - /// 缃戝叧鍗忚皟鍣∕ac淇℃伅 - /// </summary> - private class CoordinatorMacInfo - { - /// <summary> - /// 璋冨櫒Mac - /// </summary> - public string MacAddr = string.Empty; + return data; } #endregion @@ -1171,14 +1147,14 @@ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg)); return -1; } - PanIdInfo data = null; + 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); - data = Newtonsoft.Json.JsonConvert.DeserializeObject<PanIdInfo>(jobject["Data"].ToString()); + panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString()); } }; realWay.Actions += action; @@ -1187,34 +1163,128 @@ realWay.Send("ZbGw/GetPanId", jObject.ToString()); int TimeOut = 0; - while (data == null && TimeOut < 30) + while (panId == -1 && TimeOut < 30) { System.Threading.Thread.Sleep(100); TimeOut++; } realWay.Actions -= action; - if (data == null) + if (panId == -1) { //鑾峰彇鍗忚皟鍣≒anID澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail); msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); this.ShowTipMsg(msg); - return -1; } - return data.PANID; + 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> - /// 缃戝叧PanId淇℃伅 + /// 璁剧疆缃戝叧鑷姩澶囦唤璁剧疆 /// </summary> - private class PanIdInfo + /// <param name="zbGateway"></param> + /// <param name="statu"></param> + /// <returns></returns> + public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu) { - /// <summary> - /// PanId - /// </summary> - public int PANID = -1; + 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 @@ -2317,27 +2387,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; } -- Gitblit v1.8.0