From 652243206427f35a256400a149a1734085824cb9 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 02 九月 2020 17:35:03 +0800
Subject: [PATCH] 2020-09-02-4

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs |  165 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 156 insertions(+), 9 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
index cda2d6e..bda2e51 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -115,7 +115,7 @@
         /// </summary>
         public int ZigbeeType;
         /// <summary>
-        /// 褰撳墠杩愯绋嬪簭鐗堟湰淇℃伅銆� 鏈�澶�64瀛楄妭
+        /// 鍥轰欢鐗堟湰
         /// </summary>
         public int ImgVersion;
         /// <summary>
@@ -157,7 +157,11 @@
         /// <summary>
         /// 杈撳嚭绨囧垪琛�
         /// </summary>
-        public List<OutClusterObj> OutClusterList = new List<OutClusterObj>();
+        public List<OutClusterObj> OutClusterList = new List<OutClusterObj>();
+        /// <summary>
+        /// 鐢ㄤ簬璁板綍璁惧鏈�鏂颁笂鎶ョ殑灞炴�х姸鎬佷俊鎭�
+        /// </summary>
+        public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>();
 
         [Newtonsoft.Json.JsonIgnore]
         public DateTime LastDateTime = DateTime.MinValue;
@@ -165,7 +169,13 @@
         /// 鏄惁宸茬粡璇诲彇浜嗚澶囩姸鎬�(姝ゅ睘鎬ф槸缁欎富椤典娇鐢ㄧ殑)
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
-        public bool HadReadDeviceStatu = false;
+        public bool HadReadDeviceStatu = false;
+
+        /// <summary>
+        /// 鏄惁鏄綆鐢甸噺(杩欎釜鍙橀噺鐩墠鏄粰浼犳劅鍣ㄧ敤鐨�)
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public bool IsBatteryDown = false;
 
         /// <summary>
         /// 绛夊緟浠庣綉鍏虫帴鏀舵暟鎹殑鏃堕棿
@@ -199,12 +209,12 @@
                 {
                     return null;
                 }
-                var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.getGatewayBaseInfo != null) && (obj.getGatewayBaseInfo.gwID == CurrentGateWayId));
+                var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == CurrentGateWayId));
                 if (gateWay == null)
                 {
                     gateWay = new ZbGateway { IsVirtual = true, };
-                    gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId;
-                    gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId;
+                    gateWay.GwId = CurrentGateWayId;
+                    gateWay.HomeId = Shared.Common.Config.Instance.HomeId;
                     ZbGateway.GateWayList.Add(gateWay);
                 }
 
@@ -248,9 +258,21 @@
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
             }
+            else if (strDeviceType == ZigBee.Device.DeviceType.ColorDimmerSwitch.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.LevelControlSwitch.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte);
+            }
             else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString())
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringController.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte);
             }
             else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString())
             {
@@ -300,6 +322,14 @@
             {
                 return Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte);
             }
+            else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString())
+            {
+                return Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString())
+            {
+                return Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte);
+            }
             else { return null; }
             //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓�
             device.Type = (DeviceType)device.DeviceID;
@@ -339,6 +369,11 @@
         /// </summary>
         public void ReSave()
         {
+            if (Shared.Common.Config.Instance.Home.IsShowTemplate == true)
+            {
+                //灞曠ず妯℃澘鏃�,涓嶅厑璁镐繚瀛樻枃浠�(闃叉灞炴�т笂鎶ョ敤鐨�)
+                return;
+            }
             if (IconPath == string.Empty)
             {
                 //淇濆瓨璁惧鍥炬爣(杩欓噷浼氫繚瀛樹竴娆�,涓嬮潰灏变笉鐢ㄤ繚瀛樹簡)
@@ -369,6 +404,11 @@
                 {
                     //璋冨厜鍣�
                     IconPath = "Device/Light.png";
+                }
+                else if (this.Type == DeviceType.ColorTemperatureLight)
+                {
+                    //鑹叉俯鐏�
+                    IconPath = "Device/ColorLightTemperature.png";
                 }
                 else if (this.Type == DeviceType.OnOffOutput)
                 {
@@ -439,7 +479,7 @@
             /// </summary>
             public int AttributeId;
             /// <summary>
-            /// 灞炴�у�硷紝鏈�澶у崰鐢�4涓瓧鑺�
+            /// 灞炴�у�硷紝杩欎釜涓滆タ涓嶉渶瑕佷粈涔堥珮浣嶅湪鍚庝綆浣嶅湪鍓�,瀹冨凡缁忔槸杞负浜�10杩涘埗
             /// </summary>
             public int AttributeData;
             /// <summary>
@@ -662,6 +702,10 @@
             /// 濂藉儚鏄簭鍒楀彿
             /// </summary>
             public string ProductCode = string.Empty;
+            /// <summary>
+            /// 璁惧鍔熻兘绫诲瀷(绌烘皵寮�鍏冲拰缁х數鍣ㄤ笓鐢�)
+            /// </summary>
+            public int FunctionType = -1;
             /// <summary>
             /// 杈撳叆绨囧垪琛�
             /// </summary>
@@ -820,6 +864,109 @@
         }
         #endregion
 
+        #region 涓�閿洿鏂板洓瀵稿睆鎸夐敭灞炴��
+        /// <summary>
+        /// 鍚屾璁惧鍔熻兘
+        /// </summary>
+        /// <returns></returns>
+        public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint)
+        {
+            if (Gateway == null)
+            {
+                return null;
+            }
+
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                SynchronizationDeviceResponseAllData resContent = null;
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "Error_Respon")
+                    {
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+
+                        if (temp == null)
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+                        else
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "Bind/SyncMsgToBindSourceRespon")
+                    {
+                        var res = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
+                        if (res == null)
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { result = res };
+                            System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
+                        }
+                    }
+                };
+                Gateway.Actions = action;
+                DebugPrintLog("Bind/SyncMsgToBindSourceRespon_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5010 } };
+                    Gateway.Send("Bind/SyncMsgToBindSource", jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (resContent != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
+                {
+                    resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                DebugPrintLog("Bind/SyncMsgToBindSource_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return resContent;
+            });
+
+        }
+
+        /// <summary>
+        /// 鍚屾璁惧,缃戝叧鍙嶉鍏蜂綋淇℃伅
+        /// </summary>
+        [System.Serializable]
+        public class SynchronizationDeviceResponseAllData
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public ErrorResponData errorResponData;
+            /// <summary>
+            /// 鍚屾缁撴灉
+            /// 0:鎴愬姛锛氱綉鍏冲唴閮ㄨ嚜鍔ㄥ啓鍏ヨ澶囩洰鏍囧悕瀛椼�佽澶囩洰鏍囧姛鑳界被鍨嬨�佸満鏅洰鏍囧悕瀛椼�乽tc鏃堕棿鍐欏叆4瀵稿睆
+            /// 1:澶辫触
+            /// </summary>
+            public int result;
+        }
+        #endregion
+
         #region 鍒犻櫎璁惧锛堜娇璁惧绂荤綉锛�
         /// <summary>
         /// 鍒犻櫎璁惧锛堜娇璁惧绂荤綉锛�
@@ -870,7 +1017,7 @@
                     }
                 };
                 Gateway.Actions += action;
-                System.Console.WriteLine("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+                DebugPrintLog("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
 
                 try
                 {
@@ -908,7 +1055,7 @@
                     d = new RemoveDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
                 }
                 Gateway.Actions -= action;
-                System.Console.WriteLine("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+                DebugPrintLog("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return d;
             });

--
Gitblit v1.8.0