New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | | using System.Threading.Tasks;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | {
|
| | | /// <summary>
|
| | | /// 干接点的逻辑
|
| | | /// </summary>
|
| | | public class HdlDevicePanelLogic
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 干接点的逻辑
|
| | | /// </summary> |
| | | private static HdlDevicePanelLogic m_Current = null; |
| | | /// <summary>
|
| | | /// 干接点的逻辑
|
| | | /// </summary> |
| | | public static HdlDevicePanelLogic Current
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_Current == null)
|
| | | {
|
| | | m_Current = new HdlDevicePanelLogic();
|
| | | }
|
| | | return m_Current;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 干接点的私有属性 keys:设备主键,value:各级别的值
|
| | | /// </summary>
|
| | | private Dictionary<string, DryContactFunctionInfo> dicDryContactFunction = new Dictionary<string, DryContactFunctionInfo>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化
|
| | | /// </summary>
|
| | | public HdlDevicePanelLogic()
|
| | | {
|
| | | //从本地文件还原干接点的私有属性
|
| | | this.LoadDryContactFunctionFromLocaltion();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 颜色调节___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取按键面板指定端点的【指示灯开关颜色】的信息(出错会返回null)
|
| | | /// </summary>
|
| | | /// <param name="panel">按键面板的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public async Task<Panel.KeyColorData> GetPanelEpointColorInfo(Panel panel)
|
| | | {
|
| | | Panel.KeyNum keyNum = (Panel.KeyNum)panel.DeviceEpoint;
|
| | | var result = await panel.GetPanelColorInfoAsync(keyNum);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || result.keyColorData == null)
|
| | | {
|
| | | //获取按键面板颜色调节信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelColorRegulationInfoFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | return result.keyColorData;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置按键面板指定端点的【指示灯开关颜色】的信息
|
| | | /// </summary>
|
| | | /// <param name="panel">按键面板的某一个回路</param>
|
| | | /// <param name="colorData">开和关的颜色都需要一起设置</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetPanelEpointColorInfo(Panel panel, Panel.KeyColorData colorData)
|
| | | {
|
| | | var keyNum = new Panel.KeyNumStatus();
|
| | | Type type = keyNum.GetType();
|
| | | type.InvokeMember("Key" + panel.DeviceEpoint, System.Reflection.BindingFlags.SetField, null, keyNum, new object[] { true });
|
| | |
|
| | | var result = await panel.SetPanelColorInfoAsync(colorData, keyNum);
|
| | | if (result == null || result.responseData == null)
|
| | | {
|
| | | //设置按键面板指示灯颜色失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.responseData.status != 0)
|
| | | {
|
| | | //设置按键面板指示灯颜色失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A干接点颜色调节, colorData);
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 亮度调节___________________________
|
| | | /// <summary>
|
| | | /// 获取设备亮度配置(ui叫亮度调节,使用返回值的panelDirectionsLevel)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public async Task<Panel.PanelSwitchLevelInfo> GetDeviceLightSettion(CommonDevice device)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.GetPanelSwitchLevelAsync();
|
| | | panel = null;
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || string.IsNullOrEmpty(result.errorMessageBase) == false)
|
| | | {
|
| | | //获取按键面板亮度调节信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelLightRegulationInfoFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备亮度(ui叫亮度调节)
|
| | | /// </summary>
|
| | | /// <param name="panel">设备对象</param>
|
| | | /// <param name="directionsLevel">0-100(这个是点击后的值)</param>
|
| | | /// <param name="backlightLevel">0-100(这个是点击前的值)</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetDeviceLightSettion(CommonDevice device, int directionsLevel, int backlightLevel)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.SetKeyLevelAsync(directionsLevel, backlightLevel);
|
| | | panel = null;
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result == null || result.responseData == null)
|
| | | {
|
| | | //设置亮度调节失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result.responseData.status != 0)
|
| | | {
|
| | | //设置亮度调节失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | var backData = new Newtonsoft.Json.Linq.JObject
|
| | | { |
| | | { "directionsLevel",directionsLevel }, |
| | | { "backlightLevel", backlightLevel } |
| | | };
|
| | | //备份设备
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A干接点亮度调节, backData);
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 接近感应___________________________
|
| | | /// <summary>
|
| | | /// 获取接近感应配置(ui叫接近感应,使用返回值的panelProximitySensorInfo)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public async Task<Panel.PanelProximitySensorInfo> GetDeviceProximitySensorsSettion(CommonDevice device)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.GetProximitySensorAsync();
|
| | | panel = null;
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | | if (result == null || result.panelProximitySensorInfo == null || string.IsNullOrEmpty(result.errorMessageBase) == false)
|
| | | {
|
| | | //获取接近感应信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.GetPanelProximityFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | return result.panelProximitySensorInfo;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 配置接近传感
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <para>sensorEnable:传感器使能</para> |
| | | /// <returns></returns>
|
| | | public async Task<bool> SetProximitySensorStatus(CommonDevice device, bool sensorEnable)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.SetProximitySensor(sensorEnable);
|
| | | panel = null;
|
| | |
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result == null || result.responseData == null)
|
| | | {
|
| | | //接近传感配置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.SetPannelProximityFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | // 备份设备
|
| | | var backData = new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "sensorEnable",sensorEnable }
|
| | | };
|
| | | //备份设备
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A面板接近感应功能, backData);
|
| | | return true;
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region ■ 节能模式___________________________
|
| | | /// <summary>
|
| | | /// 获取设备节能模式的配置状态(ui叫节能模式)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public async Task<Panel.PanelSaveEnergyModeInfo> GetDeviceEnergyConservationMode(CommonDevice device)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.GetPanelSaveEnergyModeAsync();
|
| | | panel = null;
|
| | |
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || result.panelSaveEnergyModeInfo == null)
|
| | | {
|
| | | //获取按键面板节能模式信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelEnergyConservationInfoFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | return result.panelSaveEnergyModeInfo;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备的节能模式(ui叫节能模式)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="modeEnable">节能模式是否有效</param>
|
| | | /// <param name="modeTime">无操作进入节能模式时间 0-255</param>
|
| | | /// <param name="level">节能模式亮度:0-100</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> SetDeviceEnergyConservationMode(CommonDevice device, bool modeEnable, int modeTime, int level)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.SetKeyModeAsync(modeEnable, modeTime, level);
|
| | | panel = null;
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result == null || result.responseData == null)
|
| | | {
|
| | | //节能模式配置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result.responseData.status != 0)
|
| | | {
|
| | | //节能模式配置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | var backData = new Newtonsoft.Json.Linq.JObject
|
| | | { |
| | | { "modeEnable",modeEnable }, |
| | | { "modeTime", modeTime }, |
| | | { "level", level } |
| | | };
|
| | | //备份设备
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A干接点节能模式, backData);
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取干接点配置信息_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取干接点配置信息
|
| | | /// </summary>
|
| | | /// <param name="panel">干接点对象</param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<CommonDevice.AttributeDataObj>> GetDryContactConfigureInfo(CommonDevice device)
|
| | | {
|
| | | //借用它的函数
|
| | | var panel = new Panel();
|
| | | panel.DeviceAddr = device.DeviceAddr;
|
| | | panel.DeviceEpoint = device.DeviceEpoint;
|
| | | panel.CurrentGateWayId = device.CurrentGateWayId;
|
| | |
|
| | | var result = await panel.ReadPanelConfigureInfoAsync();
|
| | | panel = null;
|
| | |
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || result.deviceStatusReportData == null)
|
| | | {
|
| | | //获取设备配置信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceConfigureInfoFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | //如果不是6的话,这个数据是不对的
|
| | | if (result.deviceStatusReportData.CluterID != 6)
|
| | | {
|
| | | return new List<CommonDevice.AttributeDataObj>();
|
| | | }
|
| | | return result.deviceStatusReportData.AttriBute;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取干接点功能系___________________
|
| | |
|
| | | /// <summary>
|
| | | /// <para>获取干接点功能系(异常时返回null,或者它没有指定功能,也会返回null)</para>
|
| | | /// <para>第一级别(参数全部省略时):</para>
|
| | | /// <para> 1024:灯类|256:按键类|768:PIR类</para>
|
| | | /// <para>第二级别:</para>
|
| | | /// <para> 1:特殊功能|100:Switch,开关(按键类)</para>
|
| | | /// <para> 200:Dimmer,调光(按键类)|300:Curtain,窗帘(按键类)</para>
|
| | | /// <para> 0:EnergySavingMode,节能模式(灯类)|1:SleepMode,睡眠模式(灯类)</para>
|
| | | /// <para> 100:WhiteBalance,白平衡(灯类)|101:RGBColor,RGB指示灯颜色(灯类)</para>
|
| | | /// <para> 102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
| | | /// <para>第三级别:</para>
|
| | | /// <para>1:场景触发|65535:禁止发送功能</para>
|
| | | /// <para>100:SwitchOpen,开关开(按键类)|101:SwitchClose,开关关(按键类)</para>
|
| | | /// <para>102:SwitchChange,开关切换(按键类)|200:DimmerStepUp,增大调光(按键类)</para>
|
| | | /// <para>201:DimmerStepDown,降低调光(按键类)|202:DimmerStepChange,调光切换(按键类)</para>
|
| | | /// <para>300:CurtainOpen,窗帘开(按键类)|301:CurtainClose,窗帘关(按键类)</para>
|
| | | /// <para>302:CurtainStop,窗帘停|303:CurtainUpStop,窗帘上升停</para>
|
| | | /// <para>304:CurtainDownstop,窗帘下降停</para>
|
| | | /// </summary>
|
| | | /// <param name="panel">干接点对象</param>
|
| | | /// <param name="level1">请参照第一级别的参数,省略时返回第一级别列表,设置时返回第二级别列表</param>
|
| | | /// <param name="level2">请参照第二级别的参数,省略时返回第二级别列表,设置时返回第三级别列表</param>
|
| | | /// <param name="reLevel3">重新获取第三级别的数据</param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<int>> GetDryContactFunction(Panel panel, int level1 = -1, int level2 = -1, bool reLevel3 = false)
|
| | | {
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(panel);
|
| | | if (dicDryContactFunction.ContainsKey(mainkeys) == false)
|
| | | {
|
| | | //创建对象
|
| | | dicDryContactFunction[mainkeys] = new DryContactFunctionInfo();
|
| | | }
|
| | | var functionInfo = dicDryContactFunction[mainkeys];
|
| | |
|
| | | //获取第一级别(属性应该不会改变)
|
| | | Panel.PanelPrivateFunctionsResponseInfo result = null;
|
| | | if (functionInfo.listLevel1 == null)
|
| | | {
|
| | | result = await this.GetDryContactFunctionInterface(panel);
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //保存属性
|
| | | this.SetDryContactFunctionToMemory(panel, result.privateFuncTypeLevelFirstList, -1, -1);
|
| | | if (level1 == -1)
|
| | | {
|
| | | return result.privateFuncTypeLevelFirstList;
|
| | | }
|
| | | }
|
| | |
|
| | | //获取第二级别(属性应该不会改变)
|
| | | if (functionInfo.dicLevel2.ContainsKey(level1) == false)
|
| | | {
|
| | | result = await this.GetDryContactFunctionInterface(panel, new int[] { level1 });
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //保存属性
|
| | | this.SetDryContactFunctionToMemory(panel, result.privateFuncTypeLevelSecondList, level1, -1);
|
| | | if (level2 == -1)
|
| | | {
|
| | | return result.privateFuncTypeLevelSecondList;
|
| | | }
|
| | | }
|
| | |
|
| | | //获取第三级别(属性有可能会改变)
|
| | | if (reLevel3 == true || functionInfo.dicLevel3.ContainsKey(level2) == false)
|
| | | {
|
| | | result = await this.GetDryContactFunctionInterface(panel, new int[] { level1, level2 });
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //保存属性
|
| | | this.SetDryContactFunctionToMemory(panel, result.privateFuncTypeLevelThirdList, level1, level2);
|
| | | }
|
| | | //从本地缓存当中获取它的私有属性
|
| | | return this.GetDryContactFunctionFromLocation(panel, level1, level2);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取按键面板的功能
|
| | | /// </summary>
|
| | | /// <param name="panel">按键面板的某一个回路</param>
|
| | | /// <param name="parameter">
|
| | | /// <para>方法1:当int[]传空,返回值是“面板具有的功能大类,即返回“第一级别。1024:灯类,256:按键类,768:PIR类</para> |
| | | /// <para>方法2:、当int[]值为第一级别PrivateFuncTypeFir中选择一个。</para> |
| | | /// <para>返回值是“面按键发送功能类”,即返回“第二级别。</para> |
| | | /// <para>100:Switch,开关(按键类);200:Dimmer,调光(按键类);300:Curtain,窗帘(按键类)</para> |
| | | /// <para>0:EnergySavingMode,节能模式(灯类);1:SleepMode,睡眠模式(灯类);100:WhiteBalance,白平衡(灯类);101:RGBColor,RGB指示灯颜色(灯类);102:RGBLevel,RGB指示灯亮度(灯类)</para> |
| | | /// <para>方法3:当int[]值为第一级别PrivateFuncTypeFir中选择一个,接着再选第二级别PrivateFunTypeSec中选择一个 </para> |
| | | /// <para>返回值是“面按键具体功能配置”,即返回“第二级别。</para> |
| | | /// <para>100:SwitchOpen,开关开(按键类);101:SwitchClose,开关关(按键类);102:SwitchChange,开关切换(按键类)</para> |
| | | /// <para>200:DimmerStepUp,增大调光(按键类);201:DimmerStepDown,降低调光(按键类);202:DimmerStepChange,调光切换(按键类)</para> |
| | | /// <para>300:CurtainOpen,窗帘开(按键类);301:CurtainClose,窗帘关(按键类);302:CurtainStop,窗帘停;303:CurtainUpStop,窗帘上升停;304:CurtainDownstop,窗帘下降停</para>
|
| | | /// </param>
|
| | | /// <returns></returns>
|
| | | private async Task<Panel.PanelPrivateFunctionsResponseInfo> GetDryContactFunctionInterface(Panel panel, params int[] parameter)
|
| | | {
|
| | | var result = await panel.GetPanelPrivateFunctionsAsync(parameter);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || result.panelPrivateFunctionsResponseInfo == null)
|
| | | {
|
| | | //获取按键功能类信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelFunctionInfoFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | |
|
| | | return result.panelPrivateFunctionsResponseInfo;
|
| | | }
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 修改干接点私有属性_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 修改干接点第三级别的私有属性
|
| | | /// </summary>
|
| | | /// <param name="panel">干接点对象</param>
|
| | | /// <param name="i_value">干接点的第三级别属性的值,具体请参照第三级别属性</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> EditorDryContactThirdFunction(Panel panel, int i_value)
|
| | | {
|
| | | var result = await panel.ConfigureHdlKeyValueAsync((Panel.KeyMode)i_value);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result == null || result.setWritableValueResponData == null)
|
| | | {
|
| | | //设备属性变更失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceAttributeChangedFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.setWritableValueResponData.Status == 134)
|
| | | {
|
| | | //设备不支持此属性(XXX)
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceNotSupportTheAttribute);
|
| | | msg += "(" + i_value + ")";
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.setWritableValueResponData.Status == 135)
|
| | | {
|
| | | //无效的设备属性值(XXX)
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceAttributeIsIneffectiveness);
|
| | | msg += "(" + i_value + ")";
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.setWritableValueResponData.Status == 141)
|
| | | {
|
| | | //无效的数据类型(XXX)
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDataTypeIsIneffectiveness);
|
| | | msg += "(" + i_value + ")";
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (result.setWritableValueResponData.Status != 0)
|
| | | {
|
| | | //设备属性变更失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceAttributeChangedFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A干接点第三级别私有属性, i_value);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 简约面板震动功能___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取简约面板震动功能的信息(null表示出错)
|
| | | /// </summary>
|
| | | /// <param name="device">某一回路</param>
|
| | | /// <returns></returns>
|
| | | public VibrationInfo GetPanelVibrationData(CommonDevice device)
|
| | | {
|
| | | var returnData = new VibrationInfo();
|
| | | var gateway = device.Gateway;
|
| | | if (gateway == null)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return null;
|
| | | }
|
| | | string checkTopic = HdlGatewayLogic.Current.GetGatewayId(gateway) + "/" + "ZbDataPassthrough";
|
| | | bool canBreak = false;
|
| | |
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | if (topic == checkTopic)
|
| | | {
|
| | | try
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | string PassData = jobject["Data"]["PassData"].ToString();
|
| | | if (PassData.Length != 18)
|
| | | {
|
| | | return;
|
| | | }
|
| | | string mytopic = PassData[4].ToString() + PassData[5].ToString() + PassData[2].ToString() + PassData[3].ToString();
|
| | | if (mytopic != "0802")
|
| | | {
|
| | | return;
|
| | | }
|
| | | returnData.A震动使能 = PassData.Substring(10, 2) == "01" ? true : false;
|
| | | returnData.A震动强度 = Convert.ToInt32(PassData.Substring(12, 2), 16);
|
| | | returnData.A震动时间 = Convert.ToInt32(PassData.Substring(14, 4), 16);
|
| | |
|
| | | canBreak = true;
|
| | | }
|
| | | catch { }
|
| | | }
|
| | | };
|
| | | gateway.Actions += action;
|
| | | try
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "PassData", "050108110101" } };
|
| | | jObject.Add("Data", data);
|
| | | gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
| | | }
|
| | | catch { }
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (canBreak == false && TimeOut < 60)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | | gateway.Actions -= action;
|
| | |
|
| | | if (TimeOut >= 60)
|
| | | {
|
| | | //获取震动反馈配置信息失败
|
| | | string errorMsg = Language.StringByID(R.MyInternationalizationString.uGetVibrationFeedbackSettionFail);
|
| | | errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "回复超时", false);
|
| | | this.ShowTipMsg(errorMsg);
|
| | | return null;
|
| | | }
|
| | | return returnData;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置简约面板震动功能的信息
|
| | | /// </summary>
|
| | | /// <param name="device">某一回路</param>
|
| | | /// <param name="datainfo">设置的信息</param>
|
| | | /// <returns></returns>
|
| | | public bool SetPanelVibrationData(CommonDevice device, VibrationInfo datainfo)
|
| | | {
|
| | | var gateway = device.Gateway;
|
| | | if (gateway == null)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return false;
|
| | | }
|
| | | string checkTopic = HdlGatewayLogic.Current.GetGatewayId(gateway) + "/" + "ZbDataPassthrough";
|
| | | bool canBreak = false;
|
| | |
|
| | | bool success = false;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | if (topic == checkTopic)
|
| | | {
|
| | | try
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | if (jobject["DeviceAddr"].ToString() != device.DeviceAddr)
|
| | | {
|
| | | //不是同一个东西
|
| | | return;
|
| | | }
|
| | | string PassData = jobject["Data"]["PassData"].ToString();
|
| | | if (PassData.Length != 16)
|
| | | {
|
| | | return;
|
| | | }
|
| | | string mytopic = PassData[4].ToString() + PassData[5].ToString() + PassData[2].ToString() + PassData[3].ToString();
|
| | | if (mytopic != "0002")
|
| | | {
|
| | | return;
|
| | | }
|
| | | int command = Convert.ToInt32(PassData[10].ToString() + PassData[11].ToString() + PassData[12].ToString() + PassData[13].ToString(), 16);
|
| | | int status = Convert.ToInt32(PassData[14].ToString() + PassData[15].ToString(), 16);
|
| | | if (status == 0)
|
| | | {
|
| | | //成功
|
| | | success = true;
|
| | | }
|
| | | canBreak = true;
|
| | | }
|
| | | catch { }
|
| | | }
|
| | | };
|
| | | gateway.Actions += action;
|
| | | try
|
| | | {
|
| | | string passData = "0800081104";
|
| | | passData += datainfo.A震动使能 ? "01" : "00";
|
| | | passData += Convert.ToString(datainfo.A震动强度, 16).PadLeft(2, '0');
|
| | | string time = Convert.ToString(datainfo.A震动时间, 16).PadLeft(4, '0');
|
| | | //低位在前,高位在后
|
| | | passData += time.Substring(2, 2);
|
| | | passData += time.Substring(0, 2);
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } };
|
| | | jObject.Add("Data", data);
|
| | | gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
| | | }
|
| | | catch { }
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (canBreak == false && TimeOut < 60)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | | gateway.Actions -= action;
|
| | |
|
| | | if (success == false)
|
| | | {
|
| | | //设置震动反馈配置信息失败
|
| | | string errorMsg = Language.StringByID(R.MyInternationalizationString.uSetVibrationFeedbackSettionFail);
|
| | | if (TimeOut >= 60)
|
| | | {
|
| | | errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "回复超时", false);
|
| | | }
|
| | | this.ShowTipMsg(errorMsg);
|
| | | return false;
|
| | | }
|
| | | //备份设备
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A简约面板震动功能, datainfo);
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | return success;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 简约面板震动功能信息
|
| | | /// </summary>
|
| | | public class VibrationInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 震动使能
|
| | | /// </summary>
|
| | | public bool A震动使能 = false;
|
| | | /// <summary>
|
| | | /// 震动强度(十进制)
|
| | | /// </summary>
|
| | | public int A震动强度 = 0;
|
| | | /// <summary>
|
| | | /// 震动时间(十进制)
|
| | | /// </summary>
|
| | | public int A震动时间 = 0;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 缓存中的设备私有属性_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 从缓存中获取设备的私有属性
|
| | | /// </summary>
|
| | | /// <param name="panel"></param>
|
| | | /// <param name="level1"></param>
|
| | | /// <param name="level2"></param>
|
| | | /// <returns></returns>
|
| | | private List<int> GetDryContactFunctionFromLocation(Panel panel, int level1 = -1, int level2 = -1)
|
| | | {
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(panel);
|
| | | if (dicDryContactFunction.ContainsKey(mainkeys) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var listLevel = new List<int>();
|
| | | var functionInfo = dicDryContactFunction[mainkeys];
|
| | |
|
| | | //第一级别
|
| | | if (level1 == -1)
|
| | | {
|
| | | if (functionInfo.listLevel1 == null)
|
| | | {
|
| | | //第一级别从来都没有获取过
|
| | | return null;
|
| | | }
|
| | | listLevel.AddRange(functionInfo.listLevel1);
|
| | | }
|
| | | //第二级别
|
| | | else if (level2 == -1)
|
| | | {
|
| | | if (functionInfo.dicLevel2.ContainsKey(level1) == false)
|
| | | {
|
| | | //第二级别从来都没有获取过
|
| | | return null;
|
| | | }
|
| | | listLevel.AddRange(functionInfo.dicLevel2[level1]);
|
| | | }
|
| | | //第三级别
|
| | | else
|
| | | {
|
| | | if (functionInfo.dicLevel3.ContainsKey(level2) == false)
|
| | | {
|
| | | //第三级别从来都没有获取过
|
| | | return null;
|
| | | }
|
| | | listLevel.AddRange(functionInfo.dicLevel3[level2]);
|
| | | }
|
| | | return listLevel;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将设备的私有属性存入缓存中
|
| | | /// </summary>
|
| | | /// <param name="panel"></param>
|
| | | /// <param name="listLevel"></param>
|
| | | /// <param name="level1"></param>
|
| | | /// <param name="level2"></param>
|
| | | private void SetDryContactFunctionToMemory(Panel panel, List<int> listLevel, int level1, int level2)
|
| | | {
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(panel);
|
| | | if (dicDryContactFunction.ContainsKey(mainkeys) == false)
|
| | | {
|
| | | //创建对象
|
| | | dicDryContactFunction[mainkeys] = new DryContactFunctionInfo();
|
| | | }
|
| | | var functionInfo = dicDryContactFunction[mainkeys];
|
| | |
|
| | | //第一级别
|
| | | if (level1 == -1)
|
| | | {
|
| | | //这个属性应该是不会变的
|
| | | functionInfo.listLevel1 = new List<int>();
|
| | | functionInfo.listLevel1.AddRange(listLevel);
|
| | | }
|
| | | //第二级别
|
| | | else if (level2 == -1)
|
| | | {
|
| | | if (functionInfo.dicLevel2.ContainsKey(level1) == false)
|
| | | {
|
| | | functionInfo.dicLevel2[level1] = new List<int>();
|
| | | }
|
| | | functionInfo.dicLevel2[level1].Clear();
|
| | | functionInfo.dicLevel2[level1].AddRange(listLevel);
|
| | | }
|
| | | //第三级别
|
| | | else
|
| | | {
|
| | | if (functionInfo.dicLevel3.ContainsKey(level2) == false)
|
| | | {
|
| | | //初始化容器
|
| | | functionInfo.dicLevel3[level2] = new List<int>();
|
| | | }
|
| | | //第三级别的属性有可能会变更
|
| | | functionInfo.dicLevel3[level2].Clear();
|
| | | functionInfo.dicLevel3[level2].AddRange(listLevel);
|
| | | }
|
| | | //保存现阶段的干接点的私有属性到本地文件
|
| | | this.SaveDryContactFunctionToLocaltion();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存现阶段的干接点的私有属性到本地文件
|
| | | /// </summary>
|
| | | private void SaveDryContactFunctionToLocaltion()
|
| | | {
|
| | | var file = Newtonsoft.Json.JsonConvert.SerializeObject(dicDryContactFunction);
|
| | |
|
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(file);
|
| | | Common.Global.WriteFileByBytesByHomeId(DirNameResourse.DryContactFunctionFile, bytes);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从本地文件还原干接点的私有属性
|
| | | /// </summary>
|
| | | private void LoadDryContactFunctionFromLocaltion()
|
| | | {
|
| | | if (Common.Global.IsExistsByHomeId(DirNameResourse.DryContactFunctionFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | byte[] filebyte = Common.Global.ReadFileByHomeId(DirNameResourse.DryContactFunctionFile);
|
| | | string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
|
| | | this.dicDryContactFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, DryContactFunctionInfo>>(strvalue);
|
| | | }
|
| | |
|
| | | #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
|
| | |
|
| | | #region ■ 结构体_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 干接点功能信息
|
| | | /// </summary>
|
| | | private class DryContactFunctionInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 第一级别(注意,这个东西和【dicLevel2,dicLevel3】不同步,因为它遵从于获取后才保存的原则)
|
| | | /// </summary>
|
| | | public List<int> listLevel1 = null;
|
| | | /// <summary>
|
| | | /// 第二级别(主键为第一级别。注意,这个东西和【listLevel1,dicLevel3】不同步,因为它遵从于获取后才保存的原则)
|
| | | /// </summary>
|
| | | public Dictionary<int, List<int>> dicLevel2 = new Dictionary<int, List<int>>();
|
| | | /// <summary>
|
| | | /// 第三级别(主键为第二级别。注意,这个东西和【listLevel1,dicLevel2】不同步,因为它遵从于获取后才保存的原则)
|
| | | /// </summary>
|
| | | public Dictionary<int, List<int>> dicLevel3 = new Dictionary<int, List<int>>();
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|