From 3272ca5b51e19f7f8a827b0f68400570a547fe60 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 28 四月 2020 15:02:44 +0800
Subject: [PATCH] 2020-04-28-1

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs |  286 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 281 insertions(+), 5 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
index ef8c355..90a72cc 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
@@ -153,8 +153,8 @@
         /// 璁剧疆璁惧浜害锛坲i鍙寒搴﹁皟鑺傦級
         /// </summary>
         /// <param name="panel">璁惧瀵硅薄</param>
-        /// <param name="directionsLevel">鎸囩ず鐏寒搴� 0-100(鐜伴樁娈典笉鐢ㄨ繖涓�)</param>
-        /// <param name="backlightLevel">鑳屽厜鐏寒搴� 0-100(ui鍙寒搴﹁皟鑺�)</param>
+        /// <param name="directionsLevel">0-100(杩欎釜鏄偣鍑诲悗鐨勫��)</param>
+        /// <param name="backlightLevel">0-100(杩欎釜鏄偣鍑诲墠鐨勫��)</param>
         /// <returns></returns>
         public async Task<bool> SetDeviceLightSettion(CommonDevice device, int directionsLevel, int backlightLevel)
         {
@@ -203,6 +203,87 @@
             return true;
         }
 
+        #endregion
+
+        #region 鈻� 鎺ヨ繎鎰熷簲___________________________
+        /// <summary>
+        /// 鑾峰彇鎺ヨ繎鎰熷簲閰嶇疆锛坲i鍙帴杩戞劅搴�,浣跨敤杩斿洖鍊肩殑panelProximitySensorInfo锛�
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <returns></returns>
+        public async Task<Panel.PanelProximitySensorInfo> GetDeviceProximitySensorsSettion(CommonDevice device)
+        {
+            //鍊熺敤瀹冪殑鍑芥暟
+            var panel = new Panel();
+            panel.DeviceAddr = device.DeviceAddr;
+            panel.DeviceEpoint = device.DeviceEpoint;
+            panel.CurrentGateWayId = device.CurrentGateWayId;
+
+            var result = await panel.GetProximitySensorAsync();
+            panel = null;
+            //鍏遍�氶敊璇娴�
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowErrorMsg(error);
+                return null;
+            }
+            if (result == null || result.panelProximitySensorInfo == null || string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                //鑾峰彇鎺ヨ繎鎰熷簲淇℃伅澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.GetPanelProximityFail);
+                this.ShowErrorMsg(msg);
+                return null;
+            }
+            return result.panelProximitySensorInfo;
+        }
+
+
+        /// <summary>
+        /// 閰嶇疆鎺ヨ繎浼犳劅
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <para>sensorEnable:浼犳劅鍣ㄤ娇鑳�</para> 
+        /// <returns></returns>
+        public async Task<bool> SetProximitySensorStatus(CommonDevice device, bool sensorEnable)
+        {
+            //鍊熺敤瀹冪殑鍑芥暟
+            var panel = new Panel();
+            panel.DeviceAddr = device.DeviceAddr;
+            panel.DeviceEpoint = device.DeviceEpoint;
+            panel.CurrentGateWayId = device.CurrentGateWayId;
+
+            var result = await panel.SetProximitySensor(sensorEnable);
+            panel = null;
+
+            //鍏遍�氶敊璇娴�
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowErrorMsg(error);
+                return false;
+            }
+
+            if (result == null || result.responseData == null)
+            {
+                //鎺ヨ繎浼犳劅閰嶇疆澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.SetPannelProximityFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            // 澶囦唤璁惧
+            var backData = new Newtonsoft.Json.Linq.JObject
+            {
+                { "sensorEnable",sensorEnable }
+            };
+            //澶囦唤璁惧
+            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A闈㈡澘鎺ヨ繎鎰熷簲鍔熻兘, backData);
+            return true;
+        }
         #endregion
 
         #region 鈻� 鑺傝兘妯″紡___________________________
@@ -479,12 +560,12 @@
         #region 鈻� 淇敼骞叉帴鐐圭鏈夊睘鎬________________
 
         /// <summary>
