黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
ZigbeeApp/Shared/Phone/Common/Logic/HdlDeviceAttributeLogic.cs
File was renamed from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAttributeLogic.cs
@@ -4,7 +4,7 @@
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
namespace Shared.Phone
{
    /// <summary>
    /// 设备属性的逻辑类
@@ -63,6 +63,95 @@
            jObject.Add("Data", data);
            return jObject.ToString();
        }
        #endregion
        #region ■ 读取设备硬件信息___________________
        /// <summary>
        /// 读取设备硬件信息
        /// </summary>
        /// <param name="device">设备回路</param>
        public void ReadDeviceAllHardFirmwareInfo(CommonDevice device)
        {
            if (device == null)
            {
                return;
            }
            var jObject = new Newtonsoft.Json.Linq.JObject
            {
                { "DeviceAddr",device.DeviceAddr },
                { "Epoint", device.DeviceEpoint },
                { "Cluster_ID", (int)Cluster_ID.Basic },
                { "Command", 108 }
            };
            var attriBute = new Newtonsoft.Json.Linq.JArray
            {
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", 4}//生产商名字
               },
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", 5}//型号码(也叫模块ID)
               },
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", 6}//生产日期
               },
                  new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", 7}//电源
               },
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", 13}//序列号
               }
            };
            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
            jObject.Add("Data", data);
            HdlGatewayLogic.Current.SendJobjectData(device.CurrentGateWayId, "GetDeviceStatus", jObject.ToString());
        }
        #endregion
        #region ■ 获取设备固件版本信息_______________
        /// <summary>
        /// 读取设备固件版本信息
        /// </summary>
        /// <param name="device"></param>
        public void ReadDeviceFirmwareVersion(OTADevice device)
        {
            var jObject = new Newtonsoft.Json.Linq.JObject
            {
                { "DeviceAddr",device.DeviceAddr },
                { "Epoint", device.DeviceEpoint },
                { "Cluster_ID", (int)Cluster_ID.Ota },
                { "Command", 108 }
            };
            var attriBute = new Newtonsoft.Json.Linq.JArray
            {
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", (int)AttriButeId.ImgVersion}
               },
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", (int)AttriButeId.mgHWversion}
               },
               new Newtonsoft.Json.Linq.JObject
               {
                 { "AttriButeId", (int)AttriButeId.ImgTypeId}
               }
            };
            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
            jObject.Add("Data", data);
            HdlGatewayLogic.Current.SendJobjectData(device.CurrentGateWayId, "GetDeviceStatus", jObject.ToString());
        }
        #endregion
@@ -226,7 +315,7 @@
        #endregion
        #region ■ PM2.5_______________________________
        #region ■ PM2.5______________________________
        /// <summary>
        /// SendPmSensorComand
        /// </summary>
