From 404cdc88627f942df7944af04ee05b9d527752d6 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 30 九月 2019 13:22:40 +0800
Subject: [PATCH] 合并了徐梅的按键面板绑定

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs |  477 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 237 insertions(+), 240 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs
index 6c8926a..97b37d5 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs
@@ -1,4 +1,4 @@
-锘縰sing System;
+锘縰sing System;
 using System.Collections.Generic;
 using Newtonsoft.Json.Linq;
 
@@ -10,11 +10,11 @@
         public IASZone()
         {
             this.Type = DeviceType.IASZone;
-        }
-        /// <summary>
-        /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
-        /// <para>鏈夊嚑涓瓑绾у氨鏄剧ず鍑犱釜鍒诲害</para>
-        /// </summary>
+        }
+        /// <summary>
+        /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
+        /// <para>鏈夊嚑涓瓑绾у氨鏄剧ず鍑犱釜鍒诲害</para>
+        /// </summary>
         public int LightLevelCount = -1;
 
         #region IAS瀹夐槻淇℃伅涓婃姤.
@@ -47,7 +47,7 @@
             ///鍦ㄨ澶囩姸鎬佹敼鍙樹箣鍚庡欢鏃禗elay(鍗曚綅锛�1/4绉�)
             /// </summary>
             public int Delay;
-            /// <summary>
+            /// <summary>
             /// hdl
             ///1 - opened or alarmed
             ///0 - closed or not alarmed
@@ -102,155 +102,154 @@
         }
         #endregion
 
-        #region 鑾峰彇PIR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級.
-        ///<summary >
-        ///鑾峰彇PIR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級
-        /// <para>reserve:0-ff</para>
-        /// </summary>
-        public async System.Threading.Tasks.Task<PirLightAbilitySizeInfo> GetPIRLightAbilitySizeAsync(string reserve = "01")
-        {
-            PirLightAbilitySizeInfo result = null;
-            if (Gateway == null)
-            {
-                result = new PirLightAbilitySizeInfo { 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 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)
-                        {
-                            result = new PirLightAbilitySizeInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
-                        }
-
-                        else
-                        {
-                            result = new PirLightAbilitySizeInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
-                        }
-                    }
-
-                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
-                    {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
-
-                        if (gatewayTemp.clientDataPassthroughResponseData == null)
-                        {
-                            result = new PirLightAbilitySizeInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
-                        }
-                        else
-                        {
-                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
-                            {
-                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
-                                if (data.Length == 12)
+        #region 鑾峰彇PIR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級.
+        ///<summary >
+        ///鑾峰彇PIR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級
+        /// <para>reserve:0-ff</para>
+        /// </summary>
+        public async System.Threading.Tasks.Task<PirLightAbilitySizeInfo> GetPIRLightAbilitySizeAsync(string reserve = "01")
+        {
+            PirLightAbilitySizeInfo result = null;
+            if (Gateway == null)
+            {
+                result = new PirLightAbilitySizeInfo { 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 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)
+                        {
+                            result = new PirLightAbilitySizeInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+
+                        else
+                        {
+                            result = new PirLightAbilitySizeInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
+                    {
+                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
+                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+
+                        if (gatewayTemp.clientDataPassthroughResponseData == null)
+                        {
+                            result = new PirLightAbilitySizeInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
+                                if (data.Length == 12)
                                 {
-                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
-                                    if (command == "0304")
-                                    {
-                                        var cou = data[10].ToString() + data[11].ToString();
-                                        int countTemp = Convert.ToInt32(cou, 16);
-                                        LightLevelCount = countTemp;
+                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
+                                    if (command == "0304")
+                                    {
+                                        var cou = data[10].ToString() + data[11].ToString();
+                                        int countTemp = Convert.ToInt32(cou, 16);
+                                        LightLevelCount = countTemp;
                                         result = new PirLightAbilitySizeInfo { LightLevelCount = countTemp };
-                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0303_{ topic}");
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0303_{ topic}");
                                     }
-                                }
-                            }
-                        }
-                    }
-                };
-
-                Gateway.Actions += action;
-                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
-
-                try
-                {
-                    OpenPassthroughControl(Gateway);
-                    var passData = SendPIRLightAbilitySizeData(reserve);
-                    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 PirLightAbilitySizeInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
-                }
-                Gateway.Actions -= action;
-                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
-                return result;
-            });
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var passData = SendPIRLightAbilitySizeData(reserve);
+                    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 PirLightAbilitySizeInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        /// <summary>
+        /// 鍙戦�丳IR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級鏁版嵁
+        /// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para>
+        /// </summary>
+        string SendPIRLightAbilitySizeData(string reserve)
+        {
+            string data = "";
+            string dataLength = "05";
+            string dataComand1 = "03";
+            string dataComand2 = "03";
+            string dataSerialNum = "01";
+            string addDataLength = "01";
+            string reserveData = reserve;
+
+            try
+            {
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                    reserveData;
+            }
+            catch { };
+
+            return data;
         }
 
-        /// <summary>
-        /// 鍙戦�丳IR鍏夋劅绛夌骇锛堝厜鐓ц兘鍔涘�硷級鏁版嵁
-        /// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para>
-        /// </summary>
-        string SendPIRLightAbilitySizeData(string reserve)
-        {
-            string data = "";
-            string dataLength = "05";
-            string dataComand1 = "03";
-            string dataComand2 = "03";
-            string dataSerialNum = "01";
-            string addDataLength = "01";
-            string reserveData = reserve;
-
-            try
-            {
-                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
-                    reserveData;
-            }
-            catch { };
-
-            return data;
-        }
-
-        /// <summary>
-        /// PIR閰嶇疆鍙傛暟鍥炲
-        /// </summary>
-        public PirLightAbilitySizeInfo lightLevelSizeInfo;
-        [System.Serializable]
-        public class PirLightAbilitySizeInfo
-        {
-            /// <summary>
-            /// 閿欒淇℃伅
-            /// </summary>
-            public string errorMessageBase;
-            /// <summary>
-            /// 缃戝叧淇℃伅閿欒鍙嶉
-            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
-            /// </summary>
-            public ErrorResponData errorResponData;
-            /// <summary>
-            /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
-            /// <para>鏈夊嚑涓瓑绾у氨鏄剧ず鍑犱釜鍒诲害</para>
-            /// </summary>
-            public int LightLevelCount = -1;
-        }
-
-        #endregion
+        /// <summary>
+        /// PIR閰嶇疆鍙傛暟鍥炲
+        /// </summary>
+        public PirLightAbilitySizeInfo lightLevelSizeInfo;
+        [System.Serializable]
+        public class PirLightAbilitySizeInfo
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public ErrorResponData errorResponData;
+            /// <summary>
+            /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
+            /// <para>鏈夊嚑涓瓑绾у氨鏄剧ず鍑犱釜鍒诲害</para>
+            /// </summary>
+            public int LightLevelCount = -1;
+        }
+
+        #endregion
 
         #region PIR浼犳劅鍣ㄥ弬鏁伴厤缃�
         ///<summary >
@@ -298,36 +297,35 @@
                         }
                         else
                         {
-                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
-                            {
-                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
-                                if (data.Length == 16)
-                                {
-                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
-                                    if (command == "0002")
+                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = gatewayTemp.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 = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
+                                        tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                         tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                         result = new ResponseAllData { responseData = tempD };
-                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0300_{ topic}");
-                                    }
-                                }
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0300_{ topic}");
+                                    }
+                                }
                             }
                         }
                     }
