HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-08-11 26d1cdf2f5246c1ad7890e6740444c4a6a80e6fb
ZigbeeApp/Shared/Phone/ZigBee/Device/Panel.cs
@@ -323,7 +323,7 @@
        /// PIR配置参数回复
        /// </summary>
        [System.Serializable]
        public class PanelPrivateFunctionsResponseAllInfo:ErrorResponCommon
        public class PanelPrivateFunctionsResponseAllInfo : ErrorResponCommon
        {
            /// <summary>
            /// 光感等级个数(Lux能力)
@@ -1105,6 +1105,174 @@
        }
        #endregion
        #region  校正温度
        ///<summary >
        /// 校正温度
        /// </summary>
        public async System.Threading.Tasks.Task<ResponseAllData> CorrectTemperature(double correctValue, int direction = 0, int type = 0)
        {
            ResponseAllData result = null;
            if (Gateway == null)
            {
                result = new ResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new ResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (clientDataPassthroughResponseData == null)
                        {
                            result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = clientDataPassthroughResponseData.PassData;
                                if (data.Length == 16)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new ResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        if (tempD.command == "0503")
                                        {
                                            result = new ResponseAllData { responseData = tempD };
                                            DebugPrintLog($"UI收到通知后的主题_command:0500_{ topic}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
                try
                {
                    var passData = CorrectTemperatureData(correctValue,direction, type);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
                return result;
            });
        }
        /// <summary>
        /// 校正温度
        /// [该条协议另外2个参数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>