黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
@@ -15,10 +15,20 @@
            this.Type = DeviceType.OnOffSwitch;
        }
        /// <summary>
        /// 多功能面板中被绑定的目标
        /// </summary>
      [Newtonsoft.Json.JsonIgnore]
        public System.Collections.Generic.Dictionary<string, List<BindListAllInfo>> bindTargetsFromMutilfunctionPanelList = new System.Collections.Generic.Dictionary<string, List<BindListAllInfo>>();
        /// <summary>
        /// 按键模式(私有功能)
        /// </summary>
        public int panelMode = 65535;
        /// <summary>
        ///当前选择的简约多功能面板的类型【简约多功能面板】
        /// 0:场景  1:开关  2:插座  3:灯光  4:遮阳 5:空调 6:新风
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int currentMutilfunctionBindType = 0;
        /// <summary>
        /// 当前选择模式
        /// </summary>
@@ -318,7 +328,7 @@
        /// PIR配置参数回复
        /// </summary>
        [System.Serializable]
        public class PanelPrivateFunctionsResponseAllInfo:ErrorResponCommon
        public class PanelPrivateFunctionsResponseAllInfo : ErrorResponCommon
        {
            /// <summary>
            /// 光感等级个数(Lux能力)
@@ -773,7 +783,6 @@
            string dataSerialNum = "01";
            string addDataLength = "03";
            string kStatus = "";
            string kNum = "";
            int attributeData = 0;
            try
@@ -1101,6 +1110,174 @@
        }
        #endregion
        #region  校正温度
        ///<summary >
        /// 校正温度
        /// </summary>
        public async System.Threading.Tasks.Task<ResponseAllData> CorrectTemperature(double correctValue, int direction = 0, int type = 0)
        {
            ResponseAllData result = null;
            if (Gateway == null)
            {
                result = new ResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new ResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (clientDataPassthroughResponseData == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = clientDataPassthroughResponseData.PassData;
                                if (data.Length == 16)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new ResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        if (tempD.command == "0503")
                                        {
                                            result = new ResponseAllData { responseData = tempD };
                                            DebugPrintLog($"UI收到通知后的主题_command:0500_{ topic}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    var passData = CorrectTemperatureData(correctValue,direction, type);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 校正温度
        /// [该条协议另外2个参数UI和设备都不需要,设备都同事要求传感器距离和传感器触发延迟时间都默认是FFFF]
        /// </summary>
        /// <param name="correctValue">校正温度值</param>
        /// <returns></returns>
        string CorrectTemperatureData(double correctValue,int direction=0, int type = 0)
        {
            string data = "";
            string dataLength = "09";
            string dataComand1 = "03";
            string dataComand2 = "05";
            string dataSerialNum = "01";
            string addDataLength = "05";
            string typeString = "";
            string directString = "";
            string correctValueString = "";
            try
            {
                if (type == 1)
                {
                    typeString = "0100";
                }
                else
                {
                    typeString = "0000";
                }
                if (direction == 1)
                {
                    directString = "01";
                }
                else if (direction == 2)
                {
                    directString = "02";
                }
                else
                {
                    directString = "00";
                }
                int curV = (int)(correctValue * 100);
                var tempBytes = new byte[2];
                for (int i = 0; i < 2; i++)
                {
                    tempBytes[i] = (byte)(curV >> (i * 8) & 0xff);
                }
                var curV1 = Convert.ToString(tempBytes[0], 16);
                var curV2 = Convert.ToString(tempBytes[1], 16);
                if (curV1.Length == 1)
                {
                    curV1 = "0" + curV1;
                }
                if (curV2.Length == 1)
                {
                    curV2 = "0" + curV2;
                }
                correctValueString = (curV1 + curV2).ToUpper();
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                  typeString + directString + correctValueString;
            }
            catch { };
            return data;
        }
        #endregion
        #region 获取按键指示灯开关颜色.
        /// <summary>
@@ -1145,12 +1322,12 @@
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            ///按键开状态(指示)亮度(这个是点击后的值)
            ///按键开状态(指示)亮度(这个是点击后的值,或者 1-6干接点的背光灯)
            /// </summary>
            public int panelDirectionsLevel = -1;
            /// <summary>
            /// 按键关状态(背光)亮度(这个是点击前的值)
            /// 按键关状态(背光)亮度(这个是点击前的值,或者 第七干接点的背光灯)
            /// </summary>
            public int panelBacklightLevel = -1;
        }
@@ -1361,7 +1538,7 @@
            /// 传感器使能
            ///false-disable  true-enable
            /// </summary>
            public bool enable;
            public bool enable= false;
            /// <summary>
            ///传感器距离