黄学彪
2020-05-11 2e7e5f9af5b32cfe1fc3c6ba40bf7eb984bbd0a4
ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs
@@ -16,73 +16,12 @@
        /// WcdType=4:开合帘
        /// WcdType=0:卷帘
        /// </summary>
        public int WcdType = 0;
        /// <summary>
        ///窗帘当前高度,单位:cm.
        /// </summary>
        public int WcdCurrentPositionLift = 0;
        public int WcdType = -1;
        /// <summary>
        /// 当前窗帘所在的位置(百分比).
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int WcdCurrentPositionLiftPercentage = 0;
        //{
        //    get
        //    {
        //        if (DeviceStatusReport.CluterID == 258)
        //        {
        //            var attriButeList = DeviceStatusReport.AttriBute;
        //            foreach (var attriBute in attriButeList)
        //            {
        //                if (attriBute.AttributeId == 8)
        //                {
        //                    return attriBute.AttriButeData;
        //                }
        //            }
        //        }
        //        return 0;
        //    }
        //}
        /// <summary>
        /// 窗帘全开所在的角度,单位:0.1°
        /// </summary>
        public int WcdInstalledOpenLimitTilt = 0;
        /// <summary>
        /// 窗帘全关所在的角度,单位:0.1°
        /// </summary>
        public int WcdInstalledClosedLimitTilt = 0;
        /// <summary>
        /// 当前开合帘电机方向
        /// <para> (false:电机方向正向;true:电机方向反向;)</para> .
        /// </summary>
        public bool WcdCurrentDirection = false;
        /// <summary>
        /// 当前开合帘维护模式
        /// <para>fasle:电机运转正常;true:电机在维修模式下运行;</para>
        /// </summary>
        public bool WcdCurrentMaintenance = false;
        /// <summary>
        /// 当前窗帘开合帘限位开(上)限位
        /// 注意这里值是网关返回的实际值,UI上显示的值要实际处理
        /// </summary>
        public int WcdCurrentWcdInstalOpenLimit = 0;
        /// <summary>
        /// 当前开合帘限位关(下)限位
        /// 注意这里值是网关返回的实际值,UI上显示的值要实际处理
        /// </summary>
        public int WcdCurrentInstalCloseLimit = 0;
        /// <summary>
        /// 当前开合帘总的长度
        /// </summary>
        public int WcdCurrentLength = 0;
        /// <summary>
        /// 读取当前窗帘的模式
@@ -91,6 +30,30 @@
        public void ReadWcdType()
        {
            ReadAttri(Device.Cluster_ID.WindowCovering, AttriButeId.WindowCoveringType);
        }
        /// <summary>
        /// 读取当前窗帘模式
        /// </summary>
        /// <param name="commonDevice"></param>
        /// <param name="action"></param>
        public static void ReadWcdTypeAction(CommonDevice commonDevice, Action action)
        {
            new System.Threading.Thread(() =>
            {
                (commonDevice as Rollershade).ReadWcdType();
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalSeconds < 10)
                {
                    System.Threading.Thread.Sleep(100);
                    if ((commonDevice as Rollershade).WcdType != -1)
                    {
                        break;
                    }
                }
                action?.Invoke();
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
@@ -209,7 +172,7 @@
            var data = new JObject {
                    { "Value", value }
                 };
            jObject.Add("Data", data);
            jObject.Add("Data", data);
            Gateway?.Send("DeviceControl", jObject.ToString());
        }
@@ -231,7 +194,7 @@
            var data = new JObject {
                    { "Value", value }
                 };
            jObject.Add("Data", data);
            jObject.Add("Data", data);
            Gateway?.Send("DeviceControl", jObject.ToString());
        }
@@ -253,7 +216,7 @@
            var data = new JObject {
                    { "Value", value }
                };
            jObject.Add("Data", data);
            jObject.Add("Data", data);
            Gateway?.Send("DeviceControl", jObject.ToString());
        }
@@ -276,7 +239,7 @@
            var data = new JObject {
                    { "Value", value }
                 };
            jObject.Add("Data", data);
            jObject.Add("Data", data);
            Gateway?.Send("DeviceControl", jObject.ToString());
        }
@@ -301,8 +264,7 @@
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -316,7 +278,6 @@
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
@@ -336,15 +297,15 @@
                try
                {
                    int attributeData = 0;
                    int bit0 = 0;
                    int bit0 = 0;
                    if (isDirectionReversed)
                    {
                        bit0 = 1;
                    }
                    }
                    attributeData = bit0 * 1;
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } };
                    jObject.Add("Data", data);
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
@@ -391,8 +352,7 @@
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -406,7 +366,6 @@
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
@@ -425,9 +384,9 @@
                try
                {
                    int attributeData = 0;
                    int bit2 = 0;
                    int attributeData = 0;
                    int bit2 = 0;
                    if (isMotorMaintenance)
                    {
                        bit2 = 1;
@@ -435,7 +394,7 @@
                    attributeData = bit2 * 4;
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } };
                    jObject.Add("Data", data);
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
@@ -481,8 +440,7 @@
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -496,7 +454,6 @@
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
@@ -519,15 +476,15 @@
                    switch (installedLimit)
                    {
                        case CurtainPrivateInstalledLimi.UpLimit:
                            tempLimit = 1;
                            tempLimit = 2;
                            break;
                        case CurtainPrivateInstalledLimi.DownLimit:
                            tempLimit = 2;
                            tempLimit = 1;
                            break;
                    }
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0xea01 }, { "AttributeDataType", 32 }, { "AttributeData", tempLimit } };
                    jObject.Add("Data", data);
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
@@ -560,11 +517,11 @@
            /// <summary>
            /// 窗帘全开所在的位置(上限位)
            /// </summary>
            UpLimit = 1,
            UpLimit = 2,
            /// <summary>
            /// 窗帘全关所在的位置(下限位)
            /// </summary>
            DownLimit = 2,
            DownLimit = 1,
        }
        #endregion
@@ -589,8 +546,7 @@
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -604,7 +560,6 @@
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
@@ -622,11 +577,11 @@
                System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString());
                try
                {
                {
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0xea02 }, { "AttributeDataType", 32 }, { "AttributeData", 1 } };
                    jObject.Add("Data", data);
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
@@ -688,8 +643,7 @@
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                        if (temp == null)
                        {
@@ -703,7 +657,6 @@
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
                        if (tempData == null)
@@ -726,10 +679,10 @@
                    switch (limiType)
                    {
                        case LimiType.DownLimit:
                            tempLimit = 8;
                            tempLimit = 2;
                            break;
                        case LimiType.UpLimit:
                            tempLimit = 2;
                            tempLimit = 8;
                            break;
                    }
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
@@ -767,13 +720,13 @@
            /// <summary>
            /// 删除窗帘上限位
            /// </summary>
            UpLimit = 0x02,
            UpLimit = 0x08,
            /// <summary>
            /// 删除窗帘下限位
            /// </summary>
            DownLimit = 0x08,
            DownLimit = 0x02,
        }
        }
        #endregion
    }
}