陈嘉乐
2020-07-10 48ba446936b51fffafa7c3600c0dadc6ac0e8c20
ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MQTTnet;
using Newtonsoft.Json.Linq;
using Shared.Common;
namespace ZigBee.Device
{
@@ -15,25 +17,107 @@
        /// <summary>
        /// 按键模式(私有功能)
        /// </summary>
        public int panelMode = -1;
        /// <summary>
        ///按键开状态(指示)亮度
        /// </summary>
        public int panelDirectionsLevel = -1;
        public int panelMode = 65535;
        /// <summary>
        /// 按键关状态(背光)亮度
        /// 当前选择模式
        /// </summary>
        public int panelBacklightLevel = -1;
        [Newtonsoft.Json.JsonIgnore]
        public string currentKeySelectModeText = "";
        /// <summary>
        /// 当前选择的楼层ID
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string currentSelectFloorId = string.Empty;
        /// <summary>
        /// 当前选择的房间ID【新风面板】
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string currentSelectRoomId = string.Empty;
        /// <summary>
        /// 绑定的楼层房间信息
        /// </summary>
        [System.Serializable]
        public class FloorRoomBindObj
        {
            /// <summary>
            /// 楼层ID
            /// </summary>
            public string floodID;
            /// <summary>
            /// 楼层名称
            /// </summary>
            public string floodName;
            /// <summary>
            /// 房间ID
            /// </summary>
            public string roomID;
            /// <summary>
            /// 房间名称
            /// </summary>
            public string roomName;
            /// <summary>
            /// 绑定目标ID
            /// </summary>
            public string BindID;
            /// <summary>
            /// 绑定目标名称
            /// </summary>
            public string BindName;
            /// <summary>
            /// 图片路径
            /// </summary>
            public string IconPath = "";
        }
        // <summary>
        /// 按键中被绑定的目标列表
        /// </summary>
        public System.Collections.Generic.List<BindListResponseObj> bindList = new System.Collections.Generic.List<BindListResponseObj> { };
        [Newtonsoft.Json.JsonIgnore]
        public List<BindListResponseObj> bindList = new List<BindListResponseObj>();
        /// <summary>
        /// 按键支持的私有模式列表
        /// 私有功能类
        /// <para>256:Key,按键类类 </para>
        /// <para>768:PIR,PIR类</para>
        /// <para>1024:Light,灯类</para>
        /// </summary>
        public System.Collections.Generic.List<string> priFunList = new System.Collections.Generic.List<string> { };
        public List<int> privateFuncFirstLevelList = new List<int>();
        /// <summary>
        /// 第二级信息
        /// <para>1:特殊功能</para>
        /// <para>100:Switch,开关(按键类)</para>
        /// <para>200:Dimmer,调光(按键类)</para>
        /// <para>300:Curtain,窗帘(按键类)</para>
        /// <para>0:EnergySavingMode,节能模式(灯类)</para>
        /// <para>1:SleepMode,睡眠模式(灯类)</para>
        /// <para>100:WhiteBalance,白平衡(灯类)</para>
        /// <para>101:RGBColor,RGB指示灯颜色(灯类)</para>
        /// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
        /// </summary>
        public List<int> privateFuncSecondLevelList = new List<int>();
        /// <summary>
        /// 第三级信息
        /// <para>1:场景触发(特殊功能)</para>
        /// <para>65535:禁止发送功能(特殊功能)</para>
        /// <para>100:SwitchOpen,开关开(按键类)</para>
        /// <para>101:SwitchClose,开关关(按键类)</para>
        /// <para>102:SwitchChange,开关切换(按键类)</para>
        /// <para>200:DimmerStepUp,增大调光(按键类)</para>
        /// <para>201:DimmerStepDown,降低调光(按键类)</para>
        /// <para>202:DimmerStepChange,调光切换(按键类)</para>
        /// <para>300:CurtainOpen,窗帘开(按键类)</para>
        /// <para>301:CurtainClose,窗帘关(按键类)</para>
        /// <para>302:CurtainStop,窗帘停</para>
        /// <para>303:CurtainUpStop,窗帘上升停</para>
        /// <para>304:CurtainDownstop,窗帘下降停</para>
        /// </summary>
        public List<int> privateFuncThirdLevelList = new List<int>();
        #region 获取面板的私有信息.
        /// <summary>
        ///获取面板的私有信息
@@ -67,8 +151,7 @@
                    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());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -83,18 +166,17 @@
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        if (clientDataPassthroughResponseData == null)
                        {
                            result = new PanelPrivateFunctionsResponseAllInfo { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                var data = clientDataPassthroughResponseData.PassData;
                                if (data.Length > 12)
                                {
@@ -120,6 +202,11 @@
                                                {
                                                    int curIndex = 4 * j;
                                                    tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                    //if (privateFuncFirstLevelList.Contains(256) == false)
                                                    //{
                                                    //    privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                    //}
                                                }
                                                break;
                                            case 2:
@@ -134,12 +221,19 @@
                                                    if (j == 0)
                                                    {
                                                        tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //if (privateFuncFirstLevelList.Contains(256) == false)
                                                        //{
                                                        //    privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //}
                                                    }
                                                    else
                                                    {
                                                        tempD.privateFuncTypeLevelSecondList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //if (privateFuncSecondLevelList.Contains(1) == false || privateFuncSecondLevelList.Contains(100) == false || privateFuncSecondLevelList.Contains(200) == false || privateFuncSecondLevelList.Contains(300) == false)
                                                        //{
                                                        //    privateFuncSecondLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //}
                                                    }
                                                }
                                                break;
                                            case 3:
@@ -154,19 +248,30 @@
                                                    if (j == 0)
                                                    {
                                                        tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //if (privateFuncFirstLevelList.Contains(256) == false)
                                                        //{
                                                        //    privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //}
                                                    }
                                                    else if (j == 1)
                                                    {
                                                        tempD.privateFuncTypeLevelSecondList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //if (privateFuncSecondLevelList.Contains(1) == false || privateFuncSecondLevelList.Contains(100) == false || privateFuncSecondLevelList.Contains(200) == false || privateFuncSecondLevelList.Contains(300) == false)
                                                        //{
                                                        //    privateFuncSecondLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //}
                                                    }
                                                    else
                                                    {
                                                        tempD.privateFuncTypeLevelThirdList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
                                                        //if (privateFuncThirdLevelList.Contains(1) == false || privateFuncThirdLevelList.Contains(65535) == false || privateFuncThirdLevelList.Contains(100) == false || privateFuncThirdLevelList.Contains(101) == false || privateFuncThirdLevelList.Contains(102) == false || privateFuncThirdLevelList.Contains(200) == false || privateFuncThirdLevelList.Contains(201) == false || privateFuncThirdLevelList.Contains(202) == false || privateFuncThirdLevelList.Contains(300) == false || privateFuncThirdLevelList.Contains(301) == false || privateFuncThirdLevelList.Contains(302) == false || privateFuncThirdLevelList.Contains(303) == false || privateFuncThirdLevelList.Contains(304) == false)
                                                        //{
                                                        //    privateFuncThirdLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16)); ;
                                                        //}
                                                    }
                                                }
                                                break;
                                        }
                                        panelPrivateFunctionsResponseInfo = tempD;
                                        result = new PanelPrivateFunctionsResponseAllInfo { panelPrivateFunctionsResponseInfo = tempD };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0003_{topic}");
                                    }
@@ -181,11 +286,10 @@
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SendPanelPrivateFunctions(args);
                    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 { }
@@ -214,17 +318,8 @@
        /// PIR配置参数回复
        /// </summary>
        [System.Serializable]
        public class PanelPrivateFunctionsResponseAllInfo
        public class PanelPrivateFunctionsResponseAllInfo:ErrorResponCommon
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 光感等级个数(Lux能力)
            /// <para>有几个等级就显示几个刻度</para>
@@ -233,9 +328,8 @@
        }
        /// <summary>
        /// PIR配置参数回复
        /// 配置参数回复
        /// </summary>
        public PanelPrivateFunctionsResponseInfo panelPrivateFunctionsResponseInfo;
        [System.Serializable]
        public class PanelPrivateFunctionsResponseInfo
        {
@@ -245,8 +339,8 @@
            /// <para>2:第二级别</para>
            /// <para>3:第三级别</para>
            /// </summary>
            public int funLevel = -1;
            public int funLevel = -1;
            /// <summary>
            /// 私有功能类
            /// <para>256:Key,按键类类 </para>
@@ -285,8 +379,8 @@
            /// <para>303:CurtainUpStop,窗帘上升停</para>
            /// <para>304:CurtainDownstop,窗帘下降停</para>
            /// </summary>
            public List<int> privateFuncTypeLevelThirdList = new List<int>();
            public List<int> privateFuncTypeLevelThirdList = new List<int>();
        }
        /// <summary>
@@ -306,7 +400,7 @@
            string addDataLength = "";
            string value0 = "";
            string value1 = "";
            string value2 = "";
            string value2 = "";
            try
            {
@@ -316,18 +410,18 @@
                    {
                        dataLength = string.Concat(0, 2 * args.Length + 5);
                    }
                    else
                    {
                    else
                    {
                        dataLength = Convert.ToString(2 * args.Length + 5, 16);
                    }
                    }
                    if (Convert.ToString(2 * args.Length, 16).Length == 1)
                    {
                        addDataLength = string.Concat(0, 2 * args.Length + 1);
                    }
                    else
                    {
                    {
                        addDataLength = Convert.ToString(2 * args.Length + 1, 16);
                    }
@@ -336,7 +430,7 @@
                        switch (args.Length)
                        {
                            case 1:
                                value0 = "02";
                                value0 = "02";
                                switch (args[0])
                                {
                                    case 1024:
@@ -396,15 +490,15 @@
                                    case 768:
                                        value1 = "0003";
                                        break;
                                }
                                break;
                        }
                                }
                                break;
                        }
                    }
                }
                else
                {
                }
                else
                {
                    dataLength = "05";
                    addDataLength = "01";
                    value0 = "01";
@@ -412,8 +506,8 @@
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                        value0 + value1 + value2;
            }
            catch { };
            catch { };
            return data;
        }
