| | |
| | | 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
|
| | | 厂商代号: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 |
| | | /// 厂商代码 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协议功能的通行 |
| | | /// 如:是AC功能:特性: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协议厂商代码 |
| | | /// </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> |
| | | /// 使用次数 |
| | |
| | | /// <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; |
| | | } |