@@ -273,87 +362,6 @@
                 { "AttriButeId", (int)AttriButeId.MeasuredValue}
               }
            };
            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
            jObject.Add("Data", data);
            device.Gateway?.Send("GetDeviceStatus", jObject.ToString());
        }
        #endregion
        #region ■ 晾衣架_______________________________
        /// <summary>
        /// SendAirerComand
        ///回路2:读取照明开关状态
        ///回路3:读取风干开关状态和时间值
        ///回路4:读取烘干开关状态和时间值
        ///回路5:读取消毒开关状态和时间值
        /// </summary>
        /// <param name="device">设备</param>
        /// <param name="ctrlEpoint">控制端点</param>
        public void SendAirerComand(CommonDevice device, int ctrlEpoint)
        {
            if (device == null)
            {
                return;
            }
            new System.Threading.Thread(() =>
            {
                SendAirerStatuComand(device, ctrlEpoint);
                System.Threading.Thread.Sleep(300);
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// SendAirerStatuComand
        /// </summary>
        /// <param name="device">设备</param>
        private void SendAirerStatuComand(CommonDevice device, int ctrlEpoint = 1)
        {
            if (device == null)
            {
                return;
            }
            var jObject = new Newtonsoft.Json.Linq.JObject
            {
                { "DeviceAddr",device.DeviceAddr },
                { "Epoint", ctrlEpoint },
                { "Cluster_ID", (int)Cluster_ID.Switch},
                { "Command", 108 }
            };
            Newtonsoft.Json.Linq.JArray attriBute = new Newtonsoft.Json.Linq.JArray();
            //晾衣架的晾衣架的(烘干,风干,消毒,照明状态读取)
            attriBute = new Newtonsoft.Json.Linq.JArray
             {
                new Newtonsoft.Json.Linq.JObject
               {
                    //晾衣架的照明开关状态
                 { "AttriButeId", (int)AttriButeId.Switch}
               }
             };
            //if (device.DeviceEpoint != 2)
            //{
            //由于设备不支持时间功能,后期才支持,注意处理时间要根据烘干,风干,消毒是否开才发送相应大时间读取数据
            //attriBute = new Newtonsoft.Json.Linq.JArray {
            //        new Newtonsoft.Json.Linq.JObject
            //       {
            //            //晾衣架的开关状态(烘干,风干,消毒)
            //         { "AttriButeId", (int)AttriButeId.Switch}
            //       },
            //           new Newtonsoft.Json.Linq.JObject
            //       {
            //            //晾衣架的晾衣架的(烘干,风干,消毒)剩余时间
            //         { "AttriButeId", (int)AttriButeId.AirerRemainTime}
            //       },
            //       new Newtonsoft.Json.Linq.JObject
            //       {
            //           //晾衣架的(烘干,风干,消毒)时间
            //         { "AttriButeId", (int)AttriButeId.AirerTime}
            //       }
            //    };
            //}
            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
            jObject.Add("Data", data);
            device.Gateway?.Send("GetDeviceStatus", jObject.ToString());
@@ -503,7 +511,7 @@
                colorDevice.ReadLevel();
                System.Threading.Thread.Sleep(300);
                colorDevice.ReadColorTemperature();
                if (LocalDevice.Current.IsMiniLight(device) == true)
                if (HdlDeviceCommonLogic.Current.IsMiniLight(device) == true)
                {
                    //mini夜灯需要读取蜂鸣器状态
                    System.Threading.Thread.Sleep(300);
@@ -576,5 +584,75 @@
        }
        #endregion
        #region ■ 读取设备固定属性___________________
        /// <summary>
        /// 读取设备固定属性(false:不需要发送命令)
        /// </summary>
        /// <param name="i_device">设备回路</param>
        public bool ReadDeviceAllFixedAttribute(CommonDevice i_device)
        {
            if (i_device == null)
            {
                return false;
            }
            var localDevice = HdlDeviceCommonLogic.Current.GetDevice(i_device.DeviceAddr, i_device.DeviceEpoint);
            if (localDevice == null)
            {
                //ota也会跑进来
                return false;
            }
            Newtonsoft.Json.Linq.JObject jObject = null;
            Newtonsoft.Json.Linq.JArray attriBute = null;
            //窗帘
            if (localDevice.Type == DeviceType.WindowCoveringDevice
                && ((Rollershade)localDevice).WcdType == -1)
            {
                this.GetCurtainFixedAttributeComand(localDevice, ref jObject, ref attriBute);
            }
            if (jObject == null)
            {
                //不需要发送
                return false;
            }
            //发送
            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
            jObject.Add("Data", data);
            localDevice.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
            return true;
        }
        #region 获取窗帘固定属性命令__
        /// <summary>
        /// 获取窗帘固定属性命令
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="jObject">标题数据</param>
        /// <param name="attriBute">属性数据</param>
        private void GetCurtainFixedAttributeComand(CommonDevice device, ref Newtonsoft.Json.Linq.JObject jObject, ref Newtonsoft.Json.Linq.JArray attriBute)
        {
            jObject = new Newtonsoft.Json.Linq.JObject
            {
               { "DeviceAddr",device.DeviceAddr },
               { "Epoint", device.DeviceEpoint },
               { "Cluster_ID", (int)Cluster_ID.WindowCovering },
               { "Command", 108 }
            };
            attriBute = new Newtonsoft.Json.Linq.JArray
            {
               new Newtonsoft.Json.Linq.JObject
               {
                  { "AttriButeId", (int)AttriButeId.WindowCoveringType }
               }
            };
        }
        #endregion
        #endregion
    }
}