old mode 100644
new mode 100755
File was renamed from Home0630/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using ZigBee.Device; |
| | | using System.Threading.Tasks; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 设备绑定的逻辑 |
| | | /// </summary> |
| | | public class HdlDeviceBindLogic |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 设备绑定的逻辑 |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | | using System.Threading.Tasks;
|
| | | using Newtonsoft.Json.Linq;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | {
|
| | | /// <summary>
|
| | | /// 设备绑定的逻辑
|
| | | /// </summary>
|
| | | public class HdlDeviceBindLogic
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设备绑定的逻辑
|
| | | /// </summary> |
| | | private static HdlDeviceBindLogic m_Current = null; |
| | | /// <summary> |
| | | /// 设备绑定的逻辑 |
| | | /// <summary>
|
| | | /// 设备绑定的逻辑
|
| | | /// </summary> |
| | | public static HdlDeviceBindLogic Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new HdlDeviceBindLogic(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取设备下面绑定的设备_____________ |
| | | |
| | | /// <summary> |
| | | /// 获取设备下面绑定的设备(错误时返回null),这个是给pir传感器用的 |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <returns></returns> |
| | | public List<CommonDevice> GetBindTargetDevice(CommonDevice mainDevice) |
| | | { |
| | | var result = this.GetDeviceBindAsync(mainDevice); |
| | | if (result == null || result.getAllBindResponseData == null) |
| | | { |
| | | //获取设备的绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | var listDevice = new List<CommonDevice>(); |
| | | foreach (var data in result.getAllBindResponseData.BindList) |
| | | { |
| | | CommonDevice deviceTemp = Common.LocalDevice.Current.GetDevice(data.BindMacAddr, data.BindEpoint); |
| | | if (deviceTemp == null) |
| | | { |
| | | continue; |
| | | } |
| | | listDevice.Add(deviceTemp); |
| | | } |
| | | return listDevice; |
| | | } |
| | | |
| | | /// <summary> |
| | | ///获取所有绑定 |
| | | /// </summary> |
| | | public BindObj.GetDeviceBindResponseAllData GetDeviceBindAsync(CommonDevice device) |
| | | { |
| | | //如果当前住宅是虚拟住宅 |
| | | if (Common.Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | var listBind = ModelData.DeviceModelDataLogic.Current.GetDeviceBindList(device, "Bind/GetDeviceBind"); |
| | | return new BindObj.GetDeviceBindResponseAllData() |
| | | { |
| | | getAllBindResponseData = new BindObj.GetDeviceBindResponseData |
| | | { |
| | | Result = 0, |
| | | BindList = listBind |
| | | } |
| | | }; |
| | | } |
| | | |
| | | var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } }; |
| | | string sendData = jObject.ToString(); |
| | | //发送 |
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/GetDeviceBind", sendData, "Bind/GetDeviceBind_Respon", 6); |
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) |
| | | { |
| | | return null; |
| | | } |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.GetDeviceBindResponseData>(result.ReceiptData); |
| | | return new BindObj.GetDeviceBindResponseAllData() { getAllBindResponseData = tempData }; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 执行绑定设备目标___________________ |
| | | |
| | | /// <summary> |
| | | /// 绑定设备的目标(返回成功设置的设备,错误时,返回null) |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <param name="listDevice">要绑定的目标设备</param> |
| | | /// <param name="BindCluster">BindCluster</param> |
| | | /// <returns></returns> |
| | | public List<CommonDevice> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6) |
| | | { |
| | | if (listDevice.Count == 0) |
| | | { |
| | | return new List<CommonDevice>(); |
| | | } |
| | | |
| | | var dicDevice = new Dictionary<string, CommonDevice>(); |
| | | |
| | | //组装数据 |
| | | var addData = new IASZone.AddBindData(); |
| | | addData.DeviceAddr = mainDevice.DeviceAddr; |
| | | addData.Epoint = mainDevice.DeviceEpoint; |
| | | foreach (var device in listDevice) |
| | | { |
| | | var info = new IASZone.AddBindListObj(); |
| | | info.BindCluster = BindCluster; |
| | | info.BindMacAddr = device.DeviceAddr; |
| | | info.BindEpoint = device.DeviceEpoint; |
| | | info.BindType = 0; |
| | | |
| | | addData.BindList.Add(info); |
| | | |
| | | //返回成功设备的时候使用 |
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); |
| | | dicDevice[mainkeys] = device; |
| | | } |
| | | //执行绑定 |
| | | var result = this.AddDeviceBindAsync(addData); |
| | | if (result == null || result.addedDeviceBindResponseData == null) |
| | | { |
| | | //绑定目标设置失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | |
| | | var listSuccess = new List<CommonDevice>(); |
| | | foreach (var data in result.addedDeviceBindResponseData.BindList) |
| | | { |
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint); |
| | | if (dicDevice.ContainsKey(mainkeys) == true) |
| | | { |
| | | listSuccess.Add(dicDevice[mainkeys]); |
| | | } |
| | | } |
| | | |
| | | if (listSuccess.Count == 0) |
| | | { |
| | | //绑定目标设置失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | return listSuccess; |
| | | } |
| | | |
| | | /// <summary> |
| | | ///设备绑定 |
| | | /// </summary> |
| | | public BindObj.AddedDeviceBindResponseAllData AddDeviceBindAsync(BindObj.AddBindData addBindData) |
| | | { |
| | | //如果当前住宅是虚拟住宅 |
| | | if (Common.Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | return ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind"); |
| | | } |
| | | |
| | | var device = Common.LocalDevice.Current.GetDevice(addBindData.DeviceAddr, addBindData.Epoint); |
| | | //获取发送的命令字符 |
| | | var sendData = this.GetAddDeviceListBindCommandText(addBindData); |
| | | //发送 |
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetBind", sendData, "Bind/SetBind_Respon", 20); |
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | //修改缓存 |
| | | ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind"); |
| | | |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceBindResponseData>(result.ReceiptData); |
| | | return new BindObj.AddedDeviceBindResponseAllData() { addedDeviceBindResponseData = tempData }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取添加设备绑定的命令字符 |
| | | /// </summary> |
| | | /// <param name="addBindData"></param> |
| | | /// <returns></returns> |
| | | public string GetAddDeviceListBindCommandText(BindObj.AddBindData addBindData) |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } }; |
| | | var bindList = new JArray { }; |
| | | foreach (var bindInfo in addBindData.BindList) |
| | | { |
| | | if (bindInfo.BindType == 0) |
| | | { |
| | | var dInfo = new JObject{{ "BindMacAddr",bindInfo.BindMacAddr},{ "BindEpoint", bindInfo.BindEpoint} , |
| | | { "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}}; |
| | | bindList.Add(dInfo); |
| | | } |
| | | else if (bindInfo.BindType == 1) |
| | | { |
| | | var dInfo = new JObject{{ "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}, |
| | | { "BindScenesId", bindInfo.BindScenesId}}; |
| | | bindList.Add(dInfo); |
| | | } |
| | | } |
| | | var data = new JObject { { "BindName", addBindData.BindName }, { "BindList", bindList } }; |
| | | jObject.Add("Data", data); |
| | | return jObject.ToString(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 删除设备绑定的目标_________________ |
| | | |
| | | /// <summary> |
| | | /// 删除设备绑定的目标 |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <param name="deleteDevice">要删除的绑定目标设备</param> |
| | | /// <param name="BindCluster">BindCluster</param> |
| | | /// <returns></returns> |
| | | public bool DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6) |
| | | { |
| | | //组装数据 |
| | | var deleteData = new IASZone.DelDeviceBindData(); |
| | | deleteData.DeviceAddr = mainDevice.DeviceAddr; |
| | | deleteData.Epoint = mainDevice.DeviceEpoint; |
| | | |
| | | var info = new IASZone.RemoveBindListObj(); |
| | | info.BindCluster = BindCluster; |
| | | info.BindMacAddr = deleteDevice.DeviceAddr; |
| | | info.BindEpoint = deleteDevice.DeviceEpoint; |
| | | info.BindType = 0; |
| | | |
| | | deleteData.RemoveBindList.Add(info); |
| | | |
| | | //执行删除 |
| | | var result = this.DelDeviceBindAsync(deleteData); |
| | | if (result == null || result.delDeviceBindResponseData == null) |
| | | { |
| | | //删除绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | |
| | | foreach (var data in result.delDeviceBindResponseData.RemoveBindList) |
| | | { |
| | | //0:成功 1:设备不在绑定列表中 ,也可以代表成功 |
| | | if (data.Result == 0 || data.Result == 1 || data.Result == 5) |
| | | { |
| | | return true; |
| | | } |
| | | //3:失败,在等待节点设备确认是否解除绑定成功 |
| | | else if (data.Result == 3) |
| | | { |
| | | //其他绑定目标正在删除中,请稍后再试 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait); |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | //2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功 |
| | | else if (data.Result == 2) |
| | | { |
| | | if (result.removeBindResultResponseData == null) |
| | | { |
| | | //删除绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | //成功 |
| | | if (result.removeBindResultResponseData.Result == 0) |
| | | { |
| | | return true; |
| | | } |
| | | //136:控制设备本地绑定列表中无此绑定 |
| | | else if (result.removeBindResultResponseData.Result == 136) |
| | | { |
| | | //这个可以当做成功 |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | //删除绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static HdlDeviceBindLogic Current
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_Current == null)
|
| | | {
|
| | | m_Current = new HdlDeviceBindLogic();
|
| | | }
|
| | | return m_Current;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | | |
| | |
|
| | | #region ■ 获取设备下面绑定的设备_____________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备下面绑定的设备(错误时返回null),这个是给pir传感器用的
|
| | | /// </summary>
|
| | | /// <param name="mainDevice">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetBindTargetDevice(CommonDevice mainDevice)
|
| | | {
|
| | | var result = this.GetDeviceBindAsync(mainDevice);
|
| | | if (result == null || result.getAllBindResponseData == null)
|
| | | {
|
| | | //获取设备的绑定目标失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | | var listDevice = new List<CommonDevice>();
|
| | | foreach (var data in result.getAllBindResponseData.BindList)
|
| | | {
|
| | | CommonDevice deviceTemp = Common.LocalDevice.Current.GetDevice(data.BindMacAddr, data.BindEpoint);
|
| | | if (deviceTemp == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | listDevice.Add(deviceTemp);
|
| | | }
|
| | | return listDevice;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | ///获取所有绑定
|
| | | /// </summary>
|
| | | public BindObj.GetDeviceBindResponseAllData GetDeviceBindAsync(CommonDevice device)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | var listBind = ModelData.DeviceModelDataLogic.Current.GetDeviceBindList(device, "Bind/GetDeviceBind");
|
| | | return new BindObj.GetDeviceBindResponseAllData()
|
| | | {
|
| | | getAllBindResponseData = new BindObj.GetDeviceBindResponseData
|
| | | {
|
| | | Result = 0,
|
| | | BindList = listBind
|
| | | }
|
| | | };
|
| | | }
|
| | |
|
| | | var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
|
| | | string sendData = jObject.ToString();
|
| | | //发送
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/GetDeviceBind", sendData, "Bind/GetDeviceBind_Respon", 6);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.GetDeviceBindResponseData>(result.ReceiptData);
|
| | | return new BindObj.GetDeviceBindResponseAllData() { getAllBindResponseData = tempData };
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 执行绑定设备目标___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 绑定设备的目标(返回成功设置的设备,错误时,返回null)
|
| | | /// </summary>
|
| | | /// <param name="mainDevice">设备对象</param>
|
| | | /// <param name="listDevice">要绑定的目标设备</param>
|
| | | /// <param name="BindCluster">BindCluster</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
|
| | | {
|
| | | if (listDevice.Count == 0)
|
| | | {
|
| | | return new List<CommonDevice>();
|
| | | }
|
| | |
|
| | | var dicDevice = new Dictionary<string, CommonDevice>();
|
| | |
|
| | | //组装数据
|
| | | var addData = new IASZone.AddBindData();
|
| | | addData.DeviceAddr = mainDevice.DeviceAddr;
|
| | | addData.Epoint = mainDevice.DeviceEpoint;
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | var info = new IASZone.AddBindListObj();
|
| | | info.BindCluster = BindCluster;
|
| | | info.BindMacAddr = device.DeviceAddr;
|
| | | info.BindEpoint = device.DeviceEpoint;
|
| | | info.BindType = 0;
|
| | |
|
| | | addData.BindList.Add(info);
|
| | |
|
| | | //返回成功设备的时候使用
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | dicDevice[mainkeys] = device;
|
| | | }
|
| | | //执行绑定
|
| | | var result = this.AddDeviceBindAsync(addData);
|
| | | if (result == null || result.addedDeviceBindResponseData == null)
|
| | | {
|
| | | //绑定目标设置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return null;
|
| | | }
|
| | |
|
| | | var listSuccess = new List<CommonDevice>();
|
| | | foreach (var data in result.addedDeviceBindResponseData.BindList)
|
| | | {
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
|
| | | if (dicDevice.ContainsKey(mainkeys) == true)
|
| | | {
|
| | | listSuccess.Add(dicDevice[mainkeys]);
|
| | | }
|
| | | }
|
| | |
|
| | | if (listSuccess.Count == 0)
|
| | | {
|
| | | //绑定目标设置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return listSuccess;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | ///设备绑定
|
| | | /// </summary>
|
| | | public BindObj.AddedDeviceBindResponseAllData AddDeviceBindAsync(BindObj.AddBindData addBindData)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind");
|
| | | }
|
| | |
|
| | | var device = Common.LocalDevice.Current.GetDevice(addBindData.DeviceAddr, addBindData.Epoint);
|
| | | //获取发送的命令字符
|
| | | var sendData = this.GetAddDeviceListBindCommandText(addBindData);
|
| | | //发送
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetBind", sendData, "Bind/SetBind_Respon", 20);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | //修改缓存
|
| | | ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind");
|
| | |
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceBindResponseData>(result.ReceiptData);
|
| | | return new BindObj.AddedDeviceBindResponseAllData() { addedDeviceBindResponseData = tempData };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取添加设备绑定的命令字符
|
| | | /// </summary>
|
| | | /// <param name="addBindData"></param>
|
| | | /// <returns></returns>
|
| | | public string GetAddDeviceListBindCommandText(BindObj.AddBindData addBindData)
|
| | | {
|
| | | var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
|
| | | var bindList = new JArray { };
|
| | | foreach (var bindInfo in addBindData.BindList)
|
| | | {
|
| | | if (bindInfo.BindType == 0)
|
| | | {
|
| | | var dInfo = new JObject{{ "BindMacAddr",bindInfo.BindMacAddr},{ "BindEpoint", bindInfo.BindEpoint} ,
|
| | | { "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}};
|
| | | bindList.Add(dInfo);
|
| | | }
|
| | | else if (bindInfo.BindType == 1)
|
| | | {
|
| | | var dInfo = new JObject{{ "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType},
|
| | | { "BindScenesId", bindInfo.BindScenesId}};
|
| | | bindList.Add(dInfo);
|
| | | }
|
| | | }
|
| | | var data = new JObject { { "BindName", addBindData.BindName }, { "BindList", bindList } };
|
| | | jObject.Add("Data", data);
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 删除设备绑定的目标_________________
|
| | | |
| | |
|
| | | /// <summary>
|
| | | /// 删除设备绑定的目标
|
| | | /// </summary>
|
| | | /// <param name="mainDevice">设备对象</param>
|
| | | /// <param name="deleteDevice">要删除的绑定目标设备</param>
|
| | | /// <param name="BindCluster">BindCluster</param>
|
| | | /// <returns></returns>
|
| | | public bool DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
|
| | | {
|
| | | //组装数据
|
| | | var deleteData = new IASZone.DelDeviceBindData();
|
| | | deleteData.DeviceAddr = mainDevice.DeviceAddr;
|
| | | deleteData.Epoint = mainDevice.DeviceEpoint;
|
| | |
|
| | | var info = new IASZone.RemoveBindListObj();
|
| | | info.BindCluster = BindCluster;
|
| | | info.BindMacAddr = deleteDevice.DeviceAddr;
|
| | | info.BindEpoint = deleteDevice.DeviceEpoint;
|
| | | info.BindType = 0;
|
| | |
|
| | | deleteData.RemoveBindList.Add(info);
|
| | |
|
| | | //执行删除
|
| | | var result = this.DelDeviceBindAsync(deleteData);
|
| | | if (result == null || result.delDeviceBindResponseData == null)
|
| | | {
|
| | | //删除绑定目标失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
|
| | | {
|
| | | //0:成功 1:设备不在绑定列表中 ,也可以代表成功
|
| | | if (data.Result == 0 || data.Result == 1 || data.Result == 5)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | //3:失败,在等待节点设备确认是否解除绑定成功
|
| | | else if (data.Result == 3)
|
| | | {
|
| | | //其他绑定目标正在删除中,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | //2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功
|
| | | else if (data.Result == 2)
|
| | | {
|
| | | if (result.removeBindResultResponseData == null)
|
| | | {
|
| | | //删除绑定目标失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | else
|
| | | {
|
| | | //成功
|
| | | if (result.removeBindResultResponseData.Result == 0)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | //136:控制设备本地绑定列表中无此绑定
|
| | | else if (result.removeBindResultResponseData.Result == 136)
|
| | | {
|
| | | //这个可以当做成功
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //删除绑定目标失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除设备绑定的目标
|
| | | /// </summary>
|
| | |
| | | /// <summary> |
| | | /// 读取面板的配置信息 |
| | | /// </summary> |
| | | public Panel.PanelConfigureInfoResponAllData ReadPanelConfigureInfoAsync(CommonDevice device) |
| | | { |
| | | //如果当前住宅是虚拟住宅 |
| | | if (Common.Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | return ModelData.DeviceModelDataLogic.Current.ReadPanelConfigureKeyModel(device); |
| | | } |
| | | |
| | | var JObject = new JObject {{ "DeviceAddr",device.DeviceAddr },{ "Epoint", device.DeviceEpoint }, |
| | | { "Cluster_ID", (int)Cluster_ID.HdlKey },{ "Command", 108 }}; |
| | | var attriBute = new JArray { new JObject { { "AttriButeId", (int)AttriButeId.HdlKey } } }; |
| | | var data = new JObject { { "AttriBute", attriBute } }; |
| | | JObject.Add("Data", data); |
| | | |
| | | //发送数据 |
| | | var sendData = JObject.ToString(); |
| | | string receiptTopic = "DeviceStatusReport/" + device.DeviceAddr + "/" + device.DeviceEpoint + "/" + (int)Cluster_ID.HdlKey + "/" + (int)AttriButeId.HdlKey; |
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetDeviceStatus", sendData, receiptTopic); |
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(result.ReceiptData); |
| | | return new Panel.PanelConfigureInfoResponAllData { deviceStatusReportData = tempData }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取配置面板功能的命令字符 |
| | | /// </summary> |
| | | public Panel.PanelConfigureInfoResponAllData ReadPanelConfigureInfoAsync(CommonDevice device)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return ModelData.DeviceModelDataLogic.Current.ReadPanelConfigureKeyModel(device);
|
| | | }
|
| | |
|
| | | var JObject = new JObject {{ "DeviceAddr",device.DeviceAddr },{ "Epoint", device.DeviceEpoint },
|
| | | { "Cluster_ID", (int)Cluster_ID.HdlKey },{ "Command", 108 }};
|
| | | var attriBute = new JArray { new JObject { { "AttriButeId", (int)AttriButeId.HdlKey } } };
|
| | | var data = new JObject { { "AttriBute", attriBute } };
|
| | | JObject.Add("Data", data);
|
| | |
|
| | | //发送数据
|
| | | var sendData = JObject.ToString();
|
| | | string receiptTopic = "DeviceStatusReport/" + device.DeviceAddr + "/" + device.DeviceEpoint + "/" + (int)Cluster_ID.HdlKey + "/" + (int)AttriButeId.HdlKey;
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetDeviceStatus", sendData, receiptTopic);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(result.ReceiptData);
|
| | | return new Panel.PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取配置面板功能的命令字符
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="value">键值</param> |
| | | /// <param name="clusterID">镞ID</param> |
| | | /// <returns></returns> |
| | | /// <returns></returns>
|
| | | public string GetConfigureHdlKeyCommandText(string DeviceAddr, int DeviceEpoint, Panel.KeyMode value, int clusterID = 6) |
| | | { |
| | | {
|
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 6533 }, { "AttributeDataType", 33 }, { "AttributeData", (int)value } }; |
| | | jObject.Add("Data", data); |
| | | return jObject.ToString(); |
| | | } |
| | | |
| | | #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 UserCenter.ShowMsgControl(ShowMsgType.Tip, msg); |
| | | contr.Show(); |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | }
|
| | |
|
| | | #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 UserCenter.ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|