-                };
-
-                Gateway.Actions += action;
-                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
 
                 try
                 {
-                    OpenPassthroughControl(Gateway);
                     var passData = SetPIRSensorData(configureParamates);
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                     var data = new JObject { { "PassData", passData } };
-                    jObject.Add("Data", data);
+                    jObject.Add("Data", data);
                     Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                 }
                 catch { }
@@ -372,13 +370,13 @@
             /// PIR閰嶇疆鍙傛暟
             /// </summary>
             public ConfigureParamates configureParamates;
-        }
-
-        /// <summary>
-        /// PIR閰嶇疆鍙傛暟
-        /// </summary>
-        public ConfigureParamates configureParamates;
-        /// <summary>
+        }
+
+        /// <summary>
+        /// PIR閰嶇疆鍙傛暟
+        /// </summary>
+        public ConfigureParamates configureParamates;
+        /// <summary>
         /// PIR閰嶇疆鍙傛暟
         /// </summary>
         [System.Serializable]
@@ -391,7 +389,7 @@
             /// </summary>
             public bool levelEnable;
             /// <summary>
-            /// 鍏夌収搴︾瓑绾�
+            /// 鍏夌収搴︾瓑绾�
             /// <para>鍊硷細0-10</para>
             /// </summary>
             public int levelSize = -1;
