From 2bec9c838d2d688025698de8ec1de401ffd7dd1f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 11 八月 2020 14:13:55 +0800
Subject: [PATCH] 20200811

---
 HDL_ON/Entity/Function/Function.cs |  182 +++++++++++++++++++++++---------------------
 1 files changed, 95 insertions(+), 87 deletions(-)

diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index 6e0770d..8f996e3 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -28,58 +28,56 @@
         /// 鏈�灏忓��
         /// </summary>
         public int min;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public string data_type = "";
+
+        /// <summary>
+        /// 褰撳墠鍊�
+        /// app杞欢鑷畾涔夊睘鎬�
+        /// 鐢ㄦ潵璁板綍褰撳墠鐘舵��
+        /// </summary>
+        public object curValues;
     }
 
     public class Function
     {
-        /*
-        HDL缁熶竴鍗忚鏍煎紡锛�16bytes
-        鍘傚晢浠e彿锛�2bytes
-        閫氳鏂瑰紡锛氭湁绾�/鏃犵嚎/ZIGBEE绛�1bytes
-        浜у搧璇嗗埆鐮侊細浠ユ坊鍔犺澶囩殑骞存湀鏃ユ椂鍒嗙 + 闅忔満鏁�  8bytes  Category
-        鍔熻兘绫诲埆锛�1bytes
-        鏁版嵁琛ㄧ储寮曞湴鍧�锛�2bytes
-        鍥炶矾锛�2bytes
-        涓句緥锛� 0001-00-2019101209001234-01-0001-0001
-        */
         public Function()
         {
-            dicPropert = new Dictionary<string, string>();
-            if (trait == null || trait.Count == 0)
-            {
-                foreach (var t in trait)
-                {
-                    dicPropert.TryAdd(t.attri,t.min.ToString());
-                }
-            }
         }
         #region base info
         /// <summary>
-        /// 鍔熻兘ID
-        /// 鍘傚晢浠g爜	2bytes;     01	HDL
-        /// 閫氳鏂瑰紡	1byte ;     01	HDL Bus; 02	Zigbee;03	KNX;04	Z-Wave
-        /// 浜у搧GUID	8bytes
-        /// 浜у搧绫诲埆	1byte ;     01  璋冨厜鍣�;02缁х數鍣�;03骞叉帴鐐规ā鍧�;04浼犳劅鍣�;05闈㈡澘
-        /// 鐗╂ā鍨嬬被鍨�2bytes      01 寮�鍏崇被    --01寮�鍏�;02鎻掑骇
-        ///		                02	鐓ф槑     --01寮�鍏崇被;02璋冨厜绫�;03鑹叉俯;04LED
-        ///		                03	閬槼     --01绐楀笜鐢垫満;02鐧惧彾绐�;03寮�鍚堝笜;04鍗峰笜
-        ///		                04	鎭掓俯鍣�    --01绌鸿皟;02鍦版殩;03姣涚粏绌鸿皟
-        ///             		05	鏂伴		
-        ///             		06	褰遍煶		
-        ///             		07	闊充箰		
-        ///		                08	鑳芥簮		
-        ///		                09	瀹夐槻
-        /// 閫氶亾鍙�	2bytes
-        /// Key_id  2bytes
+        /// HDL缁熶竴鍗忚鏍煎紡锛�14bytes
+        /// 涓句緥锛� 鏉ユ簮   鍘傚晢浠g爜 閫氳鏂瑰紡  浜у搧鏃堕棿鎴�   浜у搧绫诲埆 鐗╂ā鍨嬬被  閫氶亾鍙�   澶у皬绫诲埆
+        //       1byte	1byte	1byte	  4byte	    1byte	2byte   2byte   2byte
+        /// 鏉ユ簮锛�00	榛樿鍘熺敓鎬佺郴缁熸暟鎹� 銆�01	缃戝叧鎴栬�呭叾浠朅璁惧銆�02	璋冭瘯杞欢銆�03	APP搴旂敤绋嬪簭銆�04	绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
+        /// 鍘傚晢浠g爜锛�01	HDL
+        /// 閫氳鏂瑰紡锛�01	HDL Bus銆�02	Zigbee銆�03 KNX銆�04 Z-Wave
+        /// 浜у搧鏃堕棿鎴筹細4bytes	浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
+        /// 浜у搧绫诲埆锛�01	璋冨厜鍣ㄣ��02 缁х數鍣ㄣ��03	骞叉帴鐐规ā鍧椼��04	浼犳劅鍣ㄣ��05 闈㈡澘
+        /// 鐗╂ā鍨嬬被鍨嬶細
+		///     01	寮�鍏崇被锛�01 寮�鍏炽��02 鎻掑骇銆�03	
+		///     02	鐓ф槑锛� 01 寮�鍏炽��02	璋冨厜銆�03	鑹叉俯銆�04	LED
+        ///     03	閬槼锛� 01	绐楀笜鐢垫満銆�02 鐧惧彾绐椼��03 寮�鍚堝笜銆�04 鍗峰笜
+		///     04	鎭掓俯鍣細01 绌鸿皟銆�02 鍦版殩銆�03 姣涚粏绌鸿皟
+        ///     05	鏂伴		
+        ///     06	褰遍煶		
+        ///     07	闊充箰		
+        ///     08	鑳芥簮		
+        ///     09	瀹夐槻
+        /// 澶х被鍒�	1bytes	锛堥鐣欙級
+        /// 灏忕被鍒�	1byte	锛堥鐣欙級
         /// </summary>
-        public string sid = "00010112345678901234560101230123AABB";
+        public string sid = "03010112345678010123012301230101";
 
         /// <summary>
-        /// A鍗忚鍔熻兘鐨勯�氳
+        /// A鍗忚鍔熻兘鐨勭壒鎬�
         /// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature
         /// attri
         /// </summary>
-        public List<Trait> trait = new List<Trait>();
+        public List<Trait> function = new List<Trait>();
 
         /// <summary>
         /// 鎴块棿ID鍒楄〃
@@ -95,10 +93,10 @@
         #endregion
 
 
-        /// <summary>
-        /// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃
-        /// </summary>
-        public Dictionary<string, string> dicPropert;
+        ///// <summary>
+        ///// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃
+        ///// </summary>
+        //public Dictionary<string, string> dicPropert;
 
         /// <summary>
         /// 鍔熻兘绫诲埆
@@ -110,8 +108,9 @@
             {
                 try
                 {
-                    var _functionCategoryString = sid.Substring(24, 2);
-                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), Convert.ToInt32(_functionCategoryString));
+                    var _functionCategoryString = sid.Substring(16, 2);
+                    var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
+                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
                 }
                 catch (Exception ex)
                 {
@@ -125,7 +124,7 @@
         {
             get
             {
-                var _functionTypeString = sid.Substring(24, 4);
+                var _functionTypeString = sid.Substring(16, 4);
                 return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
             }
         }
@@ -154,7 +153,8 @@
         /// </summary>
         public string lastState = "";
 
-
+        [Newtonsoft.Json.JsonIgnore]
+        public Trait trait_on_off;
         /// <summary>
         /// 寮�鍏崇姸鎬�
         /// 0:鍏�
@@ -167,14 +167,34 @@
             {
                 try
                 {
-                    string o = "off";
-                    dicPropert.TryGetValue("on_off", out o);
-                    return o == "" ? "off" : o;
+                    if (trait_on_off == null)
+                    {
+                        trait_on_off = function.Find((obj) => obj.attri == "on_off");
+                        //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
+                        if (trait_on_off == null)
+                        {
+                            trait_on_off = new Trait()
+                            {
+                                attri = "on_off",
+                                value = new List<string> { "on", "off" },
+                                max = 1,
+                                min = 0,
+                            };
+                        }
+                        trait_on_off.curValues = trait_on_off.value[trait_on_off.min];
+                    }
+                    return trait_on_off.curValues.ToString();
                 }
                 catch
                 {
                     MainPage.Log("on_off 鏁版嵁鑾峰彇澶辫触.");
-                    dicPropert.TryAdd("on_off", "0");
+                    function.Add( new Trait()
+                    {
+                        attri = "on_off",
+                        value = new List<string> { "on", "off" },
+                        max = 1,
+                        min = 0,
+                    });
                     return "off";
                 }
             }
@@ -182,12 +202,34 @@
             {
                 try
                 {
-                    dicPropert["on_off"] = value.ToString();
+                    if (trait_on_off == null)
+                    {
+                        trait_on_off = function.Find((obj) => obj.attri == "on_off");
+                        //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
+                        if (trait_on_off == null)
+                        {
+                            trait_on_off = new Trait()
+                            {
+                                attri = "on_off",
+                                value = new List<string> { "on", "off" },
+                                max = 1,
+                                min = 0,
+                            };
+                        }
+                        trait_on_off.curValues = trait_on_off.min;
+                    }
+                    trait_on_off.curValues = value;
                 }
-                catch
+                catch (Exception ex)
                 {
-                    MainPage.Log("on_off 鏁版嵁鍒锋柊澶辫触.");
-                    dicPropert.TryAdd("on_off", value.ToString());
+                    MainPage.Log($"on_off 鏁版嵁鍒锋柊澶辫触: {ex.Message}");
+                    function.Add(new Trait()
+                    {
+                        attri = "on_off",
+                        value = new List<string> { "on", "off" },
+                        max = 1,
+                        min = 0,
+                    });
                 }
             }
         }
@@ -214,39 +256,6 @@
         /// 鍥哄畾鐨勫簭鍙�
         /// </summary>
         public int fixedSerialNumber = int.MaxValue;
-
-        /// <summary>
-        /// A鍗忚鏁版嵁
-        /// </summary>
-        public List<string> PropertyArray
-        {
-            get
-            {
-                try
-                {
-                    if (trait == null)
-                        return new List<string>();
-                    var proArr = new List<string>();
-                    foreach (var pro in trait)
-                    {
-                        if (!dicPropert.ContainsKey(pro.attri))
-                        {
-                            dicPropert.TryAdd(pro.attri, "0");
-                        }
-                        if (!proArr.Contains(pro.attri))
-                        {
-                            proArr.Add(pro.attri);
-                        }
-                    }
-                    return proArr;
-                }
-                catch (Exception ex)
-                {
-                    MainPage.Log($"Get PropertyArray error : {ex.Message}");
-                    return new List<string>();
-                }
-            }
-        }
 
         /// <summary>
         /// 鑾峰彇A鍗忚鎺у埗瀛楃涓�
@@ -291,7 +300,6 @@
             }
             return roomNameList;
         }
-
 
         /// <summary>
         /// 鏇存柊鏃堕棿

--
Gitblit v1.8.0