From 6a9ad7ec93218913a2ce3b898bb036f18f8f0da4 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期四, 13 八月 2020 17:06:36 +0800 Subject: [PATCH] 20200813 --- HDL_ON/Entity/Function/Function.cs | 298 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 243 insertions(+), 55 deletions(-) diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs index 31d23ac..45f4951 100644 --- a/HDL_ON/Entity/Function/Function.cs +++ b/HDL_ON/Entity/Function/Function.cs @@ -2,40 +2,254 @@ 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 name; + /// <summary> + /// 灞炴�х殑鍊� + /// </summary> + public List<string> value; + /// <summary> + /// 鏈�澶у�� + /// </summary> + public int max; + /// <summary> + /// 鏈�灏忓�� + /// </summary> + public int min; + + /// <summary> + /// 鏁版嵁绫诲瀷 + /// </summary> + public string data_type = ""; + + /// <summary> + /// 褰撳墠鍊� + /// app杞欢鑷畾涔夊睘鎬� + /// 鐢ㄦ潵璁板綍褰撳墠鐘舵�� + /// </summary> + public object curValues = new object(); + } + /// <summary> + /// 璁惧鍔熻兘oid + /// </summary> + public class FunctionOid + { + public string oid; + public string name; + public string machine_id; + public string net_id; + public string dev_id; + public string channels; + } + + + public class Function + { + public Function() + { + } + #region base info + /// <summary> + /// 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 = "03010112345678010123012301230101"; + + /// <summary> + /// A鍗忚鍔熻兘鐨勭壒鎬� + /// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature + /// attri + /// </summary> + public List<Trait> function = new List<Trait>(); + /// <summary> /// 鎴块棿ID鍒楄〃 /// 璇ュ姛鑳芥坊鍔犲埌鍒版埧闂村垪琛� /// </summary> public List<string> roomIdList = new List<string>(); - /// <summary> - /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬� - /// </summary> - public string lastState = ""; /// <summary> - /// 鍔熻兘绫诲瀷锛� - /// 濡傦細鐏笅闈㈢殑缁х數鍣�/璋冨厜鍣�/RGB灞炰簬鍚屼竴绉嶅姛鑳戒笉鍚岀被鍨嬬殑鐏� + /// bus鍗忚鏁版嵁鏍煎紡 + /// 浣跨敤A鍗忚鎺у埗鏃讹紝鏀瑰睘鎬т负绌� /// </summary> - public string functionType { + public BusData bus_Data; + #endregion + + /// <summary> + /// 鍔熻兘绫诲埆 + /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被 + /// </summary> + public FunctionCategory functionCategory + { get { - return GetFunctionType(); + try + { + var _functionCategoryString = sid.Substring(16, 2); + var _functionCategory = Convert.ToInt32(_functionCategoryString, 16); + return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory); + } + catch (Exception ex) + { + MainPage.Log($"get FunctionCategory error : {ex.Message}"); + return FunctionCategory.UnKown; + } + } + } + + public FunctionType functionType + { + get + { + var _functionTypeString = sid.Substring(16, 4); + return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16)); } } /// <summary> - /// bus鍗忚鏁版嵁鏍煎紡 + /// 澶囨敞 /// </summary> - public BusData bus_Data; + public string name; + /// <summary> + /// A鍗忚鍘傚晢浠g爜 + /// </summary> + public string vendor_code + { + get + { + string vendorCode = "HDL"; + var code = sid.Substring(0, 4); + if (code == "0001") + vendorCode = "HDL"; + return vendorCode; + } + } + + /// <summary> + /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string lastState = ""; + + [Newtonsoft.Json.JsonIgnore] + public Trait trait_on_off; + /// <summary> + /// 寮�鍏崇姸鎬� + /// 0:鍏� + /// 1:寮� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string on_off + { + get + { + try + { + 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 鏁版嵁鑾峰彇澶辫触."); + function.Add( new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }); + return "off"; + } + } + set + { + try + { + 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 (Exception ex) + { + MainPage.Log($"on_off 鏁版嵁鍒锋柊澶辫触: {ex.Message}"); + function.Add(new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }); + } + } + } + + /// <summary> + /// 鏄惁鏀惰棌 + /// </summary> + public bool collection = false; /// <summary> /// 浣跨敤娆℃暟 @@ -44,67 +258,34 @@ /// <summary> /// 浣跨敤棰戠巼 /// </summary> - public double usageFrequency = 0; + public double usageFrequency { + get + { + return usageCount / 7; + } + } /// <summary> /// 鍥哄畾鐨勫簭鍙� /// </summary> public int fixedSerialNumber = int.MaxValue; /// <summary> - /// A鍗忚鏁版嵁 - /// </summary> - public List<string> PropertyArray - { - get - { - try - { - if (trait == null) - return new List<string>(); - var proArr = trait.Split(',').ToList(); - foreach (var pro in proArr) - { - if (!dicPropert.ContainsKey(pro)) - { - dicPropert.TryAdd(pro, "0"); - } - } - return proArr; - } - catch (Exception ex) - { - MainPage.Log($"Get PropertyArray error : {ex.Message}"); - return new List<string>(); - } - } - } - - /// <summary> /// 鑾峰彇A鍗忚鎺у埗瀛楃涓� /// </summary> /// <param name="command">鎺у埗鍛戒护锛歸rite锛宺ead</param> /// <returns></returns> - public virtual JObject GetSendJObject(string command) + public virtual JObject GetSendJObject(CommandType_A command) { - var sendJob = new JObject { { "vendor_code", a_Protocol_Namespace }, { "Command", command }, { "Type", "device" }, }; + var sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "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; } @@ -121,6 +302,8 @@ foreach(var roomId in roomIdList) { var findRoom = DB_ResidenceData.residenceData.rooms.Find(obj => obj.sid == roomId); + if (findRoom == null) + continue; if(roomNameList != "") { roomNameList += ","; @@ -129,5 +312,10 @@ } return roomNameList; } + + /// <summary> + /// 鏇存柊鏃堕棿 + /// </summary> + public DateTime refreshTime = DateTime.MinValue; } } -- Gitblit v1.8.0