| | |
| | | public Function() |
| | | { |
| | | } |
| | | /// <summary> |
| | | /// 数据存储文件名 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string savePath |
| | | { |
| | | get |
| | | { |
| | | return "FunctionData_" + sid; |
| | | } |
| | | } |
| | | |
| | | #region base info |
| | | /// <summary> |
| | | /// HDL统一协议格式:14bytes
|
| | | /// 举例: 来源 厂商代码 通讯方式 产品时间戳 产品类别 物模型类 通道号 大小类别
|
| | | // 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte |
| | | /// 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 |
| | |
| | | /// 小类别 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协议功能的特性 |
| | | /// 如:是AC功能:特性:on_off,mode,fan,temperature |
| | | /// attri |
| | | /// </summary> |
| | | public List<FunctionAttributes> function = new List<FunctionAttributes>(); |
| | | 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> |
| | |
| | | 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> |
| | | /// 最后控制的一次状态 |
| | |
| | | { |
| | | if (_trait_on_off == null) |
| | | { |
| | | _trait_on_off = function.Find((obj) => obj.key == "on_off"); |
| | | _trait_on_off = attributes.Find((obj) => obj.key == "on_off"); |
| | | //找不到属性需要声明一个,防止报错闪退 |
| | | if (_trait_on_off == null) |
| | | { |
| | |
| | | // _trait_on_off = value; |
| | | //} |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否收藏 |
| | | /// </summary> |
| | | public bool collection = false; |
| | | |
| | | /// <summary> |
| | | /// 使用次数 |
| | |
| | | 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; |
| | | } |
| | |
| | | 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) |
| | |
| | | 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> |
| | |
| | | public DateTime refreshTime = DateTime.MinValue; |
| | | |
| | | /// <summary> |
| | | /// 获取控制发送数据 |
| | | /// 获取本地控制数据 |
| | | /// </summary> |
| | | public AprotocolControlObj GetControlSendData(Dictionary<string, string> commandDictionary) |
| | | public GatewayAlinkControlObj GetGatewayAlinkControlData(Dictionary<string, string> commandDictionary) |
| | | { |
| | | var sendDataObj = new AprotocolControlObj(); |
| | | var sendDataObj = new GatewayAlinkControlObj(); |
| | | sendDataObj.id = Control.Ins.msg_id.ToString(); |
| | | sendDataObj.time_stamp = Control.Ins.Get_TimeStamp(); |
| | | |
| | | |
| | | var acd = new AprotocolControlData(); |
| | | var acd = new AlinkControlData(); |
| | | acd.sid = sid; |
| | | #if DEBUG |
| | | acd.sid = "0001016FB925AB02020100010101"; |
| | | #endif |
| | | var aca = new AprotocolControlAttribute(); |
| | | var aca = new AlinkControlAttributes(); |
| | | foreach(var dic in commandDictionary) |
| | | { |
| | | aca.key = dic.Key; |
| | |
| | | |
| | | 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 AprotocolControlObj |
| | | public class GatewayAlinkControlObj |
| | | { |
| | | public List<AprotocolControlData> objects = new List<AprotocolControlData>(); |
| | | public List<AlinkControlData> objects = new List<AlinkControlData>(); |
| | | |
| | | public string time_stamp = ""; |
| | | public string id = ""; |
| | |
| | | /// <summary> |
| | | /// A协议控制数据 |
| | | /// </summary> |
| | | public class AprotocolControlData |
| | | public class AlinkControlData |
| | | { |
| | | |
| | | public string sid = ""; |
| | | public List<AprotocolControlAttribute> status = new List<AprotocolControlAttribute>(); |
| | | public List<AlinkControlAttributes> status = new List<AlinkControlAttributes>(); |
| | | } |
| | | /// <summary> |
| | | /// A协议控制属性对象 |
| | | /// a协议控制动作数据 |
| | | /// </summary> |
| | | public class AprotocolControlAttribute |
| | | public class AlinkControlAttributes |
| | | { |
| | | public string key; |
| | | public string value; |
| | | /// <summary> |
| | | /// 属性名 |
| | | /// 列:on_off |
| | | /// </summary> |
| | | public string key = ""; |
| | | /// <summary> |
| | | /// 属性值 |
| | | /// 列:on |
| | | /// </summary> |
| | | public string value = ""; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 最小值 |
| | | /// </summary> |
| | | public int min; |
| | | |
| | | /// <summary> |
| | | /// 数据类型 |
| | | /// </summary> |
| | | public string data_type = ""; |
| | | |
| | | /// <summary> |
| | | /// 当前值 |
| | | /// </summary> |
| | | public object curValue = new object(); |
| | | |
| | | |
| | | //----app自定义 |
| | | /// <summary> |
| | |
| | | } |
| | | } |
| | | /// <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 |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |