From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期四, 03 十二月 2020 15:35:42 +0800 Subject: [PATCH] 2020-12-03-1 --- HDL_ON/Entity/Function/Function.cs | 390 ++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 286 insertions(+), 104 deletions(-) diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs index 053e45b..86daa59 100644 --- a/HDL_ON/Entity/Function/Function.cs +++ b/HDL_ON/Entity/Function/Function.cs @@ -1,5 +1,6 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.DriverLayer; using Shared; namespace HDL_ON.Entity @@ -12,23 +13,13 @@ public Function() { } - /// <summary> - /// 鏁版嵁瀛樺偍鏂囦欢鍚� - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public string savePath - { - get - { - return "FunctionData_" + sid; - } - } + #region base info /// <summary> /// HDL缁熶竴鍗忚鏍煎紡锛�14bytes /// 涓句緥锛� 鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆 - // 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte + /// 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 @@ -48,25 +39,76 @@ /// 灏忕被鍒� 1byte 锛堥鐣欙級 /// </summary> public string sid = "0301011234567801012301230123"; + /// <summary> + /// 澶囨敞 + /// </summary> + public string name; + /// <summary> + /// 璁惧ID + /// 浜戠璐熻矗鐢熸垚 + /// </summary> + public string deviceId = "0"; + /// <summary> + /// 璁惧spk + /// </summary> + public string spk = ""; + /// <summary> + /// 鍔熻兘绫诲埆 + /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被 + /// </summary> + public FunctionCategory functionCategory + { + get + { + 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; + } + } + } + ///// <summary> + ///// 鍔熻兘绫诲瀷 + ///// </summary> + public FunctionType functionType + { + get + { + var _functionTypeString = sid.Substring(16, 4); + return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16)); + + } + } /// <summary> /// A鍗忚鍔熻兘鐨勭壒鎬� /// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature /// attri /// </summary> - public List<Trait> function = new List<Trait>(); + public List<FunctionAttributes> attributes = new List<FunctionAttributes>(); /// <summary> /// 鎴块棿ID鍒楄〃 /// 璇ュ姛鑳芥坊鍔犲埌鍒版埧闂村垪琛� /// </summary> - public List<string> roomIdList = new List<string>(); + public List<string> roomIds = new List<string>(); /// <summary> /// bus鍗忚鏁版嵁鏍煎紡 /// 浣跨敤A鍗忚鎺у埗鏃讹紝鏀瑰睘鎬т负绌� /// </summary> public BusData bus_Data; + /// <summary> + /// 鏄惁鏀惰棌 + /// </summary> + public bool collect = false; + #endregion /// <summary> /// 寤舵椂 /// </summary> @@ -101,43 +143,6 @@ return text; } } - #endregion - - /// <summary> - /// 鍔熻兘绫诲埆 - /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被 - /// </summary> - public FunctionCategory functionCategory - { - get - { - 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> - /// 澶囨敞 - /// </summary> - public string name; /// <summary> /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬� @@ -145,27 +150,27 @@ [Newtonsoft.Json.JsonIgnore] public string lastState = ""; - Trait _trait_on_off; + FunctionAttributes _trait_on_off; [Newtonsoft.Json.JsonIgnore] - public Trait trait_on_off + public FunctionAttributes trait_on_off { get { if (_trait_on_off == null) { - _trait_on_off = function.Find((obj) => obj.name == "on_off"); + _trait_on_off = attributes.Find((obj) => obj.key == "on_off"); //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂�� if (_trait_on_off == null) { - _trait_on_off = new Trait() + _trait_on_off = new FunctionAttributes() { - name = "on_off", - value_key = new List<string> { "on", "off" }, + key = "on_off", + value = new List<string> { "on", "off" }, max = 1, min = 0, }; } - _trait_on_off.value = "on"; + _trait_on_off.curValue = "on"; } return _trait_on_off; } @@ -174,11 +179,6 @@ // _trait_on_off = value; //} } - - /// <summary> - /// 鏄惁鏀惰棌 - /// </summary> - public bool collection = false; /// <summary> /// 浣跨敤娆℃暟 @@ -203,7 +203,7 @@ string busId = ""; if (bus_Data != null) { - busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID; + busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.loopId; } return busId; } @@ -215,12 +215,14 @@ public string GetRoomListName() { string roomNameList = ""; - foreach(var roomId in roomIdList) + foreach(var roomId in roomIds) { var findRoom = DB_ResidenceData.rooms.Find(obj => obj.sid == roomId); if (findRoom == null) + { continue; - if(roomNameList != "") + } + if (roomNameList != "") { roomNameList += ","; } @@ -233,47 +235,162 @@ return roomNameList; } /// <summary> + /// 鏁版嵁瀛樺偍鏂囦欢鍚� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string savePath + { + get + { + return "FunctionData_" + sid; + } + } + /// <summary> /// 淇濆瓨鍔熻兘鏁版嵁 /// </summary> public void SaveFunctionData() { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes("FunctionData_" + this.sid, ssd); + FileUtils.WriteFileByBytes( savePath + this.sid, ssd); MainPage.Log($"Save FunctionData {this.functionType} : {this.sid}"); + } + + /// <summary> + /// 杞崲鎴愬満鏅姛鑳藉璞� + /// </summary> + /// <returns></returns> + public SceneFunction ConvertSceneFunction() + { + var sFunc = new SceneFunction(); + foreach (var attr in attributes) + { + sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() }); + } + return sFunc; } /// <summary> /// 鏇存柊鏃堕棿 /// </summary> public DateTime refreshTime = DateTime.MinValue; + + /// <summary> + /// 鑾峰彇鏈湴鎺у埗鏁版嵁 + /// </summary> + public GatewayAlinkControlObj GetGatewayAlinkControlData(Dictionary<string, string> commandDictionary) + { + var sendDataObj = new GatewayAlinkControlObj(); + sendDataObj.id = Control.Ins.msg_id.ToString(); + sendDataObj.time_stamp = Control.Ins.Get_TimeStamp(); + + + var acd = new AlinkControlData(); + acd.sid = sid; +#if DEBUG + acd.sid = "0001016FB925AB02020100010101"; +#endif + var aca = new AlinkControlAttributes(); + foreach(var dic in commandDictionary) + { + aca.key = dic.Key; + aca.value = dic.Value; + acd.status.Add(aca); + } + + sendDataObj.objects.Add(acd); + + return sendDataObj; + } + /// <summary> + /// 鑾峰彇Api鎺у埗鏁版嵁 + /// </summary> + /// <returns></returns> + public ApiAlinkControlActionObj GetApiControlData(Dictionary<string,string> keyValues) + { + ApiAlinkControlActionObj aaao = new ApiAlinkControlActionObj(); + aaao.deviceId = this.deviceId; + aaao.spk = this.spk; + foreach (var kv in keyValues) + { + aaao.attributes.Add(new AlinkControlAttributes() + { + key = kv.Key, + value = kv.Value, + }); + } + return aaao; + } + } + + /// <summary> + /// 杩滅▼鎺у埗 + /// api a鍗忚鎺у埗鍔ㄤ綔瀵硅薄 + /// </summary> + public class ApiAlinkControlActionObj + { + /// <summary> + /// 璁惧ID + /// </summary> + public string deviceId = "0"; + /// <summary> + /// spk + /// 鍒�:light.switch + /// </summary> + public string spk = ""; + + public List<AlinkControlAttributes> attributes = new List<AlinkControlAttributes>(); + } + + /// <summary> + /// 鏈湴鎺у埗 + /// A鍗忚鎺у埗鏁版嵁鐨勫璞� + /// </summary> + public class GatewayAlinkControlObj + { + public List<AlinkControlData> objects = new List<AlinkControlData>(); + + public string time_stamp = ""; + public string id = ""; + } + /// <summary> + /// A鍗忚鎺у埗鏁版嵁 + /// </summary> + public class AlinkControlData + { + public string sid = ""; + public List<AlinkControlAttributes> status = new List<AlinkControlAttributes>(); + } + /// <summary> + /// a鍗忚鎺у埗鍔ㄤ綔鏁版嵁 + /// </summary> + public class AlinkControlAttributes + { + /// <summary> + /// 灞炴�у悕 + /// 鍒�:on_off + /// </summary> + public string key = ""; + /// <summary> + /// 灞炴�у�� + /// 鍒�:on + /// </summary> + public string value = ""; } /// <summary> /// 鍔熻兘灞炴�� /// 灞炴�у瓧娈佃В鏋愶細attri :灞炴�у唴瀹癸紝value 灞炴�х殑鍊硷紝max 鏈�澶у�� min 鏈�灏忓�� /// </summary> - public class Trait + public class FunctionAttributes { /// <summary> - /// 灞炴�у悕绉� + /// 灞炴�ч敭鍚� /// </summary> - public string name; - List<string> _value_key; + public string key; /// <summary> /// 灞炴�х殑鍊煎垪琛� /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<string> value_key - { - get - { - return _value_key; - } - set - { - _value_key = value; - } - } + public List<string> value = new List<string>(); /// <summary> /// 鏈�澶у�� /// </summary> @@ -282,17 +399,14 @@ /// 鏈�灏忓�� /// </summary> public int min; - /// <summary> /// 鏁版嵁绫诲瀷 /// </summary> public string data_type = ""; - /// <summary> /// 褰撳墠鍊� /// </summary> - public object value = new object(); - + public object curValue = new object(); //----app鑷畾涔� /// <summary> @@ -309,9 +423,10 @@ return _uintString; } var us = ""; - switch (name) + switch (key) { case "temperature": + case "set_temperature": us = "掳C"; break; case "percent": @@ -333,7 +448,7 @@ get { string text = ""; - switch (name) + switch (key) { case "on_off": text = Language.StringByID(StringId.OnOff); @@ -351,6 +466,7 @@ text = Language.StringByID(StringId.FanSpeed); break; case "temperature": + case "set_temperature": text = Language.StringByID(StringId.Temp); break; case "delay": @@ -366,7 +482,7 @@ //case "lock": //case "ico": //case "swing": - //case "set_ point": + //case "set_point": //case "pm25": //case "volume": //case "vol_step": @@ -396,7 +512,7 @@ /// </summary> public string GetCurValueText() { - return GetValueText(value.ToString()); + return GetValueText(curValue.ToString()); } /// <summary> @@ -407,17 +523,18 @@ { string text = ""; value = value.Replace("{}", ""); - switch (name) + switch (key) { case "on_off": text = value == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF); break; case "temperature": + case "set_temperature": case "brightness": case "percent": if (value == "") { - this.value = this.min; + this.curValue = this.min; text = this.min.ToString(); } else @@ -462,21 +579,21 @@ text = Language.StringByID(StringId.Timer); break; default: - if (this.value_key.Contains("cool")) + if (this.value.Contains("cool")) { - this.value = "cool"; + this.curValue = "cool"; text = Language.StringByID(StringId.Cool); } - else if (this.value_key.Contains("day")) + else if (this.value.Contains("day")) { - this.value = "day"; + this.curValue = "day"; text = Language.StringByID(StringId.Day); } else { - foreach (var v in this.value_key) + foreach (var v in this.value) { - this.value = v; + this.curValue = v; text = GetCurValueText(); } } @@ -499,16 +616,16 @@ text = Language.StringByID(StringId.Auto); break; default: - if (this.value_key.Contains("low")) + if (this.value.Contains("low")) { - this.value = "low"; + this.curValue = "low"; text = Language.StringByID(StringId.LowWindSpeed); } else { - foreach (var v in this.value_key) + foreach (var v in this.value) { - this.value = v; + this.curValue = v; text = GetCurValueText(); } } @@ -521,7 +638,7 @@ //case "lock": //case "ico": //case "swing": - //case "set_ point": + //case "set_point": //case "pm25": //case "volume": //case "vol_step": @@ -557,6 +674,48 @@ } } /// <summary> + /// 鍔熻兘灞炴�ч敭鍚嶅垪琛� + /// </summary> + public static class FunctionAttributeKey + { + /// <summary> + /// 寮�鍏� + /// </summary> + public const string OnOff = "on_off"; + /// <summary> + /// 浜害 + /// </summary> + public const string Brightness = "brightness"; + /// <summary> + /// 棰滆壊 + /// </summary> + public const string Color = "color"; + /// <summary> + /// 妯″紡 + /// </summary> + public const string Mode = "mode"; + /// <summary> + /// 椋庨�� + /// </summary> + public const string FanSpeed = "fan"; + /// <summary> + /// 娓╁害 + /// </summary> + public const string Temp = "temperature"; + /// <summary> + /// 寤舵椂 + /// </summary> + public const string Delay = "delay"; + /// <summary> + /// 鑹叉俯 + /// </summary> + public const string CCT = "cct"; + /// <summary> + /// 鐧惧垎姣� + /// </summary> + public const string Percent = "percent"; + } + /// <summary> /// 璁惧鍔熻兘oid /// </summary> public class FunctionOid @@ -569,4 +728,27 @@ public string channels; } + /// <summary> + /// 鍏煎鏃у崗璁帶鍒� + /// </summary> + public class BusData + { + public string addresses = "FFFF"; + public byte SubnetID + { + get + { + return Convert.ToByte(addresses.Substring(0, 2), 16); + } + } + public byte DeviceID + { + get + { + return Convert.ToByte(addresses.Substring(2, 2), 16); + } + } + public byte loopId; + } + } -- Gitblit v1.8.0