@@ -428,7 +522,7 @@
            /// <para>768:PIR,PIR类</para>
            /// <para>1024:Light,灯类</para>
            /// </summary>
            public int privateFuncTypeOne;
            public int privateFuncTypeOne;
        }
        /// <summary>
@@ -448,8 +542,8 @@
            /// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
            /// </summary>
            public int privateFuncTypeTwo;
        }
        }
        /// <summary>
        /// 私有功能类(第三级别)信息
        /// </summary>
@@ -488,6 +582,7 @@
            {
                return null;
            }
            return result.panelPrivateFunctionsResponseInfo.privateFuncTypeLevelFirstList;
        }
@@ -567,8 +662,7 @@
                    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());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -583,28 +677,31 @@
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        if (clientDataPassthroughResponseData == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                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 = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                        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);
                                        result = new ResponseAllData { responseData = tempD };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}");
                                        if (tempD.command == "0400")
                                        {
                                            result = new ResponseAllData { responseData = tempD };
                                            System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}");
                                        }
                                    }
                                }
                            }
@@ -617,11 +714,10 @@
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = ControlKeyData(keyNum, keyStatus);
                    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 { }
@@ -677,7 +773,6 @@
            string dataSerialNum = "01";
            string addDataLength = "03";
            string kStatus = "";
            string kNum = "";
            int attributeData = 0;
            try
@@ -697,8 +792,8 @@
                string td = attributeData.ToString("X4");
                char[] td1 = td.ToCharArray();
                string tempAttributeData = string.Concat(td1[2].ToString(), td1[3].ToString(), td1[0].ToString(), td1[1].ToString());
                string tempAttributeData = string.Concat(td1[2].ToString(), td1[3].ToString(), td1[0].ToString(), td1[1].ToString());
                switch (keyStatus)
                {
                    case KeyStatus.close:
@@ -723,103 +818,6 @@
        #endregion
        #region 配置按键指示灯颜色.
        ///<summary >
        ///配置按键指示灯颜色
        /// </summary>
        public async System.Threading.Tasks.Task<ResponseAllData> SetPanelColorInfoAsync(KeyColorData keyColorData, KeyNumStatus keyNumStatus)
        {
            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 = 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:0401_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SetPanelColorData(keyColorData, keyNumStatus);
                    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>
        /// 绑定设备信息,网关反馈信息
@@ -842,136 +840,6 @@
            public KeyColorData keyColorData;
        }
        /// <summary>
        /// 配置按键指示灯颜色数据
        /// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para>
        /// </summary>
        /// <returns>The passthorugh data.</returns>
        /// <param name="keyColorData">Key color data.</param>
        /// <param name="keyNum">Key number.</param>
        string SetPanelColorData(KeyColorData keyColorData, KeyNumStatus keyNumStatus)
        {
            string data = "";
            string dataLength = "0c";
            string dataComand1 = "01";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "08";
            int attributeData = 0;
            try
            {
                for (int i = 1; i <= 16; i++)
                {
                    Type type = keyNumStatus.GetType();
                    var obj = type.InvokeMember("Key" + i, System.Reflection.BindingFlags.GetField, null, keyNumStatus, null);
                    int value0 = 0;
                    if (Convert.ToBoolean(obj) == true)
                    {
                        value0 = 1;
                    }
                    int v = (int)Math.Pow(2, i - 1);
                    attributeData += value0 * v;
                }
                string td = attributeData.ToString("X4");
                char[] td1 = td.ToCharArray();
                string tempAttributeData = string.Concat(td1[2].ToString(), td1[3].ToString(), td1[0].ToString(), td1[1].ToString());
                string temp = "";
                var tempColor1 = keyColorData.OpenColorR.ToString();
                var sbString1 = new System.Text.StringBuilder();
                switch (tempColor1.Length)
                {
                    case 1:
                        temp = "0" + tempColor1;
                        break;
                    case 2:
                        temp = tempColor1;
                        break;
                }
                sbString1.Append(temp.ToUpper());
                var tempColor2 = keyColorData.OpenColorG.ToString();
                var sbString2 = new System.Text.StringBuilder();
                switch (tempColor2.Length)
                {
                    case 1:
                        temp = "0" + tempColor2;
                        break;
                    case 2:
                        temp = tempColor2;
                        break;
                }
                sbString2.Append(temp.ToUpper());
                var tempColor3 = keyColorData.OpenColorB.ToString();
                var sbString3 = new System.Text.StringBuilder();
                switch (tempColor3.Length)
                {
                    case 1:
                        temp = "0" + tempColor3;
                        break;
                    case 2:
                        temp = tempColor3;
                        break;
                }
                sbString3.Append(temp.ToUpper());
                var tempColor4 = keyColorData.CloseColorR.ToString();
                var sbString4 = new System.Text.StringBuilder();
                switch (tempColor3.Length)
                {
                    case 1:
                        temp = "0" + tempColor4;
                        break;
                    case 2:
                        temp = tempColor4;
                        break;
                }
                sbString4.Append(temp.ToUpper());
                var tempColor5 = keyColorData.CloseColorG.ToString();
                var sbString5 = new System.Text.StringBuilder();
                switch (tempColor5.Length)
                {
                    case 1:
                        temp = "0" + tempColor5;
                        break;
                    case 2:
                        temp = tempColor5;
                        break;
                }
                sbString5.Append(temp.ToUpper());
                var tempColor6 = keyColorData.CloseColorB.ToString();
                var sbString6 = new System.Text.StringBuilder();
                switch (tempColor6.Length)
                {
                    case 1:
                        temp = "0" + tempColor6;
                        break;
                    case 2:
                        temp = tempColor6;
                        break;
                }
                sbString6.Append(temp.ToUpper());
                if (keyColorData != null)
                {
                    data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                           tempAttributeData + sbString1 + sbString2 + sbString3 +
                           sbString4 + sbString5 + sbString6;
                }
            }
            catch { };
            return data;
        }
        /// <summary>
        /// 按键指示灯颜色信息
        /// </summary>
        public KeyColorData keyColorData;
        // <summary>
        /// 按键指示灯颜色信息
        /// </summary>
@@ -1096,13 +964,12 @@
        }
        #endregion
        #region 配置按键指示灯面板亮度属性.
        #region  配置接近传感
        ///<summary >
        ///配置按键指示灯面板亮度属性
        /// <para>directionsLevel:指示灯亮度 0-100</para>
        /// <para>backlightLevel:背光灯亮度 0-100</para>
        /// 配置接近传感
        /// <para>sensorEnable:传感器使能</para>
        /// </summary>
        public async System.Threading.Tasks.Task<ResponseAllData> SetKeyLevelAsync(int directionsLevel, int backlightLevel)
        public async System.Threading.Tasks.Task<ResponseAllData> SetProximitySensor(bool sensorEnable)
        {
            ResponseAllData result = null;
            if (Gateway == null)
@@ -1119,8 +986,7 @@
                    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());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -1132,30 +998,33 @@
                            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());
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        if (clientDataPassthroughResponseData == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                        {
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                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 = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                        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);
                                        result = new ResponseAllData { responseData = tempD };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0402_{ topic}");
                                        if (tempD.command == "0500")
                                        {
                                            result = new ResponseAllData { responseData = tempD };
                                            DebugPrintLog($"UI收到通知后的主题_command:0500_{ topic}");
                                        }
                                    }
                                }
                            }
@@ -1168,8 +1037,7 @@
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SetPanelLevelData(directionsLevel, backlightLevel);
                    var passData = SetProximitySensorData(sensorEnable);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
