From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 16 四月 2020 17:10:57 +0800
Subject: [PATCH] 请合并代码

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceHardInfoLogic.cs |  326 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 326 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceHardInfoLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceHardInfoLogic.cs
new file mode 100755
index 0000000..03de7f2
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceHardInfoLogic.cs
@@ -0,0 +1,326 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 璁惧纭欢淇℃伅鐨勯�昏緫
+    /// </summary>
+    public class HdlDeviceHardInfoLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 璁惧纭欢淇℃伅鐨勯�昏緫
+        /// </summary>
+        private static HdlDeviceHardInfoLogic m_Current = null;
+        /// <summary>
+        /// 璁惧纭欢淇℃伅鐨勯�昏緫
+        /// </summary>
+        public static HdlDeviceHardInfoLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlDeviceHardInfoLogic();
+                }
+                return m_Current;
+            }
+        }
+
+        /// <summary>
+        /// 璁惧鑾峰彇纭欢淇℃伅鍚庣殑鍥炶皟鍑芥暟
+        /// </summary>
+        private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicDeviceHardInfoBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>();
+        /// 鑾峰彇纭欢淇℃伅鐨勫璞¤澶�
+        /// </summary>
+        private HashSet<string> hsGetHardInfoDevice = new HashSet<string>();
+
+        #endregion
+
+        #region 鈻� 涓诲叆鍙e嚱鏁癬________________________
+
+        /// <summary>
+        /// 璇诲彇浠ュ強璁剧疆璁惧纭欢淇℃伅
+        /// </summary>
+        /// <param name="device">璁惧鍥炶矾</param>
+        /// <param name="backAction">鍥炶皟鍑芥暟</param>
+        public void SetAllHardFirmwareInfoToDevice(CommonDevice device, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null)
+        {
+            if (device == null)
+            {
+                return;
+            }
+            lock (hsGetHardInfoDevice)
+            {
+                //鍏堢Щ闄�
+                this.RemoveDeviceHardInfoThread(device);
+
+                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+                this.hsGetHardInfoDevice.Add(mainkeys);
+
+                if (backAction != null)
+                {
+                    //鍥炶皟鍑芥暟
+                    this.dicDeviceHardInfoBackAction[mainkeys] = backAction;
+                }
+                //璁剧疆璁惧鐨勭‖浠朵俊鎭�(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼)
+                this.SetHardFirmwareInfoToDevice(device);
+            }
+        }
+
+        /// <summary>
+        /// 璁剧疆璁惧鐨勭‖浠朵俊鎭�(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼)
+        /// </summary>
+        /// <param name="device"></param>
+        private void SetHardFirmwareInfoToDevice(CommonDevice device)
+        {
+            if (HdlGatewayReceiveLogic.Current.IsEsixt("DeviceGetHardFirmwareInfo") == false)
+            {
+                //娣诲姞浜嬩欢
+                HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceGetHardFirmwareInfo", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, this.SetHardFirmwareInfoByInterfaceResult);
+            }
+            //鍙戦�佸懡浠�
+            this.SetHardFirmwareInfoComand(device);
+        }
+
+        #endregion
+
+        #region 鈻� 鍙戦�佸懡浠__________________________
+
+        /// <summary>
+        /// 鍙戦�佽幏鍙栫‖浠朵俊鎭殑鍛戒护
+        /// </summary>
+        /// <param name="device"></param>
+        public void SetHardFirmwareInfoComand(CommonDevice device)
+        {
+            var jObject = new Newtonsoft.Json.Linq.JObject
+            {
+                { "DeviceAddr",device.DeviceAddr },
+                { "Epoint", device.DeviceEpoint },
+                { "Cluster_ID", (int)Cluster_ID.Basic },
+                { "Command", 108 }
+            };
+            var attriBute = new Newtonsoft.Json.Linq.JArray
+            {
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 { "AttriButeId", 4}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 { "AttriButeId", 5}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 { "AttriButeId", 6}
+               },
+                  new Newtonsoft.Json.Linq.JObject
+               {
+                 { "AttriButeId", 7}
+               },
+               new Newtonsoft.Json.Linq.JObject
+               {
+                 { "AttriButeId", 13}
+               }
+            };
+            var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
+            jObject.Add("Data", data);
+            device.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆灞炴�__________________________
+
+        /// <summary>
+        /// 璁剧疆璁惧鐨勭‖浠朵俊鎭� -1:寮傚父  0:鎺ㄩ�佺殑杩欎釜涓滆タ骞朵笉鏄‖浠朵俊鎭�  1:姝e父
+        /// </summary>
+        /// <param name="report">涓婃姤淇℃伅</param>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <returns></returns>
+        public int SetHardFirmwareInfo(CommonDevice.DeviceStatusReportData report, CommonDevice device)
+        {
+            if (report == null)
+            {
+                return -1;
+            }
+            //灞炴�ф槸鍚︽敼鍙�
+            bool AttriButeChanged = false;
+            //鏄惁鏄纭殑鎺ㄩ�佹暟鎹�
+            bool isRightData = false;
+            foreach (var data in report.AttriBute)
+            {
+                //鐢熶骇鍟嗗悕瀛�
+                if (data.AttributeId == 4)
+                {
+                    isRightData = true;
+                    if (data.AttriButeDataHex.Length > 2)
+                    {
+                        var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                        if (device.ManufacturerName != value)
+                        {
+                            //灞炴�у彉鏇翠簡
+                            AttriButeChanged = true;
+                        }
+                        device.ManufacturerName = value;
+                    }
+                }
+                //鍨嬪彿鐮�(涔熷彨妯″潡ID)
+                if (data.AttributeId == 5)
+                {
+                    isRightData = true;
+                    if (data.AttriButeDataHex.Length > 2)
+                    {
+                        var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                        if (device.ModelIdentifier != value)
+                        {
+                            //灞炴�у彉鏇翠簡
+                            AttriButeChanged = true;
+                        }
+                        device.ModelIdentifier = value;
+                    }
+                }
+                //鐢熶骇鏃ユ湡
+                if (data.AttributeId == 6)
+                {
+                    isRightData = true;
+                    if (data.AttriButeDataHex.Length > 2)
+                    {
+                        var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                        if (device.ProductionDate != value)
+                        {
+                            //灞炴�у彉鏇翠簡
+                            AttriButeChanged = true;
+                        }
+                        device.ProductionDate = value;
+                    }
+                }
+                //鐢垫簮
+                if (data.AttributeId == 7)
+                {
+                    isRightData = true;
+                    device.PowerSource = data.AttriButeData;
+                }
+                //搴忓垪鍙�
+                if (data.AttributeId == 13)
+                {
+                    isRightData = true;
+                    if (data.AttriButeDataHex.Length > 2)
+                    {
+                        string value;
+                        if (Common.LocalDevice.Current.IsHdlDevice(device) == false)
+                        {
+                            //绗笁鏂硅澶�
+                            value = data.AttriButeDataHex.Substring(2);
+                        }
+                        else
+                        {
+                            //娌充笢璁惧
+                            value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                        }
+                        if (device.SerialNumber != value)
+                        {
+                            //灞炴�у彉鏇翠簡
+                            AttriButeChanged = true;
+                        }
+                        device.SerialNumber = value;
+                    }
+                }
+            }
+            if (isRightData == false)
+            {
+                //杩欎釜涓嶆槸纭欢淇℃伅鐨勬帹閫�
+                return 0;
+            }
+
+            //濡傛灉灞炴�у彉鏇翠簡
+            if (AttriButeChanged == true)
+            {
+                if (device.IsCustomizeImage == false)
+                {
+                    //UI閲嶆柊鐢熸垚
+                    device.IconPath = string.Empty;
+                    device.ReSave();
+                }
+            }
+            return 1;
+        }
+
+        #endregion
+
+        #region 鈻� 鎺ュ彛鎺ㄩ�佸鐞哶______________________
+
+        /// <summary>
+        /// 鏍规嵁鎺ュ彛鎺ㄩ�佺殑淇℃伅锛岃缃澶囩‖浠朵俊鎭�
+        /// </summary>
+        /// <param name="device"></param>
+        private void SetHardFirmwareInfoByInterfaceResult(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:姝e父
+                if (this.SetHardFirmwareInfo(device.DeviceStatusReport, localDevice) != 1)
+                {
+                    return;
+                }
+                localDevice.ReSave();
+
+                this.hsGetHardInfoDevice.Remove(mainKeys);
+                if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true)
+                {
+                    var action = this.dicDeviceHardInfoBackAction[mainKeys];
+                    //璋冪敤鍥炶皟鍑芥暟
+                    action?.Invoke(device, device.DeviceStatusReport);
+                    //鐒跺悗绉婚櫎
+                    this.dicDeviceHardInfoBackAction.Remove(mainKeys);
+                    action = null;
+                }
+            }
+        }
+
+        #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);
+                }
+                if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true)
+                {
+                    var action = this.dicDeviceHardInfoBackAction[mainKeys];
+                    //鐒跺悗绉婚櫎
+                    this.dicDeviceHardInfoBackAction.Remove(mainKeys);
+                    action = null;
+                }
+            }
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0