| | |
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | | using System.Threading.Tasks;
|
| | | using Newtonsoft.Json.Linq;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | {
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<int> GetPirLightAbilitySize(IASZone iASZone)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return 100;
|
| | | }
|
| | | var data = await iASZone.GetPIRLightAbilitySizeAsync();
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(data);
|
| | |
| | | /// </summary>
|
| | | /// <param name="iASZone"></param>
|
| | | /// <returns></returns>
|
| | | public async Task<IASZone.ConfigureParamates> GetPirSensorLightSettion(IASZone iASZone)
|
| | | public IASZone.ConfigureParamates GetPirSensorLightSettion(IASZone iASZone)
|
| | | {
|
| | | var data = await iASZone.GetPIRSensorParamateAsync();
|
| | | var data = this.GetPIRSensorParamateAsync(iASZone);
|
| | | if (data == null || data.configureParamates == null)
|
| | | {
|
| | | //获取传感器设置信息失败
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<int> GetPirSensorLux(IASZone iASZone, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return 70;
|
| | | }
|
| | | var data = await iASZone.GetPirLuxAbilitySizeAsync();
|
| | | if (data == null || data.pirLux == -1)
|
| | | {
|
| | |
| | | return data.pirLux;
|
| | | }
|
| | |
|
| | | ///<summary >
|
| | | ///PIR传感器参数配置
|
| | | /// </summary>
|
| | | public IASZone.ParamatesInfo GetPIRSensorParamateAsync(CommonDevice device)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.GetPirSensorLightSettion(device);
|
| | | }
|
| | | var sendData = this.GetPirSensorParamateCommadText(device.DeviceAddr);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0302", 34, 9);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var data = result.ReceiptData;
|
| | |
|
| | | var tempD = new IASZone.ConfigureParamates();
|
| | |
|
| | | var le = data[10].ToString() + data[11].ToString();
|
| | | tempD.levelEnable = le == "01";
|
| | |
|
| | | var size = data[12].ToString() + data[13].ToString();
|
| | | tempD.levelSize = Convert.ToInt32(size, 16);
|
| | |
|
| | | var cdl = data[14].ToString() + data[15].ToString();
|
| | | tempD.controlDevEnable = cdl == "01";
|
| | |
|
| | | tempD.transitionTime = Convert.ToInt32(data[18].ToString() + data[19].ToString() + data[16].ToString() + data[17].ToString(), 16);
|
| | | tempD.iasReportPeriod = Convert.ToInt32(data[22].ToString() + data[23].ToString() + data[20].ToString() + data[21].ToString(), 16);
|
| | | tempD.mode = Convert.ToInt32(data[24].ToString() + data[25].ToString(), 16);
|
| | | tempD.type = Convert.ToInt32(data[26].ToString() + data[27].ToString(), 16);
|
| | | tempD.dimmerOnTime = Convert.ToInt32(data[28].ToString() + data[29].ToString(), 16);
|
| | | tempD.dimmerOffTime = Convert.ToInt32(data[30].ToString() + data[31].ToString(), 16);
|
| | | tempD.dimmerLevel = Convert.ToInt32(data[32].ToString() + data[33].ToString(), 16);
|
| | |
|
| | | return new IASZone.ParamatesInfo { configureParamates = tempD };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取PIR传感器参数配置的命令字符
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | private string GetPirSensorParamateCommadText(string DeviceAddr)
|
| | | {
|
| | | var passData = "050103010101";
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
| | | var data = new JObject { { "PassData", passData } };
|
| | | jObject.Add("Data", data);
|
| | |
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置配置信息_______________________
|
| | |
| | | /// <summary>
|
| | | /// 设置PIR传感器的【配置信息】
|
| | | /// </summary>
|
| | | /// <param name="iASZone">传感器对象</param>
|
| | | /// <param name="device">传感器对象</param>
|
| | | /// <param name="configure">灯光配置</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetPirSensorSettion(IASZone iASZone, IASZone.ConfigureParamates configure)
|
| | | public bool SetPirSensorSettion(CommonDevice device, IASZone.ConfigureParamates configure)
|
| | | {
|
| | | var result = await iASZone.SetPIRSensorParamateAsync(configure);
|
| | | var result = this.SetPIRSensorParamateAsync(device, configure);
|
| | | if (result == null || result.responseData == null)
|
| | | {
|
| | | //设置传感器配置信息失败
|
| | |
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设置
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(iASZone, GatewayBackupEnum.APir灯光配置, configure);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// PIR传感器参数配置
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <param name="configureParamates"></param>
|
| | | /// <returns></returns>
|
| | | public IASZone.ResponseAllData SetPIRSensorParamateAsync(CommonDevice device, IASZone.ConfigureParamates configureParamates)
|
| | | {
|
| | | //如果是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.SetPirSensorLightSettion(device, configureParamates, "ClientDataPassthrough");
|
| | | }
|
| | | //发送数据
|
| | | var sendData = this.GetPirSensorSettionCommandText(device.DeviceAddr, configureParamates);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0002", 16, 9);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | string data = result.ReceiptData;
|
| | | var tempD = new IASZone.ResponseData();
|
| | | tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
|
| | | tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
| | |
|
| | | return new CommonDevice.ResponseAllData { responseData = tempD };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取修改PIR传感器配置的命令字符
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr"></param>
|
| | | /// <param name="configureParamates"></param>
|
| | | /// <returns></returns>
|
| | | public string GetPirSensorSettionCommandText(string DeviceAddr, IASZone.ConfigureParamates configureParamates)
|
| | | {
|
| | | var passData = this.GetPIRSensorSettionPassData(configureParamates);
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
| | | var data = new JObject { { "PassData", passData } };
|
| | | jObject.Add("Data", data);
|
| | |
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取修改PIR传感器配置的命令字符
|
| | | /// </summary>
|
| | | private string GetPIRSensorSettionPassData(IASZone.ConfigureParamates configureParamates)
|
| | | {
|
| | | string data = "";
|
| | | string dataLength = "10";
|
| | | string dataComand1 = "00";
|
| | | string dataComand2 = "03";
|
| | | string dataSerialNum = "01";
|
| | | string addDataLength = "0C";
|
| | | string levelEnable = "";
|
| | | string levelSize = "";
|
| | | string controlDevEnable = "";
|
| | | string transitionTime = "";
|
| | | string iasReportPeriod = "";
|
| | | string mode = "";
|
| | | string type = "";
|
| | | string dimmerOnTime = "";
|
| | | string dimmerOffTime = "";
|
| | | try
|
| | | {
|
| | | if (configureParamates != null)
|
| | | {
|
| | | //levelEnable
|
| | | if (configureParamates.levelEnable)
|
| | | {
|
| | | levelEnable = "01";
|
| | | }
|
| | | else
|
| | | {
|
| | | levelEnable = "00";
|
| | | }
|
| | | //光照等级
|
| | | if (configureParamates.levelSize > 0)
|
| | | {
|
| | | var tempLevelEnable = Convert.ToString(configureParamates.levelSize, 16);
|
| | | levelSize = tempLevelEnable.ToString().PadLeft(2, '0');
|
| | | }
|
| | | else
|
| | | {
|
| | | levelSize = "00";
|
| | | }
|
| | | //controlDevEnable
|
| | | if (configureParamates.controlDevEnable)
|
| | | {
|
| | | controlDevEnable = "01";
|
| | | }
|
| | | else
|
| | | {
|
| | | controlDevEnable = "00";
|
| | | }
|
| | | //transitionTime,iasReportPeriod
|
| | | for (int j = 0; j < 2; j++)
|
| | | {
|
| | | var tempBytes = new byte[2];
|
| | | if (j == 0)
|
| | | {
|
| | | for (int i = 0; i < 2; i++)
|
| | | {
|
| | | tempBytes[i] = (byte)(configureParamates.transitionTime >> (i * 8) & 0xff);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < 2; i++)
|
| | | {
|
| | | tempBytes[i] = (byte)(configureParamates.iasReportPeriod >> (i * 8) & 0xff);
|
| | | }
|
| | | }
|
| | | var time1 = Convert.ToString(tempBytes[0], 16);
|
| | | var time2 = Convert.ToString(tempBytes[1], 16);
|
| | | if (time1.Length == 1)
|
| | | {
|
| | | time1 = "0" + time1;
|
| | | }
|
| | | if (time2.Length == 1)
|
| | | {
|
| | | time2 = "0" + time2;
|
| | | }
|
| | | if (j == 0)
|
| | | {
|
| | | transitionTime = (time1 + time2).ToUpper();
|
| | |
|
| | | }
|
| | | else
|
| | | {
|
| | | iasReportPeriod = (time1 + time2).ToUpper();
|
| | | }
|
| | | }
|
| | | //mode
|
| | | if (configureParamates.mode == 1)
|
| | | {
|
| | | mode = "01";
|
| | | }
|
| | | else
|
| | | {
|
| | | mode = "00";
|
| | | }
|
| | | //type
|
| | | if (configureParamates.type == 1)
|
| | | {
|
| | | type = "01";
|
| | | }
|
| | | else
|
| | | {
|
| | | type = "00";
|
| | | }
|
| | | //dimmerOnTime
|
| | | if (configureParamates.dimmerOnTime > 0)
|
| | | {
|
| | | var tempDimmerOnTime = Convert.ToString(configureParamates.dimmerOnTime, 16);
|
| | | dimmerOnTime = tempDimmerOnTime.ToString().PadLeft(2, '0');
|
| | | }
|
| | | else
|
| | | {
|
| | | dimmerOnTime = "00";
|
| | | }
|
| | | dimmerOnTime = dimmerOnTime.ToUpper();
|
| | | if (configureParamates.dimmerOffTime > 0)
|
| | | {
|
| | | var tempDimmerOffTime = Convert.ToString(configureParamates.dimmerOffTime, 16);
|
| | | dimmerOffTime = tempDimmerOffTime.ToString().PadLeft(2, '0');
|
| | | }
|
| | | else
|
| | | {
|
| | | dimmerOffTime = "00";
|
| | | }
|
| | | dimmerOffTime = dimmerOffTime.ToUpper();
|
| | | //dimmerLevel |
| | | string temp = "";
|
| | | var sbString = new System.Text.StringBuilder();
|
| | | string temp2 = Convert.ToString(configureParamates.dimmerLevel, 16);
|
| | | switch (temp2.Length)
|
| | | {
|
| | | case 1:
|
| | | temp = "0" + temp2;
|
| | | break;
|
| | | case 2:
|
| | | temp = temp2;
|
| | | break;
|
| | | }
|
| | | sbString.Append(temp.ToUpper());
|
| | |
|
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
| | | levelEnable + levelSize + controlDevEnable + transitionTime + iasReportPeriod
|
| | | + mode + type + dimmerOnTime + dimmerOffTime + sbString;
|
| | | }
|
| | | }
|
| | | catch { };
|
| | |
|
| | | return data;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|