| | |
| | | using System;
|
| | | using Newtonsoft.Json;
|
| | | using Newtonsoft.Json.Linq;
|
| | | using Shared.Phone.ModelData;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | |
| | | #region ■ 手拉控制___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置手拉控制状态值
|
| | | /// 设置手拉控制状态值 ☆☆☆☆☆
|
| | | /// </summary>
|
| | | /// <param name="rollershade">窗帘对象</param>
|
| | | /// <param name="device">窗帘对象</param>
|
| | | /// <param name="bolStatu">手拉控制状态值</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetHandPullControl(Rollershade rollershade, bool bolStatu)
|
| | | public bool SetHandPullControl(CommonDevice device, bool bolStatu)
|
| | | {
|
| | | var result = await rollershade.SetCurtianMaintenanceAsync(bolStatu);
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | //如果是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | //添加缓存
|
| | | DeviceModelDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, "SetWritableValue");
|
| | | return true;
|
| | | }
|
| | | //获取发送的命令字符
|
| | | var sendData = this.GetHandPullControlText(device.DeviceAddr, device.DeviceEpoint, bolStatu);
|
| | | //发送给网关
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | return false;
|
| | | }
|
| | | if (result == null || result.setWritableValueResponData == null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //切换手拉控制失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
|
| | |
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.setWritableValueResponData.Status != 0)
|
| | |
|
| | | var data = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
|
| | | if (data.Status != 0)
|
| | | {
|
| | | //切换手拉控制失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份属性
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A窗帘手拉控制, bolStatu);
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取更改手拉控制状态的字符串命令 ☆☆☆☆☆
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">DeviceAddr</param>
|
| | | /// <param name="DeviceEpoint">DeviceEpoint</param>
|
| | | /// <param name="bolStatu">手拉控制状态值</param>
|
| | | /// <returns></returns>
|
| | | public string GetHandPullControlText(string DeviceAddr, int DeviceEpoint, bool bolStatu)
|
| | | {
|
| | | int bit2 = bolStatu == true ? 1 : 0;
|
| | | int attributeData = bit2 * 4;
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
|
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } };
|
| | | jObject.Add("Data", data);
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="rollershade">窗帘对象</param>
|
| | | /// <param name="bolStatu">false:电机方向正向;true:电机方向反向</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetCurtainDirection(Rollershade rollershade, bool bolStatu)
|
| | | public bool SetCurtainDirection(CommonDevice rollershade, bool bolStatu)
|
| | | {
|
| | | var result = await rollershade.SetCurtainDirectionAsync(bolStatu);
|
| | | var result = this.SetCurtainDirectionAsync(rollershade, bolStatu);
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | |
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | await this.BackupCurtainDirection(rollershade, bolStatu);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 备份窗帘方向
|
| | | /// 设置开合帘电机方向
|
| | | /// <para>isDirectionReversed (false:电机方向正向;true:电机方向反向;)</para> .
|
| | | /// </summary>
|
| | | /// <param name="rollershade">窗帘对象</param>
|
| | | /// <param name="bolStatu">false:电机方向正向;true:电机方向反向</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> BackupCurtainDirection(Rollershade rollershade, bool bolStatu)
|
| | | private CommonDevice.SetWritableValueResponAllData SetCurtainDirectionAsync(CommonDevice device, bool isDirectionReversed)
|
| | | {
|
| | | //备份设备
|
| | | return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A窗帘方向, bolStatu);
|
| | | //如果当前是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, "SetWritableValue");
|
| | | }
|
| | | //获取编辑窗帘方向的命令字符
|
| | | var sendData = this.GetCurtainDirectionCommadText(device.DeviceAddr, device.DeviceEpoint, isDirectionReversed);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | var tempData = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
|
| | | return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取编辑窗帘方向的命令字符
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr"></param>
|
| | | /// <param name="DeviceEpoint"></param>
|
| | | /// <param name="isDirectionReversed"></param>
|
| | | /// <returns></returns>
|
| | | public string GetCurtainDirectionCommadText(string DeviceAddr,int DeviceEpoint, bool isDirectionReversed)
|
| | | {
|
| | | int bit0 = isDirectionReversed == true ? 1 : 0;
|
| | | int attributeData = bit0 * 1;
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
|
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } };
|
| | | jObject.Add("Data", data);
|
| | |
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 开合帘限位配置_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置开合帘限位
|
| | | /// </summary>
|
| | | /// <param name="rollershade"></param>
|
| | | /// <param name="upLimit">开限位</param>
|
| | | /// <param name="downLimit">合限位</param>
|
| | | /// <param name="curtainLength">导轨长度(这个是给虚拟设备用的)</param>
|
| | | /// <returns></returns>
|
| | | public bool SetAutoOpenCurtainLimitPoint(CommonDevice rollershade, int upLimit, int downLimit, int curtainLength)
|
| | | {
|
| | | //如果当前是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, "SetWritableValue");
|
| | | }
|
| | | //获取编辑开合帘限位的命令字符
|
| | | var sendData = this.GetAutoOpenCurtainLimitPointCommandText(rollershade.DeviceAddr, rollershade.DeviceEpoint, upLimit, downLimit);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(rollershade, "SetWritableValue", sendData, "SetWritableValue_Respon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //设置窗帘限位点失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
|
| | | if (tempData.Status != 0)
|
| | | {
|
| | | //设置窗帘限位点失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 获取编辑开合帘限位的命令字符
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr"></param>
|
| | | /// <param name="DeviceEpoint"></param>
|
| | | /// <param name="upLimit"></param>
|
| | | /// <param name="downLimit"></param>
|
| | | /// <returns></returns>
|
| | | public string GetAutoOpenCurtainLimitPointCommandText(string DeviceAddr, int DeviceEpoint, int upLimit, int downLimit)
|
| | | {
|
| | | //这个是开合帘 "2,0x00ff,0x00ff"格式 合限位在前,开限位在后
|
| | | string convertData = "\"2,0x" + Convert.ToString(downLimit, 16).PadLeft(4, '0');
|
| | | convertData += ",0x" + Convert.ToString(upLimit, 16).PadLeft(4, '0') + "\"";
|
| | | //然后将它们转为ASK码数值,然后再转为16进制
|
| | | //总计长度为17(这里是16进制)
|
| | | string sendData = "11";
|
| | | foreach (char c in convertData)
|
| | | {
|
| | | sendData += Convert.ToString((int)c, 16).PadLeft(2, '0');
|
| | | }
|
| | |
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
|
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 24 }, { "AttributeDataType", 65 }, { "AttributeData", sendData } };
|
| | | jObject.Add("Data", data);
|
| | |
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | {
|
| | | sendData += Convert.ToString((int)c, 16).PadLeft(2, '0');
|
| | | }
|
| | | result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData);
|
| | | //result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData);
|
| | | }
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (upLimit != -1 && downLimit != -1)
|
| | | {
|
| | | //备份设备
|
| | | await this.BackupCurtainLimitPoint(rollershade, upLimit, downLimit);
|
| | | }
|
| | |
|
| | | return true;
|
| | |
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 备份窗帘限位点
|
| | | /// </summary>
|
| | | /// <param name="rollershade">窗帘对象</param>
|
| | | /// <param name="upLimit">上限位的值,百分比(备份用)</param>
|
| | | /// <param name="downLimit">下限位的值,百分比(备份用)</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> BackupCurtainLimitPoint(Rollershade rollershade, int upLimit, int downLimit)
|
| | | {
|
| | | //备份设备
|
| | | var backData = new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "upLimit",upLimit },
|
| | | { "downLimit", downLimit }
|
| | | };
|
| | | //备份设备
|
| | | return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A窗帘上下限位, backData);
|
| | | }
|
| | |
|
| | | #endregion
|