From 26d1cdf2f5246c1ad7890e6740444c4a6a80e6fb Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 11 八月 2020 13:21:10 +0800
Subject: [PATCH] 合并了新代码

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 169 insertions(+), 1 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
index bd75dce..440f8f0 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
@@ -323,7 +323,7 @@
         /// PIR閰嶇疆鍙傛暟鍥炲
         /// </summary>
         [System.Serializable]
-        public class PanelPrivateFunctionsResponseAllInfo:ErrorResponCommon
+        public class PanelPrivateFunctionsResponseAllInfo : ErrorResponCommon
         {
             /// <summary>
             /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
@@ -1105,6 +1105,174 @@
         }
         #endregion
 
+        #region  鏍℃娓╁害
+        ///<summary >
+        /// 鏍℃娓╁害 
+        /// </summary>
+        public async System.Threading.Tasks.Task<ResponseAllData> CorrectTemperature(double correctValue, int direction = 0, int type = 0)
+        {
+            ResponseAllData result = null;
+            if (Gateway == null)
+            {
+                result = new ResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" };
+                return result;
+            }
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+
+                        if (temp == null)
+                        {
+                            result = new ResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+
+                        else
+                        {
+                            result = new ResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
+                    {
+                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+
+                        if (clientDataPassthroughResponseData == null)
+                        {
+                            result = new ResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            if (clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = clientDataPassthroughResponseData.PassData;
+                                if (data.Length == 16)
+                                {
+                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
+                                    if (command == "0002")
+                                    {
+                                        var tempD = new ResponseData();
+                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
+                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
+                                        if (tempD.command == "0503")
+                                        {
+                                            result = new ResponseAllData { responseData = tempD };
+                                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0500_{ topic}");
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var passData = CorrectTemperatureData(correctValue,direction, type);
+                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                    var data = new JObject { { "PassData", passData } };
+                    jObject.Add("Data", data);
+                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (result != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
+                {
+                    result = new ResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        /// <summary>
+        /// 鏍℃娓╁害
+        /// [璇ユ潯鍗忚鍙﹀2涓弬鏁癠I鍜岃澶囬兘涓嶉渶瑕侊紝璁惧閮藉悓浜嬭姹備紶鎰熷櫒璺濈鍜屼紶鎰熷櫒瑙﹀彂寤惰繜鏃堕棿閮介粯璁ゆ槸FFFF]
+        /// </summary>
+        /// <param name="correctValue">鏍℃娓╁害鍊�</param> 
+        /// <returns></returns>
+        string CorrectTemperatureData(double correctValue,int direction=0, int type = 0)
+        {
+            string data = "";
+            string dataLength = "09";
+            string dataComand1 = "03";
+            string dataComand2 = "05";
+            string dataSerialNum = "01";
+            string addDataLength = "05";
+            string typeString = "";
+            string directString = "";
+            string correctValueString = "";
+            try
+            {
+                if (type == 1)
+                {
+                    typeString = "0100";
+                }
+                else
+                {
+                    typeString = "0000";
+                }
+
+                if (direction == 1)
+                {
+                    directString = "01";
+                }
+                else if (direction == 2)
+                {
+                    directString = "02";
+                }
+                else
+                {
+                    directString = "00";
+                }
+
+                int curV = (int)(correctValue * 100);
+                var tempBytes = new byte[2];
+                for (int i = 0; i < 2; i++)
+                {
+                    tempBytes[i] = (byte)(curV >> (i * 8) & 0xff);
+                }
+                var curV1 = Convert.ToString(tempBytes[0], 16);
+                var curV2 = Convert.ToString(tempBytes[1], 16);
+                if (curV1.Length == 1)
+                {
+                    curV1 = "0" + curV1;
+                }
+                if (curV2.Length == 1)
+                {
+                    curV2 = "0" + curV2;
+                }
+
+                correctValueString = (curV1 + curV2).ToUpper();
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                  typeString + directString + correctValueString;
+            }
+            catch { };
+
+            return data;
+        }
+        #endregion
+
         #region 鑾峰彇鎸夐敭鎸囩ず鐏紑鍏抽鑹�.
 
         /// <summary>

--
Gitblit v1.8.0