-        /// 淇敼骞叉帴鐐圭鏈夊睘鎬�
+        /// 淇敼骞叉帴鐐圭涓夌骇鍒殑绉佹湁灞炴��
         /// </summary>
         /// <param name="panel">骞叉帴鐐瑰璞�</param>
         /// <param name="i_value">骞叉帴鐐圭殑绗笁绾у埆灞炴�х殑鍊�,鍏蜂綋璇峰弬鐓х涓夌骇鍒睘鎬�</param>
         /// <returns></returns>
-        public async Task<bool> EditorDryContactFunction(Panel panel, int i_value)
+        public async Task<bool> EditorDryContactThirdFunction(Panel panel, int i_value)
         {
             var result = await panel.ConfigureHdlKeyValueAsync((Panel.KeyMode)i_value);
             //鍏遍�氶敊璇娴�
@@ -537,13 +618,208 @@
                 return false;
             }
             //澶囦唤璁惧
-            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�, i_value);
+            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A骞叉帴鐐圭涓夌骇鍒鏈夊睘鎬�, i_value);
 
             return true;
         }
 
         #endregion
 
+        #region 鈻� 绠�绾﹂潰鏉块渿鍔ㄥ姛鑳絖__________________
+
+        /// <summary>
+        /// 鑾峰彇绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅(null琛ㄧず鍑洪敊)
+        /// </summary>
+        /// <param name="device">鏌愪竴鍥炶矾</param>
+        /// <returns></returns>
+        public VibrationInfo GetPanelVibrationData(CommonDevice device)
+        {
+            var returnData = new VibrationInfo();
+            var gateway = device.Gateway;
+            if (gateway == null)
+            {
+                //閿欒:缃戝叧瀵硅薄涓㈠け
+                this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+                return null;
+            }
+            string checkTopic = HdlGatewayLogic.Current.GetGatewayId(gateway) + "/" + "ZbDataPassthrough";
+            bool canBreak = false;
+
+            Action<string, string> action = (topic, message) =>
+            {
+                if (topic == checkTopic)
+                {
+                    try
+                    {
+                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                        string PassData = jobject["Data"]["PassData"].ToString();
+                        if (PassData.Length != 18)
+                        {
+                            return;
+                        }
+                        string mytopic = PassData[4].ToString() + PassData[5].ToString() + PassData[2].ToString() + PassData[3].ToString();
+                        if (mytopic != "0802")
+                        {
+                            return;
+                        }
+                        returnData.A闇囧姩浣胯兘 = PassData.Substring(10, 2) == "01" ? true : false;
+                        returnData.A闇囧姩寮哄害 = Convert.ToInt32(PassData.Substring(12, 2), 16);
+                        returnData.A闇囧姩鏃堕棿 = Convert.ToInt32(PassData.Substring(14, 4), 16);
+
+                        canBreak = true;
+                    }
+                    catch { }
+                }
+            };
+            gateway.Actions += action;
+            try
+            {
+                var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                var data = new Newtonsoft.Json.Linq.JObject { { "PassData", "050108110101" } };
+                jObject.Add("Data", data);
+                gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+            }
+            catch { }
+
+            int TimeOut = 0;
+            while (canBreak == false && TimeOut < 60)
+            {
+                System.Threading.Thread.Sleep(100);
+                TimeOut++;
+            }
+            gateway.Actions -= action;
+
+            if (TimeOut >= 60)
+            {
+                //鑾峰彇闇囧姩鍙嶉閰嶇疆淇℃伅澶辫触
+                string errorMsg = Language.StringByID(R.MyInternationalizationString.uGetVibrationFeedbackSettionFail);
+                errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "鍥炲瓒呮椂", false);
+                this.ShowTipMsg(errorMsg);
+                return null;
+            }
+            return returnData;
+        }
+
+        /// <summary>
+        /// 璁剧疆绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅
+        /// </summary>
+        /// <param name="device">鏌愪竴鍥炶矾</param>
+        /// <param name="datainfo">璁剧疆鐨勪俊鎭�</param>
+        /// <returns></returns>
+        public bool SetPanelVibrationData(CommonDevice device, VibrationInfo datainfo)
+        {
+            var gateway = device.Gateway;
+            if (gateway == null)
+            {
+                //閿欒:缃戝叧瀵硅薄涓㈠け
+                this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+                return false;
+            }
+            string checkTopic = HdlGatewayLogic.Current.GetGatewayId(gateway) + "/" + "ZbDataPassthrough";
+            bool canBreak = false;
+
+            bool success = false;
+            Action<string, string> action = (topic, message) =>
+            {
+                if (topic == checkTopic)
+                {
+                    try
+                    {
+                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                        if (jobject["DeviceAddr"].ToString() != device.DeviceAddr)
+                        {
+                            //涓嶆槸鍚屼竴涓笢瑗�
+                            return;
+                        }
+                        string PassData = jobject["Data"]["PassData"].ToString();
+                        if (PassData.Length != 16)
+                        {
+                            return;
+                        }
+                        string mytopic = PassData[4].ToString() + PassData[5].ToString() + PassData[2].ToString() + PassData[3].ToString();
+                        if (mytopic != "0002")
+                        {
+                            return;
+                        }
+                        int command = Convert.ToInt32(PassData[10].ToString() + PassData[11].ToString() + PassData[12].ToString() + PassData[13].ToString(), 16);
+                        int status = Convert.ToInt32(PassData[14].ToString() + PassData[15].ToString(), 16);
+                        if (status == 0)
+                        {
+                            //鎴愬姛
+                            success = true;
+                        }
+                        canBreak = true;
+                    }
+                    catch { }
+                }
+            };
+            gateway.Actions += action;
+            try
+            {
+                string passData = "0800081104";
+                passData += datainfo.A闇囧姩浣胯兘 ? "01" : "00";
+                passData += Convert.ToString(datainfo.A闇囧姩寮哄害, 16).PadLeft(2, '0');
+                string time = Convert.ToString(datainfo.A闇囧姩鏃堕棿, 16).PadLeft(4, '0');
+                //浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚�
+                passData += time.Substring(2, 2);
+                passData += time.Substring(0, 2);
+
+                var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } };
+                jObject.Add("Data", data);
+                gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+            }
+            catch { }
+
+            int TimeOut = 0;
+            while (canBreak == false && TimeOut < 60)
+            {
+                System.Threading.Thread.Sleep(100);
+                TimeOut++;
+            }
+            gateway.Actions -= action;
+
+            if (success == false)
+            {
+                //璁剧疆闇囧姩鍙嶉閰嶇疆淇℃伅澶辫触
+                string errorMsg = Language.StringByID(R.MyInternationalizationString.uSetVibrationFeedbackSettionFail);
+                if (TimeOut >= 60)
+                {
+                    errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "鍥炲瓒呮椂", false);
+                }
+                this.ShowTipMsg(errorMsg);
+                return false;
+            }
+            //澶囦唤璁惧
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绠�绾﹂潰鏉块渿鍔ㄥ姛鑳�, datainfo);
+            }, ShowErrorMode.NO);
+
+            return success;
+        }
+
+        /// <summary>
+        /// 绠�绾﹂潰鏉块渿鍔ㄥ姛鑳戒俊鎭�
+        /// </summary>
+        public class VibrationInfo
+        {
+            /// <summary>
+            /// 闇囧姩浣胯兘
+            /// </summary>
+            public bool A闇囧姩浣胯兘 = false;
+            /// <summary>
+            /// 闇囧姩寮哄害(鍗佽繘鍒�)
+            /// </summary>
+            public int A闇囧姩寮哄害 = 0;
+            /// <summary>
+            /// 闇囧姩鏃堕棿(鍗佽繘鍒�)
+            /// </summary>
+            public int A闇囧姩鏃堕棿 = 0;
+        }
+
+        #endregion
+
         #region 鈻� 缂撳瓨涓殑璁惧绉佹湁灞炴�______________
 
         /// <summary>

--
Gitblit v1.8.0