From 944b87b6bcccb095cd73f13f4410fb20faf48f74 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期三, 25 十二月 2019 11:21:06 +0800
Subject: [PATCH] 2019.12.25

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs |  185 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 163 insertions(+), 22 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs
index 1116805..4953b41 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>
@@ -13,7 +13,6 @@
         /// </summary>
         public async System.Threading.Tasks.Task<AddedDeviceBindResponseAllData> AddDeviceBindAsync(AddBindData addBindData)
         {
-
             return await System.Threading.Tasks.Task.Run(async () =>
             {
                 var result = new AddedDeviceBindResponseAllData();
@@ -74,10 +73,11 @@
                         {
                             result.addBindResultResponseData = tempData;
                         }
+                        DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
                     }
                 };
                 mainGateway.Actions += action;
-                DebugPrintLog("Bind/SetBind_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+                DebugPrintLog("Bind/SetBind_Actions 鍚姩" + "_" + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
                 try
                 {
                     if (addBindData != null)
@@ -90,9 +90,9 @@
                             {
                                 var dInfo = new JObject{
                             { "BindMacAddr",bindInfo.BindMacAddr},
-                         { "BindEpoint", bindInfo.BindEpoint} ,
-                         { "BindCluster", bindInfo.BindCluster} ,
-                         { "BindType",bindInfo.BindType}
+                            { "BindEpoint", bindInfo.BindEpoint} ,
+                            { "BindCluster", bindInfo.BindCluster} ,
+                            { "BindType",bindInfo.BindType}
                             };
                                 bindList.Add(dInfo);
                             }
@@ -100,15 +100,15 @@
                             {
                                 var dInfo = new JObject{
                              { "BindCluster", bindInfo.BindCluster} ,
-                         { "BindType",bindInfo.BindType},
-                         { "BindScenesId", bindInfo.BindScenesId}
+                             { "BindType",bindInfo.BindType},
+                             { "BindScenesId", bindInfo.BindScenesId}
                             };
                                 bindList.Add(dInfo);
                             }
                         }
                         var data = new JObject{
-                    {"BindName",addBindData.BindName},
-                    { "BindList", bindList }
+                            {"BindName",addBindData.BindName},
+                             { "BindList", bindList }
                     };
                         jObject.Add("Data", data);
                         //ZbGateway.MainGateWay.CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo?.gwID;
@@ -127,7 +127,21 @@
                     {
                         continue;
                     }
-                    if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0).Count)
+                    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)
                         {
@@ -144,7 +158,7 @@
                     result.errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔";
                 }
                 mainGateway.Actions -= action;
-                System.Console.WriteLine($"Bind/SetBind_Actions 閫�鍑� {System.DateTime.Now}");
+                System.Console.WriteLine($"Bind/SetBind_Actions 閫�鍑� { System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond}");
                 return result;
             });
         }
@@ -405,7 +419,6 @@
                 }
                 catch { }
 
-
                 var dateTime = DateTime.Now;
                 while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                 {
@@ -414,7 +427,21 @@
                     {
                         continue;
                     }
-                    if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0).Count)
+                    if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
+                    {
+                        if (responseData.removeBindResultResponseData != null)
+                        {
+                            break;
+                        }
+                    }
+                    else if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
+                    {
+                        if (responseData.removeBindResultResponseData != null)
+                        {
+                            break;
+                        }
+                    }
+                    else if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 4).Count)
                     {
                         if (responseData.removeBindResultResponseData != null)
                         {
@@ -426,14 +453,12 @@
                         break;
                     }
                 }
-
                 if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                 {
                     responseData.errorMessageBase = "鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔";
                 }
                 mainGateway.Actions -= action;
                 System.Console.WriteLine("DeviceBind/DelBind_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
                 return responseData;
             });
         }
@@ -749,7 +774,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 +809,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 +826,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 +897,7 @@
             /// <summary>
             /// 璇ユ璇诲彇杩斿洖缁戝畾鍒楄〃涓暟
             /// </summary>
-            public int ReturnBindNum;
+            public int ReturnBindNum;
             /// <summary>
             /// 缁戝畾鍒楄〃锛屽綋Result=0鏃跺瓨鍦�
             /// </summary>
@@ -912,5 +937,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