From c1de48884fa145a16a0f8bcee93274dcfaa0ff82 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 07 五月 2020 10:40:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-2020xm

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

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs
new file mode 100755
index 0000000..65da172
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/IASZone.cs
@@ -0,0 +1,911 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+
+namespace ZigBee.Device
+{
+    [System.Serializable]
+    public class IASZone : BindObj
+    {
+        public IASZone()
+        {
+            this.Type = DeviceType.IASZone;
+        }
+        /// <summary>
+        /// 鍏夋劅绛夌骇涓暟锛圠ux鑳藉姏锛�
+        /// <para>鏈夊嚑涓瓑绾у氨鏄剧ず鍑犱釜鍒诲害</para>
+        /// </summary>
+        public int LightLevelCount = -1;
+
+        /// <summary>
+        /// 褰撳墠Lux鍊� 
+        /// </summary>
+        public int PirLux = -1;
+
+        #region IAS瀹夐槻淇℃伅涓婃姤.
+        /// <summary>
+        /// IAS瀹夐槻淇℃伅涓婃姤
+        /// <para>褰撳畨闃茶澶囧睘鎬х姸鎬佹敼鍙樻椂鍊欙紙渚嬪涓�姘у寲纰充紶鎰熷櫒妫�娴嬪埌涓�姘у寲纰虫皵浣擄級锛岃澶囧皢涓婃姤灞炴�х姸鎬佸彉鍖栨暟鎹��</para>
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public IASInfoData iASInfo;
+        /// <summary>
+        /// IAS瀹夐槻淇℃伅涓婃姤
+        /// <para>褰撳畨闃茶澶囧睘鎬х姸鎬佹敼鍙樻椂鍊欙紙渚嬪涓�姘у寲纰充紶鎰熷櫒妫�娴嬪埌涓�姘у寲纰虫皵浣擄級锛岃澶囧皢涓婃姤灞炴�х姸鎬佸彉鍖栨暟鎹��</para>
+        /// </summary>
+        [System.Serializable]
+        public class IASInfoData
+        {
+            /// <summary>
+            ///璁惧鐘舵�侊紙锛�
+            /// <para>涓嬮潰鐨� Alarm1鍒癇atteryDefect瀹炲垯鏄ZoneStatus浜岃繘鍒舵牸寮忕殑瑙f瀽</para>
+            /// </summary>
+            public int ZoneStatus;
+            /// <summary>
+            ///鑷畾涔夎澶囩姸鎬�
+            /// </summary>
+            public int ExtendedStatus;
+            /// <summary>
+            ///鍖哄煙ID
+            /// </summary>
+            public int ZoneId;
+            /// <summary>
+            ///鍦ㄨ澶囩姸鎬佹敼鍙樹箣鍚庡欢鏃禗elay(鍗曚綅锛�1/4绉�)
+            /// </summary>
+            public int Delay;
+            /// <summary>
+            /// hdl
+            ///1 - opened or alarmed
+            ///0 - closed or not alarmed
+            /// </summary>
+            public int Alarm1;
+            /// <summary>
+            ///1 - opened or alarmed
+            ///0 - closed or not alarmed
+            /// </summary>
+            public int Alarm2;
+            /// <summary>
+            ///1 - Tampered
+            ///0 - Not tampered
+            /// </summary>
+            public int Tamper;
+            /// <summary>
+            ///1 - Low battery
+            ///0 - Battery OK
+            /// </summary>
+            public int Battery;
+            /// <summary>
+            ///1 - Reports
+            ///0 - Does not report
+            /// </summary>
+            public int SupervisionReports;
+            /// <summary>
+            ///1 - Reports restore
+            ///0 - Does not report restore
+            /// </summary>
+            public int RestoreReports;
+
+            /// <summary>
+            ///1 - Trouble/Failure
+            ///0 - OK
+            /// </summary>
+            public int Trouble;
+            /// <summary>
+            ///1 - AC/Mains fault
+            ///0 - AC/Mains OK
+            /// </summary>
+            public int MaAC_Mainsins;
+            /// <summary>
+            ///1 - Sensor is in test mode
+            ///0 - Sensor is operation mode
+            /// </summary>
+            public int Test;
+            /// <summary>
+            ///1 - Sensor detects a defective battery
+            ///0 - Sensor battery is functioning normally
+            /// </summary>
+            public int BatteryDefect;
+        }
+        #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)
+                                {
+                                    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}");
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+
+                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>
+        /// 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 >
+        ///PIR浼犳劅鍣ㄥ弬鏁伴厤缃�
+        /// </summary>
+        public async System.Threading.Tasks.Task<ResponseAllData> SetPIRSensorParamateAsync(ConfigureParamates configureParamates)
+        {
+            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 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 ResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+
+                        else
+                        {
+                            result = new ResponseAllData { 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 ResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        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")
+                                    {
+                                        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 == "0300")
+                                        {
+                                            result = new ResponseAllData { responseData = tempD };
+                                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0300_{ topic}");
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    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);
+                    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>
+        /// PIR閰嶇疆鍙傛暟鍥炲
+        /// </summary>
+        public ParamatesInfo paramatesInfo;
+        [System.Serializable]
+        public class ParamatesInfo
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public ErrorResponData errorResponData;
+            /// <summary>
+            /// PIR閰嶇疆鍙傛暟
+            /// </summary>
+            public ConfigureParamates configureParamates;
+        }
+
+        /// <summary>
+        /// PIR閰嶇疆鍙傛暟
+        /// </summary>
+        public ConfigureParamates configureParamates;
+        /// <summary>
+        /// PIR閰嶇疆鍙傛暟
+        /// </summary>
+        [System.Serializable]
+        public class ConfigureParamates
+        {
+            /// <summary>
+            /// 浜害锛堝厜鐓у害锛変娇鑳�
+            /// <para> false锛�0锛�:涓嶄娇鑳�</para>
+            /// <para>true锛�1锛�:浣胯兘</para>
+            /// </summary>
+            public bool levelEnable;
+            /// <summary>
+            /// 鍏夌収搴︾瓑绾�
+            /// <para>鍊硷細0-10</para>
+            /// </summary>
+            public int levelSize = -1;
+            /// <summary>
+            ///鎺у埗璁惧浣胯兘浣�
+            ///<para> false锛�0锛�:涓嶄娇鑳�</para>
+            /// <para>true锛�1锛�:浣胯兘</para>
+            /// </summary>
+            public bool controlDevEnable;
+            /// <summary>
+            /// 瑙﹀彂寮�鐏埌瑙﹀彂鍏崇伅鐨勬椂闂撮棿闅�
+            /// <para>0-65535 鍗曚綅绉�</para>
+            /// </summary>
+            public int transitionTime;
+            /// <summary>
+            /// IAS涓婃姤鍛ㄦ湡
+            /// <para>10-0xffff 绉�</para>
+            /// </summary>
+            public int iasReportPeriod;
+            /// <summary>
+            /// 鍏夌収搴︾瓑绾�
+            /// <para>0锛氬崐鑷姩妯″紡</para>
+            /// <para>1锛氳嚜鍔ㄦā寮�</para>
+            /// </summary>
+            public int mode = 0;
+            /// <summary>
+            /// 寮�鐏被鍨�
+            /// <para>鍊硷細0锛氳皟鍏�</para>
+            ///<para>1锛氬紑鍏� </para>
+            /// </summary>
+            public int type = 0;
+            /// <summary>
+            /// 璋冨厜妯″紡锛屽埌杈惧紑鐏寒搴︾殑鏃堕棿
+            /// <para>鍊硷細0-10 绉�</para>
+            /// </summary>
+            public int dimmerOnTime = 0;
+            /// <summary>
+            /// 璋冨厜妯″紡锛屽叧鐏埌杈�0%鎵�闇�瑕佺殑鏃堕棿
+            /// <para>鍊硷細0-10 绉�</para>
+            /// </summary>
+            public int dimmerOffTime = 0;
+            /// <summary>
+            /// 璋冨厜妯″紡寮�鐏殑浜害
+            /// <para>0-0xff 锛堥鐣欙級</para>
+            /// </summary>
+            public int dimmerLevel = 0;
+        }
+
+        /// <summary>
+        /// 閰嶇疆PIR閰嶇疆鍙傛暟
+        /// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para>
+        /// </summary>
+        string SetPIRSensorData(ConfigureParamates configureParamates)
+        {
+            string data = "";
+            string dataLength = "10";
+            string dataComand1 = "00";
+            string dataComand2 = "03";
+            string dataSerialNum = "01";
+            string addDataLength = "0C";
+            string levelEnable = "";
+            string levelSize = "";
+            string controlDevEnable = "";
+            string transitionTime = "";
+            string iasReportPeriod = "";
+            string mode = "";
+            string type = "";
+            string dimmerOnTime = "";
+            string dimmerOffTime = "";
+            string dimmerLevel = "";
+            try
+            {
+                if (configureParamates != null)
+                {
+                    //levelEnable
+                    if (configureParamates.levelEnable)
+                    {
+                        levelEnable = "01";
+                    }
+                    else
+                    {
+                        levelEnable = "00";
+                    }
+                    //鍏夌収绛夌骇
+                    if (configureParamates.levelSize > 0)
+                    {
+                        var tempLevelEnable = Convert.ToString(configureParamates.levelSize, 16);
+                        levelSize = tempLevelEnable.ToString().PadLeft(2, '0');
+                    }
+                    else
+                    {
+                        levelSize = "00";
+                    }
+                    //controlDevEnable
+                    if (configureParamates.controlDevEnable)
+                    {
+                        controlDevEnable = "01";
+                    }
+                    else
+                    {
+                        controlDevEnable = "00";
+                    }
+                    //transitionTime,iasReportPeriod
+                    for (int j = 0; j < 2; j++)
+                    {
+                        var tempBytes = new byte[2];
+                        if (j == 0)
+                        {
+                            for (int i = 0; i < 2; i++)
+                            {
+                                tempBytes[i] = (byte)(configureParamates.transitionTime >> (i * 8) & 0xff);
+                            }
+                        }
+                        else
+                        {
+                            for (int i = 0; i < 2; i++)
+                            {
+                                tempBytes[i] = (byte)(configureParamates.iasReportPeriod >> (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;
+                        }
+                        if (j == 0)
+                        {
+                            transitionTime = (time1 + time2).ToUpper();
+
+                        }
+                        else
+                        {
+                            iasReportPeriod = (time1 + time2).ToUpper();
+                        }
+                    }
+                    //mode
+                    if (configureParamates.mode == 1)
+                    {
+                        mode = "01";
+                    }
+                    else
+                    {
+                        mode = "00";
+                    }
+                    //type
+                    if (configureParamates.type == 1)
+                    {
+                        type = "01";
+                    }
+                    else
+                    {
+                        type = "00";
+                    }
+                    //dimmerOnTime
+                    if (configureParamates.dimmerOnTime > 0)
+                    {
+                        var tempDimmerOnTime = Convert.ToString(configureParamates.dimmerOnTime, 16);
+                        dimmerOnTime = tempDimmerOnTime.ToString().PadLeft(2, '0');
+                    }
+                    else
+                    {
+                        dimmerOnTime = "00";
+                    }
+                    dimmerOnTime = dimmerOnTime.ToUpper();
+                    if (configureParamates.dimmerOffTime > 0)
+                    {
+                        var tempDimmerOffTime = Convert.ToString(configureParamates.dimmerOffTime, 16);
+                        dimmerOffTime = tempDimmerOffTime.ToString().PadLeft(2, '0');
+                    }
+                    else
+                    {
+                        dimmerOffTime = "00";
+                    }
+                    dimmerOffTime = dimmerOffTime.ToUpper();
+                    //dimmerLevel 
+                    string temp = "";
+                    var sbString = new System.Text.StringBuilder();
+                    string temp2 = Convert.ToString(configureParamates.dimmerLevel, 16);
+                    switch (temp2.Length)
+                    {
+                        case 1:
+                            temp = "0" + temp2;
+                            break;
+                        case 2:
+                            temp = temp2;
+                            break;
+                    }
+                    sbString.Append(temp.ToUpper());
+
+                    data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                    levelEnable + levelSize + controlDevEnable + transitionTime + iasReportPeriod
+                    + mode + type + dimmerOnTime + dimmerOffTime + sbString;
+                }
+            }
+            catch { };
+
+            return data;
+        }
+        #endregion
+
+        #region 鑾峰彇PIR閰嶇疆鏁版嵁
+        ///<summary >
+        ///PIR浼犳劅鍣ㄥ弬鏁伴厤缃�
+        /// <para>reserve:0-ff</para>
+        /// </summary>
+        public async System.Threading.Tasks.Task<ParamatesInfo> GetPIRSensorParamateAsync(string reserve = "01")
+        {
+            ParamatesInfo result = null;
+            if (Gateway == null)
+            {
+                result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+
+                        else
+                        {
+                            result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
+                                if (data.Length == 34)
+                                {
+                                    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, 16);
+
+                                        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);
+                                        tempD.iasReportPeriod = Convert.ToInt32(data[22].ToString() + data[23].ToString() + data[20].ToString() + data[21].ToString(), 16);
+                                        tempD.mode = Convert.ToInt32(data[24].ToString() + data[25].ToString(), 16);
+                                        tempD.type = Convert.ToInt32(data[26].ToString() + data[27].ToString(), 16);
+                                        tempD.dimmerOnTime = Convert.ToInt32(data[28].ToString() + data[29].ToString(), 16);
+                                        tempD.dimmerOffTime = Convert.ToInt32(data[30].ToString() + data[31].ToString(), 16);
+                                        tempD.dimmerLevel = Convert.ToInt32(data[32].ToString() + data[33].ToString(), 16);
+
+                                        configureParamates = tempD;
+                                        result = new ParamatesInfo { configureParamates = tempD };
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0301_{ topic}");
+
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    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);
+                    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 ParamatesInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        /// <summary>
+        ///PIR鍏夌収鑳藉姏鍊�
+        /// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para>
+        /// </summary>
+        string GetPIRSensorData(string reserve)
+        {
+            string data = "";
+            string dataLength = "05";
+            string dataComand1 = "01";
+            string dataComand2 = "03";
+            string dataSerialNum = "01";
+            string addDataLength = "01";
+            string reserveData = reserve;
+
+            try
+            {
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                    reserveData;
+            }
+            catch { };
+
+            return data;
+        }
+        #endregion
+
+        #region 鑾峰彇PIR lux鍊硷紙Lux鍊硷級
+        ///<summary >
+        ///鑾峰彇PIR lux鍊硷紙Lux鍊硷級
+        /// <para>reserve:0-ff</para>
+        /// </summary>
+        public async System.Threading.Tasks.Task<PirLuxAbilitySizeInfo> GetPirLuxAbilitySizeAsync(string reserve = "01")
+        {
+            PirLuxAbilitySizeInfo result = null;
+            if (Gateway == null)
+            {
+                result = new PirLuxAbilitySizeInfo { 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 PirLuxAbilitySizeInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+
+                        else
+                        {
+                            result = new PirLuxAbilitySizeInfo { 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 PirLuxAbilitySizeInfo { 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 == "0306")
+                                    {
+                                        var cou = data[10].ToString() + data[11].ToString();
+                                        int countTemp = Convert.ToInt32(cou, 16);
+                                        PirLux = countTemp;
+                                        result = new PirLuxAbilitySizeInfo { pirLux = countTemp };
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0303_{ topic}");
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var passData = SendPIRLuxAbilitySizeData(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 PirLuxAbilitySizeInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        /// <summary>
+        ///鑾峰彇PIR lux鍊�
+        /// </summary>
+        string SendPIRLuxAbilitySizeData(string reserve)
+        {
+            string data = "";
+            string dataLength = "05";
+            string dataComand1 = "05";
+            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 PirLuxAbilitySizeInfo pirLuxAbilitySizeInfo;
+        [System.Serializable]
+        public class PirLuxAbilitySizeInfo
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public ErrorResponData errorResponData;
+            /// <summary>
+            /// 褰撳墠Lux鍊� 
+            /// <para>0-0xff Lux</para>
+            /// </summary>
+            public int pirLux = -1;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0