From 4f0ab0ad21ce450b7856d50f98322a7899361386 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 22 九月 2020 10:30:01 +0800
Subject: [PATCH] 不要下载这个备份
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs | 543 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 465 insertions(+), 78 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
index 9e23559..e255b33 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
@@ -3,6 +3,7 @@
using System.Text;
using ZigBee.Device;
using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
namespace Shared.Phone.UserCenter
{
@@ -37,13 +38,13 @@
#region 鈻� 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶嘷____________
/// <summary>
- /// 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶�(閿欒鏃惰繑鍥瀗ull)
+ /// 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶�(閿欒鏃惰繑鍥瀗ull),杩欎釜鏄粰pir浼犳劅鍣ㄧ敤鐨�
/// </summary>
/// <param name="mainDevice">璁惧瀵硅薄</param>
/// <returns></returns>
- public async Task<List<CommonDevice>> GetBindTargetDevice(CommonDevice mainDevice)
+ public List<CommonDevice> GetBindTargetDevice(CommonDevice mainDevice)
{
- var result = (BindObj.GetDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "GetDeviceBindAsync");
+ var result = this.GetDeviceBindAsync(mainDevice);
if (result == null || result.getAllBindResponseData == null)
{
//鑾峰彇璁惧鐨勭粦瀹氱洰鏍囧け璐�
@@ -67,6 +68,37 @@
return listDevice;
}
+ /// <summary>
+ ///鑾峰彇鎵�鏈夌粦瀹�
+ /// </summary>
+ public BindObj.GetDeviceBindResponseAllData GetDeviceBindAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ var listBind = TemplateData.TemplateDeviceDataLogic.Current.GetDeviceBindList(device);
+ return new BindObj.GetDeviceBindResponseAllData()
+ {
+ getAllBindResponseData = new BindObj.GetDeviceBindResponseData
+ {
+ Result = 0,
+ BindList = listBind
+ }
+ };
+ }
+
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
+ string sendData = jObject.ToString();
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/GetDeviceBind", sendData, "Bind/GetDeviceBind_Respon", 6);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.GetDeviceBindResponseData>(result.ReceiptData);
+ return new BindObj.GetDeviceBindResponseAllData() { getAllBindResponseData = tempData };
+ }
+
#endregion
#region 鈻� 鎵ц缁戝畾璁惧鐩爣___________________
@@ -78,7 +110,7 @@
/// <param name="listDevice">瑕佺粦瀹氱殑鐩爣璁惧</param>
/// <param name="BindCluster">BindCluster</param>
/// <returns></returns>
- public async Task<List<CommonDevice>> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
+ public List<CommonDevice> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
{
if (listDevice.Count == 0)
{
@@ -105,8 +137,8 @@
string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
dicDevice[mainkeys] = device;
}
-
- var result = (BindObj.AddedDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "AddDeviceBindAsync", addData);
+ //鎵ц缁戝畾
+ var result = this.AddDeviceBindAsync(addData);
if (result == null || result.addedDeviceBindResponseData == null)
{
//缁戝畾鐩爣璁剧疆澶辫触
@@ -122,65 +154,123 @@
foreach (var data in result.addedDeviceBindResponseData.BindList)
{
string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
- //0:娣诲姞鎴愬姛 3:宸茬粡瀛樺湪锛屼篃鍙互浠h〃鎴愬姛
- if (data.Result == 0 || data.Result == 3)
+ if (dicDevice.ContainsKey(mainkeys) == true)
{
- if (dicDevice.ContainsKey(mainkeys) == true)
- {
- listSuccess.Add(dicDevice[mainkeys]);
- }
- }
- //1锛氬け璐ワ紝鑺傜偣璁惧鎴栧満鏅笉瀛樺湪
- else if (data.Result == 1)
- {
- if (dicDevice.ContainsKey(mainkeys) == true)
- {
- //璁惧鍚嶇О 缁戝畾澶辫触
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
- this.ShowTipMsg(msg);
- }
- }
- //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
- else if (data.Result == 2)
- {
- if (result.addBindResultResponseData == null)
- {
- //璁惧鍚嶇О 缁戝畾澶辫触
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
- this.ShowTipMsg(msg);
- }
- else
- {
- //娣诲姞鎴愬姛
- if (result.addBindResultResponseData.Result == 0)
- {
- if (dicDevice.ContainsKey(mainkeys) == true)
- {
- listSuccess.Add(dicDevice[mainkeys]);
- }
- }
- //璁惧鍚嶇О 缁戝畾鍒楄〃宸叉弧
- else if (result.addBindResultResponseData.Result == 140)
- {
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.uBindListIsFull);
- this.ShowTipMsg(msg);
- }
- else
- {
- //璁惧鍚嶇О 缁戝畾澶辫触
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
- this.ShowTipMsg(msg);
- }
- }
+ listSuccess.Add(dicDevice[mainkeys]);
}
}
+ if (listSuccess.Count == 0)
+ {
+ //缁戝畾鐩爣璁剧疆澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
+ this.ShowTipMsg(msg);
+ }
return listSuccess;
}
+
+ /// <summary>
+ ///璁惧缁戝畾
+ /// </summary>
+ public BindObj.AddedDeviceBindResponseAllData AddDeviceBindAsync(BindObj.AddBindData addBindData)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.AddDeviceBindList(addBindData, null);
+ }
+
+ var device = Common.LocalDevice.Current.GetDevice(addBindData.DeviceAddr, addBindData.Epoint);
+ //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+ var sendData = this.GetAddDeviceListBindCommandText(addBindData);
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetBind", sendData, "Bind/SetBind_Respon", 20);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.AddDeviceBindList(addBindData, result.JsonData[0]);
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceBindResponseData>(result.ReceiptData);
+ return new BindObj.AddedDeviceBindResponseAllData() { addedDeviceBindResponseData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇娣诲姞璁惧缁戝畾鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="addBindData"></param>
+ /// <returns></returns>
+ public string GetAddDeviceListBindCommandText(BindObj.AddBindData addBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
+ var bindList = new JArray { };
+ foreach (var bindInfo in addBindData.BindList)
+ {
+ if (bindInfo.BindType == 0)
+ {
+ var dInfo = new JObject{{ "BindMacAddr",bindInfo.BindMacAddr},{ "BindEpoint", bindInfo.BindEpoint} ,
+ { "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}};
+ bindList.Add(dInfo);
+ }
+ else if (bindInfo.BindType == 1)
+ {
+ var dInfo = new JObject{{ "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType},
+ { "BindScenesId", bindInfo.BindScenesId}};
+ bindList.Add(dInfo);
+ }
+ }
+ var data = new JObject { { "BindName", addBindData.BindName }, { "BindList", bindList } };
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ ///璁惧缁戝畾銆愪竴瀵逛竴 缁戝畾锛屼竴涓寜閿洖璺彧鑳界粦瀹氫竴涓澶囥��
+ /// </summary>
+ public BindObj.AddedDeviceSingleBindResponseAllData AddDeviceSingleBindAsync(BindObj.AddSingleBindData addSingleBindData)
+ {
+ var device = Common.LocalDevice.Current.GetDevice(addSingleBindData.DeviceAddr, addSingleBindData.Epoint);
+ //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+ var sendData = this.GetAddDeviceListSingleBindCommandText(addSingleBindData);
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetSingleBind", sendData, "Bind/SetSingleBind_Respon", 20);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceSingleBindResponseData>(result.ReceiptData);
+ return new BindObj.AddedDeviceSingleBindResponseAllData() { addedDeviceSingleBindResponseData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇娣诲姞璁惧缁戝畾鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="addBindData"></param>
+ /// <returns></returns>
+ public string GetAddDeviceListSingleBindCommandText(BindObj.AddSingleBindData addSingleBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", addSingleBindData.DeviceAddr }, { "Epoint", addSingleBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5020 } };
+ var data = new JObject { };
+ var bindClusterList = new JArray { };
+ foreach (var cluster in addSingleBindData.BindClusterList)
+ {
+ bindClusterList.Add(cluster);
+ }
+ if (addSingleBindData.BindType == 0)
+ {
+ data = new JObject { { "BindName", addSingleBindData.BindName }, { "BindType", addSingleBindData.BindType }, { "BindClusterList", bindClusterList }, { "BindMacAddr", addSingleBindData.BindMacAddr }, { "BindEpoint", addSingleBindData.BindEpoint } };
+ }
+ else if (addSingleBindData.BindType == 1)
+ {
+ data = new JObject { { "BindName", addSingleBindData.BindName }, { "BindType", addSingleBindData.BindType }, { "BindClusterList", bindClusterList }, { "BindScenesId", addSingleBindData.BindScenesId } };
+
+ }
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
+
#endregion
@@ -193,7 +283,7 @@
/// <param name="deleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
/// <param name="BindCluster">BindCluster</param>
/// <returns></returns>
- public async Task<bool> DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
+ public bool DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
{
//缁勮鏁版嵁
var deleteData = new IASZone.DelDeviceBindData();
@@ -208,7 +298,8 @@
deleteData.RemoveBindList.Add(info);
- var result = (BindObj.DelDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "DelDeviceBindAsync", deleteData);
+ //鎵ц鍒犻櫎
+ var result = this.DelDeviceBindAsync(deleteData);
if (result == null || result.delDeviceBindResponseData == null)
{
//鍒犻櫎缁戝畾鐩爣澶辫触
@@ -278,7 +369,7 @@
/// <param name="listDeleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
/// <param name="BindCluster">BindCluster</param>
/// <returns>杩斿洖鐨勬槸鎴愬姛鍒犻櫎鐨勮澶�</returns>
- public async Task<List<CommonDevice>> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
+ public List<CommonDevice> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
{
//缁勮鏁版嵁
var deleteData = new IASZone.DelDeviceBindData();
@@ -301,7 +392,7 @@
}
var listSuccess = new List<CommonDevice>();
- var result = (BindObj.DelDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "DelDeviceBindAsync", deleteData);
+ var result = this.DelDeviceBindAsync(deleteData);
if (result == null || result.delDeviceBindResponseData == null)
{
//鍒犻櫎缁戝畾鐩爣澶辫触
@@ -365,25 +456,321 @@
return listSuccess;
}
+ /// <summary>
+ /// 鍒犻櫎璁惧鐨勭粦瀹氱洰鏍�
+ /// </summary>
+ /// <param name="delDeviceBindData"></param>
+ /// <returns></returns>
+ public BindObj.DelDeviceBindResponseAllData DelDeviceBindAsync(BindObj.DelDeviceBindData delDeviceBindData)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
+ }
+ var device = Common.LocalDevice.Current.GetDevice(delDeviceBindData.DeviceAddr, delDeviceBindData.Epoint);
+ //鑾峰彇闇�瑕佸彂閫佺殑鏁版嵁
+ var sendData = this.GetDeleteDeviceBindCommandText(delDeviceBindData);
+ //鍙戦�佸懡浠�
+ var result = this.SendDeleteBindJobjectDataToGateway(device, "Bind/RemoveBind",
+ sendData, new List<string>() { "Bind/RemoveBind_Respon", "Bind/RemoveBindResult" }, 6);
+
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var responseData = new BindObj.DelDeviceBindResponseAllData();
+ if (result.listReceiptData[0] != null)
+ {
+ var tempData1 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(result.listReceiptData[0]);
+ responseData.delDeviceBindResponseData = tempData1;
+ }
+
+ if (result.listReceiptData[1] != null)
+ {
+ var tempData2 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(result.listReceiptData[1]);
+ responseData.removeBindResultResponseData = tempData2;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
+
+ return responseData;
+ }
+
+ /// <summary>
+ ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭�
+ /// </summary>
+ public BindObj.ClearBindInfoResponseAllData ClearBindInfoAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ClearDeviceAllBind(device);
+ }
+
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
+ var sendData = jObject.ToString();
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/ClearBindInfo", sendData, "Bind/ClearBindInfo_Respon", 25);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.ClearDeviceAllBind(device);
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.ClearBindInfoResponseData>(result.ReceiptData);
+ return new BindObj.ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
+ }
+
+
+ /// <summary>
+ /// 鑾峰彇鍒犻櫎璁惧缁戝畾鍒楄〃鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="delDeviceBindData"></param>
+ /// <returns></returns>
+ public string GetDeleteDeviceBindCommandText(BindObj.DelDeviceBindData delDeviceBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
+ var removeBindList = new JArray { };
+ foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
+ {
+ //鍒犻櫎璁惧
+ if (removeBindInfo.BindType == 0)
+ {
+ var dInfo = new JObject{{ "BindMacAddr",removeBindInfo.BindMacAddr},{ "BindEpoint", removeBindInfo.BindEpoint} ,
+ { "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType}};
+ removeBindList.Add(dInfo);
+ }
+ //鍒犻櫎鍦烘櫙
+ else if (removeBindInfo.BindType == 1)
+ {
+ var dInfo = new JObject{{ "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType},
+ { "BindScenesId", removeBindInfo.BindScenesId}};
+ removeBindList.Add(dInfo);
+ }
+ }
+ var data = new JObject { { "RemoveBindList", removeBindList } };
+ jObject.Add("Data", data);
+
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 鍙戦�佸垹闄ょ粦瀹氱殑鏁版嵁鍒扮綉鍏筹紝骞舵帴鍙楃綉鍏宠繑鍥炵殑鏁版嵁,listReceiptData涓鸿繑鍥炲��(鍒犻櫎缁戝畾鐨勬帴鍙e緢鐗规畩,闇�瑕佺嫭绔嬪嚭鏉�)
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
+ /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param>
+ /// <param name="listReceiptTopic">鎸囧畾鎺ユ敹鍝簺涓婚</param>
+ /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
+ /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
+ private ReceiptGatewayResult SendDeleteBindJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 3)
+ {
+ var reResult = new ReceiptGatewayResult();
+ reResult.listReceiptData = new string[listReceiptTopic.Count];
+ var myGateway = device.Gateway;
+ if (myGateway == null)
+ {
+ //鑾峰彇缃戝叧瀵硅薄澶辫触
+ reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
+ reResult.ErrorMsgDiv = -1;
+ return reResult;
+ }
+ //缃戝叧ID
+ string gatewayID = device.Gateway.GwId;
+ //閿欒涓婚
+ string errorTopic = gatewayID + "/" + "Error_Respon";
+ //妫�娴嬪璞$殑涓婚
+ for (int i = 0; i < listReceiptTopic.Count; i++)
+ {
+ listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
+ }
+
+ bool canbreak = false;
+ BindObj.DelDeviceBindResponseData delDeviceBindData = null;
+ BindObj.RemoveBindResultResponseData removeBindResult = null;
+
+ Action<string, string> receiptAction = (topic, message) =>
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+ //缃戝叧鍥炲閿欒
+ if (topic == errorTopic)
+ {
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+ reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
+ }
+ //濡傛灉鏄寚瀹氱殑涓婚
+ for (int i = 0; i < listReceiptTopic.Count; i++)
+ {
+ if (topic == listReceiptTopic[i])
+ {
+ string deviceMac = jobject["DeviceAddr"].ToString();
+ int deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
+ if (device.DeviceAddr != deviceMac)
+ {
+ //涓嶆槸鍚屼竴涓笢瑗縈ac
+ return;
+ }
+ if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
+ {
+ //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣
+ return;
+ }
+ reResult.listReceiptData[i] = jobject["Data"].ToString();
+
+ if (i == 0)
+ {
+ //"Bind/RemoveBind_Respon"涓婚
+ delDeviceBindData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(reResult.listReceiptData[i]);
+ }
+ else if (i == 1)
+ {
+ //"Bind/RemoveBindResult"涓婚
+ removeBindResult = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(reResult.listReceiptData[i]);
+ }
+
+ if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
+ {
+ canbreak = true;
+ }
+ else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
+ {
+ if (removeBindResult != null)
+ {
+ canbreak = true;
+ }
+ }
+ else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
+ {
+ if (removeBindResult != null)
+ {
+ canbreak = true;
+ }
+ }
+ else
+ {
+ canbreak = true;
+ }
+ }
+ }
+
+ };
+ myGateway.Actions += receiptAction;
+ //鍙戦�佹暟鎹�
+ myGateway.Send(sendTopic, sendData);
+
+ //瓒呮椂鏃堕棿
+ int TimeOut = 0;
+ waitTime = 20 * waitTime;
+ while (canbreak == false && TimeOut < waitTime)
+ {
+ //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
+ System.Threading.Thread.Sleep(50);
+ TimeOut++;
+ }
+ myGateway.Actions -= receiptAction;
+ receiptAction = null;
+ if (canbreak == false)
+ {
+ //瓒呮椂
+ reResult.ErrorMsgDiv = 0;
+ }
+ else
+ {
+ //姝e父鎺ユ敹鍒扮綉鍏宠繑鍥炵殑鏁版嵁
+ if (reResult.listReceiptData.Length == 1)
+ {
+ //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲�
+ reResult.ReceiptData = reResult.listReceiptData[0];
+ reResult.listReceiptData = null;
+ }
+ }
+
+ return reResult;
+ }
+
+
+ #endregion
+
+ #region 鈻� 閰嶇疆闈㈡澘鍔熻兘_______________________
+
+ ///<summary >
+ ///閰嶇疆闈㈡澘鍔熻兘
+ ///<para>value:缁欓潰鏉块厤缃殑妯″紡</para>
+ /// </summary>
+ public CommonDevice.SetWritableValueResponAllData ConfigureHdlKeyValueAsync(CommonDevice device, Panel.KeyMode value, int clusterID = 6)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, null);
+ }
+ //鑾峰彇鍙戦�佹暟鎹�
+ var sendData = this.GetConfigureHdlKeyCommandText(device.DeviceAddr, device.DeviceEpoint, value, clusterID);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, result.JsonData[0]);
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+ return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
+ }
+
+ /// <summary>
+ /// 璇诲彇闈㈡澘鐨勯厤缃俊鎭�
+ /// </summary>
+ public Panel.PanelConfigureInfoResponAllData ReadPanelConfigureInfoAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ReadPanelConfigureKeyModel(device);
+ }
+
+ var JObject = new JObject {{ "DeviceAddr",device.DeviceAddr },{ "Epoint", device.DeviceEpoint },
+ { "Cluster_ID", (int)Cluster_ID.HdlKey },{ "Command", 108 }};
+ var attriBute = new JArray { new JObject { { "AttriButeId", (int)AttriButeId.HdlKey } } };
+ var data = new JObject { { "AttriBute", attriBute } };
+ JObject.Add("Data", data);
+
+ //鍙戦�佹暟鎹�
+ var sendData = JObject.ToString();
+ string receiptTopic = "DeviceStatusReport/" + device.DeviceAddr + "/" + device.DeviceEpoint + "/" + (int)Cluster_ID.HdlKey + "/" + (int)AttriButeId.HdlKey;
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetDeviceStatus", sendData, receiptTopic);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(result.ReceiptData);
+ return new Panel.PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇閰嶇疆闈㈡澘鍔熻兘鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <param name="value">閿��</param>
+ /// <param name="clusterID">闀濱D</param>
+ /// <returns></returns>
+ public string GetConfigureHdlKeyCommandText(string DeviceAddr, int DeviceEpoint, Panel.KeyMode value, int clusterID = 6)
+ {
+ var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } };
+ var data = new JObject { { "Undivided", 0 }, { "AttributeId", 6533 }, { "AttributeDataType", 33 }, { "AttributeData", (int)value } };
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
#endregion
#region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <summary>
- /// 鎵ц鎸囧畾璁惧瀵硅薄绫婚噷闈㈢殑鏂规硶(娉ㄦ剰锛氳繖涓槸涓撻棬璋冪敤寮傛锛屽苟涓旂瓑寰呭紓姝ュ畬鎴愮殑楂樼鎶�鍑芥暟,涓嶈皟鐢ㄥ紓姝ョ殑鎯呭喌锛屽埆浣跨敤姝ゅ嚱鏁�)
- /// </summary>
- /// <param name="device">闇�瑕佹墽琛岀殑璁惧鐨勮澶囧璞�</param>
- /// <param name="method">鎸囧畾瑕佸姞杞界殑鏂规硶鍚�</param>
- /// <param name="parameter">鍚姩鍙傛暟</param>
- private async Task<object> LoadDeviceMethodByNameAsync(CommonDevice device, string method, params object[] parameter)
- {
- var task = device.GetType().InvokeMember(method, System.Reflection.BindingFlags.InvokeMethod, null, device, parameter) as Task;
- await task;
-
- var result = task.GetType().GetProperty("Result").GetValue(task, null);
- return result;
- }
/// <summary>
/// 鏄剧ず閿欒淇℃伅绐楀彛
--
Gitblit v1.8.0