From 002a3f2e9d2f9579c01f88af12bd8a320003569f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 31 三月 2020 08:57:19 +0800
Subject: [PATCH] 20200331

---
 HDL_ON/Entity/Function/Function.cs |  183 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 163 insertions(+), 20 deletions(-)

diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index 31d23ac..b7a8a44 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -2,40 +2,192 @@
 using System.Collections.Generic;
 using System.Linq;
 using Newtonsoft.Json.Linq;
+using HDL_ON;
 
 namespace HDL_ON.Entity
 {
-    public class Function : A_Protocol_FunctionInfo
+    /// <summary>
+    /// 鍔熻兘灞炴��
+    /// 灞炴�у瓧娈佃В鏋愶細attri :灞炴�у唴瀹癸紝value 灞炴�х殑鍊硷紝max 鏈�澶у�� min 鏈�灏忓��
+    /// </summary>
+    public class Trait
     {
         /// <summary>
-        /// 鏄惁鏀惰棌
+        /// 灞炴�у唴瀹�
         /// </summary>
-        public bool collection = false;
+        public string attri;
+        /// <summary>
+        /// 灞炴�х殑鍊�
+        /// </summary>
+        public string value;
+        /// <summary>
+        /// 鏈�澶у��
+        /// </summary>
+        public int max;
+        /// <summary>
+        /// 鏈�灏忓��
+        /// </summary>
+        public int min;
+    }
+
+    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
+        /// </summary>
+        public string sid = "00010112345678901234560101230123AABB";
+
+        /// <summary>
+        /// A鍗忚鍔熻兘鐨勯�氳
+        /// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature
+        /// attri
+        /// </summary>
+        public List<Trait> trait = new List<Trait>();
+
         /// <summary>
         /// 鎴块棿ID鍒楄〃
         /// 璇ュ姛鑳芥坊鍔犲埌鍒版埧闂村垪琛�
         /// </summary>
         public List<string> roomIdList = new List<string>();
+
+        /// <summary>
+        /// bus鍗忚鏁版嵁鏍煎紡
+        /// 浣跨敤A鍗忚鎺у埗鏃讹紝鏀瑰睘鎬т负绌�
+        /// </summary>
+        public BusData bus_Data;
+        #endregion
+
+
+        /// <summary>
+        /// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃
+        /// </summary>
+        public Dictionary<string, string> dicPropert;
+
+        /// <summary>
+        /// 鍔熻兘绫诲埆
+        /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
+        /// </summary>
+        public FunctionCategory functionCategory
+        {
+            get
+            {
+                var _functionCategoryString = sid.Substring(22, 2);
+                return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), Convert.ToInt32(_functionCategoryString));
+            }
+        }
+
+        public FunctionType functionType
+        {
+            get
+            {
+                var _functionTypeString = sid.Substring(24, 4);
+                return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
+            }
+        }
+
+        /// <summary>
+        /// 澶囨敞
+        /// </summary>
+        public string name;
+        /// <summary>
+        /// A鍗忚鍘傚晢浠g爜
+        /// </summary>
+        public string vendor_code
+        {
+            get
+            {
+                string vendorCode = "HDL";
+                var code = sid.Substring(0, 4);
+                if (code == "00001")
+                    vendorCode = "HDL";
+                return vendorCode;
+            }
+        }
+
         /// <summary>
         /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬�
         /// </summary>
         public string lastState = "";
 
+
         /// <summary>
-        /// 鍔熻兘绫诲瀷锛�
-        /// 濡傦細鐏笅闈㈢殑缁х數鍣�/璋冨厜鍣�/RGB灞炰簬鍚屼竴绉嶅姛鑳戒笉鍚岀被鍨嬬殑鐏�
+        /// 寮�鍏崇姸鎬�
+        /// 0:鍏�
+        /// 1:寮�
         /// </summary>
-        public string functionType {
+        [Newtonsoft.Json.JsonIgnore]
+        public string on_off
+        {
             get
             {
-                return GetFunctionType();
+                try
+                {
+                    string o = "off";
+                    dicPropert.TryGetValue("on_off", out o);
+                    return o == "" ? "off" : o;
+                }
+                catch
+                {
+                    MainPage.Log("on_off 鏁版嵁鑾峰彇澶辫触.");
+                    dicPropert.TryAdd("on_off", "0");
+                    return "off";
+                }
+            }
+            set
+            {
+                try
+                {
+                    dicPropert["on_off"] = value.ToString();
+                }
+                catch
+                {
+                    MainPage.Log("on_off 鏁版嵁鍒锋柊澶辫触.");
+                    dicPropert.TryAdd("on_off", value.ToString());
+                }
             }
         }
 
         /// <summary>
-        /// bus鍗忚鏁版嵁鏍煎紡
+        /// 鏄惁鏀惰棌
         /// </summary>
-        public BusData bus_Data;
+        public bool collection = false;
 
         /// <summary>
         /// 浣跨敤娆℃暟
@@ -86,25 +238,16 @@
         /// <returns></returns>
         public virtual JObject GetSendJObject(string command)
         {
-            var sendJob = new JObject { { "vendor_code", a_Protocol_Namespace }, { "Command", command }, { "Type", "device" }, };
+            var sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command }, { "Type", "device" }, };
             var data = new JObject { { "sid", sid } };
             sendJob.Add("objects", data);
             return sendJob;
         }
 
-        /// <summary>
-        /// 杩斿洖鍔熻兘绫诲瀷
-        /// </summary>
-        protected virtual string GetFunctionType()
-        {
-            return functionCategory.ToString();
-        }
-
-
         public string GetBusId ()
         {
             string busId = "";
-            if(bus_Data!=null)
+            if (bus_Data != null)
             {
                 busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID;
             }

--
Gitblit v1.8.0