From 404cdc88627f942df7944af04ee05b9d527752d6 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 30 九月 2019 13:22:40 +0800 Subject: [PATCH] 合并了徐梅的按键面板绑定 --- ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs | 130 +++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 123 insertions(+), 7 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs index 1116805..2e6dd46 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs @@ -5,7 +5,7 @@ namespace ZigBee.Device { [System.Serializable] - public class BindObj :CommonDevice + public class BindObj : CommonDevice { #region 璁惧缁戝畾 /// <summary> @@ -749,7 +749,7 @@ /// <summary> ///浠庤妭鐐硅澶囨湰鍦拌褰曡鍙栫粦瀹氬垪琛ㄤ俊鎭� /// </summary> - public async System.Threading.Tasks.Task<GetDeviceLocalBindResponseAllData> GetDeviceLocalBindAsync(int startIndex=0) + public async System.Threading.Tasks.Task<GetDeviceLocalBindResponseAllData> GetDeviceLocalBindAsync(int startIndex = 0) { return await System.Threading.Tasks.Task.Run(async () => { @@ -784,8 +784,8 @@ if (topic == gatewayID + "/" + "Bind/GetDeviceLocalBind_Respon") { var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; - var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDeviceLocalBindResponseData>(jobject["Data"].ToString()); - if (tempData == null) + var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDeviceLocalBindResponseData>(jobject["Data"].ToString()); + if (tempData == null) { d = new GetDeviceLocalBindResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; } @@ -801,8 +801,8 @@ try { DebugPrintLog("Bind/GetDeviceLocalBind_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); - var jObject = new JObject { { "DeviceAddr", DeviceAddr },{ "Cluster_ID", 0 }, { "Command", 5008 } }; - var data = new JObject {{ "StartIndex", startIndex } }; + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Cluster_ID", 0 }, { "Command", 5008 } }; + var data = new JObject { { "StartIndex", startIndex } }; mainGateway.Send("Bind/GetDeviceLocalBind", jObject.ToString()); } catch { } @@ -872,7 +872,7 @@ /// <summary> /// 璇ユ璇诲彇杩斿洖缁戝畾鍒楄〃涓暟 /// </summary> - public int ReturnBindNum; + public int ReturnBindNum; /// <summary> /// 缁戝畾鍒楄〃锛屽綋Result=0鏃跺瓨鍦� /// </summary> @@ -912,5 +912,121 @@ public int BindEpoint; } #endregion + + #region 鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭� + /// <summary> + ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭� + /// </summary> + public async System.Threading.Tasks.Task<ClearBindInfoResponseAllData> ClearBindInfoAsync() + { + if (Gateway == null) + { + return null; + } + return await System.Threading.Tasks.Task.Run(async () => + { + ClearBindInfoResponseAllData d = null; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + + if (topic == gatewayID + "/" + "Error_Respon") + { + var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + + if (temp == null) + { + d = new ClearBindInfoResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + else + { + d = new ClearBindInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + + if (topic == gatewayID + "/" + "Bind/ClearBindInfo_Respon") + { + var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; + var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClearBindInfoResponseData>(jobject["Data"].ToString()); + if (tempData == null) + { + d = new ClearBindInfoResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + d = new ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData }; + System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); + } + } + }; + Gateway.Actions += action; + DebugPrintLog("Bind/ClearBindInfo_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); + + try + { + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } }; + Gateway.Send("Bind/ClearBindInfo", jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (d != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) + { + d = new ClearBindInfoResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("Bind/ClearBindInfo_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return d; + }); + } + + /// <summary> + ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氭暟鎹�,缃戝叧鍙嶉淇℃伅 + /// </summary> + public ClearBindInfoResponseAllData clearBindInfoResponseAllData; + [System.Serializable] + public class ClearBindInfoResponseAllData + { + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string errorMessageBase; + /// <summary> + /// 缃戝叧淇℃伅閿欒鍙嶉 + /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + /// </summary> + public ErrorResponData errorResponData; + /// <summary> + /// 鎺у埗璁惧缁戝畾鐨勮澶囧垪琛ㄥ洖澶嶆暟鎹� + /// </summary> + public ClearBindInfoResponseData clearBindInfoResponseData; + } + + /// <summary> + /// 鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭洖澶嶇殑鏁版嵁 + /// </summary> + public ClearBindInfoResponseData clearBindInfoResponseData; + [System.Serializable] + public class ClearBindInfoResponseData + { + /// <summary> + /// 0锛氭垚鍔� + ///<para>1锛氱粦瀹氫俊鎭笉瀛樺湪</para> + /// </summary> + public int Result; + } + + #endregion } } -- Gitblit v1.8.0