From 2e7e5f9af5b32cfe1fc3c6ba40bf7eb984bbd0a4 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 11 五月 2020 17:52:06 +0800 Subject: [PATCH] ??????? --- ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs | 191 ++++++++--------------------------------------- 1 files changed, 32 insertions(+), 159 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs index 0def10a..562405e 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs @@ -15,11 +15,11 @@ { return await System.Threading.Tasks.Task.Run(async () => { - var result = new AddedDeviceBindResponseAllData(); + AddedDeviceBindResponseAllData result = null; var mainGateway = ZbGateway.MainGateWay; if (mainGateway == null) { - result.errorMessageBase = "褰撳墠娌℃湁涓荤綉鍏�"; + result = new AddedDeviceBindResponseAllData { errorMessageBase = "褰撳墠娌℃湁涓荤綉鍏�" }; return result; } Action<string, string> action = (topic, message) => @@ -28,8 +28,7 @@ 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 = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID }; - var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); if (temp == null) { @@ -43,37 +42,16 @@ } else if (topic == gatewayID + "/" + "Bind/SetBind_Respon") { - var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID }; - var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString()); - if (tempBindList == null) + var tempResult = Newtonsoft.Json.JsonConvert.DeserializeObject<AddedDeviceBindResponseData>(jobject["Data"].ToString()); + if (tempResult == null) { - result.errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�"; + result = new AddedDeviceBindResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; } else { - var dataBindRes = new AddedDeviceBindResponseData(); - for (int m = 0; tempBindList != null && m < tempBindList.Count; m++) - { - var tempBind = tempBindList[m]; - dataBindRes.BindList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindListResponseObj>(tempBind.ToString())); - } - if (dataBindRes != null) - { - result.addedDeviceBindResponseData = dataBindRes; - DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}"); - } + result = new AddedDeviceBindResponseAllData { addedDeviceBindResponseData = tempResult }; + DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}"); } - } - else if (topic == gatewayID + "/" + "Bind/BindResult") - { - var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID }; - var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindResultResponseData>(jobject["Data"].ToString()); - - if (tempData != null) - { - result.addBindResultResponseData = tempData; - } - DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}"); } }; mainGateway.Actions += action; @@ -111,7 +89,6 @@ { "BindList", bindList } }; jObject.Add("Data", data); - //ZbGateway.MainGateWay.CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo?.gwID; mainGateway.Send("Bind/SetBind", jObject.ToString()); } } @@ -120,42 +97,17 @@ } var dateTime = DateTime.Now; - while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + while ((DateTime.Now - dateTime).TotalMilliseconds < 20 * 1000) { - await System.Threading.Tasks.Task.Delay(100); - if (result == null || result.addedDeviceBindResponseData == null) - { - continue; - } - if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count) - { - if (result.addBindResultResponseData != null) - { - break; - } - } - else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count) - { - if (result.addBindResultResponseData != null) - { - break; - } - } - else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count) - { - if (result.addBindResultResponseData != null) - { - break; - } - } - else + await System.Threading.Tasks.Task.Delay(10); + if (result != null) { break; } } - if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) + if ((DateTime.Now - dateTime).TotalMilliseconds > 20 * 1000) { - result.errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔"; + result = new AddedDeviceBindResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; } mainGateway.Actions -= action; System.Console.WriteLine($"Bind/SetBind_Actions 閫�鍑� { System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond}"); @@ -163,22 +115,9 @@ }); } - /// <summary> - /// 缁戝畾璁惧淇℃伅,缃戝叧鍙嶉淇℃伅 - /// </summary> - public AddedDeviceBindResponseAllData addedDeviceBindResponseAllData; [System.Serializable] - public class AddedDeviceBindResponseAllData + public class AddedDeviceBindResponseAllData : ErrorResponCommon { - /// <summary> - /// 閿欒淇℃伅 - /// </summary> - public string errorMessageBase; - /// <summary> - /// 缃戝叧淇℃伅閿欒鍙嶉 - /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> - /// </summary> - public ErrorResponData errorResponData; /// <summary> /// 缃戝叧鐩存帴鍙嶉缁戝畾璁惧淇℃伅 /// </summary> @@ -189,10 +128,6 @@ public AddBindResultResponseData addBindResultResponseData; } - /// <summary> - /// 缁戝畾璁惧淇℃伅 - /// </summary> - public AddedDeviceBindResponseData addedDeviceBindResponseData; [System.Serializable] public class AddedDeviceBindResponseData { @@ -203,7 +138,12 @@ /// <summary> ///缁戝畾鍒楄〃 锛屽綋Status=0鏃跺瓨鍦� /// </summary> - public List<AddBindListResponseObj> BindList = new List<AddBindListResponseObj>(); + public List<BindListResponseObj> BindList = new List<BindListResponseObj>(); + /// <summary> + /// 0锛氱粦瀹氭墍鏈夌洰鏍囨垚鍔� + ///<para>1锛氱粦瀹氱洰鏍囧け璐ワ紝缁戝畾璁惧鐩爣鏈夋紡鎺�</para> + /// </summary> + public int Result = -1; } /// <summary> @@ -259,7 +199,6 @@ /// <summary> /// 缁戝畾璁惧鐨勬暟鎹� /// </summary> - public AddBindData addBindData; [System.Serializable] public class AddBindData { @@ -335,8 +274,7 @@ // if (topic == gatewayID + "/" + "Error_Respon") // { - // var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; - // var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + // var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); // if (temp == null) // { @@ -350,7 +288,6 @@ // //鍦烘櫙绉婚櫎 // if (topic == gatewayID + "/" + "Bind/RemoveBind_Respon") // { - // var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; // var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelDeviceBindResponseData>(jobject["Data"].ToString()); // if (tempData == null) @@ -366,7 +303,6 @@ // //璁惧绉婚櫎 // if (topic == gatewayID + "/" + "Bind/RemoveBindResult") // { - // var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; // var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveBindResultResponseData>(jobject["Data"].ToString()); // if (tempData != null) @@ -454,8 +390,7 @@ if (topic == gatewayID + "/" + "Error_Respon") { - var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; - var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); if (temp == null) { @@ -470,7 +405,6 @@ if (topic == gatewayID + "/" + "Bind/RemoveBind_Respon") { - var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelDeviceBindResponseData>(jobject["Data"].ToString()); if (tempData == null) @@ -487,7 +421,6 @@ if (topic == gatewayID + "/" + "Bind/RemoveBindResult") { - var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveBindResultResponseData>(jobject["Data"].ToString()); if (tempData != null) @@ -584,22 +517,9 @@ /// <summary> ///瑙i櫎缁戝畾鏁版嵁,缃戝叧鍙嶉淇℃伅 /// </summary> - public DelDeviceBindResponseAllData delDeviceBindResponseAllData; - /// <summary> - ///瑙i櫎缁戝畾鏁版嵁,缃戝叧鍙嶉淇℃伅 - /// </summary> [System.Serializable] - public class DelDeviceBindResponseAllData + public class DelDeviceBindResponseAllData : ErrorResponCommon { - /// <summary> - /// 閿欒淇℃伅 - /// </summary> - public string errorMessageBase; - /// <summary> - /// 缃戝叧淇℃伅閿欒鍙嶉 - /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> - /// </summary> - public ErrorResponData errorResponData; /// <summary> /// 瑙i櫎缁戝畾鏁版嵁淇℃伅 /// </summary> @@ -611,10 +531,6 @@ public RemoveBindResultResponseData removeBindResultResponseData; } - /// <summary> - /// 瑙i櫎缁戝畾鏁版嵁 - /// </summary> - public DelDeviceBindResponseData delDeviceBindResponseData; /// <summary> /// 瑙i櫎缁戝畾鏁版嵁 /// </summary> @@ -675,10 +591,6 @@ public string DeviceName; } - /// <summary> - /// 瑙i櫎缁戝畾鏁版嵁 - /// </summary> - public DelDeviceBindData delDeviceBindData; /// <summary> /// 瑙i櫎缁戝畾鏁版嵁 /// </summary> @@ -754,8 +666,7 @@ if (topic == gatewayID + "/" + "Error_Respon") { - var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; - var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); if (temp == null) { @@ -769,7 +680,6 @@ if (topic == gatewayID + "/" + "Bind/GetDeviceBind_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<GetDeviceBindResponseData>(jobject["Data"].ToString()); //var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString()); if (tempData == null) @@ -816,19 +726,9 @@ /// <summary> ///鑾峰彇鎵�鏈夌粦瀹氭暟鎹�,缃戝叧鍙嶉淇℃伅 /// </summary> - public GetDeviceBindResponseAllData getAllBindResponseAllData; [System.Serializable] - public class GetDeviceBindResponseAllData + public class GetDeviceBindResponseAllData : ErrorResponCommon { - /// <summary> - /// 閿欒淇℃伅 - /// </summary> - public string errorMessageBase; - /// <summary> - /// 缃戝叧淇℃伅閿欒鍙嶉 - /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> - /// </summary> - public ErrorResponData errorResponData; /// <summary> /// 鎺у埗璁惧缁戝畾鐨勮澶囧垪琛ㄥ洖澶嶆暟鎹� /// </summary> @@ -838,7 +738,6 @@ /// <summary> /// 鑾峰彇鎵�鏈夌粦瀹氬洖澶嶇殑鏁版嵁 /// </summary> - public GetDeviceBindResponseData getAllBindResponseData; [System.Serializable] public class GetDeviceBindResponseData { @@ -911,8 +810,7 @@ if (topic == gatewayID + "/" + "Error_Respon") { - var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; - var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); if (temp == null) { @@ -926,7 +824,6 @@ 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) { @@ -973,19 +870,9 @@ /// <summary> ///浠庤妭鐐硅澶囨湰鍦拌褰曡鍙栫粦瀹氬垪琛ㄤ俊鎭洖澶嶇殑鏁版嵁,缃戝叧鍙嶉淇℃伅 /// </summary> - public GetDeviceLocalBindResponseAllData getDeviceLocalBindResponseAllData; [System.Serializable] - public class GetDeviceLocalBindResponseAllData + public class GetDeviceLocalBindResponseAllData : ErrorResponCommon { - /// <summary> - /// 閿欒淇℃伅 - /// </summary> - public string errorMessageBase; - /// <summary> - /// 缃戝叧淇℃伅閿欒鍙嶉 - /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> - /// </summary> - public ErrorResponData errorResponData; /// <summary> /// 浠庤妭鐐硅澶囨湰鍦拌褰曡鍙栫粦瀹氬垪琛ㄤ俊鎭洖澶嶇殑鏁版嵁 /// </summary> @@ -995,7 +882,6 @@ /// <summary> /// 浠庤妭鐐硅澶囨湰鍦拌褰曡鍙栫粦瀹氬垪琛ㄤ俊鎭洖澶嶇殑鏁版嵁 /// </summary> - public GetDeviceLocalBindResponseData getDeviceLocalBindResponseData; [System.Serializable] public class GetDeviceLocalBindResponseData { @@ -1076,8 +962,7 @@ 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()); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); if (temp == null) { @@ -1091,7 +976,6 @@ 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) { @@ -1115,7 +999,7 @@ catch { } var dateTime = DateTime.Now; - while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + while ((DateTime.Now - dateTime).TotalMilliseconds < 25 * 1000) { await System.Threading.Tasks.Task.Delay(10); if (d != null) @@ -1123,8 +1007,8 @@ break; } } - //涓�閿竻闄ょ洰鏍囷紝浼氬洜涓虹洰鏍囨暟閲忓鑰屽姞闀挎椂闂达紝鐩墠鏆傚畾10绉� - if ((DateTime.Now - dateTime).TotalMilliseconds > 10 * 1000) + //涓�閿竻闄ょ洰鏍囷紝浼氬洜涓虹洰鏍囨暟閲忓鑰屽姞闀挎椂闂达紝鐩墠鏆傚畾20绉� + if ((DateTime.Now - dateTime).TotalMilliseconds > 25 * 1000) { d = new ClearBindInfoResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; } @@ -1138,19 +1022,9 @@ /// <summary> ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氭暟鎹�,缃戝叧鍙嶉淇℃伅 /// </summary> - public ClearBindInfoResponseAllData clearBindInfoResponseAllData; [System.Serializable] - public class ClearBindInfoResponseAllData + public class ClearBindInfoResponseAllData : ErrorResponCommon { - /// <summary> - /// 閿欒淇℃伅 - /// </summary> - public string errorMessageBase; - /// <summary> - /// 缃戝叧淇℃伅閿欒鍙嶉 - /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> - /// </summary> - public ErrorResponData errorResponData; /// <summary> /// 鎺у埗璁惧缁戝畾鐨勮澶囧垪琛ㄥ洖澶嶆暟鎹� /// </summary> @@ -1160,7 +1034,6 @@ /// <summary> /// 鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭洖澶嶇殑鏁版嵁 /// </summary> - public ClearBindInfoResponseData clearBindInfoResponseData; [System.Serializable] public class ClearBindInfoResponseData { -- Gitblit v1.8.0