using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Threading.Tasks;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 窗帘的逻辑
|
/// </summary>
|
public class HdlDeviceCurtainLogic
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 窗帘的逻辑
|
/// </summary>
|
private static HdlDeviceCurtainLogic m_Current = null;
|
/// <summary>
|
/// 窗帘的逻辑
|
/// </summary>
|
public static HdlDeviceCurtainLogic Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
m_Current = new HdlDeviceCurtainLogic();
|
}
|
return m_Current;
|
}
|
}
|
|
#endregion
|
|
#region ■ 手拉控制___________________________
|
|
/// <summary>
|
/// 设置手拉控制状态值
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <param name="bolStatu">手拉控制状态值</param>
|
/// <returns></returns>
|
public async Task<bool> SetHandPullControl(Rollershade rollershade, bool bolStatu)
|
{
|
var result = await rollershade.SetCurtianMaintenanceAsync(bolStatu);
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null)
|
{
|
//切换手拉控制失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//切换手拉控制失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
//备份属性
|
await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A窗帘手拉控制, bolStatu);
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 窗帘方向配置_______________________
|
|
/// <summary>
|
/// 配置窗帘的方向
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <param name="bolStatu">false:电机方向正向;true:电机方向反向</param>
|
/// <returns></returns>
|
public async Task<bool> SetCurtainDirection(Rollershade rollershade, bool bolStatu)
|
{
|
var result = await rollershade.SetCurtainDirectionAsync(bolStatu);
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null)
|
{
|
//窗帘方向设置失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//窗帘方向设置失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
//备份设备
|
await this.BackupCurtainDirection(rollershade, bolStatu);
|
|
return true;
|
}
|
|
/// <summary>
|
/// 备份窗帘方向
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <param name="bolStatu">false:电机方向正向;true:电机方向反向</param>
|
/// <returns></returns>
|
public async Task<bool> BackupCurtainDirection(Rollershade rollershade, bool bolStatu)
|
{
|
//备份设备
|
return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A窗帘方向, bolStatu);
|
}
|
|
#endregion
|
|
#region ■ 窗帘限位配置_______________________
|
|
/// <summary>
|
/// 执行确认及覆盖窗帘限位点
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <param name="limiType">确认及覆盖上限位还是下限位</param>
|
/// <param name="upLimit">上限位的值,百分比(备份用)</param>
|
/// <param name="downLimit">下限位的值,百分比(备份用)</param>
|
/// <returns></returns>
|
public async Task<bool> CommitCurtainLimitPoint(Rollershade rollershade, Rollershade.CurtainPrivateInstalledLimi limiType, int upLimit, int downLimit)
|
{
|
var result = await rollershade.SetCurtainInstalledLimitAsync(limiType);
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null)
|
{
|
//设置窗帘限位点失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//设置窗帘限位点失败
|
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;
|
}
|
|
/// <summary>
|
/// 删除限位点
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <param name="limiType">删除上限位还是删除下限位</param>
|
/// <returns></returns>
|
public async Task<bool> DeleteCurtainLimitPoint(Rollershade rollershade, Rollershade.LimiType limiType)
|
{
|
var result = await rollershade.DeleteCurtainLimitsAsync(limiType);
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null)
|
{
|
//重置窗帘限位点失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//重置窗帘限位点失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail);
|
this.ShowTipMsg(msg);
|
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
|
|
#region ■ 获取窗帘限位配置___________________
|
|
/// <summary>
|
/// 发送获取窗帘限位配置的命令
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
public void SetGetCurtainLimitSettionComand(Rollershade rollershade)
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject
|
{
|
{ "DeviceAddr",rollershade.DeviceAddr },
|
{ "Epoint", rollershade.DeviceEpoint },
|
{ "Cluster_ID", (int)Cluster_ID.WindowCovering },
|
{ "Command", 108 }
|
};
|
var attriBute = new Newtonsoft.Json.Linq.JArray
|
{
|
new Newtonsoft.Json.Linq.JObject
|
{
|
//开合帘方向
|
{ "AttriButeId", (int)AttriButeId.WindowCoveringMode}
|
},
|
new Newtonsoft.Json.Linq.JObject
|
{
|
//开合帘总长
|
{ "AttriButeId", (int)AttriButeId.WindowCoveringLength}
|
},
|
new Newtonsoft.Json.Linq.JObject
|
{
|
//开限位
|
{ "AttriButeId", (int)AttriButeId.InstalledOpenLimitLift}
|
},
|
new Newtonsoft.Json.Linq.JObject
|
{
|
//合限位
|
{ "AttriButeId", (int)AttriButeId.InstalledClosedLimitLift}
|
}
|
};
|
var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
|
jObject.Add("Data", data);
|
rollershade.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
|
}
|
|
#endregion
|
|
#region ■ 重置窗帘___________________________
|
|
/// <summary>
|
/// 重置窗帘
|
/// </summary>
|
/// <param name="rollershade">窗帘对象</param>
|
/// <returns></returns>
|
public async Task<bool> RestoreCurtain(Rollershade rollershade)
|
{
|
var result = await rollershade.RestoreCurtainLimitAsync();
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null)
|
{
|
//重置窗帘失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//重置窗帘失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 显示错误信息窗口
|
/// </summary>
|
/// <param name="msg"></param>
|
private void ShowErrorMsg(string msg)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var contr = new ShowMsgControl(ShowMsgType.Error, msg);
|
contr.Show();
|
});
|
}
|
|
/// <summary>
|
/// 显示Tip信息窗口
|
/// </summary>
|
/// <param name="msg"></param>
|
private void ShowTipMsg(string msg)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
|
contr.Show();
|
});
|
}
|
|
#endregion
|
}
|
}
|