HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-29 9a4629512ccf8359efd88671c9317c3cc7faf0c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 设备固定信息的逻辑
    /// </summary>
    public class HdlDeviceFixedAttributeLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备固定信息的逻辑
        /// </summary>
        private static HdlDeviceFixedAttributeLogic m_Current = null;
        /// <summary>
        /// 设备固定信息的逻辑
        /// </summary>
        public static HdlDeviceFixedAttributeLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlDeviceFixedAttributeLogic();
                }
                return m_Current;
            }
        }
 
        #endregion
 
        #region ■ 主入口函数_________________________
 
        /// <summary>
        /// 读取以及设置设备固定属性(false:不需要发送命令)
        /// </summary>
        /// <param name="i_device">设备回路</param>
        public bool SetAllFixedAttributeToDevice(CommonDevice i_device)
        {
            if (i_device == null)
            {
                return false;
            }
            var localDevice = Common.LocalDevice.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.GetCurtainComand(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;
        }
 
        #endregion
 
        #region ■ 获取窗帘命令_______________________
 
        /// <summary>
        /// 获取窗帘命令
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="jObject">标题数据</param>
        /// <param name="attriBute">属性数据</param>
        private void GetCurtainComand(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
    }
}