@@ -436,15 +434,15 @@
                     else
                     {
                         levelEnable = "00";
-                    }
-                    //鍏夌収绛夌骇
-                    if (configureParamates.levelSize > 0)
-                    {
-                        levelSize = configureParamates.levelSize.ToString().PadLeft(2, '0');
-                    }
-                    else
-                    {
-                        levelSize = "00";
+                    }
+                    //鍏夌収绛夌骇
+                    if (configureParamates.levelSize > 0)
+                    {
+                        levelSize = configureParamates.levelSize.ToString().PadLeft(2, '0');
+                    }
+                    else
+                    {
+                        levelSize = "00";
                     }
 
                     if (configureParamates.controlDevEnable)
@@ -455,22 +453,22 @@
                     {
                         controlDevEnable = "00";
                     }
-
-                    var tempBytes = new byte[2];
-                    for (int i = 0; i < 2; i++)
-                    {
-                        tempBytes[i] = (byte)(configureParamates.transitionTime >> (i * 8) & 0xff);
+
+                    var tempBytes = new byte[2];
+                    for (int i = 0; i < 2; i++)
+                    {
+                        tempBytes[i] = (byte)(configureParamates.transitionTime >> (i * 8) & 0xff);
                     }
-                    var time1 = Convert.ToString(tempBytes[0], 16);
-                    var time2 = Convert.ToString(tempBytes[1], 16);
-                    if (time1.Length == 1)
-                    {
-                        time1 = "0" + time1;
-                    }
-                    if (time2.Length == 1)
-                    {
-                        time2 = "0" + time2;
-                    }
+                    var time1 = Convert.ToString(tempBytes[0], 16);
+                    var time2 = Convert.ToString(tempBytes[1], 16);
+                    if (time1.Length == 1)
+                    {
+                        time1 = "0" + time1;
+                    }
+                    if (time2.Length == 1)
+                    {
+                        time2 = "0" + time2;
+                    }
                     transitionTime = (time1 + time2).ToUpper();
                 }
 
@@ -534,57 +532,56 @@
                             {
                                 var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                 if (data.Length == 20)
-                                {
-                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
-                                    if (command == "0302")
-                                    {
-                                        var le = data[10].ToString() + data[11].ToString();
-                                        var tempD = new ConfigureParamates();
-
-                                        if (le == "01")
-                                        {
-                                            tempD.levelEnable = true;
-                                        }
-                                        else
-                                        {
-                                            tempD.levelEnable = false;
-                                        }
-
-                                        var size = data[12].ToString() + data[13].ToString();
-                                        tempD.levelSize = Convert.ToInt32(size);
-
-                                        var cdl = data[14].ToString() + data[15].ToString();
-                                        if (cdl == "01")
-                                        {
-                                            tempD.controlDevEnable = true;
-                                        }
-                                        else
-                                        {
-                                            tempD.controlDevEnable = false;
-                                        }
-
-                                        tempD.transitionTime = Convert.ToInt32(data[18].ToString() + data[19].ToString() + data[16].ToString() + data[17].ToString(), 16);
-                                        configureParamates = tempD;
+                                {
+                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
+                                    if (command == "0302")
+                                    {
+                                        var le = data[10].ToString() + data[11].ToString();
+                                        var tempD = new ConfigureParamates();
+
+                                        if (le == "01")
+                                        {
+                                            tempD.levelEnable = true;
+                                        }
+                                        else
+                                        {
+                                            tempD.levelEnable = false;
+                                        }
+
+                                        var size = data[12].ToString() + data[13].ToString();
+                                        tempD.levelSize = Convert.ToInt32(size);
+
+                                        var cdl = data[14].ToString() + data[15].ToString();
+                                        if (cdl == "01")
+                                        {
+                                            tempD.controlDevEnable = true;
+                                        }
+                                        else
+                                        {
+                                            tempD.controlDevEnable = false;
+                                        }
+
+                                        tempD.transitionTime = Convert.ToInt32(data[18].ToString() + data[19].ToString() + data[16].ToString() + data[17].ToString(), 16);
+                                        configureParamates = tempD;
                                         result = new ParamatesInfo { configureParamates = tempD };
-                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0301_{ topic}");
-
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0301_{ topic}");
+
                                     }
                                 }
                             }
                         }
                     }
-                };
+                };
 
                 Gateway.Actions += action;
-                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
 
                 try
-                {
-                    OpenPassthroughControl(Gateway);
+                {
                     var passData = GetPIRSensorData(reserve);
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                     var data = new JObject { { "PassData", passData } };
-                    jObject.Add("Data", data);
+                    jObject.Add("Data", data);
                     Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                 }
                 catch { }
@@ -633,7 +630,7 @@
             return data;
         }
         #endregion
-
+
 
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0