@@ -1198,209 +1066,33 @@
        }
        /// <summary>
        /// 控制按键指示灯
        /// 配置接近传感
        /// [该条协议另外2个参数UI和设备都不需要,设备都同事要求传感器距离和传感器触发延迟时间都默认是FFFF]
        /// </summary>
        string SetPanelLevelData(int level1, int level2)
        /// <param name="sensorEnable">传感器使能  0-disable  1-enable</param>
        /// <returns></returns>
        string SetProximitySensorData(bool sensorEnable)
        {
            string data = "";
            string dataLength = "06";
            string dataComand1 = "02";
            string dataComand2 = "04";
            string dataLength = "09";
            string dataComand1 = "00";
            string dataComand2 = "05";
            string dataSerialNum = "01";
            string addDataLength = "02";
            string l1 = "";
            string l2 = "";
            string addDataLength = "05";
            string sEnable = "";
            try
            {
                var sbString1 = new System.Text.StringBuilder();
                var sbString2 = new System.Text.StringBuilder();
                string temp1 = Convert.ToString(level1, 16);
                string temp2 = Convert.ToString(level2, 16);
                switch (temp1.Length)
                if (sensorEnable)
                {
                    case 1:
                        l1 = "0" + temp1;
                        break;
                    case 2:
                        l1 = temp1;
                        break;
                }
                switch (temp2.Length)
                {
                    case 1:
                        l2 = "0" + temp2;
                        break;
                    case 2:
                        l2 = temp2;
                        break;
                }
                sbString1.Append(l1.ToString().ToUpper());
                sbString2.Append(l2.ToString().ToUpper());
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                    sbString1 + sbString2;
            }
            catch { };
            return data;
        }
        #endregion
        #region  配置按键指示灯面板节能模式.
        ///<summary >
        /// 配置按键指示灯面板节能模式
        /// <para>modeEnable:节能模式使能</para>
        /// <para>modeTime:无操作进入节能模式时间 0-ff</para>
        /// <para>节能模式亮度:0-100</para>
        /// </summary>
        public async System.Threading.Tasks.Task<ResponseAllData> SetKeyModeAsync(bool modeEnable, int modeTime, int level)
        {
            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 = 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:0403_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SetPanelModeModeData(modeEnable, modeTime, level);
                    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>
        /// 配置按键指示灯面板节能模式
        /// </summary>
        string SetPanelModeModeData(bool modeEnable, int modeTime, int modelevel)
        {
            string data = "";
            string dataLength = "07";
            string dataComand1 = "03";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "03";
            string mode = "";
            string time = "";
            string level = "";
            try
            {
                if (modeEnable)
                {
                    mode = "01";
                    sEnable = "01";
                }
                else
                {
                    mode = "00";
                }
                var sbString1 = new System.Text.StringBuilder();
                string temp = Convert.ToString(modeTime, 16);
                switch (temp.Length)
                {
                    case 1:
                        time = "0" + temp;
                        break;
                    case 2:
                        time = temp;
                        break;
                    sEnable = "00";
                }
                var sbString2 = new System.Text.StringBuilder();
                string temp2 = Convert.ToString(modelevel, 16);
                switch (temp2.Length)
                {
                    case 1:
                        level = "0" + temp2;
                        break;
                    case 2:
                        level = temp2;
                        break;
                }
                sbString1.Append(time.ToUpper());
                sbString2.Append(level.ToUpper());
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                   mode + sbString1 + sbString2;
                  sEnable + "FFFFFFFF";
            }
            catch { };
@@ -1409,234 +1101,6 @@
        #endregion
        #region 获取按键指示灯开关颜色.
        ///<summary >
        ///获取按键指示灯开关颜色.
        /// </summary>
        public async System.Threading.Tasks.Task<KeyColorDataResponseAllData> GetPanelColorInfoAsync(KeyNum keyNum)
        {
            KeyColorDataResponseAllData result = null;
            if (Gateway == null)
            {
                result = new KeyColorDataResponseAllData { 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 KeyColorDataResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new KeyColorDataResponseAllData { 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 KeyColorDataResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 24)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0405")
                                    {
                                        var key1 = data[10] + data[11];
                                        var key = data[10].ToString() + data[11].ToString();
                                        var tempR = new KeyColorData();
                                        tempR.OpenColorR = data[12].ToString() + data[13].ToString(); ;
                                        tempR.OpenColorG = data[14].ToString() + data[15].ToString(); ;
                                        tempR.OpenColorB = data[16].ToString() + data[17].ToString(); ;
                                        tempR.CloseColorR = data[18].ToString() + data[19].ToString(); ;
                                        tempR.CloseColorG = data[20].ToString() + data[21].ToString(); ;
                                        tempR.CloseColorB = data[22].ToString() + data[23].ToString(); ;
                                        switch (key)
                                        {
                                            case "01":
                                                tempR.keyNum = KeyNum.Key1;
                                                break;
                                            case "02":
                                                tempR.keyNum = KeyNum.Key2;
                                                break;
                                            case "03":
                                                tempR.keyNum = KeyNum.Key3;
                                                break;
                                            case "04":
                                                tempR.keyNum = KeyNum.Key4;
                                                break;
                                            case "05":
                                                tempR.keyNum = KeyNum.Key5;
                                                break;
                                            case "06":
                                                tempR.keyNum = KeyNum.Key6;
                                                break;
                                            case "07":
                                                tempR.keyNum = KeyNum.Key7;
                                                break;
                                            case "08":
                                                tempR.keyNum = KeyNum.Key8;
                                                break;
                                            case "09":
                                                tempR.keyNum = KeyNum.Key9;
                                                break;
                                            case "0a":
                                                tempR.keyNum = KeyNum.Key10;
                                                break;
                                            case "0b":
                                                tempR.keyNum = KeyNum.Key11;
                                                break;
                                            case "0c":
                                                tempR.keyNum = KeyNum.Key12;
                                                break;
                                            case "0d":
                                                tempR.keyNum = KeyNum.Key13;
                                                break;
                                            case "0e":
                                                tempR.keyNum = KeyNum.Key14;
                                                break;
                                            case "0f":
                                                tempR.keyNum = KeyNum.Key15;
                                                break;
                                        }
                                        keyColorData = tempR;
                                        result = new KeyColorDataResponseAllData { keyColorData = tempR };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0404_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = GetkeyColorData(keyNum);
                    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 KeyColorDataResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 获取按键指示灯开关颜色
        /// </summary>
        string GetkeyColorData(KeyNum keyNum)
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "04";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string kNum = "";
            try
            {
                switch (keyNum)
                {
                    case KeyNum.Key1:
                        kNum = "01";
                        break;
                    case KeyNum.Key2:
                        kNum = "02";
                        break;
                    case KeyNum.Key3:
                        kNum = "03";
                        break;
                    case KeyNum.Key4:
                        kNum = "04";
                        break;
                    case KeyNum.Key5:
                        kNum = "05";
                        break;
                    case KeyNum.Key6:
                        kNum = "06";
                        break;
                    case KeyNum.Key7:
                        kNum = "07";
                        break;
                    case KeyNum.Key8:
                        kNum = "08";
                        break;
                    case KeyNum.Key9:
                        kNum = "09";
                        break;
                    case KeyNum.Key10:
                        kNum = "0A";
                        break;
                    case KeyNum.Key11:
                        kNum = "0B";
                        break;
                    case KeyNum.Key12:
                        kNum = "0C";
                        break;
                    case KeyNum.Key13:
                        kNum = "0D";
                        break;
                    case KeyNum.Key14:
                        kNum = "0E";
                        break;
                    case KeyNum.Key15:
                        kNum = "0F";
                        break;
                    case KeyNum.Key16:
                        kNum = "10";
                        break;
                }
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + kNum;
            }
            catch { };
            return data;
        }
        /// <summary>
        /// 按键指示灯颜色信息对应顺序号(睡眠组号)
@@ -1663,129 +1127,6 @@
        #endregion
        #region 获取按键指示灯面板开关亮度配置.
        ///<summary >
        ///获取按键指示灯面板开关亮度配置
        /// </summary>
        public async System.Threading.Tasks.Task<PanelSwitchLevelInfo> GetPanelSwitchLevelAsync(string reserve = "01")
        {
            PanelSwitchLevelInfo result = null;
            if (Gateway == null)
            {
                result = new PanelSwitchLevelInfo { 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 PanelSwitchLevelInfo { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new PanelSwitchLevelInfo { 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 PanelSwitchLevelInfo { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 14)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0407")
                                    {
                                        var level1 = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
                                        var level2 = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
                                        panelDirectionsLevel = level1;
                                        panelBacklightLevel = level2;
                                        result = new PanelSwitchLevelInfo { panelDirectionsLevel = level1, panelBacklightLevel = level2 };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0406_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SendPanelSwitchLevelData(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 PanelSwitchLevelInfo { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 获取按键指示灯面板开关亮度配置数据
        /// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para>
        /// </summary>
        string SendPanelSwitchLevelData(string reserve)
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "06";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string reserveData = reserve;
            try
            {
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                    reserveData;
            }
            catch { };
            return data;
        }
        /// <summary>
        /// 按键指示灯面板开关亮度配置回复
@@ -1803,148 +1144,18 @@
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            ///按键开状态(指示)亮度
            ///按键开状态(指示)亮度(这个是点击后的值)
            /// </summary>
            public int panelDirectionsLevel = -1;
            /// <summary>
            /// 按键关状态(背光)亮度
            /// 按键关状态(背光)亮度(这个是点击前的值)
            /// </summary>
            public int panelBacklightLevel = -1;
        }
        #endregion
        #region 获取按键节能模式配置状态.
        ///<summary >
        ///获取按键节能模式配置状态
        /// </summary>
        public async System.Threading.Tasks.Task<PanelSwitchLevelResponInfo> GetPanelSaveEnergyModeAsync(string reserve = "01")
        {
            PanelSwitchLevelResponInfo result = null;
            if (Gateway == null)
            {
                result = new PanelSwitchLevelResponInfo { 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 PanelSwitchLevelResponInfo { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new PanelSwitchLevelResponInfo { 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 PanelSwitchLevelResponInfo { 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 == "0409")
                                    {
                                        var tempR = new PanelSaveEnergyModeInfo();
                                        if (data[10].ToString() + data[11].ToString() == "01")
                                        {
                                            tempR.enable = true;
                                        }
                                        else
                                        {
                                            tempR.enable = false;
                                        }
                                        tempR.time = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
                                        tempR.level = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        panelSaveEnergyModeInfo = tempR;
                                        result = new PanelSwitchLevelResponInfo { panelSaveEnergyModeInfo = tempR };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0408_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    OpenPassthroughControl(Gateway);
                    var passData = SendPanelSaveEnergyModeData(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 < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > 9000)// WaitReceiveDataTime)
                {
                    result = new PanelSwitchLevelResponInfo { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 获取按键节能模式配置状态数据
        /// </summary>
        string SendPanelSaveEnergyModeData(string reserve)
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "08";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string reserveData = reserve;
            try
            {
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                    reserveData;
            }
            catch { };
            return data;
        }
        /// <summary>
        /// 获取按键节能模式配置状态数据回复
@@ -1969,10 +1180,6 @@
        }
        /// <summary>
        /// 按键节能模式信息
        /// </summary>
        public PanelSaveEnergyModeInfo panelSaveEnergyModeInfo;
        /// <summary>
        /// 获取按键节能模式配置状态数据
        /// </summary>
        [System.Serializable]
@@ -1991,6 +1198,179 @@
            /// 节能模式亮度(0-100)
            /// </summary>
            public int level = -1;
        }
        #endregion
        #region 获取接近传感配置
        ///<summary >
        ///获取接近传感配置
        /// </summary>
        public async System.Threading.Tasks.Task<PanelProximitySensorResponInfo> GetProximitySensorAsync(string reserve = "01")
        {
            PanelProximitySensorResponInfo result = null;
            if (Gateway == null)
            {
                result = new PanelProximitySensorResponInfo { 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 PanelProximitySensorResponInfo { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new PanelProximitySensorResponInfo { 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 PanelProximitySensorResponInfo { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = clientDataPassthroughResponseData.PassData;
                                if (data.Length == 20)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0502")
                                    {
                                        var tempR = new PanelProximitySensorInfo();
                                        if (data[10].ToString() + data[11].ToString() == "01")
                                        {
                                            tempR.enable = true;
                                        }
                                        else
                                        {
                                            tempR.enable = false;
                                        }
                                        tempR.sensorDistance = Convert.ToInt32(data[14].ToString() + data[15].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                        tempR.sensorDelayTime = Convert.ToInt32(data[18].ToString() + data[19].ToString() + data[16].ToString() + data[17].ToString(), 16);
                                        result = new PanelProximitySensorResponInfo { panelProximitySensorInfo = tempR };
                                        System.Console.WriteLine($"UI收到通知后的主题_command:0408_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    var passData = SendProiximitySensorData(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 < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > 9000)// WaitReceiveDataTime)
                {
                    result = new PanelProximitySensorResponInfo { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 获取接近传感配置数据
        /// </summary>
        string SendProiximitySensorData(string reserve)
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "01";
            string dataComand2 = "05";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string reserveData = reserve;
            try
            {
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                    reserveData;
            }
            catch { };
            return data;
        }
        /// <summary>
        /// 获取接近传感配置数据回复
        /// </summary>
        [System.Serializable]
        public class PanelProximitySensorResponInfo
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// <para>获取接近传感配置数据</para>
            /// </summary>
            public PanelProximitySensorInfo panelProximitySensorInfo;
        }
        /// <summary>
        /// 获取接近传感配置数据
        /// </summary>
        [System.Serializable]
        public class PanelProximitySensorInfo
        {
            /// <summary>
            /// 传感器使能
            ///false-disable  true-enable
            /// </summary>
            public bool enable;
            /// <summary>
            ///传感器距离
            /// </summary>
            public int sensorDistance = -1;
            /// <summary>
            /// 传感器触发延迟时间
            /// </summary>
            public int sensorDelayTime = -1;
        }
        #endregion
@@ -1999,472 +1379,392 @@
        ///获取按键指示灯睡眠组
        ///<para>sleepGroup:睡眠组号</para>
        /// </summary>
        //public async System.Threading.Tasks.Task<PanelSleepGroupResponseAllData> GetPanelSleepGroupAsync(SleepGroup sleepGroup)
        //{
        //    PanelSleepGroupResponseAllData result = null;
        //    if (Gateway == null)
        //    {
        //        result = new PanelSleepGroupResponseAllData { 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 PanelSleepGroupResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
        //                }
        //                else
        //                {
        //                    result = new PanelSleepGroupResponseAllData { 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 PanelSleepGroupResponseAllData { errorMessageBase = "网关返回的数据为空" };
        //                }
        //                else
        //                {
        //                    if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
        //                    {
        //                        var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
        //                        if (data.Length == 14)
        //                        {
        //                            var tempR = new PanelSleepGroupResponseData();
        //                            tempR.status = int.Parse(data[12].ToString() + data[13].ToString());
        //                            switch (data[10].ToString() + data[11].ToString())
        //                            {
        //                                case "01":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group1;
        //                                    break;
        //                                case "02":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group2;
        //                                    break;
        //                                case "03":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group3;
        //                                    break;
        //                                case "04":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group4;
        //                                    break;
        //                                case "05":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group5;
        //                                    break;
        //                                case "06":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group6;
        //                                    break;
        //                                case "07":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group7;
        //                                    break;
        //                                case "08":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group8;
        //                                    break;
        //                                case "09":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group9;
        //                                    break;
        //                                case "0a":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group10;
        //                                    break;
        //                                case "0b":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group11;
        //                                    break;
        //                                case "0c":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group12;
        //                                    break;
        //                                case "0d":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group13;
        //                                    break;
        //                                case "0e":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group14;
        //                                    break;
        //                                case "0f":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group15;
        //                                    break;
        //                            }
        //                            result = new PanelSleepGroupResponseAllData { panelSleepGroupResponseData = tempR };
        //                        }
        //                    }
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //        };
        //        Gateway.Actions += action;
        //        System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
        //        try
        //        {
        //            OpenPassthroughControl(Gateway);
        //            var passData = SetPanelSleepGroupData(sleepGroup);
        //            var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
        //            var data = new JObject { { "PassData", passData } };
        //            jObject.Add("Data", data);
        //            CurrentGateWayId = Gateway.getGatewayBaseInfo?.gwID;
        //            Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
        //        }
        //        catch { }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(10);
        //            if (result != null)
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            result = new PanelSleepGroupResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
        //        }
        //        Gateway.Actions -= action;
        //        System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
        //        return result;
        //    });
        //}
        ///// <summary>
        ///// 绑定设备信息,网关反馈信息
        ///// </summary>
        //public PanelSleepGroupResponseAllData panelSleepGroupResponseAllData;
        //[System.Serializable]
        //public class PanelSleepGroupResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 绑定设备信息
        //    /// </summary>
        //    public PanelSleepGroupResponseData panelSleepGroupResponseData;
        //}
        ///// <summary>
        ///// 绑定设备信息,网关反馈信息
        ///// </summary>
        //public PanelSleepGroupResponseData panelSleepGroupResponseData;
        //[System.Serializable]
        //public class PanelSleepGroupResponseData
        //{
        //    /// <summary>
        //    /// 睡眠组号
        //    /// </summary>
        //    public SleepGroupNum sleepGroupNum;
        //    /// <summary>
        //    /// 状态
        //    /// <para>0--执行 1—唤醒</para>
        //    /// </summary>
        //    public int status;
        //}
        ///// <summary>
        ///// 配置按键指示灯睡眠组分区
        ///// </summary>
        //string SetPanelSleepGroupData(SleepGroup sleepGroup)
        //{
        //    string data = "";
        //    string dataLength = "06";
        //    string dataComand1 = "0a";
        //    string dataComand2 = "04";
        //    string dataSerialNum = "01";
        //    string addDataLength = "02";
        //    int attributeData = 0;
        //    try
        //    {
        //        int bit0 = 0, bit1 = 0, bit2 = 0, bit3 = 0, bit4 = 0, bit5 = 0, bit6 = 0, bit7 = 0, bit8 = 0, bit9 = 0, bit10 = 0, bit11 = 0, bit12 = 0, bit13 = 0, bit14 = 0, bit15 = 0;
        //        if (sleepGroup != null)
        //        {
        //            if (sleepGroup.bit0)
        //            {
        //                bit0 = 1;
        //            }
        //            if (sleepGroup.bit1)
        //            {
        //                bit1 = 1;
        //            }
        //            if (sleepGroup.bit2)
        //            {
        //                bit2 = 1;
        //            }
        //            if (sleepGroup.bit3)
        //            {
        //                bit3 = 1;
        //            }
        //            if (sleepGroup.bit4)
        //            {
        //                bit4 = 1;
        //            }
        //            if (sleepGroup.bit5)
        //            {
        //                bit5 = 1;
        //            }
        //            if (sleepGroup.bit6)
        //            {
        //                bit6 = 1;
        //            }
        //            if (sleepGroup.bit7)
        //            {
        //                bit7 = 1;
        //            }
        //            if (sleepGroup.bit8)
        //            {
        //                bit8 = 1;
        //            }
        //            if (sleepGroup.bit9)
        //            {
        //                bit9 = 1;
        //            }
        //            if (sleepGroup.bit10)
        //            {
        //                bit10 = 1;
        //            }
        //            if (sleepGroup.bit11)
        //            {
        //                bit11 = 1;
        //            }
        //            if (sleepGroup.bit12)
        //            {
        //                bit12 = 1;
        //            }
        //            if (sleepGroup.bit13)
        //            {
        //                bit13 = 1;
        //            }
        //            if (sleepGroup.bit14)
        //            {
        //                bit14 = 1;
        //            }
        //            if (sleepGroup.bit15)
        //            {
        //                bit15 = 1;
        //            }
        //            attributeData = bit0 * 1 + bit1 * 2 + bit2 * 4 + bit3 * 8 + bit4 * 16 + bit5 * 32 + bit6 * 64 + bit7 * 128 + bit8 * 256 + bit9 * 512 + bit10 * 1024 + bit11 * 2048 + bit12 * 4096 + bit13 * 8192 + bit14 * 16384 + bit15 * 32768;
        //        }
        //        string tempAttributeData = attributeData.ToString("X4");
        //        if (sleepGroup != null)
        //        {
        //            data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
        //                   tempAttributeData;
        //        }
        //    }
        //    catch { };
        //    return data;
        //}
        ///// <summary>
        ///// 睡眠组号(可位或)
        ///// </summary>
        //public class SleepGroup
        //{
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit0;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit1;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit2;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit3;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit4;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit5;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit6;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit7;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit8;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit9;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit10;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit11;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit12;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit13;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit14;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit15;
        //}
        ///// <summary>
        ///// 执行按键指示灯睡眠组
        ///// </summary>
        //public enum SleepGroupNum
        //{
        //    Group1 = 1,
        //    Group2 = 2,
        //    Group3 = 3,
        //    Group4 = 4,
        //    Group5 = 5,
        //    Group6 = 6,
        //    Group7 = 7,
        //    Group8 = 8,
        //    Group9 = 9,
        //    Group10 = 10,
        //    Group11 = 11,
        //    Group12 = 12,
        //    Group13 = 13,
        //    Group14 = 14,
        //    Group15 = 15,
        //    Group16 = 16,
        //}
        //public async System.Threading.Tasks.Task<PanelSleepGroupResponseAllData> GetPanelSleepGroupAsync(SleepGroup sleepGroup)
        //{
        //    PanelSleepGroupResponseAllData result = null;
        //    if (Gateway == null)
        //    {
        //        result = new PanelSleepGroupResponseAllData { 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 PanelSleepGroupResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
        //                }
        //                else
        //                {
        //                    result = new PanelSleepGroupResponseAllData { 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 PanelSleepGroupResponseAllData { errorMessageBase = "网关返回的数据为空" };
        //                }
        //                else
        //                {
        //                    if (clientDataPassthroughResponseData?.PassData != null)
        //                    {
        //                        var data = clientDataPassthroughResponseData.PassData;
        //                        if (data.Length == 14)
        //                        {
        //                            var tempR = new PanelSleepGroupResponseData();
        //                            tempR.status = int.Parse(data[12].ToString() + data[13].ToString());
        //                            switch (data[10].ToString() + data[11].ToString())
        //                            {
        //                                case "01":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group1;
        //                                    break;
        //                                case "02":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group2;
        //                                    break;
        //                                case "03":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group3;
        //                                    break;
        //                                case "04":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group4;
        //                                    break;
        //                                case "05":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group5;
        //                                    break;
        //                                case "06":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group6;
        //                                    break;
        //                                case "07":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group7;
        //                                    break;
        //                                case "08":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group8;
        //                                    break;
        //                                case "09":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group9;
        //                                    break;
        //                                case "0a":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group10;
        //                                    break;
        //                                case "0b":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group11;
        //                                    break;
        //                                case "0c":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group12;
        //                                    break;
        //                                case "0d":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group13;
        //                                    break;
        //                                case "0e":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group14;
        //                                    break;
        //                                case "0f":
        //                                    tempR.sleepGroupNum = SleepGroupNum.Group15;
        //                                    break;
        //                            }
        //                            result = new PanelSleepGroupResponseAllData { panelSleepGroupResponseData = tempR };
        //                        }
        //                    }
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //        };
        //        Gateway.Actions += action;
        //        System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
        //        try
        //        {
        //            OpenPassthroughControl(Gateway);
        //            var passData = SetPanelSleepGroupData(sleepGroup);
        //            var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
        //            var data = new JObject { { "PassData", passData } };
        //            jObject.Add("Data", data);
        //            CurrentGateWayId = Gateway.getGatewayBaseInfo?.gwID;
        //            Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
        //        }
        //        catch { }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(10);
        //            if (result != null)
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            result = new PanelSleepGroupResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
        //        }
        //        Gateway.Actions -= action;
        //        System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
        //        return result;
        //    });
        //}
        ///// <summary>
        ///// 绑定设备信息,网关反馈信息
        ///// </summary>
        //public PanelSleepGroupResponseAllData panelSleepGroupResponseAllData;
        //[System.Serializable]
        //public class PanelSleepGroupResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 绑定设备信息
        //    /// </summary>
        //    public PanelSleepGroupResponseData panelSleepGroupResponseData;
        //}
        ///// <summary>
        ///// 绑定设备信息,网关反馈信息
        ///// </summary>
        //public PanelSleepGroupResponseData panelSleepGroupResponseData;
        //[System.Serializable]
        //public class PanelSleepGroupResponseData
        //{
        //    /// <summary>
        //    /// 睡眠组号
        //    /// </summary>
        //    public SleepGroupNum sleepGroupNum;
        //    /// <summary>
        //    /// 状态
        //    /// <para>0--执行 1—唤醒</para>
        //    /// </summary>
        //    public int status;
        //}
        ///// <summary>
        ///// 配置按键指示灯睡眠组分区
        ///// </summary>
        //string SetPanelSleepGroupData(SleepGroup sleepGroup)
        //{
        //    string data = "";
        //    string dataLength = "06";
        //    string dataComand1 = "0a";
        //    string dataComand2 = "04";
        //    string dataSerialNum = "01";
        //    string addDataLength = "02";
        //    int attributeData = 0;
        //    try
        //    {
        //        int bit0 = 0, bit1 = 0, bit2 = 0, bit3 = 0, bit4 = 0, bit5 = 0, bit6 = 0, bit7 = 0, bit8 = 0, bit9 = 0, bit10 = 0, bit11 = 0, bit12 = 0, bit13 = 0, bit14 = 0, bit15 = 0;
        //        if (sleepGroup != null)
        //        {
        //            if (sleepGroup.bit0)
        //            {
        //                bit0 = 1;
        //            }
        //            if (sleepGroup.bit1)
        //            {
        //                bit1 = 1;
        //            }
        //            if (sleepGroup.bit2)
        //            {
        //                bit2 = 1;
        //            }
        //            if (sleepGroup.bit3)
        //            {
        //                bit3 = 1;
        //            }
        //            if (sleepGroup.bit4)
        //            {
        //                bit4 = 1;
        //            }
        //            if (sleepGroup.bit5)
        //            {
        //                bit5 = 1;
        //            }
        //            if (sleepGroup.bit6)
        //            {
        //                bit6 = 1;
        //            }
        //            if (sleepGroup.bit7)
        //            {
        //                bit7 = 1;
        //            }
        //            if (sleepGroup.bit8)
        //            {
        //                bit8 = 1;
        //            }
        //            if (sleepGroup.bit9)
        //            {
        //                bit9 = 1;
        //            }
        //            if (sleepGroup.bit10)
        //            {
        //                bit10 = 1;
        //            }
        //            if (sleepGroup.bit11)
        //            {
        //                bit11 = 1;
        //            }
        //            if (sleepGroup.bit12)
        //            {
        //                bit12 = 1;
        //            }
        //            if (sleepGroup.bit13)
        //            {
        //                bit13 = 1;
        //            }
        //            if (sleepGroup.bit14)
        //            {
        //                bit14 = 1;
        //            }
        //            if (sleepGroup.bit15)
        //            {
        //                bit15 = 1;
        //            }
        //            attributeData = bit0 * 1 + bit1 * 2 + bit2 * 4 + bit3 * 8 + bit4 * 16 + bit5 * 32 + bit6 * 64 + bit7 * 128 + bit8 * 256 + bit9 * 512 + bit10 * 1024 + bit11 * 2048 + bit12 * 4096 + bit13 * 8192 + bit14 * 16384 + bit15 * 32768;
        //        }
        //        string tempAttributeData = attributeData.ToString("X4");
        //        if (sleepGroup != null)
        //        {
        //            data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
        //                   tempAttributeData;
        //        }
        //    }
        //    catch { };
        //    return data;
        //}
        ///// <summary>
        ///// 睡眠组号(可位或)
        ///// </summary>
        //public class SleepGroup
        //{
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit0;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit1;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit2;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit3;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit4;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit5;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit6;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit7;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit8;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit9;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit10;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit11;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit12;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit13;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit14;
        //    /// <summary>
        //    /// false:关
        //    /// true:开
        //    /// </summary>
        //    public bool bit15;
        //}
        ///// <summary>
        ///// 执行按键指示灯睡眠组
        ///// </summary>
        //public enum SleepGroupNum
        //{
        //    Group1 = 1,
        //    Group2 = 2,
        //    Group3 = 3,
        //    Group4 = 4,
        //    Group5 = 5,
        //    Group6 = 6,
        //    Group7 = 7,
        //    Group8 = 8,
        //    Group9 = 9,
        //    Group10 = 10,
        //    Group11 = 11,
        //    Group12 = 12,
        //    Group13 = 13,
        //    Group14 = 14,
        //    Group15 = 15,
        //    Group16 = 16,
        //}
        #endregion
        #region 配置面板功能
        ///<summary >
        ///配置面板功能
        ///<para>value:给面板配置的模式</para>
        /// </summary>
        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> ConfigureHdlKeyValueAsync(KeyMode value)
        {
            if (Gateway == null)
            {
                return null;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                SetWritableValueResponAllData d = null;
                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)
                        {
                            d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
                        {
                            d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
                            System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString());
                try
                {
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 6 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 6533 }, { "AttributeDataType", 33 }, { "AttributeData", (int)value } };
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (d != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString());
                return d;
            });
        }
        /// <summary>
        /// 配置面板的功能模式
@@ -2487,20 +1787,30 @@
            /// 开关类型——取反.
            /// </summary>
            OnOff_OnOff = 102,
            /// <summary>
            /// 亮度类型——调大.
            /// 亮度类型——按等级调大.
            /// </summary>
            Level_Step_Up = 200,
            /// <summary>
            /// 亮度类型——调小.
            /// 亮度类型——按等级调小.
            /// </summary>
            Level_Step_Down = 201,
            /// <summary>
            /// 亮度类型——取反.
            /// 亮度类型——按等级取反.
            /// </summary>
            Level_Step_Up_Down = 202,
            /// <summary>
            /// 亮度类型——取反.
            /// </summary>
            Level_Up = 203,
            /// <summary>
            /// 亮度类型——取反.
            /// </summary>
            Level_Down = 204,
            /// <summary>
            /// 亮度类型——取反.
            /// </summary>
            Level_Up_Down = 205,
            /// <summary>
            /// 窗帘类型——开.
            /// </summary>
@@ -2521,6 +1831,10 @@
            /// 窗帘类型——下降停止.
            /// </summary>
            Wcd_Down_Stop = 304,
            /// <summary>
            /// 窗帘类型——下降停止.
            /// </summary>
            Default = 65535,
        }
        #endregion
@@ -2533,119 +1847,7 @@
        }
        #region  读取面板的配置信息
        /// <summary>
        /// 读取面板的配置信息
        /// </summary>
        public async System.Threading.Tasks.Task<PanelConfigureInfoResponAllData> ReadPanelConfigureInfoAsync(params int[] args)
        {
            if (Gateway == null)
            {
                return null;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                PanelConfigureInfoResponAllData d = null;
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];//网关返回的网关ID
                    var reportStatus = topic.Split('/')[1];//主题为设备上报的主题
                    string addr = "";//上报的设备addr
                    string epoint = "";//上报的设备epoint
                    string cluID = "";//上报的设备cluID
                    string attrId = "";//上报的设备attrId
                    if (reportStatus == "DeviceStatusReport")
                    {
                        addr = topic.Split('/')[2];
                        epoint = topic.Split('/')[3];
                        cluID = topic.Split('/')[4];
                        attrId = topic.Split('/')[5];
                    }
                    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)
                        {
                            d = new PanelConfigureInfoResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            d = new PanelConfigureInfoResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    else if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + addr + "/" + epoint + "/" + cluID + "/" + attrId)
                    {
                        var deviceID = jobject.Value<int>("Device_ID");
                        var deviceAddr = jobject.Value<string>("DeviceAddr");
                        var tempEpoint = jobject.Value<int>("Epoint");
                        var dataId = jobject.Value<int>("Data_ID");
                        var lightSwitch = new Panel { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
                        lightSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString());
                        if ((DeviceType)(deviceID) == DeviceType.OnOffSwitch)
                        {
                            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString());
                            if (tempData == null)
                            {
                                d = new PanelConfigureInfoResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
                            }
                            else
                            {
                                d = new PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
                                System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("GetDeviceStatus_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    var JObject = new JObject {
                { "DeviceAddr",DeviceAddr },
                { "Epoint", DeviceEpoint },
                { "Cluster_ID", (int)Device.Cluster_ID.HdlKey },
                { "Command", 108 }
                    };
                    var attriBute = new JArray{
                  new JObject {
                    { "AttriButeId", (int)AttriButeId.HdlKey}
                   }
                    };
                    var data = new JObject { { "AttriBute", attriBute } };
                    JObject.Add("Data", data);
                    Gateway?.Send(("GetDeviceStatus"), JObject.ToString());
                }
                catch
                {
                }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (d != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    d = new PanelConfigureInfoResponAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("GetDeviceStatus_Actions 退出" + System.DateTime.Now.ToString());
                return d;
            });
        }
        /// <summary>
        /// 网关恢复出厂设置返回数据
        /// </summary>
@@ -2668,993 +1870,132 @@
        }
        #endregion
        //#region 设备绑定
        ///// <summary>
        /////设备绑定
        ///// </summary>
        //public async System.Threading.Tasks.Task<AddedDeviceBindResponseAllData> AddDeviceBindAsync(AddBindData addBindData)
        //{
        //    return await System.Threading.Tasks.Task.Run(async () =>
        //    {
        //        var result = new AddedDeviceBindResponseAllData();
        //        var mainGateway = ZbGateway.MainGateWay;
        //        if (mainGateway == null)
        //        {
        //            result.errorMessageBase = "当前没有主网关";
        //            return result;
        //        }
        //        Action<string, string> action = (topic, message) =>
        //        {
        //            System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //            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 = mainGateway.getGatewayBaseInfo.gwID };
        //                var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
        #region 获取网关中的场景
        /// <summary>
        /// 只能获取场景信息,没有场景中的设备信息
        /// </summary>
        /// <returns></rxeturns>
        public async System.Threading.Tasks.Task<GetOnlySceneAllData> GetSceneInfoAsync()
        {
            GetOnlySceneAllData result = null;
            if (ZbGateway.MainGateWay == null)
            {
                result = new GetOnlySceneAllData { errorMessageBase = "没有主网关" };
            }
            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 tempResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
                        if (tempResult == null)
                        {
                            result = new GetOnlySceneAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new GetOnlySceneAllData { errorResponData = tempResult };
                        }
                    }
        //                if (temp == null)
        //                {
        //                    result.errorMessageBase = "网关错误回复,且数据是空";
        //                }
        //                else
        //                {
        //                    result.errorResponData = temp;
        //                    result.errorMessageBase = ErrorMess(temp.Error);
        //                }
        //            }
        //            else if (topic == gatewayID + "/" + "Bind/SetBind_Respon")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
        //                //var tempBindName = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(jobject["Data"]["BindName"].ToString());
        //                var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString());
        //                if (tempBindList == null)
        //                {
        //                    result.errorMessageBase = "网关返回的数据为空";
        //                }
        //                else
        //                {
        //                    var dataBindRes = new AddedDeviceBindResponseData();
        //                    for (int m = 0; tempBindList != null && m < tempBindList.Count; m++)
        //                    {
        //                        var tempBind = tempBindList[m];
        //                        dataBindRes.BindList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindListResponseObj>(tempBind.ToString()));
        //                    }
        //                    if (dataBindRes != null)
        //                    {
        //                        result.addedDeviceBindResponseData = dataBindRes;
        //                        System.Console.WriteLine($"UI收到通知后的主题_{topic}");
        //                    }
        //                }
        //            }
        //            else if (topic == gatewayID + "/" + "Bind/BindResult")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindResultResponseData>(jobject["Data"].ToString());
                    if (topic == gatewayID + "/" + "Scene/GetInfo_Respon")
                    {
                        var getSceneInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetSceneInfo>(jobject["Data"].ToString());
                        if (getSceneInfo == null)
                        {
                            result = new GetOnlySceneAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new GetOnlySceneAllData { getSceneInfo = getSceneInfo };
                        }
                    }
                };
                ZbGateway.MainGateWay.Actions += action;
                System.Console.WriteLine("Scene/GetInfo_Actions 启动" + System.DateTime.Now.ToString());
                var jobjectData = new JObject { { "Cluster_ID", 0 }, { "Command", 805 } };
                await ZbGateway.MainGateWay.Send(("Scene/GetInfo"), System.Text.Encoding.UTF8.GetBytes(jobjectData.ToString()));
        //                if (tempData != null)
        //                {
        //                    result.addBindResultResponseData = tempData;
        //                }
        //            }
        //        };
        //        mainGateway.Actions += action;
        //        System.Console.WriteLine("Bind/SetBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
        //        try
        //        {
        //            if (addBindData != null)
        //            {
        //                var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
        //                var bindList = new JArray { };
        //                foreach (var bindInfo in addBindData.BindList)
        //                {
        //                    if (bindInfo.BindType == 0)
        //                    {
        //                        var dInfo = new JObject{
        //                    { "BindMacAddr",bindInfo.BindMacAddr},
        //                 { "BindEpoint", bindInfo.BindEpoint} ,
        //                 { "BindCluster", bindInfo.BindCluster} ,
        //                 { "BindType",bindInfo.BindType}
        //                    };
        //                        bindList.Add(dInfo);
        //                    }
        //                    else if (bindInfo.BindType == 1)
        //                    {
        //                        var dInfo = new JObject{
        //                     { "BindCluster", bindInfo.BindCluster} ,
        //                 { "BindType",bindInfo.BindType},
        //                 { "BindScenesId", bindInfo.BindScenesId}
        //                    };
        //                        bindList.Add(dInfo);
        //                    }
        //                }
        //                var data = new JObject{
        //            {"BindName",addBindData.BindName},
        //            { "BindList", bindList }
        //            };
        //                jObject.Add("Data", data);
        //                mainGateway.Send("Bind/SetBind", jObject.ToString());
        //            }
        //        }
        //        catch
        //        {
        //        }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(100);
        //            if (result == null || result.addedDeviceBindResponseData == null)
        //            {
        //                continue;
        //            }
        //            if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0).Count)
        //            {
        //                if (result.addBindResultResponseData != null)
        //                {
        //                    break;
        //                }
        //            }
        //            else
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            result.errorMessageBase = " 回复超时,请重新操作";
        //        }
        //        mainGateway.Actions -= action;
        //        System.Console.WriteLine($"Bind/SetBind_Actions 退出 {System.DateTime.Now}");
        //        return result;
        //    });
        //}
        ///// <summary>
        ///// 绑定设备信息,网关反馈信息
        ///// </summary>
        //public AddedDeviceBindResponseAllData addedDeviceBindResponseAllData;
        //[System.Serializable]
        //public class AddedDeviceBindResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 网关直接反馈绑定设备信息
        //    /// </summary>
        //    public AddedDeviceBindResponseData addedDeviceBindResponseData;
        //    /// <summary>
        //    /// 按键设备的确认反馈绑定设备信息
        //    /// </summary>
        //    public AddBindResultResponseData addBindResultResponseData;
        //}
        ///// <summary>
        ///// 绑定设备信息
        ///// </summary>
        //public AddedDeviceBindResponseData addedDeviceBindResponseData;
        //[System.Serializable]
        //public class AddedDeviceBindResponseData
        //{
        //    /// <summary>
        //    ///绑定名称
        //    /// </summary>
        //    public string BindName;
        //    /// <summary>
        //    ///绑定列表 ,当Status=0时存在
        //    /// </summary>
        //    public List<AddBindListResponseObj> BindList = new List<AddBindListResponseObj>();
        //}
        ///// <summary>
        ///// 绑定列表的信息
        ///// </summary>
        //[System.Serializable]
        //public class AddBindListResponseObj : BindListResponseObj
        //{
        //    /// <summary>
        //    /// 0:加入成功(该状态只适用用于跨网关绑定和绑定场景。同网关设备间的绑定需要节点设备的确认成功信息,不会直接反馈成功。)
        //    ///<para>1:失败,节点设备或场景不存在。</para>
        //    ///<para>2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功。</para>
        //    ///<para>3:绑定已经存在。</para>
        //    /// </summary>
        //    public int Result;
        //}
        ///// <summary>
        ///// 按键设备的确认的信息
        ///// </summary>
        //[System.Serializable]
        //public class AddBindResultResponseData
        //{
        //    /// <summary>
        //    ///绑定结果
        //    ///<para>0:成功</para>
        //    ///<para>140:失败,控制设备的绑定列表已满</para>
        //    ///<para>其他:失败</para>
        //    /// </summary>
        //    public int Result;
        //    /// <summary>
        //    /// 绑定的cluster
        //    /// </summary>
        //    public int BindCluster;
        //    /// <summary>
        //    /// 绑定设备Mac地址, 当BindType=0时存在
        //    /// </summary>
        //    public string BindMacAddr;
        //    /// <summary>
        //    /// 绑定设备的端口号,当BindType=0时存在
        //    /// </summary>
        //    public int BindEpoint;
        //    /// <summary>
        //    /// 绑定场景,当BindType=2时存在
        //    /// </summary>
        //    public int BindScenesId;
        //    /// <summary>
        //    /// 绑定设备的名称
        //    /// </summary>
        //    public string DeviceName;
        //}
        ///// <summary>
        ///// 绑定设备的数据
        ///// </summary>
        //public AddBindData addBindData;
        //[System.Serializable]
        //public class AddBindData
        //{
        //    /// <summary>
        //    /// 控制设备节点的mac地址
        //    /// </summary>
        //    public string DeviceAddr;
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public int Epoint;
        //    /// <summary>
        //    ///绑定名称,不修改名称时忽略该选项
        //    /// </summary>
        //    public string BindName;
        //    /// <summary>
        //    ///绑定列表,不修改绑定列表时忽略该选项。
        //    /// </summary>
        //    public List<AddBindListObj> BindList = new List<AddBindListObj>();
        //}
        ///// <summary>
        ///// 控制设备绑定的信息
        ///// </summary>
        //[System.Serializable]
        //public class AddBindListObj
        //{
        //    /// <summary>
        //    /// 绑定类型
        //    ///<para>0:绑定设备 </para>
        //    ///<para>1:绑定场景</para>
        //    /// </summary>
        //    public int BindType;
        //    /// <summary>
        //    /// 绑定的cluster,需要控制设备的OutCluster列表中存在该cluster。
        //    ///如绑定某个设备的on/off,为6。
        //    /// </summary>
        //    public int BindCluster;
        //    /// <summary>
        //    /// 绑定设备Mac地址, 当BindType=0时存在
        //    /// </summary>
        //    public string BindMacAddr;
        //    /// <summary>
        //    /// 绑定设备的端口号,当BindType=0时存在
        //    /// </summary>
        //    public int BindEpoint;
        //    /// <summary>
        //    /// 绑定场景,当BindType=1时存在
        //    /// </summary>
        //    public int BindScenesId;
        //}
        //#endregion
        //#region 解除绑定
        ///// <summary>
        ///// 解除绑定
        ///// </summary>
        //public async System.Threading.Tasks.Task<DelDeviceBindResponseAllData> DelDeviceBindAsync(DelDeviceBindData delDeviceBindData)
        //{
        //    return await System.Threading.Tasks.Task.Run(async () =>
        //    {
        //        var responseData = new DelDeviceBindResponseAllData();
        //        var mainGateway = ZbGateway.MainGateWay;
        //        if (mainGateway == null)
        //        {
        //            responseData.errorMessageBase = "当前没有主网关";
        //            return responseData;
        //        }
        //        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 = mainGateway.getGatewayBaseInfo.gwID };
        //                var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
        //                if (temp == null)
        //                {
        //                    responseData.errorMessageBase = "网关错误回复,且数据是空";
        //                }
        //                else
        //                {
        //                    responseData.errorResponData = temp;
        //                    responseData.errorMessageBase = ErrorMess(temp.Error);
        //                }
        //            }
        //            if (topic == gatewayID + "/" + "Bind/RemoveBind_Respon")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelDeviceBindResponseData>(jobject["Data"].ToString());
        //                if (tempData == null)
        //                {
        //                    responseData.errorMessageBase = "网关返回的数据为空";
        //                }
        //                else
        //                {
        //                    responseData.delDeviceBindResponseData = tempData;
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //            if (topic == gatewayID + "/" + "Bind/RemoveBindResult")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveBindResultResponseData>(jobject["Data"].ToString());
        //                if (tempData != null)
        //                {
        //                    responseData.removeBindResultResponseData = tempData;
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //        };
        //        mainGateway.Actions += action;
        //        System.Console.WriteLine("DeviceBind/DelBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
        //        try
        //        {
        //            if (delDeviceBindData != null)
        //            {
        //                var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
        //                var removeBindList = new JArray { };
        //                foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
        //                {
        //                    if (removeBindInfo.BindType == 0)
        //                    {
        //                        var dInfo = new JObject{
        //                    { "BindMacAddr",removeBindInfo.BindMacAddr},
        //                 { "BindEpoint", removeBindInfo.BindEpoint} ,
        //                 { "BindCluster", removeBindInfo.BindCluster} ,
        //                 { "BindType",removeBindInfo.BindType}
        //                    };
        //                        removeBindList.Add(dInfo);
        //                    }
        //                    else if (removeBindInfo.BindType == 1)
        //                    {
        //                        var dInfo = new JObject{
        //                 { "BindCluster", removeBindInfo.BindCluster} ,
        //                 { "BindType",removeBindInfo.BindType},
        //                 { "BindScenesId", removeBindInfo.BindScenesId}
        //                    };
        //                        removeBindList.Add(dInfo);
        //                    }
        //                }
        //                var data = new JObject {
        //            {"RemoveBindList",removeBindList}
        //             };
        //                jObject.Add("Data", data);
        //                mainGateway.Send("Bind/RemoveBind", jObject.ToString());
        //            }
        //        }
        //        catch { }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(100);
        //            if (responseData == null || responseData.delDeviceBindResponseData == null)
        //            {
        //                continue;
        //            }
        //            if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0).Count)
        //            {
        //                if (responseData.removeBindResultResponseData != null)
        //                {
        //                    break;
        //                }
        //            }
        //            else
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            responseData.errorMessageBase = "回复超时,请重新操作";
        //        }
        //        mainGateway.Actions -= action;
        //        System.Console.WriteLine("DeviceBind/DelBind_Actions 退出" + System.DateTime.Now.ToString());
        //        return responseData;
        //    });
        //}
        ///// <summary>
        /////解除绑定数据,网关反馈信息
        ///// </summary>
        //public DelDeviceBindResponseAllData delDeviceBindResponseAllData;
        ///// <summary>
        /////解除绑定数据,网关反馈信息
        ///// </summary>
        //[System.Serializable]
        //public class DelDeviceBindResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 解除绑定数据信息
        //    /// </summary>
        //    public DelDeviceBindResponseData delDeviceBindResponseData;
        //    /// <summary>
        //    /// 解除绑定按键确认数据信息
        //    /// </summary>
        //    public RemoveBindResultResponseData removeBindResultResponseData;
        //}
        ///// <summary>
        ///// 解除绑定数据
        ///// </summary>
        //public DelDeviceBindResponseData delDeviceBindResponseData;
        ///// <summary>
        ///// 解除绑定数据
        ///// </summary>
        //[System.Serializable]
        //public class DelDeviceBindResponseData
        //{
        //    /// <summary>
        //    ///绑定列表 ,当Status=0时存在
        //    /// </summary>
        //    public List<RemoveBindListResponseObj> RemoveBindList = new List<RemoveBindListResponseObj>();
        //}
        ///// <summary>
        ///// 移除设备绑定的信息
        ///// </summary>
        //[System.Serializable]
        //public class RemoveBindListResponseObj : BindListResponseObj
        //{
        //    /// <summary>
        //    /// 0:移除成功(该状态只适用用于跨网关绑定、绑定场景、失效设备(设备已经从网关的设备列表中删除)。同网关设备间的解除绑定需要节点设备的确认成功信息,不会直接反馈成功。)
        //    ///<para>1:失败,设备不在绑定列表中</para>
        //    ///<para>3:失败,在等待节点设备确认是否解除绑定成功(当网关还在等待某节点设备确认是否解除绑定成功的反馈信息时,客户端再次发送解除绑定该节点设备的指令,将反馈该状态。)</para>
        //    ///<para>4:未知,由节点设备反馈发送“Bind/RemoveBindResult”主题消息确定是否成功。</para>
        //    /// </summary>
        //    public int Result;
        //}
        ///// <summary>
        ///// 移除设备绑定按键确认的信息
        ///// </summary>
        //[System.Serializable]
        //public class RemoveBindResultResponseData
        //{
        //    /// <summary>
        //    ///绑定结果
        //    ///<para>0:成功</para>
        //    ///<para>136:控制设备本地绑定列表中无此绑定</para>
        //    ///<para>其他:失败</para>
        //    /// </summary>
        //    public int Result;
        //    /// <summary>
        //    /// 绑定设备Mac地址
        //    /// </summary>
        //    public string BindMacAddr;
        //    /// <summary>
        //    /// 绑定设备的端口号
        //    /// </summary>
        //    public int BindEpoint;
        //    /// <summary>
        //    /// 绑定的cluster
        //    /// </summary>
        //    public int BindCluster;
        //    /// <summary>
        //    /// 绑定设备名称
        //    /// </summary>
        //    public string DeviceName;
        //}
        ///// <summary>
        ///// 解除绑定数据
        ///// </summary>
        //public DelDeviceBindData delDeviceBindData;
        ///// <summary>
        ///// 解除绑定数据
        ///// </summary>
        //[System.Serializable]
        //public class DelDeviceBindData
        //{
        //    /// <summary>
        //    /// 控制设备节点的mac地址
        //    /// </summary>
        //    public string DeviceAddr;
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public int Epoint;
        //    /// <summary>
        //    ///绑定列表 ,当Status=0时存在
        //    /// </summary>
        //    public List<RemoveBindListObj> RemoveBindList = new List<RemoveBindListObj>();
        //}
        ///// <summary>
        ///// 移除设备绑定的信息
        ///// </summary>
        //[System.Serializable]
        //public class RemoveBindListObj
        //{
        //    /// <summary>
        //    /// 绑定类型
        //    ///<para>0:移除设备 </para>
        //    ///<para>1:移除场景</para>
        //    /// </summary>
        //    public int BindType;
        //    /// <summary>
        //    /// 绑定的cluster
        //    /// </summary>
        //    public int BindCluster;
        //    /// <summary>
        //    /// 绑定设备Mac地址, 当BindType=0时存在
        //    /// </summary>
        //    public string BindMacAddr;
        //    /// <summary>
        //    /// 绑定设备的端口号,当BindType=0时存在
        //    /// </summary>
        //    public int BindEpoint;
        //    /// <summary>
        //    /// 绑定场景,当BindType=1时存在
        //    /// </summary>
        //    public int BindScenesId;
        //}
        //#endregion
        //#region 获取所有绑定
        ///// <summary>
        /////获取所有绑定
        ///// </summary>
        //public async System.Threading.Tasks.Task<GetDeviceBindResponseAllData> GetDeviceBindAsyncAsync()
        //{
        //    return await System.Threading.Tasks.Task.Run(async () =>
        //    {
        //        GetDeviceBindResponseAllData d = null;
        //        var mainGateway = ZbGateway.MainGateWay;
        //        if (mainGateway == null)
        //        {
        //            d = new GetDeviceBindResponseAllData { errorMessageBase = "当前没有主网关" };
        //            return d;
        //        }
        //        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 = mainGateway.getGatewayBaseInfo.gwID };
        //                var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
        //                if (temp == null)
        //                {
        //                    d = new GetDeviceBindResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
        //                }
        //                else
        //                {
        //                    d = new GetDeviceBindResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
        //                }
        //            }
        //            if (topic == gatewayID + "/" + "Bind/GetDeviceBind_Respon")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDeviceBindResponseData>(jobject["Data"].ToString());
        //                //var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString());
        //                if (tempData == null)
        //                {
        //                    d = new GetDeviceBindResponseAllData { errorMessageBase = "网关返回的数据为空" };
        //                }
        //                else
        //                {
        //                    d = new GetDeviceBindResponseAllData { getAllBindResponseData = tempData };
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //        };
        //        mainGateway.Actions += action;
        //        try
        //        {
        //            System.Console.WriteLine("Bind/GetDeviceBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
        //            var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
        //            mainGateway.Send("Bind/GetDeviceBind", jObject.ToString());
        //        }
        //        catch { }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(10);
        //            if (d != null)
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            d = new GetDeviceBindResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
        //        }
        //        mainGateway.Actions -= action;
        //        System.Console.WriteLine("Bind/GetDeviceBind_Actions 退出" + System.DateTime.Now.ToString());
        //        return d;
        //    });
        //}
        ///// <summary>
        /////获取所有绑定数据,网关反馈信息
        ///// </summary>
        //public GetDeviceBindResponseAllData getAllBindResponseAllData;
        //[System.Serializable]
        //public class GetDeviceBindResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 控制设备绑定的设备列表回复数据
        //    /// </summary>
        //    public GetDeviceBindResponseData getAllBindResponseData;
        //}
        ///// <summary>
        ///// 获取所有绑定回复的数据
        ///// </summary>
        //public GetDeviceBindResponseData getAllBindResponseData;
        //[System.Serializable]
        //public class GetDeviceBindResponseData
        //{
        //    /// <summary>
        //    /// 0:成功
        //    ///<para>1:绑定不存在</para>
        //    /// </summary>
        //    public int Result;
        //    /// <summary>
        //    /// 绑定列表 ,当Status=0时存在。
        //    /// </summary>
        //    public List<BindListResponseObj> BindList = new List<BindListResponseObj>();
        //}
        ///// <summary>
        ///// 获取所有绑定的信息
        ///// </summary>
        //public class BindListResponseObj
        //{
        //    /// <summary>
        //    /// 绑定类型
        //    ///<para>0:移除设备,同网关设备间的移除</para>
        //    ///<para>1:移除设备,跨网关设备间的移除</para>
        //    ///<para>2:移除绑定场景</para>
        //    /// </summary>
        //    public int BindType;
        //    /// <summary>
        //    /// 绑定的cluster
        //    /// </summary>
        //    public int BindCluster;
        //    /// <summary>
        //    /// 绑定设备Mac地址, 当BindType=0时存在
        //    /// </summary>
        //    public string BindMacAddr;
        //    /// <summary>
        //    /// 绑定设备的端口号,当BindType=0时存在
        //    /// </summary>
        //    public int BindEpoint;
        //    /// <summary>
        //    /// 绑定场景,当BindType=1时存在
        //    /// </summary>
        //    public int BindScenesId;
        //    /// <summary>
        //    /// 绑定的设备或场景名称
        //    /// </summary>
        //    public string ESName;
        //}
        //#endregion
        //#region 删除一个控制设备所有绑定信息
        ///// <summary>
        /////删除一个控制设备所有绑定信息
        ///// </summary>
        //public async System.Threading.Tasks.Task<ClearBindInfoResponseAllData> ClearBindInfoAsync()
        //{
        //    if (Gateway == null)
        //    {
        //        return null;
        //    }
        //    return await System.Threading.Tasks.Task.Run(async () =>
        //    {
        //        ClearBindInfoResponseAllData d = null;
        //        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)
        //                {
        //                    d = new ClearBindInfoResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
        //                }
        //                else
        //                {
        //                    d = new ClearBindInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
        //                }
        //            }
        //            if (topic == gatewayID + "/" + "Bind/ClearBindInfo_Respon")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClearBindInfoResponseData>(jobject["Data"].ToString());
        //                if (tempData == null)
        //                {
        //                    d = new ClearBindInfoResponseAllData { errorMessageBase = "网关返回的数据为空" };
        //                }
        //                else
        //                {
        //                    d = new ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
        //                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
        //                }
        //            }
        //        };
        //        Gateway.Actions += action;
        //        System.Console.WriteLine("Bind/ClearBindInfo_Actions 启动" + "_" + System.DateTime.Now.ToString());
        //        try
        //        {
        //            var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
        //            Gateway.Send("Bind/ClearBindInfo", jObject.ToString());
        //        }
        //        catch { }
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
        //        {
        //            await System.Threading.Tasks.Task.Delay(10);
        //            if (d != null)
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
        //        {
        //            d = new ClearBindInfoResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
        //        }
        //        Gateway.Actions -= action;
        //        System.Console.WriteLine("Bind/ClearBindInfo_Actions 退出" + System.DateTime.Now.ToString());
        //        return d;
        //    });
        //}
        ///// <summary>
        /////删除一个控制设备所有绑定数据,网关反馈信息
        ///// </summary>
        //public ClearBindInfoResponseAllData clearBindInfoResponseAllData;
        //[System.Serializable]
        //public class ClearBindInfoResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 控制设备绑定的设备列表回复数据
        //    /// </summary>
        //    public ClearBindInfoResponseData clearBindInfoResponseData;
        //}
        ///// <summary>
        ///// 删除一个控制设备所有绑定信息回复的数据
        ///// </summary>
        //public ClearBindInfoResponseData clearBindInfoResponseData;
        //[System.Serializable]
        //public class ClearBindInfoResponseData
        //{
        //    /// <summary>
        //    /// 0:成功
        //    ///<para>1:绑定信息不存在</para>
        //    /// </summary>
        //    public int Result;
        //}
        //#endregion
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new GetOnlySceneAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                return result;
            });
        }
        /// <summary>
        ///获取场景信息,网关反馈信息
        /// </summary>
        [System.Serializable]
        public class GetOnlySceneAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 获取场景信息
            /// </summary>
            public GetSceneInfo getSceneInfo;
        }
        /// <summary>
        /// 读取面板的配置信息(信息存到当前的对象具体值中)
        /// 获取场景信息
        /// </summary>
        //public void ReadPanelConfigureInfo()
        //{
        //    ReadAttri(Device.Cluster_ID.HdlKey, AttriButeId.HdlKey);
        //}
        [System.Serializable]
        public class GetSceneInfo
        {
            /// <summary>
            ///场景总数
            /// </summary>
            public int ScenesSum;
        //#region 获取所有做了绑定的控制设备
        ///// <summary>
        /////获取所有做了绑定的控制设备
        ///// </summary>
        //public async System.Threading.Tasks.Task<GetControlDeviceBindResponseAllData> GetControlDeviceAsync()
        //{
        //    if (Gateway == null)
        //    {
        //        return null;
        //    }
        //    return await System.Threading.Tasks.Task.Run(async () =>
        //    {
        //        var d = new GetControlDeviceBindResponseAllData { };
        //        Action<string, string> action = (topic, message) =>
        //        {
        //            var gatewayID = topic.Split('/')[0];
        //            var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
            /// <summary>
            /// 场景列表
            /// </summary>
            public List<ScenesListInfo> ScenesList = new List<ScenesListInfo>();
        }
        //            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());
        /// <summary>
        /// 场景列表中的具体信息
        /// </summary>
        [System.Serializable]
        public class ScenesListInfo
        {
            /// <summary>
            /// 场景ID
            /// </summary>
            public int ScenesId;
        //                if (temp == null)
        //                {
        //                    d.errorMessageBase = "网关错误回复,且数据是空";
        //                }
        //                else
        //                {
        //                    d.errorResponData = temp;
        //                    d.errorMessageBase = ErrorMess(temp.Error);
        //                }
        //            }
            /// <summary>
            /// 名称
            /// </summary>
            public string ScenesName;
        //            if (topic == gatewayID + "/" + "DeviceBind_AddBind_Respon")
        //            {
        //                var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
        //                var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetControlDeviceBindResponseData>(jobject["Data"].ToString());
        //                if (tempData == null)
        //                {
        //                    d.errorMessageBase = "网关返回的数据为空";
        //                }
        //                else
        //                {
        //                    d.getControlDeviceBindResponseData = tempData;
        //                }
        //            }
        //        };
        //        Gateway.Actions += action;
        //        System.Console.WriteLine("GetControlDevice_Actions 启动" + "_" + Gateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString());
        //        var jObject = new JObject {{ "Cluster_ID", 0 }, { "Command", 154 } };
        //        Gateway.Send("DeviceBind/GetControlDevice", jObject.ToString());
        //        var dateTime = DateTime.Now;
        //        while ((DateTime.Now - dateTime).TotalMilliseconds < 1000)
        //        {
        //            await System.Threading.Tasks.Task.Delay(10);
        //            if (d.getControlDeviceBindResponseData != null)
        //            {
        //                break;
        //            }
        //        }
        //        if ((DateTime.Now - dateTime).TotalMilliseconds > 10000)
        //        {
        //            d.errorMessageBase = " 回复超时,请重新操作";
        //        }
        //        Gateway.Actions -= action;
        //        System.Console.WriteLine("GetControlDevice_Actions 退出" + System.DateTime.Now.ToString());
        //        return d;
        //    });
        //}
        ///// <summary>
        ///// 获取所有做了绑定的控制设备数据,网关反馈信息
        ///// </summary>
        //public GetControlDeviceBindResponseAllData getControlDeviceBindResponseAllData;
        //[System.Serializable]
        //public class GetControlDeviceBindResponseAllData
        //{
        //    /// <summary>
        //    /// 错误信息
        //    /// </summary>
        //    public string errorMessageBase;
        //    /// <summary>
        //    /// 网关信息错误反馈
        //    /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
        //    /// </summary>
        //    public ErrorResponData errorResponData;
        //    /// <summary>
        //    /// 获取所有做了绑定的控制设备数据
        //    /// </summary>
        //    public GetControlDeviceBindResponseData getControlDeviceBindResponseData;
        //}
        ///// <summary>
        ///// 获取所有做了绑定的控制设备数据
        ///// </summary>
        //public GetControlDeviceBindResponseData getControlDeviceBindResponseData;
        //[System.Serializable]
        //public class GetControlDeviceBindResponseData
        //{
        //    /// <summary>
        //    /// 设备属性列表
        //    /// </summary>
        //    public List<DeviceObj> DeviceObj = new List<DeviceObj>();
        //}
        ///// <summary>
        ///// Command数组
        ///// </summary>
        //public class DeviceObj
        //{
        //    /// <summary>
        //    /// 控制设备的mac地址
        //    /// </summary>
        //    public string DeviceAddr;
        //    /// <summary>
        //    /// 控制设备的端口号
        //    /// </summary>
        //    public int Epoint;
        //}
        //#endregion
            /// <summary>
            /// 是否处于开启状态
            ///0:场景没有被开启
            ///1:场景处于开启状态
            /// </summary>
            public int IsOpen;
        }
        #endregion
    }
}