using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; using HDL_ON; namespace HDL_ON.Entity { /// /// 功能属性 /// 属性字段解析:attri :属性内容,value 属性的值,max 最大值 min 最小值 /// public class Trait { /// /// 属性内容 /// public string attri; /// /// 属性的值 /// public List value; /// /// 最大值 /// public int max; /// /// 最小值 /// public int min; /// /// /// public string data_type = ""; /// /// 当前值 /// app软件自定义属性 /// 用来记录当前状态 /// public object curValues; } public class Function { public Function() { } #region base info /// /// HDL统一协议格式:14bytes /// 举例: 来源 厂商代码 通讯方式 产品时间戳 产品类别 物模型类 通道号 大小类别 // 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte /// 来源:00 默认原生态系统数据 、01 网关或者其他A设备、02 调试软件、03 APP应用程序、04 第三方网关或者平台 /// 厂商代码: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 (预留) /// public string sid = "03010112345678010123012301230101"; /// /// A协议功能的特性 /// 如:是AC功能:特性:on_off,mode,fan,temperature /// attri /// public List function = new List(); /// /// 房间ID列表 /// 该功能添加到到房间列表 /// public List roomIdList = new List(); /// /// bus协议数据格式 /// 使用A协议控制时,改属性为空 /// public BusData bus_Data; #endregion ///// ///// 功能附带的属性与值的列表 ///// //public Dictionary dicPropert; /// /// 功能类别 /// 如:空调类、灯光类、窗帘类 /// 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)); } } /// /// 备注 /// public string name; /// /// A协议厂商代码 /// public string vendor_code { get { string vendorCode = "HDL"; var code = sid.Substring(0, 4); if (code == "0001") vendorCode = "HDL"; return vendorCode; } } /// /// 最后控制的一次状态 /// public string lastState = ""; [Newtonsoft.Json.JsonIgnore] public Trait trait_on_off; /// /// 开关状态 /// 0:关 /// 1:开 /// [Newtonsoft.Json.JsonIgnore] public string on_off { get { try { if (trait_on_off == null) { trait_on_off = function.Find((obj) => obj.attri == "on_off"); //找不到属性需要声明一个,防止报错闪退 if (trait_on_off == null) { trait_on_off = new Trait() { attri = "on_off", value = new List { "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 { "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"); //找不到属性需要声明一个,防止报错闪退 if (trait_on_off == null) { trait_on_off = new Trait() { attri = "on_off", value = new List { "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 { "on", "off" }, max = 1, min = 0, }); } } } /// /// 是否收藏 /// public bool collection = false; /// /// 使用次数 /// public double usageCount = 0; /// /// 使用频率 /// public double usageFrequency { get { return usageCount / 7; } } /// /// 固定的序号 /// public int fixedSerialNumber = int.MaxValue; /// /// 获取A协议控制字符串 /// /// 控制命令:write,read /// public virtual JObject GetSendJObject(CommandType_A command) { 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; } public string GetBusId () { string busId = ""; if (bus_Data != null) { busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID; } return busId; } /// /// 获取设备添加到房间的房间名称 /// /// public string GetRoomListName() { string roomNameList = ""; foreach(var roomId in roomIdList) { var findRoom = DB_ResidenceData.residenceData.rooms.Find(obj => obj.sid == roomId); if (findRoom == null) continue; if(roomNameList != "") { roomNameList += ","; } roomNameList += findRoom.floor + "·" + findRoom.name; } return roomNameList; } /// /// 更新时间 /// public DateTime refreshTime = DateTime.MinValue; } }