From a45fe56aeeac8f28a9891b83362954067c8166dc Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 14 八月 2020 09:07:05 +0800
Subject: [PATCH] 请合并新代码,更改多功能面板绑定表重复问题

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

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
new file mode 100755
index 0000000..e92d774
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
@@ -0,0 +1,286 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 璁惧鐨勫叡閫氶�昏緫
+    /// </summary>
+    public class HdlDeviceCommonLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 璁惧鐨勫叡閫氶�昏緫
+        /// </summary>
+        private static HdlDeviceCommonLogic m_Current = null;
+        /// <summary>
+        /// 璁惧鐨勫叡閫氶�昏緫
+        /// </summary>
+        public static HdlDeviceCommonLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlDeviceCommonLogic();
+                }
+                return m_Current;
+            }
+            set
+            {
+                m_Current = value;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鍙戦�佹暟鎹甠__________________________
+
+        /// <summary>
+        /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(闈為�忎紶,ReceiptData涓鸿繑鍥炲��)
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
+        /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁  JObject.ToString()鐨勪笢瑗�</param>
+        /// <param name="receiptTopic">鎸囧畾鎺ユ敹鍝釜涓婚</param>
+        /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
+        /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
+        public ReceiptGatewayResult SendJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, string receiptTopic, int waitTime = 5)
+        {
+            //鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�
+            return this.SendJobjectDataToGateway(device, sendTopic, sendData, new List<string>() { receiptTopic }, waitTime);
+        }
+
+        /// <summary>
+        /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(闈為�忎紶),listReceiptData涓鸿繑鍥炲��(鍏ㄩ儴涓婚鍏ㄩ儴鎺ユ敹寰楀埌,鎵嶄細杩斿洖,涓嶇劧浼氳繑鍥炶秴鏃�)
+        /// </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>
+        public ReceiptGatewayResult SendJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 5)
+        {
+            var reResult = new ReceiptGatewayResult();
+            reResult.listReceiptData = new string[listReceiptTopic.Count];
+            reResult.JsonData = 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];
+            }
+
+            //鎺ユ敹鏁�
+            int receiptCount = 0;
+            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 = 200;
+                        if (jobject.Property("Epoint") != null)
+                        {
+                            //鎷ユ湁姝ら敭鍊�
+                            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 (jobject.Property("Time") != null)
+                        {
+                            //闇�瑕佺Щ闄ime杩欎釜瀛楁
+                            jobject.Remove("Time");
+                        }
+                        reResult.JsonData[i] = jobject.ToString();
+                        receiptCount++;
+                    }
+                }
+
+            };
+            myGateway.Actions += receiptAction;
+            //鍙戦�佹暟鎹�
+            myGateway.Send(sendTopic, sendData);
+
+            //瓒呮椂鏃堕棿
+            int TimeOut = 0;
+            waitTime = 20 * waitTime;
+            while (receiptCount != listReceiptTopic.Count && TimeOut < waitTime)
+            {
+                //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
+                System.Threading.Thread.Sleep(50);
+                TimeOut++;
+            }
+            myGateway.Actions -= receiptAction;
+            receiptAction = null;
+            if (receiptCount != listReceiptTopic.Count)
+            {
+                reResult.ErrorMsgDiv = 0;
+            }
+            else
+            {
+                //姝e父鎺ユ敹鍒扮綉鍏宠繑鍥炵殑鏁版嵁
+                if (reResult.listReceiptData.Length == 1)
+                {
+                    //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲�
+                    reResult.ReceiptData = reResult.listReceiptData[0];
+                }
+            }
+
+            return reResult;
+        }
+
+        /// <summary>
+        /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(閫忎紶涓撶敤)
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁  JObject.ToString()鐨勪笢瑗�</param>
+        /// <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, List<int> listReceiptLength = null)
+        {
+            var reResult = new ReceiptGatewayResult();
+            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";
+            //妫�娴嬪璞$殑涓婚
+            string checkTopic = gatewayID + "/ZbDataPassthrough";
+
+            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);
+                }
+                //濡傛灉鏄寚瀹氱殑涓婚
+                if (topic == checkTopic)
+                {
+                    string deviceMac = jobject["DeviceAddr"].ToString();
+                    int deviceEpoint = 200;
+                    if (jobject.Property("Epoint") != null)
+                    {
+                        //鎷ユ湁姝ら敭鍊�
+                        deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
+                    }
+                    if (device.DeviceAddr != deviceMac)
+                    {
+                        //涓嶆槸鍚屼竴涓笢瑗縈ac
+                        return;
+                    }
+                    if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
+                    {
+                        //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣
+                        return;
+                    }
+
+                    var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+                    //闀垮害涓嶄竴鑷�
+                    if (responseData.PassData.Length != receiptDataLength)
+                    {
+                        if (listReceiptLength == null)
+                        {
+                            //濡傛灉娌℃湁闄勫姞妫�娴嬮暱搴�,鍒欑洿鎺ヨ繑鍥�
+                            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();
+                    }
+                }
+            };
+            myGateway.Actions += receiptAction;
+            //鍙戦�佹暟鎹�
+            myGateway.Send("ClientDataPassthrough", sendData);
+
+            //瓒呮椂鏃堕棿
+            int TimeOut = 0;
+            waitTime = 20 * waitTime;
+            while (reResult.ReceiptData == null && TimeOut < waitTime)
+            {
+                System.Threading.Thread.Sleep(50);
+                TimeOut++;
+            }
+            myGateway.Actions -= receiptAction;
+            receiptAction = null;
+            if (reResult.ReceiptData == null)
+            {
+                //瓒呮椂
+                reResult.ErrorMsgDiv = 0;
+            }
+            return reResult;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0