From 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 19 十一月 2020 10:23:45 +0800
Subject: [PATCH] Evoyo.Home1.1.0120111601_Release

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs |   72 +++++++++++++++++++++++++++---------
 1 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
index f3aa1f4..d9e3d0c 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
@@ -67,6 +67,8 @@
         {
             var reResult = new ReceiptGatewayResult();
             reResult.listReceiptData = new string[listReceiptTopic.Count];
+            reResult.JsonData = new string[listReceiptTopic.Count];
+
             var myGateway = device.Gateway;
             if (myGateway == null)
             {
@@ -76,7 +78,7 @@
                 return reResult;
             }
             //缃戝叧ID
-            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
+            string gatewayID = device.Gateway.GwId;
             //閿欒涓婚
             string errorTopic = gatewayID + "/" + "Error_Respon";
             //妫�娴嬪璞$殑涓婚
@@ -85,8 +87,8 @@
                 listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
             }
 
-            //鎺ユ敹鏁�
-            int receiptCount = 0;
+            //钃濇墠鍒氭暣浜嗕釜鍚屼竴涓富棰樺彲鑳戒細鎺ㄩ�佸涓繃鏉ョ殑鏈鸿兘
+            var listCheckTopic = new HashSet<string>();
             Action<string, string> receiptAction = (topic, message) =>
             {
                 var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
@@ -102,6 +104,11 @@
                 {
                     if (topic == listReceiptTopic[i])
                     {
+                        if (listCheckTopic.Contains(topic) == true)
+                        {
+                            //杩欓噷鍐欒繖涓笢瑗挎槸鏈夌偣鐢ㄥ鐨�
+                            continue;
+                        }
                         string deviceMac = jobject["DeviceAddr"].ToString();
                         int deviceEpoint = 200;
                         if (jobject.Property("Epoint") != null)
@@ -120,7 +127,17 @@
                             return;
                         }
                         reResult.listReceiptData[i] = jobject["Data"].ToString();
-                        receiptCount++;
+                        if (jobject.Property("Time") != null)
+                        {
+                            //闇�瑕佺Щ闄ime杩欎釜瀛楁
+                            jobject.Remove("Time");
+                        }
+                        reResult.JsonData[i] = jobject.ToString();
+                        if (listCheckTopic.Contains(topic) == false)
+                        {
+                            //鍔犲埌妫�娴嬩富棰樺璞′腑
+                            listCheckTopic.Add(topic);
+                        }
                     }
                 }
 
@@ -132,7 +149,7 @@
             //瓒呮椂鏃堕棿
             int TimeOut = 0;
             waitTime = 20 * waitTime;
-            while (receiptCount != listReceiptTopic.Count && TimeOut < waitTime)
+            while (listCheckTopic.Count != listReceiptTopic.Count && TimeOut < waitTime)
             {
                 //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
                 System.Threading.Thread.Sleep(50);
@@ -140,7 +157,7 @@
             }
             myGateway.Actions -= receiptAction;
             receiptAction = null;
-            if (receiptCount != listReceiptTopic.Count)
+            if (listCheckTopic.Count != listReceiptTopic.Count)
             {
                 reResult.ErrorMsgDiv = 0;
             }
@@ -151,7 +168,6 @@
                 {
                     //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲�
                     reResult.ReceiptData = reResult.listReceiptData[0];
-                    reResult.listReceiptData = null;
                 }
             }
 
@@ -166,8 +182,10 @@
         /// <param name="receiptCommand">鎸囧畾鎺ユ敹鍛戒护绗�</param>
         /// <param name="receiptDataLength">鎸囧畾鎺ユ敹鏁版嵁鐨勯暱搴�</param>
         /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
+        /// <param name="listReceiptLength">闄勫姞妫�娴嬫暟鎹帴鏀堕暱搴�,褰撴帴鏀剁殑闀垮害鍦ㄨ繖鍒楄〃閲岄潰鏃�,浠h〃鎺ユ敹鎴愬姛(鏃ㄥ湪瀵瑰簲鏂版棫璁惧,閫忎紶鍥炲鐨勯暱搴﹀彲鑳戒笉鍚�)</param>
         /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
-        public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength, int waitTime = 5)
+        public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength,
+            int waitTime = 5, List<int> listReceiptLength = null)
         {
             var reResult = new ReceiptGatewayResult();
             var myGateway = device.Gateway;
@@ -179,7 +197,7 @@
                 return reResult;
             }
             //缃戝叧ID
-            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
+            string gatewayID = device.Gateway.GwId;
             //閿欒涓婚
             string errorTopic = gatewayID + "/" + "Error_Respon";
             //妫�娴嬪璞$殑涓婚
@@ -217,18 +235,36 @@
                     }
 
                     var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
-                    //闀垮害涓�鑷�
-                    if (responseData.PassData.Length == receiptDataLength)
+                    //闀垮害涓嶄竴鑷�
+                    if (responseData.PassData.Length != receiptDataLength)
                     {
-                        var command = responseData.PassData[4].ToString() 
-                        + responseData.PassData[5].ToString()
-                        + responseData.PassData[2].ToString() 
-                        + responseData.PassData[3].ToString();
-                        //骞朵笖鏄繖涓懡浠�
-                        if (command == receiptCommand)
+                        if (listReceiptLength == null)
                         {
-                            reResult.ReceiptData = responseData.PassData;
+                            //濡傛灉娌℃湁闄勫姞妫�娴嬮暱搴�,鍒欑洿鎺ヨ繑鍥�
+                            return;
                         }
+                        if (listReceiptLength.Contains(responseData.PassData.Length) == false)
+                        {
+                            //濡傛灉闄勫姞鐨勬娴嬮暱搴﹂噷闈�,杩樹笉瀛樺湪鐨勮瘽,鐩存帴杩斿洖
+                            return;
+                        }
+                    }
+
+                    var command = responseData.PassData[4].ToString()
+                        + responseData.PassData[5].ToString()
+                        + responseData.PassData[2].ToString()
+                        + responseData.PassData[3].ToString();
+                    //骞朵笖鏄繖涓懡浠�
+                    if (command == receiptCommand)
+                    {
+                        reResult.ReceiptData = responseData.PassData;
+                        reResult.JsonData = new string[1];
+                        if (jobject.Property("Time") != null)
+                        {
+                            //闇�瑕佺Щ闄ime杩欎釜瀛楁
+                            jobject.Remove("Time");
+                        }
+                        reResult.JsonData[0] = jobject.ToString();
                     }
                 }
             };

--
Gitblit v1.8.0