From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs |  843 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 477 insertions(+), 366 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs
old mode 100755
new mode 100644
index c7b8dc2..bf9497a
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs
@@ -1,366 +1,477 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// 绐楀笜鐨勯�昏緫
-    /// </summary>
-    public class HdlDeviceCurtainLogic
-    {
-        #region 鈻� 鍙橀噺澹版槑___________________________
-
-        /// <summary>
-        /// 绐楀笜鐨勯�昏緫
-        /// </summary>
-        private static HdlDeviceCurtainLogic m_Current = null;
-        /// <summary>
-        /// 绐楀笜鐨勯�昏緫
-        /// </summary>
-        public static HdlDeviceCurtainLogic Current
-        {
-            get
-            {
-                if (m_Current == null)
-                {
-                    m_Current = new HdlDeviceCurtainLogic();
-                }
-                return m_Current;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鎵嬫媺鎺у埗___________________________
-
-        /// <summary>
-        /// 璁剧疆鎵嬫媺鎺у埗鐘舵�佸��
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param>
-        /// <returns></returns>
-        public async Task<bool> SetHandPullControl(Rollershade rollershade, bool bolStatu)
-        {
-            var result = await rollershade.SetCurtianMaintenanceAsync(bolStatu);
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null)
-            {
-                //鍒囨崲鎵嬫媺鎺у埗澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //鍒囨崲鎵嬫媺鎺у埗澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            //澶囦唤灞炴��
-            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗, bolStatu);
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 绐楀笜鏂瑰悜閰嶇疆_______________________
-
-        /// <summary>
-        /// 閰嶇疆绐楀笜鐨勬柟鍚�
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param>
-        /// <returns></returns>
-        public async Task<bool> SetCurtainDirection(Rollershade rollershade, bool bolStatu)
-        {
-            var result = await rollershade.SetCurtainDirectionAsync(bolStatu);
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null)
-            {
-                //绐楀笜鏂瑰悜璁剧疆澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //绐楀笜鏂瑰悜璁剧疆澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            //澶囦唤璁惧
-            await this.BackupCurtainDirection(rollershade, bolStatu);
-
-            return true;
-        }
-
-        /// <summary>
-        /// 澶囦唤绐楀笜鏂瑰悜
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param>
-        /// <returns></returns>
-        public async Task<bool> BackupCurtainDirection(Rollershade rollershade, bool bolStatu)
-        {
-            //澶囦唤璁惧
-            return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鏂瑰悜, bolStatu);
-        }
-
-        #endregion
-
-        #region 鈻� 绐楀笜闄愪綅閰嶇疆_______________________
-
-        /// <summary>
-        /// 鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="limiType">纭鍙婅鐩栦笂闄愪綅杩樻槸涓嬮檺浣�</param>
-        /// <param name="upLimit">涓婇檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param>
-        /// <param name="downLimit">涓嬮檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param>
-        /// <returns></returns>
-        public async Task<bool> CommitCurtainLimitPoint(Rollershade rollershade, Rollershade.CurtainPrivateInstalledLimi limiType, int upLimit, int downLimit)
-        {
-            CommonDevice.SetWritableValueResponAllData result = null;
-            if (upLimit == -1 && upLimit == -1)
-            {
-                //杩欎釜鏄嵎甯�
-                result = await rollershade.SetCurtainInstalledLimitAsync(limiType);
-            }
-            else
-            {
-                //杩欎釜鏄紑鍚堝笜 "2,0x00ff,0x00ff"鏍煎紡 鍚堥檺浣嶅湪鍓嶏紝寮�闄愪綅鍦ㄥ悗
-                string convertData = "\"2,0x" + Convert.ToString(downLimit, 16).PadLeft(4, '0');
-                convertData += ",0x" + Convert.ToString(upLimit, 16).PadLeft(4, '0') + "\"";
-                //鐒跺悗灏嗗畠浠浆涓篈SK鐮佹暟鍊�,鐒跺悗鍐嶈浆涓�16杩涘埗
-                //鎬昏闀垮害涓�17(杩欓噷鏄�16杩涘埗)
-                string sendData = "11";
-                foreach (char c in convertData)
-                {
-                    sendData += Convert.ToString((int)c, 16).PadLeft(2, '0');
-                }
-                result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData);
-            }
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null)
-            {
-                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
-                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
-                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-
-            if (upLimit != -1 && downLimit != -1)
-            {
-                //澶囦唤璁惧
-                await this.BackupCurtainLimitPoint(rollershade, upLimit, downLimit);
-            }
-
-            return true;
-        }
-
-        /// <summary>
-        /// 鍒犻櫎闄愪綅鐐�
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="limiType">鍒犻櫎涓婇檺浣嶈繕鏄垹闄や笅闄愪綅</param>
-        /// <returns></returns>
-        public async Task<bool> DeleteCurtainLimitPoint(Rollershade rollershade, Rollershade.LimiType limiType)
-        {
-            var result = await rollershade.DeleteCurtainLimitsAsync(limiType);
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null)
-            {
-                //閲嶇疆绐楀笜闄愪綅鐐瑰け璐�
-                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //閲嶇疆绐楀笜闄愪綅鐐瑰け璐�
-                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// 澶囦唤绐楀笜闄愪綅鐐�
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <param name="upLimit">涓婇檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</param>
-        /// <param name="downLimit">涓嬮檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</param>
-        /// <returns></returns>
-        public async Task<bool> BackupCurtainLimitPoint(Rollershade rollershade, int upLimit, int downLimit)
-        {
-            //澶囦唤璁惧
-            var backData = new Newtonsoft.Json.Linq.JObject
-            {
-                { "upLimit",upLimit },
-                { "downLimit", downLimit }
-            };
-            //澶囦唤璁惧
-           return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅, backData);
-        }
-
-        #endregion
-
-        #region 鈻� 鑾峰彇绐楀笜闄愪綅閰嶇疆___________________
-
-        /// <summary>
-        /// 鍙戦�佽幏鍙栫獥甯橀檺浣嶉厤缃殑鍛戒护
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        public void SetGetCurtainLimitSettionComand(Rollershade rollershade)
-        {
-            var jObject = new Newtonsoft.Json.Linq.JObject
-            {
-                { "DeviceAddr",rollershade.DeviceAddr },
-                { "Epoint", rollershade.DeviceEpoint },
-                { "Cluster_ID", (int)Cluster_ID.WindowCovering },
-                { "Command", 108 }
-            };
-            var attriBute = new Newtonsoft.Json.Linq.JArray
-            {
-               new Newtonsoft.Json.Linq.JObject
-               {
-                 //寮�鍚堝笜鏂瑰悜
-                 { "AttriButeId", (int)AttriButeId.WindowCoveringMode}
-               },
-               new Newtonsoft.Json.Linq.JObject
-               {
-                 //寮�鍚堝笜鎬婚暱
-                 { "AttriButeId", (int)AttriButeId.WindowCoveringLength}
-               },
-               new Newtonsoft.Json.Linq.JObject
-               {
-                 //寮�闄愪綅
-                 { "AttriButeId", (int)AttriButeId.InstalledOpenLimitLift}
-               },
-               new Newtonsoft.Json.Linq.JObject
-               {
-                 //鍚堥檺浣�
-                 { "AttriButeId", (int)AttriButeId.InstalledClosedLimitLift}
-               }
-            };
-            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
-            jObject.Add("Data", data);
-            rollershade.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
-        }
-
-        #endregion
-
-        #region 鈻� 閲嶇疆绐楀笜___________________________
-
-        /// <summary>
-        /// 閲嶇疆绐楀笜
-        /// </summary>
-        /// <param name="rollershade">绐楀笜瀵硅薄</param>
-        /// <returns></returns>
-        public async Task<bool> RestoreCurtain(Rollershade rollershade)
-        {
-            var result = await rollershade.RestoreCurtainLimitAsync();
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null)
-            {
-                //閲嶇疆绐楀笜澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //閲嶇疆绐楀笜澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 涓�鑸柟娉昣__________________________
-
-        /// <summary>
-        /// 鏄剧ず閿欒淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowErrorMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
-                contr.Show();
-            });
-        }
-
-        /// <summary>
-        /// 鏄剧ずTip淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowTipMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
-                contr.Show();
-            });
-        }
-
-        #endregion
-    }
-}
+锘縰sing Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Shared.Phone.TemplateData;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 绐楀笜鐨勯�昏緫
+    /// </summary>
+    public class HdlDeviceCurtainLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 绐楀笜鐨勯�昏緫
+        /// </summary>
+        private static HdlDeviceCurtainLogic m_Current = null;
+        /// <summary>
+        /// 绐楀笜鐨勯�昏緫
+        /// </summary>
+        public static HdlDeviceCurtainLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlDeviceCurtainLogic();
+                }
+                return m_Current;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鎵嬫媺鎺у埗___________________________
+
+        /// <summary>
+        /// 璁剧疆鎵嬫媺鎺у埗鐘舵�佸�� 鈽嗏槅鈽嗏槅鈽�
+        /// </summary>
+        /// <param name="device">绐楀笜瀵硅薄</param>
+        /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param>
+        /// <returns></returns>
+        public bool SetHandPullControl(CommonDevice device, bool bolStatu)
+        {
+            //濡傛灉鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                //娣诲姞缂撳瓨
+                TemplateDeviceDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, null);
+                return true;
+            }
+            //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+            var sendData = this.GetHandPullControlText(device.DeviceAddr, device.DeviceEpoint, bolStatu);
+            //鍙戦�佺粰缃戝叧
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+            if (result.ErrorMsg != null)
+            {
+                this.ShowTipMsg(result.ErrorMsg);
+                return false;
+            }
+            if (result.ErrorMsgDiv == 0)
+            {
+                //鍒囨崲鎵嬫媺鎺у埗澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            var data = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+            if (data.Status != 0)
+            {
+                //鍒囨崲鎵嬫媺鎺у埗澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            //娣诲姞缂撳瓨
+            TemplateDeviceDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, result.JsonData[0]);
+
+            return true;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏇存敼鎵嬫媺鎺у埗鐘舵�佺殑瀛楃涓插懡浠� 鈽嗏槅鈽嗏槅鈽�
+        /// </summary>
+        /// <param name="DeviceAddr">DeviceAddr</param>
+        /// <param name="DeviceEpoint">DeviceEpoint</param>
+        /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param>
+        /// <returns></returns>
+        public string GetHandPullControlText(string DeviceAddr, int DeviceEpoint, bool bolStatu)
+        {
+            int bit2 = bolStatu == true ? 1 : 0;
+            int 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);
+            return jObject.ToString();
+        }
+
+        #endregion
+
+        #region 鈻� 绐楀笜鏂瑰悜閰嶇疆_______________________
+
+        /// <summary>
+        /// 閰嶇疆绐楀笜鐨勬柟鍚�
+        /// </summary>
+        /// <param name="rollershade">绐楀笜瀵硅薄</param>
+        /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param>
+        /// <returns></returns>
+        public bool SetCurtainDirection(CommonDevice rollershade, bool bolStatu)
+        {
+            var result = this.SetCurtainDirectionAsync(rollershade, bolStatu);
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null)
+            {
+                //绐楀笜鏂瑰悜璁剧疆澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //绐楀笜鏂瑰悜璁剧疆澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            return true;
+        }
+
+        /// <summary>
+        /// 璁剧疆寮�鍚堝笜鐢垫満鏂瑰悜
+        /// <para>isDirectionReversed (false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜锛�)</para> .
+        /// </summary>
+        private CommonDevice.SetWritableValueResponAllData SetCurtainDirectionAsync(CommonDevice device, bool isDirectionReversed)
+        {
+            //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return TemplateDeviceDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, null);
+            }
+            //鑾峰彇缂栬緫绐楀笜鏂瑰悜鐨勫懡浠ゅ瓧绗�
+            var sendData = this.GetCurtainDirectionCommadText(device.DeviceAddr, device.DeviceEpoint, isDirectionReversed);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                return null;
+            }
+
+            //娣诲姞缂撳瓨
+            TemplateDeviceDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, result.JsonData[0]);
+
+            var tempData = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+            return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
+        }
+
+        /// <summary>
+        /// 鑾峰彇缂栬緫绐楀笜鏂瑰悜鐨勫懡浠ゅ瓧绗�
+        /// </summary>
+        /// <param name="DeviceAddr"></param>
+        /// <param name="DeviceEpoint"></param>
+        /// <param name="isDirectionReversed"></param>
+        /// <returns></returns>
+        public string GetCurtainDirectionCommadText(string DeviceAddr,int DeviceEpoint, bool isDirectionReversed)
+        {
+            int bit0 = isDirectionReversed == true ? 1 : 0;
+            int 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);
+
+            return jObject.ToString();
+        }
+
+        #endregion
+
+        #region 鈻� 寮�鍚堝笜闄愪綅閰嶇疆_____________________
+
+        /// <summary>
+        /// 璁剧疆寮�鍚堝笜闄愪綅
+        /// </summary>
+        /// <param name="rollershade"></param>
+        /// <param name="upLimit">寮�闄愪綅</param>
+        /// <param name="downLimit">鍚堥檺浣�</param>
+        /// <param name="curtainLength">瀵艰建闀垮害(杩欎釜鏄粰铏氭嫙璁惧鐢ㄧ殑)</param>
+        /// <returns></returns>
+        public bool SetAutoOpenCurtainLimitPoint(CommonDevice rollershade, int upLimit, int downLimit, int curtainLength)
+        {
+            //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return TemplateData.TemplateDeviceDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, null);
+            }
+            //鑾峰彇缂栬緫寮�鍚堝笜闄愪綅鐨勫懡浠ゅ瓧绗�
+            var sendData = this.GetAutoOpenCurtainLimitPointCommandText(rollershade.DeviceAddr, rollershade.DeviceEpoint, upLimit, downLimit);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(rollershade, "SetWritableValue", sendData, "SetWritableValue_Respon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+            if (tempData.Status != 0)
+            {
+                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            //娣诲姞缂撳瓨
+            TemplateDeviceDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, result.JsonData[0]);
+
+            return true;
+        }
+
+
+        /// <summary>
+        /// 鑾峰彇缂栬緫寮�鍚堝笜闄愪綅鐨勫懡浠ゅ瓧绗�
+        /// </summary>
+        /// <param name="DeviceAddr"></param>
+        /// <param name="DeviceEpoint"></param>
+        /// <param name="upLimit"></param>
+        /// <param name="downLimit"></param>
+        /// <returns></returns>
+        public string GetAutoOpenCurtainLimitPointCommandText(string DeviceAddr, int DeviceEpoint, int upLimit, int downLimit)
+        {
+            //杩欎釜鏄紑鍚堝笜 "2,0x00ff,0x00ff"鏍煎紡 鍚堥檺浣嶅湪鍓嶏紝寮�闄愪綅鍦ㄥ悗
+            string convertData = "\"2,0x" + Convert.ToString(downLimit, 16).PadLeft(4, '0');
+            convertData += ",0x" + Convert.ToString(upLimit, 16).PadLeft(4, '0') + "\"";
+            //鐒跺悗灏嗗畠浠浆涓篈SK鐮佹暟鍊�,鐒跺悗鍐嶈浆涓�16杩涘埗
+            //鎬昏闀垮害涓�17(杩欓噷鏄�16杩涘埗)
+            string sendData = "11";
+            foreach (char c in convertData)
+            {
+                sendData += Convert.ToString((int)c, 16).PadLeft(2, '0');
+            }
+
+            var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
+            var data = new JObject { { "Undivided", 0 }, { "AttributeId", 24 }, { "AttributeDataType", 65 }, { "AttributeData", sendData } };
+            jObject.Add("Data", data);
+
+            return jObject.ToString();
+        }
+
+        #endregion
+
+        #region 鈻� 绐楀笜闄愪綅閰嶇疆_______________________
+
+        /// <summary>
+        /// 鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
+        /// </summary>
+        /// <param name="rollershade">绐楀笜瀵硅薄</param>
+        /// <param name="limiType">纭鍙婅鐩栦笂闄愪綅杩樻槸涓嬮檺浣�</param>
+        /// <param name="upLimit">涓婇檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param>
+        /// <param name="downLimit">涓嬮檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param>
+        /// <returns></returns>
+        public async Task<bool> CommitCurtainLimitPoint(Rollershade rollershade, Rollershade.CurtainPrivateInstalledLimi limiType, int upLimit, int downLimit)
+        {
+            CommonDevice.SetWritableValueResponAllData result = null;
+            if (upLimit == -1 && downLimit == -1)
+            {
+                //杩欎釜鏄嵎甯�
+                result = await rollershade.SetCurtainInstalledLimitAsync(limiType);
+            }
+            else
+            {
+                //杩欎釜鏄紑鍚堝笜 "2,0x00ff,0x00ff"鏍煎紡 鍚堥檺浣嶅湪鍓嶏紝寮�闄愪綅鍦ㄥ悗
+                string convertData = "\"2,0x" + Convert.ToString(downLimit, 16).PadLeft(4, '0');
+                convertData += ",0x" + Convert.ToString(upLimit, 16).PadLeft(4, '0') + "\"";
+                //鐒跺悗灏嗗畠浠浆涓篈SK鐮佹暟鍊�,鐒跺悗鍐嶈浆涓�16杩涘埗
+                //鎬昏闀垮害涓�17(杩欓噷鏄�16杩涘埗)
+                string sendData = "11";
+                foreach (char c in convertData)
+                {
+                    sendData += Convert.ToString((int)c, 16).PadLeft(2, '0');
+                }
+                //result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData);
+            }
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null)
+            {
+                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //璁剧疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒犻櫎闄愪綅鐐�
+        /// </summary>
+        /// <param name="rollershade">绐楀笜瀵硅薄</param>
+        /// <param name="limiType">鍒犻櫎涓婇檺浣嶈繕鏄垹闄や笅闄愪綅</param>
+        /// <returns></returns>
+        public async Task<bool> DeleteCurtainLimitPoint(Rollershade rollershade, Rollershade.LimiType limiType)
+        {
+            var result = await rollershade.DeleteCurtainLimitsAsync(limiType);
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null)
+            {
+                //閲嶇疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //閲嶇疆绐楀笜闄愪綅鐐瑰け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇绐楀笜闄愪綅閰嶇疆___________________
+
+        /// <summary>
+        /// 鍙戦�佽幏鍙栫獥甯橀檺浣嶉厤缃殑鍛戒护
+        /// </summary>
+        /// <param name="rollershade">绐楀笜瀵硅薄</param>
+        public void SetGetCurtainLimitSettionComand(Rollershade rollershade)
+        {
+            var jObject = new Newtonsoft.Json.Linq.JObject
+            {
+                { "DeviceAddr",rollershade.DeviceAddr },
+                { "Epoint", rollershade.DeviceEpoint },
+                { "Cluster_ID", (int)Cluster_ID.WindowCovering },
+                { "Command", 108 }
+            };
+            var attriBute = new Newtonsoft.Json.Linq.JArray
+            {
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 //寮�鍚堝笜鏂瑰悜
+                 { "AttriButeId", (int)AttriButeId.WindowCoveringMode}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 //寮�鍚堝笜鎬婚暱
+                 { "AttriButeId", (int)AttriButeId.WindowCoveringLength}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 //寮�闄愪綅
+                 { "AttriButeId", (int)AttriButeId.InstalledOpenLimitLift}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 //鍚堥檺浣�
+                 { "AttriButeId", (int)AttriButeId.InstalledClosedLimitLift}
+               }
+            };
+            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
+            jObject.Add("Data", data);
+            rollershade.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
+        }
+
+        #endregion
+
+        #region 鈻� 閲嶇疆绐楀笜___________________________
+
+        /// <summary>
+        /// 閲嶇疆绐楀笜
+        /// </summary>
+        /// <param name="rollershade">绐楀笜瀵硅薄</param>
+        /// <returns></returns>
+        public async Task<bool> RestoreCurtain(Rollershade rollershade)
+        {
+            var result = await rollershade.RestoreCurtainLimitAsync();
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null)
+            {
+                //閲嶇疆绐楀笜澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //閲嶇疆绐楀笜澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鏄剧ず閿欒淇℃伅绐楀彛
+        /// </summary>
+        /// <param name="msg"></param>
+        private void ShowErrorMsg(string msg)
+        {
+            Application.RunOnMainThread(() =>
+            {
+                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+                contr.Show();
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ずTip淇℃伅绐楀彛
+        /// </summary>
+        /// <param name="msg"></param>
+        private void ShowTipMsg(string msg)
+        {
+            Application.RunOnMainThread(() =>
+            {
+                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+                contr.Show();
+            });
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0