| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using HDL_ON.Common; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.DriverLayer; |
| | | using Shared; |
| | | |
| | |
| | | |
| | | #region base info |
| | | /// <summary> |
| | | /// HDL统一协议格式:14bytes
|
| | | /// 举例: 来源 厂商代码 通讯方式 产品时间戳 产品类别 物模型类 通道号 大小类别
|
| | | /// HDL统一协议格式:14bytes |
| | | /// 举例: 来源 厂商代码 通讯方式 产品时间戳 产品类别 物模型类 通道号 大小类别 |
| | | /// 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte |
| | | /// 来源:00 默认原生态系统数据 、01 网关或者其他A设备、02 调试软件、03 APP应用程序、04 第三方网关或者平台
|
| | | /// 厂商代码:01 HDL
|
| | | /// 来源: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 卷帘
|
| | | /// 产品时间戳: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 (预留)
|
| | | /// 大类别 1bytes (预留) |
| | | /// 小类别 1byte (预留) |
| | | /// </summary> |
| | | public string sid = "0301011234567801012301230123"; |
| | |
| | | /// 设备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 FunctionCategory Spk_Prefix |
| | | //{ |
| | | // 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 |
| | | //public FunctionType spk |
| | | //{ |
| | | // get |
| | | // { |
| | | // var _functionTypeString = sid.Substring(16, 4); |
| | | // return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16)); |
| | | // } |
| | | //} |
| | | |
| | | string spk_Prefix; |
| | | /// <summary> |
| | | /// spk前缀 |
| | | /// 大类 |
| | | /// 功能类别 |
| | | /// 如:空调类、灯光类、窗帘类 |
| | | /// </summary> |
| | | public string Spk_Prefix |
| | | { |
| | | get |
| | | { |
| | | var _functionTypeString = sid.Substring(16, 4); |
| | | return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16)); |
| | | |
| | | if (string.IsNullOrEmpty(spk_Prefix)) |
| | | { |
| | | spk_Prefix = spk.Split(".")[0]; |
| | | } |
| | | return spk_Prefix; |
| | | } |
| | | } |
| | | string spk_Suffix; |
| | | ///// <summary> |
| | | ///// spk后缀 |
| | | ///// 小类 |
| | | ///// 功能类型 |
| | | ///// </summary> |
| | | //public string spk |
| | | //{ |
| | | // get |
| | | // { |
| | | // if (string.IsNullOrEmpty(spk_Suffix)) |
| | | // { |
| | | // try |
| | | // { |
| | | // spk_Suffix = spk.Split(".")[1]; |
| | | // } |
| | | // catch |
| | | // { |
| | | // spk_Suffix = ""; |
| | | // } |
| | | // } |
| | | // return spk_Suffix; |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// A协议功能的特性 |
| | |
| | | _trait_on_off.curValue = "off"; |
| | | } |
| | | } |
| | | if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off") |
| | | if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off" && _trait_on_off.curValue.ToString() != "stop") |
| | | { |
| | | _trait_on_off.curValue = "off"; |
| | | } |
| | | return _trait_on_off; |
| | | } |
| | | //set |
| | | //{ |
| | | // _trait_on_off = value; |
| | | //} |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 使用次数 |
| | | /// </summary> |
| | | public double usageCount = 0; |
| | | public double controlCounter = 0; |
| | | /// <summary> |
| | | /// 使用频率 |
| | | /// </summary> |
| | |
| | | { |
| | | get |
| | | { |
| | | return usageCount / 7; |
| | | return controlCounter / 7; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 固定的序号 |
| | | /// </summary> |
| | | public int fixedSerialNumber = int.MaxValue; |
| | | |
| | | /// <summary> |
| | | /// 收藏功能 |
| | | /// </summary> |
| | | public void CollectFunction() |
| | | { |
| | | var result = ""; |
| | | //var waitPage = new Loading(); |
| | | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | if (collect) |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code; |
| | | } |
| | | else |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code; |
| | | } |
| | | //提示错误 |
| | | if (result != StateCode.SUCCESS) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | collect = !collect; |
| | | IMessageCommon.Current.ShowErrorInfoAlter(result); |
| | | }); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 编辑功能绑定房间信息 |
| | | /// </summary> |
| | | public void EditBindRoomInfo(string roomId) |
| | | { |
| | | var result = ""; |
| | | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | if (collect) |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.BindDeviceToRoom(new List<string>() { deviceId }, new List<string>() { roomId }).Code; |
| | | } |
| | | else |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.UnbindDeviceToRoom(deviceId,roomId); |
| | | } |
| | | //提示错误 |
| | | if (result != StateCode.SUCCESS) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | collect = !collect; |
| | | IMessageCommon.Current.ShowErrorInfoAlter(result); |
| | | }); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | public string GetBusId() |
| | | { |
| | |
| | | } |
| | | roomNameList += findRoom.floorName +"-"+ findRoom.roomName; |
| | | } |
| | | if (roomNameList == "" && functionType == FunctionType.Scene) |
| | | if (roomNameList == "" ) |
| | | { |
| | | roomNameList = Language.StringByID(StringId.WholeZone); |
| | | } |
| | |
| | | return "FunctionData_" + sid; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存功能数据 |
| | | /// 保存功能文件 |
| | | /// </summary> |
| | | public void SaveFunctionData(bool upSevser) |
| | | public void SaveFunctionFile() |
| | | { |
| | | if (upSevser) |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | /// <summary> |
| | | /// 保存房间绑定信息 |
| | | /// </summary> |
| | | public void UpdataRoomIds() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.UpdataDevcieInfo(this); |
| | | if (pack.Code == DAL.Server.StateCode.SUCCESS) |
| | | var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this); |
| | | //直接保存本地, |
| | | SaveFunctionFile(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | else |
| | | { |
| | | Utlis.ShowTip(Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code); |
| | | IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 更新功能信息 |
| | | /// </summary> |
| | | public void UpdataFuncitonInfo() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.UpdataDevcieInfo(this); |
| | | SaveFunctionFile(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | } |
| | | else |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 更新功能名称 |
| | | /// </summary> |
| | | public void UpdataFunctionName() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.UpdataDevcieInfo(this); |
| | | SaveFunctionFile(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | } |
| | | else |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 保存功能数据 |
| | | /// </summary> |
| | | //public void SaveFunctionData(bool upSevser) |
| | | //{ |
| | | // if (upSevser) |
| | | // { |
| | | // new System.Threading.Thread(() => |
| | | // { |
| | | // var pm = new HttpServerRequest(); |
| | | // var pack = pm.UpdataDevcieInfo(this); |
| | | // if (pack.Code == StateCode.SUCCESS) |
| | | // { |
| | | // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | // FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | // } |
| | | // else |
| | | // { |
| | | // IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | // } |
| | | // }) |
| | | // { IsBackground = true }.Start(); |
| | | // } |
| | | // else |
| | | // { |
| | | // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | // FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | // } |
| | | //} |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | public const string SensorPir = "sensor.pir"; |
| | | /// <summary> |
| | | /// (门窗传感器) |
| | | /// </summary>
|
| | | /// </summary> |
| | | public const string SensorDoorWindow = "sensor.doorwindow"; |
| | | /// <summary> |
| | | /// (PM2.5传感器) |
| | | /// </summary>
|
| | | /// </summary> |
| | | public const string SensorPm25 = "sensor.pm25"; |
| | | /// <summary> |
| | | /// co2传感器 |
| | |
| | | /// 湿度传感器 |
| | | /// </summary> |
| | | public const string SensorHumidity = "sensor.humidity"; |
| | | |
| | | /// <summary> |
| | | /// 烟雾传感器 |
| | | /// </summary> |
| | | public const string SensorSmoke = "sensor.smoke"; |
| | | /// <summary> |
| | | /// 水浸传感器 |
| | | /// </summary> |
| | | public const string SensorWater = "sensor.water"; |
| | | /// <summary> |
| | | /// 燃气传感器 |
| | | /// </summary> |
| | | public const string SensorGas= "sensor.gas"; |
| | | /// <summary> |
| | | /// 红外珊栏传感器 |
| | | /// </summary> |
| | | public const string SensorShanLan = "sensor.shanlan"; |
| | | /// <summary> |
| | | /// 红外对射传感器 |
| | | /// </summary> |
| | | public const string SensorDuiShe = "sensor.duishe"; |
| | | /// <summary> |
| | | /// 超声波传感器 |
| | | /// </summary> |
| | | public const string SensoruUtrasonic = "sensor.ultrasonic"; |
| | | |
| | | /// <summary> |
| | | /// (干接点) |
| | | /// </summary>
|
| | | public const string DryContact = "dryContact.standard";
|
| | | /// </summary> |
| | | public const string SensorDryContact = "sensor.dryContact"; |
| | | /// <summary> |
| | | /// 家电、插座 |
| | | /// </summary> |
| | | public const string ElectricSocket = "electrical.socket";
|
| | | public const string ElectricSocket = "electrical.socket"; |
| | | /// <summary> |
| | | /// 家电、电视 |
| | | /// </summary> |
| | | public const string ElectricTV = "electrical.tv";
|
| | | public const string ElectricTV = "electrical.tv"; |
| | | /// <summary> |
| | | /// 家电、风扇 |
| | | /// </summary> |
| | | public const string ElectricFan = "electrical.fan"; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 功能类别 |
| | | /// </summary> |
| | | public static class FunctionCategory |
| | | { |
| | | /// <summary> |
| | | ///(灯) |
| | | /// </summary> |
| | | public const string Light = "light"; |
| | | /// <summary> |
| | | /// (窗帘) |
| | | /// </summary> |
| | | public const string Curtain = "curtain"; |
| | | /// <summary> |
| | | /// (空调) |
| | | /// </summary> |
| | | public const string AC = "ac"; |
| | | /// <summary> |
| | | /// (地热) |
| | | /// </summary> |
| | | public const string FloorHeat = "floorHeat"; |
| | | /// <summary> |
| | | /// (新风) |
| | | /// </summary> |
| | | public const string AirFresh = "airFresh"; |
| | | /// <summary> |
| | | /// (音乐) |
| | | /// </summary> |
| | | public const string Music = "music"; |
| | | /// <summary> |
| | | /// (传感器) |
| | | /// </summary> |
| | | public const string Sensor = "sensor"; |
| | | /// <summary> |
| | | /// (干接点) |
| | | /// </summary> |
| | | public const string DryContact = "dryContact"; |
| | | /// <summary> |
| | | /// 家电 |
| | | /// </summary> |
| | | public const string Electric = "electrical"; |
| | | |
| | | //Music = 0x09, |
| | | } |
| | | |
| | | |
| | | } |