| | |
| | | }
|
| | | }
|
| | |
|
| | | /// 需要获取固定属性的对象设备
|
| | | /// </summary>
|
| | | private HashSet<string> hsGetHardInfoDevice = new HashSet<string>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 主入口函数_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 读取以及设置设备固定属性
|
| | | /// 读取以及设置设备固定属性(false:不需要发送命令)
|
| | | /// </summary>
|
| | | /// <param name="device">设备回路</param>
|
| | | public void SetAllFixedAttributeToDevice(CommonDevice device)
|
| | | /// <param name="i_device">设备回路</param>
|
| | | public bool SetAllFixedAttributeToDevice(CommonDevice i_device)
|
| | | {
|
| | | if (device == null)
|
| | | if (i_device == null)
|
| | | {
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | lock (this.hsGetHardInfoDevice)
|
| | | var localDevice = Common.LocalDevice.Current.GetDevice(i_device.DeviceAddr, i_device.DeviceEpoint);
|
| | | if (localDevice == null)
|
| | | {
|
| | | //先移除
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == true)
|
| | | {
|
| | | this.hsGetHardInfoDevice.Remove(mainKeys);
|
| | | }
|
| | | if (HdlGatewayReceiveLogic.Current.IsEsixt("DeviceGetFixedAttribute") == false)
|
| | | {
|
| | | //添加事件
|
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceGetFixedAttribute", ReceiveComandDiv.A设备属性上报, this.SetFixedAttributeByInterfaceResult);
|
| | | }
|
| | | //发送命令
|
| | | this.SeFixedAttributeComand(device);
|
| | | //ota也会跑进来
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 发送命令___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 发送获取固定属性的命令
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | private void SeFixedAttributeComand(CommonDevice device)
|
| | | {
|
| | | Newtonsoft.Json.Linq.JObject jObject = null;
|
| | | Newtonsoft.Json.Linq.JArray attriBute = null;
|
| | | //窗帘
|
| | | if (device.Type == DeviceType.WindowCoveringDevice)
|
| | | if (localDevice.Type == DeviceType.WindowCoveringDevice
|
| | | && ((Rollershade)localDevice).WcdType == -1)
|
| | | {
|
| | | this.GetCurtainComand(device, ref jObject, ref attriBute);
|
| | | this.GetCurtainComand(localDevice, ref jObject, ref attriBute);
|
| | | }
|
| | | if (jObject == null)
|
| | | {
|
| | | //不需要发送
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | this.hsGetHardInfoDevice.Add(mainkeys);
|
| | | //发送
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
|
| | | jObject.Add("Data", data);
|
| | | device.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
|
| | | localDevice.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | { "AttriButeId", (int)AttriButeId.WindowCoveringType }
|
| | | }
|
| | | };
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置属性(主函数)___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备的固定属性 -1:异常 0:推送的这个东西并不是需要的 1:正常
|
| | | /// </summary>
|
| | | /// <param name="report">上报信息</param>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | private int SetFixedAttribute(CommonDevice.DeviceStatusReportData report, CommonDevice device)
|
| | | {
|
| | | if (report == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | | //窗帘
|
| | | if (device.Type == DeviceType.WindowCoveringDevice)
|
| | | {
|
| | | return this.SetCurtainAttribute(report, (Rollershade)device);
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置窗帘属性_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置窗帘属性 -1:异常 0:推送的这个东西并不是需要的 1:正常
|
| | | /// </summary>
|
| | | /// <param name="report">上报信息</param>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | private int SetCurtainAttribute(CommonDevice.DeviceStatusReportData report, Rollershade device)
|
| | | {
|
| | | if (report.CluterID != (int)Cluster_ID.WindowCovering || device == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | | //属性是否改变
|
| | | bool AttriButeChanged = false;
|
| | | int attriButeId = (int)AttriButeId.WindowCoveringType;
|
| | | foreach (var data in report.AttriBute)
|
| | | {
|
| | | if (data.AttributeId == attriButeId)
|
| | | {
|
| | | AttriButeChanged = true;
|
| | | device.WcdType = data.AttriButeData;
|
| | | }
|
| | | }
|
| | | if (AttriButeChanged == true)
|
| | | {
|
| | | //属性已经改变,则保存
|
| | | return 1;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 接口推送处理_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据接口推送的信息,设置设备硬件信息
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | private void SetFixedAttributeByInterfaceResult(CommonDevice device)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == false)
|
| | | {
|
| | | //推送的这个东西并不是指定的设备
|
| | | return;
|
| | | }
|
| | | //设置设备硬件信息
|
| | | var localDevice = Common.LocalDevice.Current.GetDevice(mainKeys);
|
| | | if (localDevice == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | lock (hsGetHardInfoDevice)
|
| | | {
|
| | | //-1:异常 0:推送的这个东西并不是需要的 1:正常
|
| | | if (this.SetFixedAttribute(device.DeviceStatusReport, localDevice) != 1)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //保存
|
| | | localDevice.ReSave();
|
| | | //移除
|
| | | this.hsGetHardInfoDevice.Remove(mainKeys);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 移除监听线程_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 移除获取设备硬件信息的监听线程
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | public void RemoveDeviceHardInfoThread(CommonDevice device)
|
| | | {
|
| | | lock (hsGetHardInfoDevice)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == true)
|
| | | {
|
| | | this.hsGetHardInfoDevice.Remove(mainKeys);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|