| | |
| | | using Shared.Phone.UserCenter; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Common |
| | | { |
| | | /// <summary> |
| | | /// 本地设备 |
| | | /// </summary> |
| | | public class LocalDevice |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 本地设备 |
| | | using Shared.Phone.UserCenter;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Common
|
| | | {
|
| | | /// <summary>
|
| | | /// 本地设备
|
| | | /// </summary>
|
| | | public class LocalDevice
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 本地设备
|
| | | /// </summary> |
| | | private static LocalDevice m_Current = null; |
| | | /// <summary> |
| | | /// 本地设备 |
| | | /// <summary>
|
| | | /// 本地设备
|
| | | /// </summary> |
| | | public static LocalDevice Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new LocalDevice(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | set |
| | | { |
| | | m_Current = value; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 本地所有设备的缓存 |
| | | /// </summary> |
| | | public List<CommonDevice> listAllDevice |
| | | { |
| | | get |
| | | { |
| | | var list = new List<CommonDevice>(); |
| | | foreach (var device in dicAllDevice.Values) |
| | | { |
| | | list.Add(device); |
| | | } |
| | | return list; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// R文件里面设备默认名字的ID的前缀 |
| | | /// </summary> |
| | | public const string deviceDefultNameFlag = "uDeviceDefultName"; |
| | | /// <summary> |
| | | /// R文件里面设备默认名字的ID |
| | | /// </summary> |
| | | public Dictionary<string, int> dicDeviceDefultNameID = null; |
| | | /// <summary> |
| | | /// 设备的模块ID的枚举(keys:模块ID(已翻译),value:设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以) |
| | | /// </summary> |
| | | private Dictionary<string, string> dicDeviceModelIdEnum = null; |
| | | /// <summary> |
| | | /// 本地所有设备的缓存(非公开) |
| | | /// </summary> |
| | | private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>(); |
| | | /// <summary> |
| | | /// 本地所有设备UI的缓存(非公开) |
| | | /// </summary> |
| | | private Dictionary<string, DeviceUI> dicAllDeviceUI = new Dictionary<string, DeviceUI>(); |
| | | /// <summary> |
| | | /// 本地所有的顶点升级设备(非公开,主键是MAC+200端口) |
| | | /// </summary> |
| | | private Dictionary<string, OTADevice> dicOTADevice = new Dictionary<string, OTADevice>(); |
| | | /// <summary> |
| | | /// 设备计数 |
| | | /// </summary> |
| | | private Dictionary<string, DeviceCountInfo> dicDeviceCount = new Dictionary<string, DeviceCountInfo>(); |
| | | /// <summary> |
| | | /// 设备文件的前缀名字 |
| | | /// </summary> |
| | | public const string deviceFirstName = "Device_"; |
| | | /// <summary> |
| | | /// 备用设备文件的前缀标识名字(为设备删除所用,这个文件一旦设备删除后就会一直存在) |
| | | /// </summary> |
| | | private string deviceBackupName = "Backup"; |
| | | /// <summary> |
| | | /// 锁 |
| | | /// </summary> |
| | | private object objLock = new object(); |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 刷新设备___________________________ |
| | | |
| | | public static LocalDevice Current
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_Current == null)
|
| | | {
|
| | | m_Current = new LocalDevice();
|
| | | }
|
| | | return m_Current;
|
| | | }
|
| | | set
|
| | | {
|
| | | m_Current = value;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存
|
| | | /// </summary>
|
| | | public List<CommonDevice> listAllDevice
|
| | | {
|
| | | get
|
| | | {
|
| | | var list = new List<CommonDevice>();
|
| | | foreach (var device in dicAllDevice.Values)
|
| | | {
|
| | | list.Add(device);
|
| | | }
|
| | | return list;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// R文件里面设备模块ID的翻译名字的前缀
|
| | | /// </summary>
|
| | | public const string deviceModelIdName = "uDeviceModelId";
|
| | | /// <summary>
|
| | | /// R文件里面设备默认名字的ID
|
| | | /// </summary>
|
| | | public Dictionary<string, int> dicDeviceDefultNameID = null;
|
| | | /// <summary>
|
| | | /// 设备的模块ID的枚举(keys:模块ID value:设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceModelIdEnum = null;
|
| | | /// <summary>
|
| | | /// 需要转换的设备的模块ID(keys:旧模块ID,value:新模块ID)
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceModelIdChanged = null;
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存(非公开)
|
| | | /// </summary>
|
| | | private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>();
|
| | | /// <summary>
|
| | | /// 本地所有的顶点升级设备(非公开,主键是MAC+200端口)
|
| | | /// </summary>
|
| | | private Dictionary<string, OTADevice> dicOTADevice = new Dictionary<string, OTADevice>();
|
| | | /// <summary>
|
| | | /// 设备的总回路(keys:Mac地址 value:全部端口号)
|
| | | /// </summary>
|
| | | private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
|
| | | /// <summary>
|
| | | /// 设备文件的前缀名字
|
| | | /// </summary>
|
| | | public const string deviceFirstName = "Device_";
|
| | | /// <summary>
|
| | | /// 锁
|
| | | /// </summary>
|
| | | private object objLock = new object();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 刷新设备___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 刷新本地设备信息 |
| | | /// </summary> |
| | | public void ReFreshByLocal() |
| | | { |
| | | this.dicAllDevice.Clear(); |
| | | this.dicAllDeviceUI.Clear(); |
| | | this.dicDeviceCount.Clear(); |
| | | this.dicDeviceEpoint.Clear(); |
| | | |
| | | //初始化R文件里面设备默认名字的ID |
| | | this.InitDeviceDefultNameIDList(); |
| | | |
| | | //获取本地全部的设备文件 |
| | | List<string> listFile = this.GetAllDeviceFile(); |
| | | foreach (string file in listFile) |
| | | { |
| | | //反序列化为指定的类,不然数据会丢失而导致无法强转 |
| | | var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file); |
| | | if (device == null || device.CurrentGateWayId == null) |
| | | { |
| | | //失效的文件,没有网关id的都删除掉 |
| | | Global.DeleteFilebyHomeId(file); |
| | | continue; |
| | | } |
| | | //如果这个设备的网关ID不存在的话 |
| | | if (Common.LocalGateway.Current.IsGatewayExist(device.CurrentGateWayId) == false) |
| | | { |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3) |
| | | { |
| | | //如果他是成员的话,帮他新建一个网关 |
| | | Common.LocalGateway.Current.AddVirtualGateway(device.CurrentGateWayId); |
| | | } |
| | | else |
| | | { |
| | | //如果是主人,或者管理员,那么这个文件是非法的,直接删除 |
| | | Global.DeleteFilebyHomeId(file); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | string mainKey = this.GetDeviceMainKeys(device); |
| | | if (device is OTADevice) |
| | | { |
| | | //200端口不需要处理 |
| | | this.dicOTADevice[mainKey] = (OTADevice)device; |
| | | continue; |
| | | } |
| | | //添加缓存 |
| | | this.dicAllDevice[mainKey] = device; |
| | | |
| | | //回路计数 |
| | | if (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == false) |
| | | { |
| | | this.dicDeviceCount[device.DeviceAddr] = new DeviceCountInfo(); |
| | | } |
| | | this.dicDeviceCount[device.DeviceAddr].Count += 1; |
| | | this.dicDeviceCount[device.DeviceAddr].hsEpoint.Add(device.DeviceEpoint); |
| | | |
| | | //检测Ui图片是否正确 |
| | | var deviceUi = this.GetDeviceUIFromLocalFile(device); |
| | | if (deviceUi == null) |
| | | { |
| | | deviceUi = new DeviceUI(); |
| | | deviceUi.DeviceFileName = device.FilePath; |
| | | deviceUi.Save(); |
| | | HdlAutoBackupLogic.AddOrEditorFile(deviceUi.FileName); |
| | | } |
| | | else |
| | | { |
| | | //这个图片本地是否存在? |
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(deviceUi.IconPath)) == true) |
| | | { |
| | | //不存在的话,重新生成 |
| | | deviceUi.IconPath = string.Empty; |
| | | deviceUi.ReSave(); |
| | | HdlAutoBackupLogic.AddOrEditorFile(deviceUi.FileName); |
| | | } |
| | | } |
| | | //添加缓存 |
| | | this.dicAllDeviceUI[deviceUi.FileName] = deviceUi; |
| | | foreach (string file in listFile)
|
| | | {
|
| | | //反序列化为指定的类,不然数据会丢失而导致无法强转
|
| | | var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file);
|
| | | if (device == null || device.CurrentGateWayId == null)
|
| | | {
|
| | | #if DEBUG
|
| | | //调查,为什么它会把全部设备删掉?
|
| | | string file1 = UserCenterLogic.CombinePath(file);
|
| | | string file2 = UserCenterLogic.CombinePath("Back_" + file);
|
| | | System.IO.File.Copy(file1, file2, true);
|
| | | #endif
|
| | | //失效的文件,没有网关id的都删除掉
|
| | | Global.DeleteFilebyHomeId(file);
|
| | | continue;
|
| | | }
|
| | | //如果这个设备的网关ID不存在的话
|
| | | if (HdlGatewayLogic.Current.IsGatewayExist(device.CurrentGateWayId) == false)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //如果他是成员的话,帮他新建一个网关
|
| | | HdlGatewayLogic.Current.AddVirtualGateway(device.CurrentGateWayId);
|
| | | }
|
| | | else
|
| | | {
|
| | | #if DEBUG
|
| | | //调查,为什么它会把全部设备删掉?
|
| | | string file1 = UserCenterLogic.CombinePath(file);
|
| | | string file2 = UserCenterLogic.CombinePath("Back_" + file);
|
| | | System.IO.File.Copy(file1, file2, true);
|
| | | #endif
|
| | | //如果是主人,或者管理员,那么这个文件是非法的,直接删除
|
| | | Global.DeleteFilebyHomeId(file);
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | string mainKey = this.GetDeviceMainKeys(device);
|
| | | if (device is OTADevice)
|
| | | {
|
| | | //200端口不需要处理
|
| | | this.dicOTADevice[mainKey] = (OTADevice)device;
|
| | | continue;
|
| | | }
|
| | | //添加缓存
|
| | | this.dicAllDevice[mainKey] = device;
|
| | |
|
| | | //回路收集
|
| | | if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>();
|
| | | }
|
| | | this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
|
| | |
|
| | | //检测Ui图片是否正确,这个图片本地是否存在?
|
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
|
| | | {
|
| | | //不存在的话,重新生成
|
| | | device.IconPath = string.Empty;
|
| | | device.ReSave();
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | | } |
| | | //成员身份的时候,删除掉非法的网关文件 |
| | | this.DeleteGatewayFileByMemberModel(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 成员身份的时候,删除掉非法的网关文件 |
| | | /// </summary> |
| | | private void DeleteGatewayFileByMemberModel() |
| | | { |
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3) |
| | | { |
| | | return; |
| | | } |
| | | var listId = new HashSet<string>(); |
| | | foreach (var device in this.dicAllDevice.Values) |
| | | { |
| | | if (listId.Contains(device.CurrentGateWayId) == false) |
| | | { |
| | | listId.Add(device.CurrentGateWayId); |
| | | } |
| | | } |
| | | var listGateway = Common.LocalGateway.Current.GetAllLocalGateway(); |
| | | foreach (var gateway in listGateway) |
| | | { |
| | | string gwId = Common.LocalGateway.Current.GetGatewayId(gateway); |
| | | if (listId.Contains(gwId) == false) |
| | | { |
| | | //这个网关对于当前这个成员来说是非法的 |
| | | Common.LocalGateway.Current.DeleteGatewayFile(gwId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加设备___________________________ |
| | | |
| | | /// <summary> |
| | | /// 将指定网关的设备存入缓存中(从新获取镜像) |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关对象</param> |
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param> |
| | | /// <returns>一直返回true</returns> |
| | | public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null) |
| | | { |
| | | //从网关获取全部的设备 |
| | | List<CommonDevice> listDevice = new List<CommonDevice>(); |
| | | List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction); |
| | | |
| | | if (list == null) |
| | | { |
| | | return false; |
| | | } |
| | | listDevice.AddRange(list); |
| | | |
| | | //获取这个网关的本地所有设备 |
| | | string gwID = Common.LocalGateway.Current.GetGatewayId(zbGateway); |
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID); |
| | | Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>(); |
| | | foreach (var device in listLocalDevices) |
| | | { |
| | | string maikey = this.GetDeviceMainKeys(device); |
| | | dicExist[maikey] = device; |
| | | } |
| | | |
| | | //添加设备的缓存 |
| | | for (int i = 0; i < listDevice.Count; i++) |
| | | { |
| | | var device = listDevice[i]; |
| | | if (device == null || device.DeviceAddr == null) |
| | | { |
| | | continue; |
| | | } |
| | | //添加缓存 |
| | | this.AddDeviceToMemory(ref device); |
| | | |
| | | //移除存在的设备内存 |
| | | string maikey = this.GetDeviceMainKeys(device); |
| | | if (dicExist.ContainsKey(maikey) == true) |
| | | { |
| | | dicExist.Remove(maikey); |
| | | } |
| | | } |
| | | |
| | | //如果本地和网关的设备不一致的时候,暂时删除本地的设备 |
| | | //注意:只是删除设备文件,房间内容什么的还存在着 |
| | | foreach (var device in dicExist.Values) |
| | | { |
| | | this.DeleteMemmoryDevice(device, false); |
| | | } |
| | | |
| | | if (listDevice.Count > 0) |
| | | { |
| | | //等待一下设备的硬件信息 |
| | | await Task.Delay(1500); |
| | | //重新变更UI |
| | | foreach (var device in listDevice) |
| | | { |
| | | if (device == null || device.DeviceAddr == null || (device is OTADevice)) |
| | | { |
| | | continue; |
| | | } |
| | | var ui = this.GetDeviceUI(device); |
| | | if (ui.IsCustomizeImage == false) |
| | | { |
| | | ui.IconPath = string.Empty; |
| | | ui.ReSave(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加设备到缓存,存在时覆盖 |
| | | /// </summary> |
| | | /// <param name="device">设备对象(这个东西有可能会被更改)</param> |
| | | /// <param name="ResetImageType">是否重置镜像类型</param> |
| | | public void AddDeviceToMemory(ref CommonDevice device, bool ResetImageType = false) |
| | | { |
| | | //尝试恢复删除了的文件 |
| | | bool backFile = this.RecoverBackupDeviceFile(ref device); |
| | | |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | //如果它是升级的顶端端点,则不能让它加入到缓存,但是可以让他生成文件 |
| | | if (device is OTADevice) |
| | | { |
| | | //尝试恢复文件成功,或者本地都没有这个设备 |
| | | if (backFile == true || this.dicOTADevice.ContainsKey(mainKeys) == false) |
| | | { |
| | | this.dicOTADevice[mainKeys] = (OTADevice)device; |
| | | } |
| | | else |
| | | { |
| | | //交换属性 |
| | | var tempDevice = this.dicOTADevice[mainKeys]; |
| | | //将DeviceInfo的属性设置到主属性中 |
| | | this.SetDeviceInfoToMain(tempDevice, device); |
| | | device = tempDevice; |
| | | } |
| | | |
| | | if (ResetImageType == true) |
| | | { |
| | | //ota设备的镜像类型初始值设置为-1 |
| | | device.ImgTypeId = -1; |
| | | device.ImgVersion = -1; |
| | | } |
| | | |
| | | bool exists = Global.IsExistsByHomeId(device.FilePath); |
| | | device.ReSave(); |
| | | |
| | | if (exists == false) |
| | | { |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | } |
| | | |
| | | //设置设备全部的镜像信息 |
| | | this.SetAllImageInfoToOtaDevice((OTADevice)device); |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true) |
| | | { |
| | | //交换属性 |
| | | var tempDevice = this.dicAllDevice[mainKeys]; |
| | | //将DeviceInfo的属性设置到主属性中 |
| | | this.SetDeviceInfoToMain(tempDevice, device); |
| | | device = tempDevice; |
| | | } |
| | | else |
| | | { |
| | | this.dicAllDevice[mainKeys] = device; |
| | | } |
| | | //获取设备的硬件信息 |
| | | this.SetAllHardFirmwareInfoToDevice(device); |
| | | |
| | | //虚拟设备的话,附加回路号 |
| | | if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty) |
| | | { |
| | | //根据设备类型获取名称 |
| | | var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); |
| | | //在端点名字的后面附加【回路】字样 |
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; |
| | | this.SetEpointName(device, dName); |
| | | new System.Threading.Thread(async () => |
| | | { |
| | | //因为虚拟设备不会经过设备入网这一步,所以直接给它一个默认名字 |
| | | await this.ReName(this.dicAllDevice[mainKeys], dName, ShowErrorMode.NO); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | //设备计数 |
| | | if (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == false) |
| | | { |
| | | this.dicDeviceCount[device.DeviceAddr] = new DeviceCountInfo(); |
| | | } |
| | | if (this.dicDeviceCount[device.DeviceAddr].hsEpoint.Contains(device.DeviceEpoint) == false) |
| | | { |
| | | this.dicDeviceCount[device.DeviceAddr].Count += 1; |
| | | this.dicDeviceCount[device.DeviceAddr].hsEpoint.Add(device.DeviceEpoint); |
| | | } |
| | | |
| | | //添加设备的时候,直接创建设备的UI图 |
| | | DeviceUI deviceUI = new DeviceUI(); |
| | | deviceUI.DeviceFileName = device.FilePath; |
| | | |
| | | bool exists2 = Global.IsExistsByHomeId(deviceUI.FileName); |
| | | deviceUI.Save(); |
| | | if (exists2 == false) |
| | | { |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(deviceUI.FileName); |
| | | this.dicAllDeviceUI[deviceUI.FileName] = deviceUI; |
| | | } |
| | | |
| | | exists2 = Global.IsExistsByHomeId(device.FilePath); |
| | | device.ReSave(); |
| | | if (exists2 == false) |
| | | { |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 恢复删除了的文件(仅限添加设备的时候) |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | private bool RecoverBackupDeviceFile(ref CommonDevice device) |
| | | { |
| | | //如果本地存在备用的文件夹的话,则使用备份的文件夹作为对象 |
| | | string backFile = deviceBackupName + device.FilePath; |
| | | if (Global.IsExistsByHomeId(device.FilePath) == true || Global.IsExistsByHomeId(backFile) == false) |
| | | { |
| | | //只有在本地目标设备文件不存在,并且备份文件存在的时候才处理 |
| | | return false; |
| | | } |
| | | |
| | | //反序列化为指定的类,不然数据会丢失而导致无法强转(★这个东西保存着以前的网关备份数据★) |
| | | var tempDevice = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(backFile); |
| | | if (tempDevice == null) |
| | | { |
| | | return false; |
| | | } |
| | | //不沿用名字,先这样吧 |
| | | this.SetMacName(tempDevice, string.Empty); |
| | | this.SetEpointName(tempDevice, string.Empty); |
| | | |
| | | //将DeviceInfo的属性设置到主属性中 |
| | | this.SetDeviceInfoToMain(tempDevice, device); |
| | | //替换对象 |
| | | device = tempDevice; |
| | | |
| | | //这里继续保留着那个备份文件,好像也没什么问题的样子 |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 修改设备___________________________ |
| | | |
| | | /// <summary> |
| | | /// 更改名字并且刷新缓存(修改失败时,会显示信息) |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="newName">新名字</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES) |
| | | { |
| | | //不再检测名字是否一样 |
| | | //成员只能修改自己本地的名字 |
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3) |
| | | { |
| | | var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName); |
| | | if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) |
| | | { |
| | | //设备名称修改失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | if (mode == ShowErrorMode.YES) |
| | | { |
| | | this.ShowErrorMsg(msg); |
| | | } |
| | | return false; |
| | | } |
| | | //备份数据 |
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A端点名称, newName); |
| | | } |
| | | |
| | | //更改名字后,刷新设备缓存 |
| | | this.SetEpointName(device, newName); |
| | | |
| | | this.BackupDeviceAfterReName(device); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更改Mac名字并且刷新缓存(修改失败时,会显示信息) |
| | | /// </summary> |
| | | /// <param name="listDevice">设备对象</param> |
| | | /// <param name="newMacName">新名字</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES) |
| | | { |
| | | if (listDevice.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | CommonDevice device = listDevice[0]; |
| | | |
| | | //不再检测名字是否一样 |
| | | //成员只能修改自己本地的名字 |
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3) |
| | | { |
| | | //修改物理名字 |
| | | var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName); |
| | | if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result == 1) |
| | | { |
| | | //设备名称修改失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | if (mode == ShowErrorMode.YES) |
| | | { |
| | | this.ShowErrorMsg(msg); |
| | | } |
| | | return false; |
| | | } |
| | | //备份数据 |
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac名称, newMacName); |
| | | } |
| | | |
| | | //修改缓存 |
| | | for (int i = 0; i < listDevice.Count; i++) |
| | | { |
| | | var device2 = listDevice[i]; |
| | | //这两个东西很特殊 |
| | | this.SetMacName(device2, newMacName); |
| | | |
| | | //更改名字后,刷新设备缓存 |
| | | this.BackupDeviceAfterReName(device2); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更改名字后,刷新设备缓存 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | private void BackupDeviceAfterReName(CommonDevice device) |
| | | { |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == false) |
| | | { |
| | | return; |
| | | } |
| | | this.dicAllDevice[mainKeys] = device; |
| | | device.ReSave(); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 删除设备___________________________ |
| | | |
| | | /// <summary> |
| | | /// 删除设备并且刷新缓存(删除失败时,会显示信息) |
| | | /// </summary> |
| | | /// <param name="listdevice">设备对象(MAC地址必须要相同)</param> |
| | | public async Task<bool> DeleteDevice(List<CommonDevice> listdevice) |
| | | { |
| | | var data = new CommonDevice.RemoveDeviceData(); |
| | | var info = new CommonDevice.RemoveDeviceListInfo(); |
| | | info.DeviceAddr = listdevice[0].DeviceAddr; |
| | | data.DeviceAddrList.Add(info); |
| | | |
| | | //删一次的时候,它会把MAC地址下面全部的设备都删除 |
| | | var result = await listdevice[0].DeleteDeviceAsync(data); |
| | | if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0) |
| | | { |
| | | //设备删除失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | |
| | | //删除文件 |
| | | foreach (CommonDevice device in listdevice) |
| | | { |
| | | this.DeleteMemmoryDevice(device); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除缓存的设备 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="deleteRoom">是否从房间删除</param> |
| | | public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) |
| | | { |
| | | //删除缓存 |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true) |
| | | { |
| | | this.dicAllDevice.Remove(mainKeys); |
| | | } |
| | | |
| | | //删除设备文件 |
| | | string filePath = device.FilePath; |
| | | if (Global.IsExistsByHomeId(filePath) == true) |
| | | { |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3) |
| | | { |
| | | //成员的话,直接删除,没有商量的余地 |
| | | Global.DeleteFilebyHomeId(filePath); |
| | | } |
| | | else |
| | | { |
| | | //不删除文件,直接改名字 |
| | | string oldFile = UserCenterLogic.CombinePath(filePath); |
| | | string newFile = UserCenterLogic.CombinePath(deviceBackupName + filePath); |
| | | Global.MoveFileToDirectory(oldFile, newFile); |
| | | //删除自动备份 |
| | | HdlAutoBackupLogic.DeleteFile(device.FilePath); |
| | | } |
| | | } |
| | | |
| | | //删除200端口文件 |
| | | string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200); |
| | | if (this.dicOTADevice.ContainsKey(otaKeys) == true) |
| | | { |
| | | string otaFile = this.dicOTADevice[otaKeys].FilePath; |
| | | if (Global.IsExistsByHomeId(otaFile) == true) |
| | | { |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3) |
| | | { |
| | | //成员的话,直接删除,没有商量的余地 |
| | | Global.DeleteFilebyHomeId(filePath); |
| | | } |
| | | else |
| | | { |
| | | //不删除文件,直接改名字 |
| | | string oldFile = UserCenterLogic.CombinePath(otaFile); |
| | | string newFile = UserCenterLogic.CombinePath(deviceBackupName + otaFile); |
| | | Global.MoveFileToDirectory(oldFile, newFile); |
| | | //删除自动备份 |
| | | HdlAutoBackupLogic.DeleteFile(otaFile); |
| | | } |
| | | } |
| | | this.dicOTADevice.Remove(otaKeys); |
| | | } |
| | | |
| | | if (deleteRoom == true && Room.CurrentRoom != null) |
| | | { |
| | | //从房间中删除 |
| | | Room.CurrentRoom.DeleteDevice(device); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除设备的备份文件(应该只有在删除网关的时候使用吧) |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | public void DeleteDeviceBackupFile(CommonDevice device) |
| | | { |
| | | string backFile = deviceBackupName + device.FilePath; |
| | | if (Global.IsExistsByHomeId(backFile) == true) |
| | | { |
| | | Global.DeleteFilebyHomeId(backFile); |
| | | HdlAutoBackupLogic.DeleteFile(backFile); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 测试设备___________________________ |
| | | |
| | | /// <summary> |
| | | /// 发送测试指令到设备 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | public void SetTestCommand(CommonDevice device) |
| | | { |
| | | device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测设备是否拥有测试的功能 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public bool DeviceIsCanTest(CommonDevice device) |
| | | { |
| | | foreach (var data in device.InClusterList) |
| | | { |
| | | //拥有on/off功能的,才支持测试 |
| | | if (data.InCluster == 3) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测设备是否拥有开关的功能(输出簇) |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public bool OutDeviceIsCanOnOff(CommonDevice device) |
| | | { |
| | | foreach (var data in device.OutClusterList) |
| | | { |
| | | //拥有on/off功能的,才支持测试 |
| | | if (data.OutCluster == 6) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测设备是否拥有开关的功能(输入簇) |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public bool InDeviceIsCanOnOff(CommonDevice device) |
| | | { |
| | | foreach (var data in device.InClusterList) |
| | | { |
| | | //拥有on/off功能的,才支持测试 |
| | | if (data.InCluster == 6) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取设备___________________________ |
| | | |
| | | /// <summary> |
| | | /// 根据网关ID获取所有的设备 |
| | | /// </summary> |
| | | /// <param name="gwId">网关ID</param> |
| | | /// <returns></returns> |
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId) |
| | | { |
| | | List<CommonDevice> list = new List<CommonDevice>(); |
| | | //各网关的所有设备 |
| | | foreach (CommonDevice device in this.dicAllDevice.Values) |
| | | { |
| | | if (gwId == device.CurrentGateWayId) |
| | | { |
| | | list.Add(device); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定设备(主键是:Mac地址+端口号),不存在时,返回null |
| | | /// </summary> |
| | | /// <param name="mainKeys">Mac地址+端口号</param> |
| | | /// <returns></returns> |
| | | public CommonDevice GetDevice(string mainKeys) |
| | | { |
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true) |
| | | { |
| | | return this.dicAllDevice[mainKeys]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定设备,不存在时,返回null |
| | | /// </summary> |
| | | /// <param name="DeviceAddr">Mac地址</param> |
| | | /// <param name="DeviceEpoint">端口号</param> |
| | | /// <returns></returns> |
| | | public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint) |
| | | { |
| | | string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint); |
| | | return this.GetDevice(mainkeys); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取本地全部的设备文件 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<string> GetAllDeviceFile() |
| | | { |
| | | List<string> listDeviceFile = new List<string>(); |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 成员身份的时候,删除掉非法的网关文件
|
| | | /// </summary>
|
| | | private void DeleteGatewayFileByMemberModel()
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var listId = new HashSet<string>();
|
| | | foreach (var device in this.dicAllDevice.Values)
|
| | | {
|
| | | if (listId.Contains(device.CurrentGateWayId) == false)
|
| | | {
|
| | | listId.Add(device.CurrentGateWayId);
|
| | | }
|
| | | }
|
| | | var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
|
| | | foreach (var gateway in listGateway)
|
| | | {
|
| | | string gwId = HdlGatewayLogic.Current.GetGatewayId(gateway);
|
| | | if (listId.Contains(gwId) == false)
|
| | | {
|
| | | //这个网关对于当前这个成员来说是非法的
|
| | | HdlGatewayLogic.Current.DeleteGatewayFile(gwId);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 添加设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 将指定网关的设备存入缓存中(从新获取镜像)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param>
|
| | | /// <returns>一直返回true</returns>
|
| | | public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
|
| | | {
|
| | | //从网关获取全部的设备
|
| | | List<CommonDevice> listDevice = new List<CommonDevice>();
|
| | | List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction);
|
| | |
|
| | | if (list == null)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | listDevice.AddRange(list);
|
| | |
|
| | | //获取这个网关的本地所有设备
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
|
| | | Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>();
|
| | | foreach (var device in listLocalDevices)
|
| | | {
|
| | | string maikey = this.GetDeviceMainKeys(device);
|
| | | dicExist[maikey] = device;
|
| | | }
|
| | |
|
| | | //添加设备的缓存
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | | if (device == null || device.DeviceAddr == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | //添加缓存
|
| | | this.AddDeviceToMemory(ref device);
|
| | |
|
| | | //移除存在的设备内存 |
| | | string maikey = this.GetDeviceMainKeys(device);
|
| | | if (dicExist.ContainsKey(maikey) == true)
|
| | | {
|
| | | dicExist.Remove(maikey);
|
| | | }
|
| | | //获取设备的固定属性
|
| | | HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | | //对未命名的设备重新命名
|
| | | if (this.GetSimpleEpointName(device) == string.Empty)
|
| | | {
|
| | | //根据设备类型获取名称
|
| | | var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
|
| | | //虚拟设备的话,附加回路号
|
| | | if (device.DriveCode > 0)
|
| | | {
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | }
|
| | | //多回路设备的话,附加回路号
|
| | | else if (dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && dicDeviceEpoint[device.DeviceAddr].Count > 1)
|
| | | {
|
| | | var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | dName = arry[0].Trim();
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | }
|
| | |
|
| | | new System.Threading.Thread(async () =>
|
| | | { |
| | | await this.ReName(device, dName, ShowErrorMode.NO);
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | }
|
| | | }
|
| | |
|
| | | //如果本地和网关的设备不一致的时候,暂时删除本地的设备
|
| | | //注意:只是删除设备文件,房间内容什么的还存在着
|
| | | foreach (var device in dicExist.Values)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device, false);
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加设备到缓存,存在时覆盖
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象(这个东西有可能会被更改)</param>
|
| | | public void AddDeviceToMemory(ref CommonDevice device)
|
| | | {
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | //如果它是升级的顶端端点,则不能让它加入到缓存,但是可以让他生成文件
|
| | | if (device is OTADevice)
|
| | | {
|
| | | if (this.dicOTADevice.ContainsKey(mainKeys) == false)
|
| | | {
|
| | | this.dicOTADevice[mainKeys] = (OTADevice)device;
|
| | | }
|
| | | else
|
| | | {
|
| | | //交换属性
|
| | | var tempDevice = this.dicOTADevice[mainKeys];
|
| | | //将DeviceInfo的属性设置到主属性中
|
| | | this.SetDeviceInfoToMain(tempDevice, device);
|
| | | device = tempDevice;
|
| | | }
|
| | |
|
| | | bool exists = Global.IsExistsByHomeId(device.FilePath);
|
| | | device.ReSave();
|
| | | if (exists == false)
|
| | | {
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | //交换属性
|
| | | var tempDevice = this.dicAllDevice[mainKeys];
|
| | | //将DeviceInfo的属性设置到主属性中
|
| | | this.SetDeviceInfoToMain(tempDevice, device);
|
| | | device = tempDevice;
|
| | | }
|
| | | else
|
| | | {
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | }
|
| | |
|
| | | //设备回路收集
|
| | | if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>();
|
| | | }
|
| | | if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false)
|
| | | {
|
| | | this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
|
| | | }
|
| | |
|
| | | bool exists2 = Global.IsExistsByHomeId(device.FilePath);
|
| | | device.ReSave();
|
| | | if (exists2 == false)
|
| | | {
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 修改设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 更改名字并且刷新缓存(修改失败时,会显示信息)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="newName">新名字</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //先别管那么多,更改名字后,刷新设备缓存
|
| | | this.SetEpointName(device, newName);
|
| | |
|
| | | this.BackupDeviceAfterReName(device);
|
| | |
|
| | | //不再检测名字是否一样
|
| | | //成员只能修改自己本地的名字
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName);
|
| | | if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1)
|
| | | {
|
| | | //设备名称修改失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | this.ShowErrorMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | //备份数据
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A端点名称, newName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 更改Mac名字并且刷新缓存(修改失败时,会显示信息)
|
| | | /// </summary>
|
| | | /// <param name="listDevice">设备对象</param>
|
| | | /// <param name="newMacName">新名字</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | if (listDevice.Count == 0)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | //先别管那么多,先修改缓存
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device2 = listDevice[i];
|
| | | //这两个东西很特殊
|
| | | this.SetMacName(device2, newMacName);
|
| | |
|
| | | //更改名字后,刷新设备缓存
|
| | | this.BackupDeviceAfterReName(device2);
|
| | | }
|
| | |
|
| | | CommonDevice device = listDevice[0];
|
| | | //不再检测名字是否一样
|
| | | //成员只能修改自己本地的名字
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | //修改物理名字
|
| | | var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName);
|
| | | if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0)
|
| | | {
|
| | | //设备名称修改失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | this.ShowErrorMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | //备份数据
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac名称, newMacName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 更改名字后,刷新设备缓存
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | private void BackupDeviceAfterReName(CommonDevice device)
|
| | | {
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | device.ReSave();
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 删除设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 删除设备并且刷新缓存(删除失败时,会显示信息)
|
| | | /// </summary>
|
| | | /// <param name="listdevice">设备对象(MAC地址必须要相同)</param>
|
| | | public async Task<bool> DeleteDevice(List<CommonDevice> listdevice)
|
| | | {
|
| | | var data = new CommonDevice.RemoveDeviceData();
|
| | | var info = new CommonDevice.RemoveDeviceListInfo();
|
| | | info.DeviceAddr = listdevice[0].DeviceAddr;
|
| | | data.DeviceAddrList.Add(info);
|
| | |
|
| | | //删一次的时候,它会把MAC地址下面全部的设备都删除
|
| | | var result = await listdevice[0].DeleteDeviceAsync(data);
|
| | | if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0)
|
| | | {
|
| | | //设备删除失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
| | |
|
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | foreach (CommonDevice device in listdevice)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除缓存的设备
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="deleteRoom">是否从房间删除</param>
|
| | | public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
|
| | | {
|
| | | //删除缓存
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | this.dicAllDevice.Remove(mainKeys);
|
| | | }
|
| | |
|
| | | //删除设备文件
|
| | | string filePath = device.FilePath;
|
| | | if (Global.IsExistsByHomeId(filePath) == true)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //成员的话,直接删除,没有商量的余地
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | }
|
| | | else
|
| | | {
|
| | | //变更:搞掉它,不留了
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | //删除自动备份
|
| | | HdlAutoBackupLogic.DeleteFile(device.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | //删除200端口文件
|
| | | string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200);
|
| | | if (this.dicOTADevice.ContainsKey(otaKeys) == true)
|
| | | {
|
| | | string otaFile = this.dicOTADevice[otaKeys].FilePath;
|
| | | if (Global.IsExistsByHomeId(otaFile) == true)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //成员的话,直接删除,没有商量的余地
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | }
|
| | | else
|
| | | {
|
| | | //变更:搞掉它,不留了
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | //删除自动备份
|
| | | HdlAutoBackupLogic.DeleteFile(otaFile);
|
| | | }
|
| | | }
|
| | | this.dicOTADevice.Remove(otaKeys);
|
| | | }
|
| | |
|
| | | if (deleteRoom == true && Room.CurrentRoom != null)
|
| | | {
|
| | | //从房间中删除
|
| | | Room.CurrentRoom.DeleteDevice(device);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 测试设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 发送定位指令到设备
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | public void SetFixedPositionCommand(CommonDevice device)
|
| | | {
|
| | | device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测设备是否拥有定位的功能
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public bool DeviceIsCanFixedPosition(CommonDevice device)
|
| | | {
|
| | | foreach (var data in device.InClusterList)
|
| | | {
|
| | | //拥有on/off功能的,才支持测试
|
| | | if (data.InCluster == 3)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测设备是否拥有开关的功能(输出簇)
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public bool OutDeviceIsCanOnOff(CommonDevice device)
|
| | | {
|
| | | foreach (var data in device.OutClusterList)
|
| | | {
|
| | | //拥有on/off功能的,才支持测试
|
| | | if (data.OutCluster == 6)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测设备是否拥有开关的功能(输入簇)
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public bool InDeviceIsCanOnOff(CommonDevice device)
|
| | | {
|
| | | foreach (var data in device.InClusterList)
|
| | | {
|
| | | //拥有on/off功能的,才支持测试
|
| | | if (data.InCluster == 6)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据网关ID获取所有的设备
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId)
|
| | | {
|
| | | List<CommonDevice> list = new List<CommonDevice>();
|
| | | //各网关的所有设备
|
| | | foreach (CommonDevice device in this.dicAllDevice.Values)
|
| | | {
|
| | | if (gwId == device.CurrentGateWayId)
|
| | | {
|
| | | list.Add(device);
|
| | | }
|
| | | }
|
| | |
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取指定设备(主键是:Mac地址+端口号),不存在时,返回null
|
| | | /// </summary>
|
| | | /// <param name="mainKeys">Mac地址+端口号</param>
|
| | | /// <returns></returns>
|
| | | public CommonDevice GetDevice(string mainKeys)
|
| | | {
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | return this.dicAllDevice[mainKeys];
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取指定设备,不存在时,返回null
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">Mac地址</param>
|
| | | /// <param name="DeviceEpoint">端口号</param>
|
| | | /// <returns></returns>
|
| | | public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint)
|
| | | {
|
| | | string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint);
|
| | | return this.GetDevice(mainkeys);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据MAC地址,获取全部回路的设备对象(已经排序)
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">Mac地址</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDevicesByMac(string DeviceAddr)
|
| | | {
|
| | | var list = new List<CommonDevice>();
|
| | | if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
|
| | | {
|
| | | return list;
|
| | | }
|
| | | foreach (var point in dicDeviceEpoint[DeviceAddr])
|
| | | {
|
| | | var device = this.GetDevice(DeviceAddr, point);
|
| | | if (device != null)
|
| | | {
|
| | | list.Add(device);
|
| | | }
|
| | | }
|
| | | //排序
|
| | | list.Sort((obj1, obj2) =>
|
| | | {
|
| | | if (obj1.DeviceEpoint > obj2.DeviceEpoint)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | });
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取本地全部的设备文件
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public List<string> GetAllDeviceFile()
|
| | | {
|
| | | List<string> listDeviceFile = new List<string>();
|
| | | List<string> listAllFile = Global.FileListByHomeId(); |
| | | foreach (string file in listAllFile) |
| | | { |
| | | if (file.StartsWith(deviceFirstName) == false) |
| | | { |
| | | //如果不是设备文件 |
| | | continue; |
| | | } |
| | | listDeviceFile.Add(file); |
| | | } |
| | | return listDeviceFile; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 附加设备的版本代号(返回Ver.XXX) |
| | | /// </summary> |
| | | /// <param name="versionValue">版本号</param> |
| | | foreach (string file in listAllFile)
|
| | | {
|
| | | if (file.StartsWith(deviceFirstName) == false)
|
| | | {
|
| | | //如果不是设备文件
|
| | | continue;
|
| | | }
|
| | | listDeviceFile.Add(file);
|
| | | }
|
| | | return listDeviceFile;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取OTA设备(200端口的)
|
| | | /// </summary>
|
| | | /// <param name="macAdrr"></param>
|
| | | /// <param name="ePoint"></param>
|
| | | /// <returns></returns>
|
| | | public OTADevice GetOTADevice(string macAdrr, int ePoint = 200)
|
| | | {
|
| | | string mainkeys = this.GetDeviceMainKeys(macAdrr, ePoint);
|
| | | if (this.dicOTADevice.ContainsKey(mainkeys) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return this.dicOTADevice[mainkeys];
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备名称_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备端点的名称(有特效)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceEpointName(CommonDevice device)
|
| | | {
|
| | | string dName = this.GetSimpleEpointName(device);
|
| | | if (string.IsNullOrEmpty(dName) == false)
|
| | | {
|
| | | return dName;
|
| | | }
|
| | | //根据设备类型获取名称
|
| | | dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
|
| | | //如果是虚拟设备
|
| | | if (device.DriveCode > 0
|
| | | || (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1))
|
| | | {
|
| | | var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | dName = arry[0].Trim();
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | }
|
| | | return dName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备MAC名称
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceMacName(CommonDevice device)
|
| | | {
|
| | | string dName = this.GetSimpleMacName(device);
|
| | | if (string.IsNullOrEmpty(dName) == false)
|
| | | {
|
| | | return dName;
|
| | | }
|
| | |
|
| | | //是否拥有配置的模块ID
|
| | | if (this.dicDeviceModelIdEnum.ContainsKey(device.ModelIdentifier) == true)
|
| | | {
|
| | | //获取模块ID名字
|
| | | return this.GetNameByModelId(device);
|
| | | }
|
| | | else
|
| | | {
|
| | | //获取第三方设备的翻译名字
|
| | | var myDeviceType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
| | | return Language.StringByID(myDeviceType.ConcreteTextId);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据模块ID,获取翻译名字
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | private string GetNameByModelId(CommonDevice device)
|
| | | {
|
| | | if (device.ModelIdentifier == string.Empty)
|
| | | {
|
| | | //未知设备
|
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice);
|
| | | }
|
| | |
|
| | | string modelKeys = device.ModelIdentifier;
|
| | | if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false)
|
| | | {
|
| | | //未知设备
|
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice);
|
| | | }
|
| | |
|
| | | string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | int ConcreteValue = Convert.ToInt32(strValue[0]);
|
| | |
|
| | | string keyName = deviceModelIdName + ConcreteValue;
|
| | | if (this.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //R文件里面设置的名字
|
| | | return Language.StringByID(this.dicDeviceDefultNameID[keyName]);
|
| | | }
|
| | |
|
| | | //未知设备
|
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 非公开,设置设备的Mac名字(此方法只是单存的变更缓存)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="macName">Mac名字</param>
|
| | | /// <returns></returns>
|
| | | private void SetMacName(CommonDevice device, string macName)
|
| | | {
|
| | | device.DeviceName = macName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 非公开,设置设备的端点名字(此方法只是单存的变更缓存)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="epointName">端点名字</param>
|
| | | /// <returns></returns>
|
| | | private void SetEpointName(CommonDevice device, string epointName)
|
| | | {
|
| | | device.DeviceEpointName = epointName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 单纯获取设备的Mac名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public string GetSimpleMacName(CommonDevice device)
|
| | | {
|
| | | return device.DeviceName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 单纯获取设备的端点名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public string GetSimpleEpointName(CommonDevice device)
|
| | | {
|
| | | return device.DeviceEpointName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化R文件里面设备默认名字的ID
|
| | | /// </summary>
|
| | | private void InitDeviceDefultNameIDList()
|
| | | {
|
| | | if (this.dicDeviceDefultNameID != null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.dicDeviceDefultNameID = new Dictionary<string, int>();
|
| | | Type type = typeof(R.MyInternationalizationString);
|
| | |
|
| | | var PropertyList = type.GetFields();
|
| | | foreach (var item in PropertyList)
|
| | | {
|
| | | if (item.Name.StartsWith(deviceModelIdName) == true
|
| | | || item.Name.StartsWith("uDeviceBelongId") == true)
|
| | | {
|
| | | this.dicDeviceDefultNameID[item.Name] = Convert.ToInt32(item.GetValue(null));
|
| | | }
|
| | | }
|
| | |
|
| | | //初始化设备枚举
|
| | | this.InitDeviceModelIdEnum();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置图标___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 变更设备的图标
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="unSelPath">图片地址(非选择)</param>
|
| | | public void ChangedDeviceIcon(CommonDevice device, string unSelPath)
|
| | | {
|
| | | if (unSelPath == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | device.IconPath = unSelPath;
|
| | | device.IsCustomizeImage = true;
|
| | | device.ReSave();
|
| | |
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备【图标】到指定的控件
|
| | | /// </summary>
|
| | | /// <param name="btnIcon">控件对象</param>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public void SetDeviceIconToControl(Button btnIcon, CommonDevice device)
|
| | | {
|
| | | string unSelectFilePath = string.Empty;
|
| | | string selectFilePath = string.Empty;
|
| | |
|
| | | //获取设备【图标】
|
| | | this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
|
| | |
|
| | | btnIcon.UnSelectedImagePath = unSelectFilePath;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备【图标】
|
| | | /// </summary>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | /// <param name="unSelectPath">图片地址</param>
|
| | | /// <param name="selectPath">图片地址</param>
|
| | | /// <returns></returns>
|
| | | public void GetDeviceIcon(CommonDevice device, ref string unSelectPath, ref string selectPath)
|
| | | {
|
| | | if (string.IsNullOrEmpty(device.IconPath) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | unSelectPath = device.IconPath;
|
| | |
|
| | | string selPath = device.OnlineIconPath;
|
| | | if (string.IsNullOrEmpty(selPath) == false)
|
| | | {
|
| | | selectPath = selPath;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备的真实图片到指定的控件
|
| | | /// </summary>
|
| | | /// <param name="btnIcon">控件对象</param>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | public void SetRealDeviceIconToControl(Button btnIcon, List<CommonDevice> listdevice)
|
| | | {
|
| | | //获取它属于什么类型的设备
|
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
|
| | | string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType);
|
| | | string strType = strConcrete.Replace("_", string.Empty);
|
| | | //将类型转为图片地址
|
| | | string imageFilePath = "RealDevice/" + strType + ".png";
|
| | | //这个图片本地是否存在?
|
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
|
| | | {
|
| | | //不存在则使用共通图片
|
| | | string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None);
|
| | | if (arry.Length == 1)
|
| | | {
|
| | | //如果它自己就是共通图片的话,不再处理
|
| | | return;
|
| | | }
|
| | | imageFilePath = "RealDevice/" + arry[0] + ".png";
|
| | | }
|
| | | btnIcon.UnSelectedImagePath = imageFilePath;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置【设备所属类型】的图标到指定的控件
|
| | | /// </summary>
|
| | | /// <param name="btnIcon">控件对象</param>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public void SetDeviceBeloneIconToControl(Button btnIcon, List<CommonDevice> listdevice)
|
| | | {
|
| | | //获取自定义设备类型
|
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
|
| | |
|
| | | string imageUnSelectFilePath = string.Empty;
|
| | | string imageSelectFilePath = string.Empty;
|
| | |
|
| | | //获取【设备所属类型】的图标
|
| | | this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath);
|
| | |
|
| | | //设置图片
|
| | | btnIcon.UnSelectedImagePath = imageUnSelectFilePath;
|
| | | btnIcon.SelectedImagePath = imageSelectFilePath;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取【设备所属类型】的图标
|
| | | /// </summary>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | /// <param name="unSelectPath">图片地址</param>
|
| | | /// <param name="selectPath">图片地址</param>
|
| | | /// <returns></returns>
|
| | | public void GetDeviceBeloneIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath)
|
| | | {
|
| | | //获取自定义设备类型
|
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
|
| | |
|
| | | //获取【设备所属类型】的图标
|
| | | this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取【设备所属类型】的图标
|
| | | /// </summary>
|
| | | /// <param name="specificType">自定义设备类型</param>
|
| | | /// <param name="unSelectPath">图片地址</param>
|
| | | /// <param name="selectPath">图片地址</param>
|
| | | /// <returns></returns>
|
| | | public void GetDeviceBeloneIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
|
| | | {
|
| | | //将具体类型转字符串
|
| | | string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
|
| | | string strType = strSpecific.Replace("_", string.Empty);
|
| | | //将类型转为图片地址
|
| | | string imageFilePath = "Device/" + strType + ".png";
|
| | | string imageSelectFilePath = "Device/" + strType + "Selected.png";
|
| | |
|
| | | //这个图片本地是否存在?
|
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
|
| | | {
|
| | | //不存在则使用共通图片
|
| | | string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None);
|
| | | if (arry.Length == 1)
|
| | | {
|
| | | //如果它自己就是共通图片的话,不再处理
|
| | | return;
|
| | | }
|
| | | imageFilePath = "Device/" + arry[0] + ".png";
|
| | | imageSelectFilePath = "Device/" + arry[0] + "Selected.png";
|
| | | }
|
| | | //设置图片
|
| | | unSelectPath = imageFilePath;
|
| | | selectPath = imageSelectFilePath;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设备UI相关_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备所匹配的设备UI对象
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public DeviceUI GetDeviceUI(CommonDevice device)
|
| | | {
|
| | | //创建一个新的东西给过去
|
| | | var deviceUi = new DeviceUI();
|
| | | deviceUi.DeviceAddr = device.DeviceAddr;
|
| | | deviceUi.DeviceEpoint = device.DeviceEpoint;
|
| | | return deviceUi;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备所匹配的设备UI对象
|
| | | /// </summary>
|
| | | /// <param name="filePath"></param>
|
| | | /// <returns></returns>
|
| | | public DeviceUI GetDeviceUI(string filePath)
|
| | | {
|
| | | string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | if (arry.Length != 5)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //创建一个新的东西给过去
|
| | | var deviceUi = new DeviceUI();
|
| | | deviceUi.DeviceAddr = arry[3];
|
| | | deviceUi.DeviceEpoint = Convert.ToInt32(arry[4]);
|
| | | return deviceUi;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取自定义的设备类型_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取【自定义的设备类型】,两种类型都设置了
|
| | | /// </summary>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public DeviceEnumInfo GetMyDeviceEnumInfo(List<CommonDevice> listdevice)
|
| | | {
|
| | | CommonDevice checkDevice = listdevice[0];
|
| | | foreach (var temp in listdevice)
|
| | | {
|
| | | //拿拥有模块ID的那个回路来判断
|
| | | if (temp.ModelIdentifier != string.Empty)
|
| | | {
|
| | | checkDevice = temp;
|
| | | }
|
| | | }
|
| | |
|
| | | //获取河东设备的设备类型
|
| | | DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(checkDevice);
|
| | | if (info != null)
|
| | | {
|
| | | return info;
|
| | | }
|
| | | //获取第三方设备的【设备类型】
|
| | | return this.GetNotHdlMyDeviceEnumInfo(listdevice);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备的【设备类型】的翻译文本(优先镜像)
|
| | | /// </summary>
|
| | | /// <param name="listDevice"></param>
|
| | | /// <param name="ApendFalge">第三方或者虚拟设备的时候,是否添加标识</param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceObjectText(List<CommonDevice> listDevice, bool ApendFalge = true)
|
| | | {
|
| | | CommonDevice checkDevice = listDevice[0];
|
| | | foreach (var temp in listDevice)
|
| | | {
|
| | | //拿拥有模块ID的那个回路来判断
|
| | | if (temp.ModelIdentifier != string.Empty)
|
| | | {
|
| | | checkDevice = temp;
|
| | | }
|
| | | }
|
| | |
|
| | | string strName = string.Empty;
|
| | | if (this.dicDeviceModelIdEnum.ContainsKey(checkDevice.ModelIdentifier) == true)
|
| | | {
|
| | | //根据模块ID,获取设备名字
|
| | | strName = this.GetNameByModelId(checkDevice);
|
| | | }
|
| | | else
|
| | | {
|
| | | //获取第三方设备的【设备类型】
|
| | | var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice);
|
| | | strName = Language.StringByID(myDeviceType.ConcreteTextId);
|
| | | }
|
| | | if (ApendFalge == true && listDevice[0].DriveCode > 0)
|
| | | {
|
| | | //虚拟设备加个标识
|
| | | strName += "✩";
|
| | | }
|
| | | else if (ApendFalge == true && this.IsHdlDevice(checkDevice) == false)
|
| | | {
|
| | | //第三方设备加个标识
|
| | | strName += "★";
|
| | | }
|
| | | return strName;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取河东设备的设备类型_____________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取Hdl设备的【自定义的设备类型】
|
| | | /// </summary>
|
| | | /// <param name="device">随便某一回路</param>
|
| | | /// <returns></returns>
|
| | | private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device)
|
| | | {
|
| | | //设备具体类型
|
| | | var info = new DeviceEnumInfo();
|
| | | info.IsHdlDevice = this.IsHdlDevice(device);
|
| | | if (device.ModelIdentifier == string.Empty)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | string modelKeys = device.ModelIdentifier;
|
| | | if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false)
|
| | | {
|
| | | //没有匹配到模块ID,则直接走第三方设备的判断
|
| | | return null;
|
| | | }
|
| | |
|
| | | string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | int ConcreteValue = Convert.ToInt32(strValue[0]);
|
| | | int BeloneValue = Convert.ToInt32(strValue[1]);
|
| | | //设置设备的【设备所属类型】
|
| | | info.BeloneType = (DeviceBeloneType)BeloneValue;
|
| | | if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + BeloneValue) == true)
|
| | | {
|
| | | //设备所属类型的翻译名字
|
| | | info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + BeloneValue];
|
| | | }
|
| | |
|
| | | //设备具体类型
|
| | | info.ConcreteType = (DeviceConcreteType)ConcreteValue;
|
| | | if (info.ConcreteType.ToString() == ConcreteValue.ToString())
|
| | | {
|
| | | info.ConcreteType = DeviceConcreteType.UnKownDevice;
|
| | | }
|
| | | return info;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取第三方设备的设备类型___________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取第三方设备的【设备类型】
|
| | | /// </summary>
|
| | | /// <param name="listdevice"></param>
|
| | | /// <returns></returns>
|
| | | public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice)
|
| | | {
|
| | | var dicType = new Dictionary<DeviceType, CommonDevice>();
|
| | | foreach (CommonDevice device in listdevice)
|
| | | {
|
| | | if (dicType.ContainsKey(device.Type) == false)
|
| | | {
|
| | | dicType[device.Type] = device;
|
| | | }
|
| | | }
|
| | | var info = new DeviceEnumInfo();
|
| | | info.IsHdlDevice = false;
|
| | | //1包含面板的话,当面板处理
|
| | | if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
|
| | | info.BeloneType = DeviceBeloneType.A按键面板;
|
| | | info.ConcreteType = DeviceConcreteType.ButtonPanel;
|
| | | }
|
| | | //3包含窗帘的话,当窗帘处理
|
| | | else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId100;
|
| | | info.BeloneType = DeviceBeloneType.A窗帘;
|
| | | info.ConcreteType = DeviceConcreteType.Curtain;
|
| | | }
|
| | | //4空气开关
|
| | | else if (dicType.ContainsKey(DeviceType.AirSwitch) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100;
|
| | | info.BeloneType = DeviceBeloneType.A空气开关;
|
| | | info.ConcreteType = DeviceConcreteType.AirSwitch;
|
| | | }
|
| | | //5继电器
|
| | | else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300;
|
| | | info.BeloneType = DeviceBeloneType.A继电器;
|
| | | info.ConcreteType = DeviceConcreteType.Relay;
|
| | | }
|
| | | //6调光器
|
| | | else if (dicType.ContainsKey(DeviceType.DimmableLight) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2500;
|
| | | info.BeloneType = DeviceBeloneType.A调光器;
|
| | | info.ConcreteType = DeviceConcreteType.DimmableLight;
|
| | | }
|
| | | //7彩灯
|
| | | else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9;
|
| | | info.BeloneType = DeviceBeloneType.A彩灯;
|
| | | info.ConcreteType = DeviceConcreteType.ColorDimmableLight;
|
| | | }
|
| | | //8空调
|
| | | else if (dicType.ContainsKey(DeviceType.Thermostat) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3600;
|
| | | info.BeloneType = DeviceBeloneType.A空调;
|
| | | info.ConcreteType = DeviceConcreteType.AirConditioner;
|
| | | }
|
| | | //9中继器
|
| | | else if (dicType.ContainsKey(DeviceType.Repeater) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3900;
|
| | | info.BeloneType = DeviceBeloneType.A中继器;
|
| | | info.ConcreteType = DeviceConcreteType.Repeater;
|
| | | }
|
| | | //10转换器
|
| | | else if (dicType.ContainsKey(DeviceType.Transverter) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4200;
|
| | | info.BeloneType = DeviceBeloneType.A转换器;
|
| | | info.ConcreteType = DeviceConcreteType.Converter;
|
| | | }
|
| | | //11智能门锁
|
| | | else if (dicType.ContainsKey(DeviceType.DoorLock) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2800;
|
| | | info.BeloneType = DeviceBeloneType.A智能门锁;
|
| | | info.ConcreteType = DeviceConcreteType.IntelligentLocks;
|
| | | }
|
| | | //2包含传感器的话,当传感器处理
|
| | | else if (dicType.ContainsKey(DeviceType.IASZone) == true)
|
| | | {
|
| | | //设置传感器具体的类型
|
| | | info.BeloneType = DeviceBeloneType.A传感器;
|
| | | this.SetSensorDeviceSpecificType(ref info, listdevice);
|
| | | }
|
| | | int value = (int)info.BeloneType;
|
| | | if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true)
|
| | | {
|
| | | //设备所属类型的翻译名字
|
| | | info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value];
|
| | | }
|
| | |
|
| | | return info;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 传感器具体的类型___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置传感器具体的类型
|
| | | /// </summary>
|
| | | /// <param name="info">自定义设备枚举信息</param>
|
| | | /// <param name="listdevice">设备对象</param>
|
| | | private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice)
|
| | | {
|
| | | //默认名字:传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
|
| | |
|
| | | //如果这个设备拥有多个回路的话,我也不知道怎么命名,只能给个默认名字
|
| | | if (listdevice.Count > 1)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var iasZone = (IASZone)listdevice[0];
|
| | | if (iasZone.IasDeviceType == 13)
|
| | | {
|
| | | //运动传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_Motion;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uMotionSensor;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 40)
|
| | | {
|
| | | //烟雾传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_Fire;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1302;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 42)
|
| | | {
|
| | | //水侵传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_Water;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1304;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 43)
|
| | | {
|
| | | //燃气传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_CarbonMonoxide;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1300;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 44)
|
| | | {
|
| | | //紧急按钮
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_EmergencyButton;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1305;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 277)
|
| | | {
|
| | | //钥匙扣
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_Keyfob;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uKeyfob;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22)
|
| | | {
|
| | | //门窗传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设备排序___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设备排序
|
| | | /// </summary>
|
| | | /// <param name="listDevice">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice)
|
| | | {
|
| | | List<CommonDevice> listSort = new List<CommonDevice>();
|
| | | var list = this.SortDeviceListByRule(listDevice);
|
| | | listSort.AddRange(list);
|
| | |
|
| | | return listSort;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// |
| | | /// </summary>
|
| | | /// <param name="listDevice">设备对象</param>
|
| | | /// <returns></returns>
|
| | | private List<CommonDevice> SortDeviceListByRule(List<CommonDevice> listDevice)
|
| | | {
|
| | | //设备排序的规则(Keys:设备类型(DeviceType) value:存放设备的容器)
|
| | | var dic = this.GetDeviceSortRule();
|
| | | foreach (CommonDevice device in listDevice)
|
| | | {
|
| | | if (device is IASZone)
|
| | | {
|
| | | //传感器有很多种
|
| | | var strType = ((IASZone)device).DeviceInfo.DeviceType.ToString();
|
| | | if (dic.ContainsKey(strType) == false || dic[strType] == null)
|
| | | {
|
| | | dic[strType] = new List<CommonDevice>();
|
| | | }
|
| | | dic[strType].Add(device);
|
| | | continue;
|
| | | }
|
| | | string checkKeys = device.Type.ToString();
|
| | | if (dic.ContainsKey(checkKeys) == false || dic[checkKeys] == null)
|
| | | {
|
| | | dic[checkKeys] = new List<CommonDevice>();
|
| | | }
|
| | | dic[checkKeys].Add(device);
|
| | | }
|
| | |
|
| | | List<CommonDevice> lstSort = new List<CommonDevice>();
|
| | | foreach (var list in dic.Values)
|
| | | {
|
| | | if (list != null && list.Count > 0)
|
| | | {
|
| | | lstSort.AddRange(list);
|
| | | }
|
| | | }
|
| | | return lstSort;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备排序的规则(Keys:设备类型(DeviceType) value:存放设备的容器)
|
| | | /// </summary>
|
| | | /// <returns></returns> |
| | | public string AppendVersion(int versionValue) |
| | | { |
| | | //转为16进制 |
| | | string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0'); |
| | | //这个是小数点前面的值 |
| | | int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16); |
| | | //这个是小数点后面的值 |
| | | int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16); |
| | | |
| | | //Ver. |
| | | string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); |
| | | return ver + value1 + "." + value2.ToString().PadLeft(3, '0'); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取OTA设备(200端口的) |
| | | /// </summary> |
| | | /// <param name="macAdrr"></param> |
| | | /// <returns></returns> |
| | | public OTADevice GetOTADevice(string macAdrr) |
| | | { |
| | | string mainkeys = this.GetDeviceMainKeys(macAdrr, 200); |
| | | if (this.dicOTADevice.ContainsKey(mainkeys) == false) |
| | | { |
| | | return null; |
| | | } |
| | | return this.dicOTADevice[mainkeys]; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设备镜像(私有类型)_________________ |
| | | |
| | | /// <summary> |
| | | /// OTA设备获取镜像后的回调函数 |
| | | /// </summary> |
| | | private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicOtaBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>(); |
| | | |
| | | /// <summary> |
| | | /// 设置设备全部的镜像信息(反复调用请使用【DeviceAttributeLogic.Current.SetFirmwareVersionComand】函数) |
| | | /// </summary> |
| | | /// <param name="tADevice"></param> |
| | | /// <param name="backAction"></param> |
| | | public void SetAllImageInfoToOtaDevice(OTADevice tADevice, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null) |
| | | { |
| | | if (tADevice == null) |
| | | { |
| | | return; |
| | | } |
| | | lock (objLock) |
| | | { |
| | | if (backAction != null) |
| | | { |
| | | this.dicOtaBackAction[tADevice.DeviceAddr] = backAction; |
| | | } |
| | | //设置设备的固件版本号(需要等待推送后才会更改) |
| | | this.SetFirmwareVersionToOtaDevice(tADevice); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置设备的固件版本号(需要等待推送后才会更改) |
| | | /// </summary> |
| | | /// <param name="tADevice"></param> |
| | | private void SetFirmwareVersionToOtaDevice(OTADevice tADevice) |
| | | { |
| | | if (DeviceAttributeLogic.Current.IsEsixt("DeviceAutoGetFirmwareVersion") == false) |
| | | { |
| | | //添加事件 |
| | | DeviceAttributeLogic.Current.AddFirmwareVersionEvent("DeviceAutoGetFirmwareVersion", this.SetFirmwareVersionByInterfaceResult); |
| | | } |
| | | //发送命令 |
| | | DeviceAttributeLogic.Current.SetFirmwareVersionComand(tADevice); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据接口推送的信息,设置固件版本号 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | private void SetFirmwareVersionByInterfaceResult(CommonDevice device) |
| | | { |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | if (this.dicOTADevice.ContainsKey(mainKeys) == false) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //设置固件版本信息 |
| | | DeviceAttributeLogic.Current.SetFirmwareVersion(device.DeviceStatusReport, this.dicOTADevice[mainKeys]); |
| | | this.dicOTADevice[mainKeys].ReSave(); |
| | | |
| | | lock (objLock) |
| | | { |
| | | if (this.dicOtaBackAction.ContainsKey(device.DeviceAddr) == true) |
| | | { |
| | | //调用回调函数 |
| | | this.dicOtaBackAction[device.DeviceAddr](device, device.DeviceStatusReport); |
| | | //然后移除 |
| | | this.dicOtaBackAction.Remove(device.DeviceAddr); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 读取以及设置设备硬件信息___________ |
| | | |
| | | /// <summary> |
| | | /// 设备获取硬件信息后的回调函数 |
| | | /// </summary> |
| | | private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicDeviceHardInfoBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>(); |
| | | /// 获取硬件信息的对象设备 |
| | | /// </summary> |
| | | private HashSet<string> hsGetHardInfoDevice = new HashSet<string>(); |
| | | |
| | | /// <summary> |
| | | /// 读取以及设置设备硬件信息 |
| | | /// </summary> |
| | | /// <param name="device">设备回路</param> |
| | | /// <param name="Reset">是否重置(不重置的情况时,如果已经有值了,则不再获取)</param> |
| | | /// <param name="backAction">回调函数</param> |
| | | public void SetAllHardFirmwareInfoToDevice(CommonDevice device, bool Reset = false, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null) |
| | | { |
| | | if (device == null) |
| | | { |
| | | return; |
| | | } |
| | | if (Reset == false) |
| | | { |
| | | if (device.ModelIdentifier != string.Empty) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | lock (objLock) |
| | | { |
| | | string mainkeys = this.GetDeviceMainKeys(device); |
| | | this.hsGetHardInfoDevice.Add(mainkeys); |
| | | |
| | | if (backAction != null) |
| | | { |
| | | this.dicDeviceHardInfoBackAction[mainkeys] = backAction; |
| | | } |
| | | //设置设备的硬件信息(需要等待推送后才会更改) |
| | | this.SetHardFirmwareInfoToDevice(device); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置设备的硬件信息(需要等待推送后才会更改) |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | private void SetHardFirmwareInfoToDevice(CommonDevice device) |
| | | { |
| | | if (DeviceAttributeLogic.Current.IsEsixt("DeviceGetHardFirmwareInfo") == false) |
| | | { |
| | | //添加事件 |
| | | DeviceAttributeLogic.Current.AddFirmwareVersionEvent("DeviceGetHardFirmwareInfo", this.SetHardFirmwareInfoByInterfaceResult); |
| | | } |
| | | //发送命令 |
| | | DeviceAttributeLogic.Current.SetHardFirmwareInfoComand(device); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据接口推送的信息,设置设备硬件信息 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | private void SetHardFirmwareInfoByInterfaceResult(CommonDevice device) |
| | | { |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == false) |
| | | { |
| | | return; |
| | | } |
| | | //设置设备硬件信息 |
| | | var localDevice = this.GetDevice(mainKeys); |
| | | if (localDevice == null) |
| | | { |
| | | return; |
| | | } |
| | | lock (objLock) |
| | | { |
| | | DeviceAttributeLogic.Current.SetHardFirmwareInfo(device.DeviceStatusReport, localDevice); |
| | | localDevice.ReSave(); |
| | | |
| | | this.hsGetHardInfoDevice.Remove(mainKeys); |
| | | if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true) |
| | | { |
| | | //调用回调函数 |
| | | this.dicDeviceHardInfoBackAction[mainKeys](device, device.DeviceStatusReport); |
| | | //然后移除 |
| | | this.dicDeviceHardInfoBackAction.Remove(mainKeys); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除获取设备硬件信息的监听线程 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | public void RemoveDeviceHardInfoThread(CommonDevice device) |
| | | { |
| | | lock (objLock) |
| | | { |
| | | string mainKeys = this.GetDeviceMainKeys(device); |
| | | this.hsGetHardInfoDevice.Remove(mainKeys); |
| | | if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true) |
| | | { |
| | | //然后移除 |
| | | this.dicDeviceHardInfoBackAction.Remove(mainKeys); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设置图标___________________________ |
| | | |
| | | /// <summary> |
| | | /// 变更设备的图标 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="unSelPath">图片地址(非选择)</param> |
| | | public void ChangedDeviceIcon(CommonDevice device, string unSelPath) |
| | | { |
| | | if (unSelPath == string.Empty) |
| | | { |
| | | return; |
| | | } |
| | | DeviceUI deviceUI = this.GetDeviceUI(device); |
| | | deviceUI.IconPath = unSelPath; |
| | | deviceUI.IsCustomizeImage = true; |
| | | deviceUI.ReSave(); |
| | | |
| | | HdlAutoBackupLogic.AddOrEditorFile(deviceUI.FileName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置设备【图标】到指定的控件 |
| | | /// </summary> |
| | | /// <param name="btnIcon">控件对象</param> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public void SetDeviceIconToControl(ButtonCommon btnIcon, CommonDevice device) |
| | | { |
| | | //获取这个设备的UI文件 |
| | | DeviceUI deviceUI = this.GetDeviceUI(device); |
| | | if (deviceUI == null) |
| | | { |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(deviceUI.IconPath) == true) |
| | | { |
| | | return; |
| | | } |
| | | btnIcon.UnSelectedImagePath = deviceUI.IconPath; |
| | | |
| | | string selPath = deviceUI.OnlineIconPath; |
| | | if (string.IsNullOrEmpty(selPath) == false) |
| | | { |
| | | btnIcon.SelectedImagePath = selPath; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置设备的【大图标】到指定的控件 |
| | | /// </summary> |
| | | /// <param name="btnIcon">控件对象</param> |
| | | /// <param name="device">设备对象</param> |
| | | public void SetDeviceBigIconToControl(ButtonCommon btnIcon, CommonDevice device) |
| | | { |
| | | //获取这个设备的UI文件 |
| | | DeviceUI deviceUI = this.GetDeviceUI(device); |
| | | if (deviceUI == null) |
| | | { |
| | | return; |
| | | } |
| | | string deviceIcon = deviceUI.OnlineIconPath; |
| | | if (string.IsNullOrEmpty(deviceIcon) == true) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //按键面板的回路图标 |
| | | if (deviceIcon == "Device/DryContactSelected.png") |
| | | { |
| | | //因为按键面板是一个点,所以需要特殊处理 |
| | | this.SetDeviceBeloneIconToControl(btnIcon, new List<CommonDevice>() { device }); |
| | | btnIcon.UnSelectedImagePath = btnIcon.SelectedImagePath; |
| | | btnIcon.SelectedImagePath = null; |
| | | } |
| | | else |
| | | { |
| | | //这里是自定义图标 |
| | | btnIcon.UnSelectedImagePath = deviceIcon; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置设备的真实图片到指定的控件 |
| | | /// </summary> |
| | | /// <param name="btnIcon">控件对象</param> |
| | | /// <param name="listdevice">设备对象</param> |
| | | public void SetRealDeviceIconToControl(ButtonCommon btnIcon, List<CommonDevice> listdevice) |
| | | { |
| | | //获取它属于什么类型的设备 |
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); |
| | | string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); |
| | | string strType = strConcrete.Replace("_", string.Empty); |
| | | //将类型转为图片地址 |
| | | string imageFilePath = "RealDevice/" + strType + ".png"; |
| | | //这个图片本地是否存在? |
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) |
| | | { |
| | | //不存在则使用共通图片 |
| | | string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None); |
| | | if (arry.Length == 1) |
| | | { |
| | | //如果它自己就是共通图片的话,不再处理 |
| | | return; |
| | | } |
| | | imageFilePath = "RealDevice/" + arry[1] + ".png"; |
| | | } |
| | | btnIcon.UnSelectedImagePath = imageFilePath; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置【设备所属类型】的图标到指定的控件 |
| | | /// </summary> |
| | | /// <param name="btnIcon">控件对象</param> |
| | | /// <param name="listdevice">设备对象</param> |
| | | /// <returns></returns> |
| | | public void SetDeviceBeloneIconToControl(ButtonCommon btnIcon, List<CommonDevice> listdevice) |
| | | { |
| | | //获取自定义设备类型 |
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); |
| | | |
| | | string imageUnSelectFilePath = string.Empty; |
| | | string imageSelectFilePath = string.Empty; |
| | | |
| | | //获取【设备所属类型】的图标 |
| | | this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); |
| | | |
| | | //设置图片 |
| | | btnIcon.UnSelectedImagePath = imageUnSelectFilePath; |
| | | btnIcon.SelectedImagePath = imageSelectFilePath; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取【设备所属类型】的图标 |
| | | /// </summary> |
| | | /// <param name="listdevice">设备对象</param> |
| | | /// <param name="unSelectPath">图片地址</param> |
| | | /// <param name="selectPath">图片地址</param> |
| | | /// <returns></returns> |
| | | public void GetDeviceBeloneIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) |
| | | { |
| | | //获取自定义设备类型 |
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); |
| | | |
| | | //获取【设备所属类型】的图标 |
| | | this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取【设备所属类型】的图标 |
| | | /// </summary> |
| | | /// <param name="specificType">自定义设备类型</param> |
| | | /// <param name="unSelectPath">图片地址</param> |
| | | /// <param name="selectPath">图片地址</param> |
| | | /// <returns></returns> |
| | | private void GetDeviceBeloneIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) |
| | | { |
| | | //将具体类型转字符串 |
| | | string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType); |
| | | string strType = strSpecific.Replace("_", string.Empty); |
| | | //将类型转为图片地址 |
| | | string imageFilePath = "Device/" + strType + ".png"; |
| | | string imageSelectFilePath = "Device/" + strType + "Selected.png"; |
| | | |
| | | //这个图片本地是否存在? |
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) |
| | | { |
| | | //不存在则使用共通图片 |
| | | string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None); |
| | | if (arry.Length == 1) |
| | | { |
| | | //如果它自己就是共通图片的话,不再处理 |
| | | return; |
| | | } |
| | | imageFilePath = "Device/" + arry[1] + ".png"; |
| | | imageSelectFilePath = "Device/" + arry[1] + "Selected.png"; |
| | | } |
| | | //设置图片 |
| | | unSelectPath = imageFilePath; |
| | | selectPath = imageSelectFilePath; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设备UI相关_________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取设备所匹配的设备UI对象 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public DeviceUI GetDeviceUI(CommonDevice device) |
| | | { |
| | | return this.GetDeviceUI("DeviceUI_" + device.FilePath); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备所匹配的设备UI对象 |
| | | /// </summary> |
| | | /// <param name="filePath"></param> |
| | | /// <returns></returns> |
| | | public DeviceUI GetDeviceUI(string filePath) |
| | | { |
| | | if (this.dicAllDeviceUI.ContainsKey(filePath) == true) |
| | | { |
| | | return this.dicAllDeviceUI[filePath]; |
| | | } |
| | | |
| | | var deviceUi = new DeviceUI(); |
| | | deviceUi.DeviceFileName = filePath.Replace("DeviceUI_", string.Empty); |
| | | deviceUi.ReSave(); |
| | | this.dicAllDeviceUI[filePath] = deviceUi; |
| | | return deviceUi; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从文件中获取指定设备的UI对象(有可能返回null) |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | private DeviceUI GetDeviceUIFromLocalFile(CommonDevice device) |
| | | { |
| | | DeviceUI deviceUI = new DeviceUI(); |
| | | deviceUI.DeviceFileName = device.FilePath; |
| | | |
| | | if (Global.IsExistsByHomeId(deviceUI.FileName) == false) |
| | | { |
| | | return null; |
| | | } |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUI.FileName)); |
| | | var tempCommon = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); |
| | | return tempCommon; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取自定义的设备类型_______________ |
| | | |
| | | /// <summary> |
| | | /// 获取【自定义的设备类型】,两种类型都设置了 |
| | | /// </summary> |
| | | /// <param name="listdevice">设备对象</param> |
| | | /// <returns></returns> |
| | | public DeviceEnumInfo GetMyDeviceEnumInfo(List<CommonDevice> listdevice) |
| | | { |
| | | //获取河东设备的设备类型 |
| | | DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(listdevice[0]); |
| | | if (info != null) |
| | | { |
| | | return info; |
| | | } |
| | | //获取第三方设备的【设备类型】 |
| | | return this.GetNotHdlMyDeviceEnumInfo(listdevice); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备的【设备类型】的翻译文本(优先镜像) |
| | | /// </summary> |
| | | /// <param name="listDevice"></param> |
| | | /// <param name="ApendFalge">第三方或者虚拟设备的时候,是否添加标识</param> |
| | | /// <returns></returns> |
| | | public string GetDeviceObjectText(List<CommonDevice> listDevice, bool ApendFalge = true) |
| | | { |
| | | string strName = string.Empty; |
| | | if (this.dicDeviceModelIdEnum.ContainsKey(listDevice[0].ModelIdentifier) == true) |
| | | { |
| | | //根据模块ID,获取设备名字 |
| | | strName = this.GetNameByModelId(listDevice[0]); |
| | | } |
| | | else |
| | | { |
| | | //获取第三方设备的【设备类型】 |
| | | var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice); |
| | | strName = Language.StringByID(myDeviceType.TextId); |
| | | } |
| | | if (ApendFalge == true && listDevice[0].DriveCode > 0) |
| | | { |
| | | //虚拟设备加个标识 |
| | | strName += "✩"; |
| | | } |
| | | else if (ApendFalge == true && this.IsHdlDevice(listDevice[0]) == false) |
| | | { |
| | | //第三方设备加个标识 |
| | | strName += "★"; |
| | | } |
| | | return strName; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取河东设备的设备类型_____________ |
| | | |
| | | /// <summary> |
| | | /// 获取Hdl设备的【自定义的设备类型】 |
| | | /// </summary> |
| | | /// <param name="device">随便某一回路</param> |
| | | /// <returns></returns> |
| | | private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device) |
| | | { |
| | | //设备具体类型 |
| | | var info = new DeviceEnumInfo(); |
| | | info.IsHdlDevice = this.IsHdlDevice(device); |
| | | if (device.ModelIdentifier == string.Empty) |
| | | { |
| | | return null; |
| | | } |
| | | string modelKeys = device.ModelIdentifier; |
| | | if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) |
| | | { |
| | | //没有匹配到模块ID,则直接走第三方设备的判断 |
| | | return null; |
| | | } |
| | | |
| | | string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); |
| | | int ConcreteValue = Convert.ToInt32(strValue[0]); |
| | | int BeloneValue = Convert.ToInt32(strValue[1]); |
| | | |
| | | //设备具体类型 |
| | | info.ConcreteType = (DeviceConcreteType)ConcreteValue; |
| | | if (info.ConcreteType.ToString() == ConcreteValue.ToString()) |
| | | { |
| | | info.ConcreteType = DeviceConcreteType.UnKownDevice; |
| | | return info; |
| | | } |
| | | |
| | | //设置设备的【设备所属类型】 |
| | | info.BeloneType = (DeviceBeloneType)BeloneValue; |
| | | |
| | | return info; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取第三方设备的设备类型___________ |
| | | |
| | | /// <summary> |
| | | /// 获取第三方设备的【设备类型】 |
| | | /// </summary> |
| | | /// <param name="listdevice"></param> |
| | | /// <returns></returns> |
| | | private DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice) |
| | | { |
| | | var dicType = new Dictionary<DeviceType, CommonDevice>(); |
| | | foreach (CommonDevice device in listdevice) |
| | | { |
| | | if (dicType.ContainsKey(device.Type) == false) |
| | | { |
| | | dicType[device.Type] = device; |
| | | } |
| | | } |
| | | var info = new DeviceEnumInfo(); |
| | | info.IsHdlDevice = false; |
| | | //1包含面板的话,当面板处理 |
| | | if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uButtonControl; |
| | | info.BeloneType = DeviceBeloneType.A按键面板; |
| | | info.ConcreteType = DeviceConcreteType.ButtonPanel; |
| | | } |
| | | //2包含传感器的话,当传感器处理 |
| | | else if (dicType.ContainsKey(DeviceType.IASZone) == true) |
| | | { |
| | | //设置传感器具体的类型 |
| | | info.BeloneType = DeviceBeloneType.A传感器; |
| | | this.SetSensorDeviceSpecificType(ref info, listdevice); |
| | | } |
| | | //3包含窗帘的话,当窗帘处理 |
| | | else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uCurtain; |
| | | info.BeloneType = DeviceBeloneType.A窗帘; |
| | | info.ConcreteType = DeviceConcreteType.Curtain; |
| | | } |
| | | //4空气开关 |
| | | else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uAirSwitch; |
| | | info.BeloneType = DeviceBeloneType.A空气开关; |
| | | info.ConcreteType = DeviceConcreteType.AirSwitch; |
| | | } |
| | | //5继电器 |
| | | else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uRelay; |
| | | info.BeloneType = DeviceBeloneType.A继电器; |
| | | info.ConcreteType = DeviceConcreteType.Relay; |
| | | } |
| | | //6调光器 |
| | | else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uDimmableLight; |
| | | info.BeloneType = DeviceBeloneType.A调光器; |
| | | info.ConcreteType = DeviceConcreteType.DimmableLight; |
| | | } |
| | | //7彩灯 |
| | | else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uColorDimmableLight; |
| | | info.BeloneType = DeviceBeloneType.A彩灯; |
| | | info.ConcreteType = DeviceConcreteType.ColorDimmableLight; |
| | | } |
| | | //8空调 |
| | | else if (dicType.ContainsKey(DeviceType.Thermostat) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.Thermostat; |
| | | info.BeloneType = DeviceBeloneType.A空调; |
| | | info.ConcreteType = DeviceConcreteType.AirConditioner; |
| | | } |
| | | //9中继器 |
| | | else if (dicType.ContainsKey(DeviceType.Repeater) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.Repeater; |
| | | info.BeloneType = DeviceBeloneType.A中继器; |
| | | info.ConcreteType = DeviceConcreteType.Repeater; |
| | | } |
| | | //10转换器 |
| | | else if (dicType.ContainsKey(DeviceType.Transverter) == true) |
| | | { |
| | | info.TextId = R.MyInternationalizationString.uConverter; |
| | | info.BeloneType = DeviceBeloneType.A转换器; |
| | | info.ConcreteType = DeviceConcreteType.Converter; |
| | | } |
| | | return info; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 传感器具体的类型___________________ |
| | | |
| | | /// <summary> |
| | | /// 设置传感器具体的类型 |
| | | /// </summary> |
| | | /// <param name="info">自定义设备枚举信息</param> |
| | | /// <param name="listdevice">设备对象</param> |
| | | private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice) |
| | | { |
| | | //默认名字:传感器 |
| | | info.ConcreteType = DeviceConcreteType.Sensor; |
| | | info.TextId = R.MyInternationalizationString.uSensor; |
| | | |
| | | //如果这个设备拥有多个回路的话,我也不知道怎么命名,只能给个默认名字 |
| | | if (listdevice.Count > 1) |
| | | { |
| | | return; |
| | | } |
| | | var iasZone = (IASZone)listdevice[0]; |
| | | if (iasZone.IasDeviceType == 13) |
| | | { |
| | | //运动传感器 |
| | | info.ConcreteType = DeviceConcreteType.Motion_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uMotionSensor; |
| | | } |
| | | else if (iasZone.IasDeviceType == 40) |
| | | { |
| | | //烟雾传感器 |
| | | info.ConcreteType = DeviceConcreteType.Fire_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uDeviceDefultName1302; |
| | | } |
| | | else if (iasZone.IasDeviceType == 42) |
| | | { |
| | | //水侵传感器 |
| | | info.ConcreteType = DeviceConcreteType.Water_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uDeviceDefultName1304; |
| | | } |
| | | else if (iasZone.IasDeviceType == 43) |
| | | { |
| | | //燃气传感器 |
| | | info.ConcreteType = DeviceConcreteType.CarbonMonoxide_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uDeviceDefultName1300; |
| | | } |
| | | else if (iasZone.IasDeviceType == 44) |
| | | { |
| | | //紧急按钮 |
| | | info.ConcreteType = DeviceConcreteType.EmergencyButton_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uDeviceDefultName1305; |
| | | } |
| | | else if (iasZone.IasDeviceType == 277) |
| | | { |
| | | //钥匙扣 |
| | | info.ConcreteType = DeviceConcreteType.Keyfob_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uKeyfob; |
| | | } |
| | | else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22) |
| | | { |
| | | //门窗传感器 |
| | | info.ConcreteType = DeviceConcreteType.DoorWindowSensor_Sensor; |
| | | info.TextId = R.MyInternationalizationString.uDeviceDefultName1301; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取设备名称_______________________ |
| | | |
| | | /// <summary> |
| | | /// 获取设备端点的名称(有特效) |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public string GetDeviceEpointName(CommonDevice device) |
| | | { |
| | | string dName = this.GetSimpleEpointName(device); |
| | | if (string.IsNullOrEmpty(dName) == false) |
| | | { |
| | | return dName; |
| | | } |
| | | //根据设备类型获取名称 |
| | | dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); |
| | | //如果是虚拟设备 |
| | | if (device.DriveCode > 0 |
| | | || (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == true && this.dicDeviceCount[device.DeviceAddr].Count > 1)) |
| | | { |
| | | var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); |
| | | dName = arry[0].Trim(); |
| | | //在端点名字的后面附加【回路】字样 |
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; |
| | | } |
| | | return dName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备MAC名称 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public string GetDeviceMacName(CommonDevice device) |
| | | { |
| | | string dName = this.GetSimpleMacName(device); |
| | | if (string.IsNullOrEmpty(dName) == false) |
| | | { |
| | | return dName; |
| | | } |
| | | |
| | | //是否拥有配置的模块ID |
| | | if (this.dicDeviceModelIdEnum.ContainsKey(device.ModelIdentifier) == true) |
| | | { |
| | | //获取模块ID名字 |
| | | return this.GetNameByModelId(device); |
| | | } |
| | | else |
| | | { |
| | | //获取第三方设备的翻译名字 |
| | | var myDeviceType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); |
| | | return Language.StringByID(myDeviceType.TextId); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 在端点名字的后面附加【回路】字样,返回格式:XXXX(NN回路),如果没有名字,则返回:NN回路 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public string AppendRoadTextToEpointName(CommonDevice device) |
| | | { |
| | | string pName = this.GetSimpleEpointName(device); |
| | | //回路 |
| | | string txtValue = Language.StringByID(R.MyInternationalizationString.uDeviceCircuit); |
| | | if (string.IsNullOrEmpty(pName) == true) |
| | | { |
| | | //NN回路 |
| | | return device.DeviceEpoint + txtValue; |
| | | } |
| | | else if (pName.Trim().EndsWith(txtValue) == true) |
| | | { |
| | | return pName; |
| | | } |
| | | //XXXX(NN回路) |
| | | return pName + "(" + device.DeviceEpoint + txtValue + ")"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据模块ID,获取翻译名字 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public string GetNameByModelId(CommonDevice device) |
| | | { |
| | | if (device.ModelIdentifier == string.Empty) |
| | | { |
| | | //未知设备 |
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice); |
| | | } |
| | | |
| | | string modelKeys = device.ModelIdentifier; |
| | | if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) |
| | | { |
| | | //未知设备 |
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice); |
| | | } |
| | | |
| | | string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); |
| | | int ConcreteValue = Convert.ToInt32(strValue[0]); |
| | | |
| | | string keyName = deviceDefultNameFlag + ConcreteValue; |
| | | if (this.dicDeviceDefultNameID.ContainsKey(keyName) == true) |
| | | { |
| | | //R文件里面设置的名字 |
| | | return Language.StringByID(this.dicDeviceDefultNameID[keyName]); |
| | | } |
| | | |
| | | //未知设备 |
| | | return Language.StringByID(R.MyInternationalizationString.UnknowDevice); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 非公开,设置设备的Mac名字(此方法只是单存的变更缓存) |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="macName">Mac名字</param> |
| | | /// <returns></returns> |
| | | private void SetMacName(CommonDevice device, string macName) |
| | | { |
| | | device.DeviceName = macName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 非公开,设置设备的端点名字(此方法只是单存的变更缓存) |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="epointName">端点名字</param> |
| | | /// <returns></returns> |
| | | private void SetEpointName(CommonDevice device, string epointName) |
| | | { |
| | | device.DeviceEpointName = epointName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 单纯获取设备的Mac名字 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public string GetSimpleMacName(CommonDevice device) |
| | | { |
| | | return device.DeviceName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 单纯获取设备的端点名字 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <returns></returns> |
| | | public string GetSimpleEpointName(CommonDevice device) |
| | | { |
| | | return device.DeviceEpointName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化R文件里面设备默认名字的ID |
| | | /// </summary> |
| | | private void InitDeviceDefultNameIDList() |
| | | { |
| | | if (this.dicDeviceDefultNameID != null) |
| | | { |
| | | return; |
| | | } |
| | | this.dicDeviceDefultNameID = new Dictionary<string, int>(); |
| | | Type type = typeof(R.MyInternationalizationString); |
| | | |
| | | var PropertyList = type.GetFields(); |
| | | foreach (var item in PropertyList) |
| | | { |
| | | if (item.Name.StartsWith(deviceDefultNameFlag) == true) |
| | | { |
| | | this.dicDeviceDefultNameID[item.Name] = Convert.ToInt32(item.GetValue(null)); |
| | | } |
| | | } |
| | | |
| | | //初始化设备枚举 |
| | | this.InitDeviceModelIdEnum(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设备排序___________________________ |
| | | |
| | | /// <summary> |
| | | /// 设备排序 |
| | | /// </summary> |
| | | /// <param name="listDevice">设备对象</param> |
| | | /// <returns></returns> |
| | | public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice) |
| | | { |
| | | List<CommonDevice> listSort = new List<CommonDevice>(); |
| | | var list = this.SortDeviceListByRule(listDevice); |
| | | listSort.AddRange(list); |
| | | |
| | | return listSort; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="listDevice">设备对象</param> |
| | | /// <returns></returns> |
| | | private List<CommonDevice> SortDeviceListByRule(List<CommonDevice> listDevice) |
| | | { |
| | | //设备排序的规则(Keys:设备类型(DeviceType) value:存放设备的容器) |
| | | var dic = this.GetDeviceSortRule(); |
| | | dic["对象外"] = new List<CommonDevice>(); |
| | | foreach (CommonDevice device in listDevice) |
| | | { |
| | | if (device is IASZone) |
| | | { |
| | | var iasZone = (IASZone)device; |
| | | //运动传感器 |
| | | if (iasZone.DeviceInfo.DeviceType == 13) |
| | | { |
| | | dic["运动传感器"].Add(device); |
| | | } |
| | | //一氧化碳传感器 |
| | | else if (iasZone.DeviceInfo.DeviceType == 43) |
| | | { |
| | | dic["一氧化碳传感器"].Add(device); |
| | | } |
| | | //紧急按钮 |
| | | else if (iasZone.DeviceInfo.DeviceType == 44) |
| | | { |
| | | dic["紧急按钮"].Add(device); |
| | | } |
| | | else |
| | | { |
| | | dic[DeviceType.IASZone.ToString()].Add(device); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | string checkKeys = device.Type.ToString(); |
| | | if (dic.ContainsKey(checkKeys) == true) |
| | | { |
| | | dic[checkKeys].Add(device); |
| | | } |
| | | else |
| | | { |
| | | dic["对象外"].Add(device); |
| | | } |
| | | } |
| | | List<CommonDevice> lstSort = new List<CommonDevice>(); |
| | | foreach (var list in dic.Values) |
| | | { |
| | | lstSort.AddRange(list); |
| | | } |
| | | return lstSort; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备排序的规则(Keys:设备类型(DeviceType) value:存放设备的容器) |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private Dictionary<string, List<CommonDevice>> GetDeviceSortRule() |
| | | { |
| | | var dic = new Dictionary<string, List<CommonDevice>>(); |
| | | //一氧化碳传感器 |
| | | dic["一氧化碳传感器"] = new List<CommonDevice>(); |
| | | //紧急按钮 |
| | | dic["紧急按钮"] = new List<CommonDevice>(); |
| | | //运动传感器 |
| | | dic["运动传感器"] = new List<CommonDevice>(); |
| | | //传感器 |
| | | dic[DeviceType.IASZone.ToString()] = new List<CommonDevice>(); |
| | | //控制面板 |
| | | dic[DeviceType.OnOffSwitch.ToString()] = new List<CommonDevice>(); |
| | | //继电器 |
| | | dic[DeviceType.OnOffOutput.ToString()] = new List<CommonDevice>(); |
| | | //卷帘 |
| | | dic[DeviceType.WindowCoveringDevice.ToString()] = new List<CommonDevice>(); |
| | | //调光灯 |
| | | dic[DeviceType.ColorDimmableLight.ToString()] = new List<CommonDevice>(); |
| | | //空气开关 |
| | | dic[DeviceType.AirSwitch.ToString()] = new List<CommonDevice>(); |
| | | |
| | | return dic; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设备目标绑定_______________________ |
| | | |
| | | /// <summary> |
| | | /// 获取设备下面绑定的设备(错误时返回null) |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <returns></returns> |
| | | public async Task<List<CommonDevice>> GetBindTargetDevice(CommonDevice mainDevice) |
| | | { |
| | | var result = (BindObj.GetDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "GetDeviceBindAsync"); |
| | | if (result == null || result.getAllBindResponseData == null) |
| | | { |
| | | //获取设备的绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | var listDevice = new List<CommonDevice>(); |
| | | foreach (var data in result.getAllBindResponseData.BindList) |
| | | { |
| | | CommonDevice deviceTemp = this.GetDevice(data.BindMacAddr, data.BindEpoint); |
| | | if (deviceTemp == null) |
| | | { |
| | | continue; |
| | | } |
| | | listDevice.Add(deviceTemp); |
| | | } |
| | | return listDevice; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定设备的目标(返回成功设置的设备,错误时,返回null) |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <param name="listDevice">要绑定的目标设备</param> |
| | | /// <param name="BindCluster">要绑定的目标设备</param> |
| | | /// <returns></returns> |
| | | public async Task<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 = (BindObj.AddedDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "AddDeviceBindAsync", addData); |
| | | if (result == null || result.addedDeviceBindResponseData == null) |
| | | { |
| | | //绑定目标设置失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | 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); |
| | | //0:添加成功 3:已经存在,也可以代表成功 |
| | | if (data.Result == 0 || data.Result == 3) |
| | | { |
| | | if (dicDevice.ContainsKey(mainkeys) == true) |
| | | { |
| | | listSuccess.Add(dicDevice[mainkeys]); |
| | | } |
| | | } |
| | | //1:失败,节点设备或场景不存在 |
| | | else if (data.Result == 1) |
| | | { |
| | | if (dicDevice.ContainsKey(mainkeys) == true) |
| | | { |
| | | //设备名称 绑定失败 |
| | | string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; |
| | | msg += Language.StringByID(R.MyInternationalizationString.BindFailed); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | } |
| | | //2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功 |
| | | else if (data.Result == 2) |
| | | { |
| | | if (result.addBindResultResponseData == null) |
| | | { |
| | | //设备名称 绑定失败 |
| | | string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; |
| | | msg += Language.StringByID(R.MyInternationalizationString.BindFailed); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | else |
| | | { |
| | | //添加成功 |
| | | if (result.addBindResultResponseData.Result == 0) |
| | | { |
| | | if (dicDevice.ContainsKey(mainkeys) == true) |
| | | { |
| | | listSuccess.Add(dicDevice[mainkeys]); |
| | | } |
| | | } |
| | | //设备名称 绑定列表已满 |
| | | else if (result.addBindResultResponseData.Result == 140) |
| | | { |
| | | string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; |
| | | msg += Language.StringByID(R.MyInternationalizationString.uBindListIsFull); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | else |
| | | { |
| | | //设备名称 绑定失败 |
| | | string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; |
| | | msg += Language.StringByID(R.MyInternationalizationString.BindFailed); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return listSuccess; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除设备绑定的目标 |
| | | /// </summary> |
| | | /// <param name="mainDevice">设备对象</param> |
| | | /// <param name="deleteDevice">要删除的绑定目标设备</param> |
| | | /// <param name="BindCluster">要绑定的目标设备</param> |
| | | /// <returns></returns> |
| | | public async Task<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 = 6; |
| | | info.BindMacAddr = deleteDevice.DeviceAddr; |
| | | info.BindEpoint = deleteDevice.DeviceEpoint; |
| | | info.BindType = 0; |
| | | |
| | | deleteData.RemoveBindList.Add(info); |
| | | |
| | | var result = (BindObj.DelDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "DelDeviceBindAsync", deleteData); |
| | | if (result == null || result.delDeviceBindResponseData == null) |
| | | { |
| | | //删除绑定目标失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | |
| | | foreach (var data in result.delDeviceBindResponseData.RemoveBindList) |
| | | { |
| | | //0:成功 1:设备不在绑定列表中 ,也可以代表成功 |
| | | if (data.Result == 0 || data.Result == 1) |
| | | { |
| | | return true; |
| | | } |
| | | //3:失败,在等待节点设备确认是否解除绑定成功 |
| | | else if (data.Result == 3) |
| | | { |
| | | //其他绑定目标正在删除中,请稍后再试 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait); |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | //4:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功 |
| | | else if (data.Result == 4) |
| | | { |
| | | 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> |
| | | /// <param name="device">需要执行的设备的设备对象</param> |
| | | /// <param name="method">指定要加载的方法名</param> |
| | | /// <param name="parameter">启动参数</param> |
| | | private async Task<object> LoadDeviceMethodByNameAsync(CommonDevice device, string method, params object[] parameter) |
| | | { |
| | | var task = device.GetType().InvokeMember(method, System.Reflection.BindingFlags.InvokeMethod, null, device, parameter) as Task; |
| | | await task; |
| | | |
| | | var result = task.GetType().GetProperty("Result").GetValue(task, null); |
| | | return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ PIR传感器__________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取PIR传感器的【光感等级总刻度】,错误时返回-1 |
| | | /// </summary> |
| | | /// <param name="iASZone"></param> |
| | | /// <returns></returns> |
| | | public async Task<int> GetPirLightAbilitySize(IASZone iASZone) |
| | | { |
| | | var data = await iASZone.GetPIRLightAbilitySizeAsync(); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.CheckCommonErrorCode(data); |
| | | if (error != null) |
| | | { |
| | | this.ShowErrorMsg(error); |
| | | return -1; |
| | | } |
| | | |
| | | if (data == null || data.errorMessageBase != null || data.LightLevelCount == -1) |
| | | { |
| | | //获取传感器光感等级失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorLightPerceptionRegulationFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return -1; |
| | | } |
| | | |
| | | return data.LightLevelCount; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取PIR传感器的【灯光配置】,错误时返回null |
| | | /// </summary> |
| | | /// <param name="iASZone"></param> |
| | | /// <returns></returns> |
| | | public async Task<IASZone.ConfigureParamates> GetPirSensorLightSettion(IASZone iASZone) |
| | | { |
| | | var data = await iASZone.GetPIRSensorParamateAsync(); |
| | | if (data == null || data.configureParamates == null) |
| | | { |
| | | //获取传感器灯光设置信息失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorLightSettionFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | return data.configureParamates; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置PIR传感器的【灯光配置】 |
| | | /// </summary> |
| | | /// <param name="iASZone">传感器对象</param> |
| | | /// <param name="configure">灯光配置</param> |
| | | /// <returns></returns> |
| | | public async Task<bool> SetPirSensorLightSettion(IASZone iASZone, IASZone.ConfigureParamates configure) |
| | | { |
| | | var result = await iASZone.SetPIRSensorParamateAsync(configure); |
| | | if (result == null || result.responseData == null) |
| | | { |
| | | //设置传感器灯光配置失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorLightSettionFail); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | if (result.responseData.status != 0) |
| | | { |
| | | //设置传感器灯光配置失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorLightSettionFail); |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | //备份设置 |
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(iASZone, GatewayBackupEnum.APir灯光配置, configure); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 按键面板功能系_____________________ |
| | | |
| | | #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 = UserCenterLogic.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="panel">按键面板的某一个回路</param> |
| | | /// <returns></returns> |
| | | public async Task<Panel.PanelSwitchLevelInfo> GetPanelSwitchLightSettion(Panel panel) |
| | | { |
| | | var result = await panel.GetPanelSwitchLevelAsync(); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.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(ui叫亮度调节)</param> |
| | | /// <returns></returns> |
| | | public async Task<bool> SetPanelSwitchLightSettion(Panel panel, int directionsLevel, int backlightLevel) |
| | | { |
| | | var result = await panel.SetKeyLevelAsync(directionsLevel, backlightLevel); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.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.errorMessageBase); |
| | | |
| | | 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(panel, GatewayBackupEnum.A按键面板亮度调节, backData); |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 节能模式 |
| | | /// <summary> |
| | | /// 获取按键面板节能模式的配置状态(ui叫节能模式) |
| | | /// </summary> |
| | | /// <param name="panel">按键面板的某一个回路</param> |
| | | /// <returns></returns> |
| | | public async Task<Panel.PanelSaveEnergyModeInfo> GetPanelEnergyConservationMode(Panel panel) |
| | | { |
| | | var result = await panel.GetPanelSaveEnergyModeAsync(); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.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.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | return result.panelSaveEnergyModeInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置按键面板的节能模式(ui叫节能模式) |
| | | /// </summary> |
| | | /// <param name="panel">按键面板的某一个回路</param> |
| | | /// <param name="modeEnable">节能模式是否有效</param> |
| | | /// <param name="modeTime">无操作进入节能模式时间 0-255</param> |
| | | /// <param name="level">节能模式亮度:0-100</param> |
| | | /// <returns></returns> |
| | | public async Task<bool> SetPanelEnergyConservationMode(Panel panel, bool modeEnable, int modeTime, int level) |
| | | { |
| | | var result = await panel.SetKeyModeAsync(modeEnable, modeTime, level); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.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.errorMessageBase); |
| | | |
| | | 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(panel, GatewayBackupEnum.A按键面板节能模式, backData); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 检测控制面板(灯类)所拥有的功能,现支持的有以下几种(必定存在键值,出错会返回null) |
| | | /// <para>键值1:亮度调节(ui叫亮度调节,针对整个设备) -> true:拥有此功能 false:无此功能</para> |
| | | /// <para>键值2:节能模式(ui叫节能模式,针对整个设备) -> true:拥有此功能 false:无此功能</para> |
| | | /// <para>键值3:颜色调节(ui叫颜色调节,只能单回路配置) -> true:拥有此功能 false:无此功能</para> |
| | | /// </summary> |
| | | /// <param name="panel">按键面板的某一个回路</param> |
| | | /// <returns></returns> |
| | | public async Task<Dictionary<string, bool>> CheckPanelLightFunctionLevel2(Panel panel) |
| | | { |
| | | var dicCheck = new Dictionary<string, bool>(); |
| | | dicCheck["亮度调节"] = false; |
| | | dicCheck["节能模式"] = false; |
| | | dicCheck["颜色调节"] = false; |
| | | |
| | | //获取第一级功能 |
| | | var result = await this.GetPanelDeviceFunctionLevel1(panel); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if (result.Contains(1024) == false) |
| | | { |
| | | //此控制面板没有灯这个东西 |
| | | return dicCheck; |
| | | } |
| | | |
| | | //获取第二级功能 |
| | | result = await this.GetPanelDeviceFunctionLevel2(panel, 1024); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if (result.Contains(102) == true) |
| | | { |
| | | //亮度调节:102 |
| | | dicCheck["亮度调节"] = true; |
| | | } |
| | | if (result.Contains(101) == true) |
| | | { |
| | | //颜色调节:101 |
| | | dicCheck["颜色调节"] = true; |
| | | } |
| | | if (result.Contains(0) == true) |
| | | { |
| | | //节能模式:0 |
| | | dicCheck["节能模式"] = true; |
| | | } |
| | | return dicCheck; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取按键面板的第一级别功能功能系(1024:灯类,256:按键类,768:PIR类) |
| | | /// </summary> |
| | | /// <param name="panel">按键面板的某一个回路</param> |
| | | /// <returns></returns> |
| | | public async Task<List<int>> GetPanelDeviceFunctionLevel1(Panel panel) |
| | | { |
| | | var result = await this.GetPanelDeviceFunction(panel); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | return result.privateFuncTypeLevelFirstList; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// <para>获取按键面板的第二级别功能功能系(以下为返回值)</para> |
| | | /// <para>100:Switch,开关(按键类)</para> |
| | | /// <para>200:Dimmer,调光(按键类)</para> |
| | | /// <para>300:Curtain,窗帘(按键类)</para> |
| | | /// <para>0:EnergySavingMode,节能模式(灯类)</para> |
| | | /// <para>1:SleepMode,睡眠模式(灯类)</para> |
| | | /// <para>100:WhiteBalance,白平衡(灯类)</para> |
| | | /// <para>101:RGBColor,RGB指示灯颜色(灯类)</para> |
| | | /// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para> |
| | | /// </summary> |
| | | /// <param name="panel">按键面板的某一个回路</param> |
| | | /// <param name="levelNo">第一级别的ID(1024:灯类,256:按键类,768:PIR类)</param> |
| | | /// <returns></returns> |
| | | public async Task<List<int>> GetPanelDeviceFunctionLevel2(Panel panel, int levelNo) |
| | | { |
| | | var result = await this.GetPanelDeviceFunction(panel, new int[] { levelNo }); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | return result.privateFuncTypeLevelSecondList; |
| | | } |
| | | |
| | | /// <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> GetPanelDeviceFunction(Panel panel, params int[] parameter) |
| | | { |
| | | var result = await panel.GetPanelPrivateFunctionsAsync(parameter); |
| | | //共通错误检测 |
| | | string error = UserCenterLogic.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.errorMessageBase); |
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return null; |
| | | } |
| | | |
| | | return result.panelPrivateFunctionsResponseInfo; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 一般方法___________________________ |
| | | |
| | | /// <summary> |
| | | /// 判断是不是河东的设备 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public bool IsHdlDevice(CommonDevice device) |
| | | { |
| | | return device.ManufacturerName == "HDL"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备的唯一主键 |
| | | /// </summary> |
| | | /// <param name="device"></param> |
| | | /// <returns></returns> |
| | | public string GetDeviceMainKeys(CommonDevice device) |
| | | { |
| | | return device.DeviceAddr + device.DeviceEpoint; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备的唯一主键 |
| | | /// </summary> |
| | | /// <param name="DeviceAddr">MAC地址</param> |
| | | /// <param name="DeviceEpoint">端口号</param> |
| | | /// <returns></returns> |
| | | public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint) |
| | | { |
| | | return DeviceAddr + DeviceEpoint; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示错误信息窗口 |
| | | /// </summary> |
| | | /// <param name="msg"></param> |
| | | private void ShowErrorMsg(string msg) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | var contr = new Phone.UserCenter.ErrorMsgControl(msg); |
| | | contr.Show(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示Tip信息窗口 |
| | | /// </summary> |
| | | /// <param name="msg"></param> |
| | | private void ShowTipMsg(string msg) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | var contr = new Phone.UserCenter.TipViewControl(msg); |
| | | contr.ShowView(); |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 结构体_____________________________ |
| | | |
| | | /// <summary> |
| | | /// 设备计数的信息 |
| | | /// </summary> |
| | | private class DeviceCountInfo |
| | | { |
| | | /// <summary> |
| | | /// 计数 |
| | | /// </summary> |
| | | public int Count = 0; |
| | | /// <summary> |
| | | /// 端口号 |
| | | /// </summary> |
| | | public HashSet<int> hsEpoint = new HashSet<int>(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | //----------------------------------分割线(自定义接口)--------------------------------------------- |
| | | |
| | | #region ■ 获取设备列表的接口_________________ |
| | | |
| | | /// <summary> |
| | | /// 从网关重新获取设备列表(★★★★★★★接收到设备时的事件,设备对象为null时,代表接收完成★★★★★★★) |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关对象</param> |
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | private Dictionary<string, List<CommonDevice>> GetDeviceSortRule()
|
| | | {
|
| | | var dic = new Dictionary<string, List<CommonDevice>>();
|
| | | //控制面板
|
| | | dic[DeviceType.OnOffSwitch.ToString()] = null;
|
| | | //卷帘
|
| | | dic[DeviceType.WindowCoveringDevice.ToString()] = null;
|
| | | //调光灯
|
| | | dic[DeviceType.ColorDimmableLight.ToString()] = null;
|
| | | //继电器
|
| | | dic[DeviceType.OnOffOutput.ToString()] = null;
|
| | | //空气开关
|
| | | dic[DeviceType.AirSwitch.ToString()] = null;
|
| | | //门窗磁传感器
|
| | | dic["21"] = null;
|
| | | dic["22"] = null;
|
| | | //水浸传感器
|
| | | dic["42"] = null;
|
| | | //烟雾传感器
|
| | | dic["40"] = null;
|
| | | //紧急按钮
|
| | | dic["44"] = null;
|
| | | //燃气传感器
|
| | | dic["43"] = null;
|
| | | //运动传感器
|
| | | dic["13"] = null;
|
| | | //钥匙扣
|
| | | dic["277"] = null;
|
| | |
|
| | | return dic;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是不是河东的设备
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public bool IsHdlDevice(CommonDevice device)
|
| | | {
|
| | | return device.ManufacturerName == "HDL";
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备的唯一主键
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceMainKeys(CommonDevice device)
|
| | | {
|
| | | return device.DeviceAddr + device.DeviceEpoint;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备的唯一主键
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">MAC地址</param>
|
| | | /// <param name="DeviceEpoint">端口号</param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint)
|
| | | {
|
| | | return DeviceAddr + DeviceEpoint;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 交换设备的模块ID
|
| | | /// </summary>
|
| | | /// <param name="modeId">模块ID</param>
|
| | | /// <returns></returns>
|
| | | public bool ChangedDeviceModeId(ref string modeId)
|
| | | {
|
| | | if (this.dicDeviceModelIdChanged.ContainsKey(modeId) == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | modeId = this.dicDeviceModelIdChanged[modeId];
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 附加设备的版本代号(返回Ver.XXX)
|
| | | /// </summary>
|
| | | /// <param name="versionValue">版本号</param>
|
| | | /// <returns></returns>
|
| | | public string AppendVersion(int versionValue)
|
| | | {
|
| | | //转为16进制
|
| | | string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0');
|
| | | //这个是小数点前面的值
|
| | | int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16);
|
| | | //这个是小数点后面的值
|
| | | int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16);
|
| | |
|
| | | //Ver.
|
| | | string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
|
| | | return ver + value1 + "." + value2.ToString().PadLeft(3, '0');
|
| | | }
|
| | |
|
| | | /// <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>
|
| | | /// 从网关重新获取设备列表(★★★★★★★接收到设备时的事件,设备对象为null时,代表接收完成★★★★★★★)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <returns></returns> |
| | | public async Task<List<CommonDevice>> GetDeviceListFromGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) |
| | | { |
| | | //如果切换到了别的界面,则不显示错误信息 |
| | | string nowFormId = UserCenterResourse.NowActionFormID; |
| | | |
| | | ZbGateway realWay = null; |
| | | if (Common.LocalGateway.Current.GetRealGateway(ref realWay, zbGateway) == false) |
| | | { |
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) |
| | | { |
| | | //错误:网关对象丢失 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | //是否达成中断的时机 |
| | | bool canBreak = false; |
| | | |
| | | //网关ID |
| | | string gatewayID = Common.LocalGateway.Current.GetGatewayId(zbGateway); |
| | | //超时时间 |
| | | int TimeOut = 0; |
| | | //设备列表 |
| | | var listDevice = new List<CommonDevice>(); |
| | | |
| | | Action<string, string> getDeviceAction = (topic, message) => |
| | | { |
| | | try |
| | | { |
| | | if (topic == gatewayID + "/" + "DeviceInfoRespon") |
| | | { |
| | | TimeOut = 0; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); |
| | | if (totalNum == 0) |
| | | { |
| | | //这个网关没有设备 |
| | | canBreak = true; |
| | | return; |
| | | } |
| | | var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); |
| | | //根据设备类型创建设备对象的实例 |
| | | var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); |
| | | if (device != null) |
| | | { |
| | | //回调函数 |
| | | deviceComingAction?.Invoke(device); |
| | | |
| | | listDevice.Add(device); |
| | | } |
| | | } |
| | | else if (topic == gatewayID + "/" + "DeviceInfoResponEnd") |
| | | { |
| | | canBreak = true; |
| | | } |
| | | } |
| | | catch { } |
| | | }; |
| | | |
| | | realWay.Actions += getDeviceAction; |
| | | try |
| | | { |
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } }; |
| | | await realWay.Send("GetDeviceInfo", jObject.ToString()); |
| | | } |
| | | catch { canBreak = true; } |
| | | |
| | | while (canBreak == false && TimeOut < 60) |
| | | { |
| | | await Task.Delay(100); |
| | | TimeOut++; |
| | | } |
| | | |
| | | realWay.Actions -= getDeviceAction; |
| | | if (TimeOut >= 60) |
| | | { |
| | | if (listDevice.Count == 0) |
| | | { |
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) |
| | | { |
| | | //获取设备列表失败 |
| | | //[XXXX]网关回复超时,请稍后再试 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); |
| | | msg += "\r\n[" + Common.LocalGateway.Current.GetGatewayName(zbGateway).ToString() + "]"; |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, "回复超时", false); |
| | | this.ShowErrorMsg(msg); |
| | | } |
| | | return null; |
| | | } |
| | | else |
| | | { |
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) |
| | | { |
| | | //网络不稳定,设备列表信息缺损 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); |
| | | this.ShowTipMsg(msg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //回调函数(接收完成) |
| | | {
|
| | | //如果切换到了别的界面,则不显示错误信息
|
| | | string nowFormId = UserCenterResourse.NowActionFormID;
|
| | |
|
| | | ZbGateway realWay = null;
|
| | | if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | //是否达成中断的时机
|
| | | bool canBreak = false;
|
| | | //网关ID
|
| | | string gatewayID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | | //设备总数
|
| | | int deviceCount = -1;
|
| | | //接收数
|
| | | int receiveCount = 0;
|
| | | //设备列表
|
| | | var listDevice = new List<CommonDevice>();
|
| | |
|
| | | Action<string, string> getDeviceAction = (topic, message) =>
|
| | | {
|
| | | try
|
| | | {
|
| | | if (topic == gatewayID + "/" + "DeviceInfoRespon")
|
| | | {
|
| | | TimeOut = 0;
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
|
| | | if (totalNum == 0)
|
| | | {
|
| | | //这个网关没有设备
|
| | | canBreak = true;
|
| | | return;
|
| | | }
|
| | | if (deviceCount == -1)
|
| | | {
|
| | | //设置需要接收多少个设备
|
| | | deviceCount = totalNum;
|
| | | }
|
| | | //设备接收数
|
| | | receiveCount++;
|
| | |
|
| | | var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
|
| | | //根据设备类型创建设备对象的实例
|
| | | var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
|
| | | if (device != null)
|
| | | {
|
| | | //回调函数
|
| | | deviceComingAction?.Invoke(device);
|
| | |
|
| | | listDevice.Add(device);
|
| | | }
|
| | | if (deviceCount == receiveCount)
|
| | | {
|
| | | //设备全部接收完成
|
| | | canBreak = true;
|
| | | }
|
| | | }
|
| | | }
|
| | | catch { }
|
| | | };
|
| | |
|
| | | realWay.Actions += getDeviceAction;
|
| | | try
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
|
| | | await realWay.Send("GetDeviceInfo", jObject.ToString());
|
| | | }
|
| | | catch { canBreak = true; }
|
| | |
|
| | | while (canBreak == false && TimeOut < 60)
|
| | | {
|
| | | await Task.Delay(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= getDeviceAction;
|
| | | getDeviceAction = null;
|
| | |
|
| | | if (TimeOut >= 60)
|
| | | {
|
| | | if (listDevice.Count == 0)
|
| | | {
|
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
|
| | | {
|
| | | //获取设备列表失败
|
| | | //[XXXX]网关回复超时,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
|
| | | msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时", false);
|
| | | this.ShowErrorMsg(msg);
|
| | | }
|
| | | return null;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
|
| | | {
|
| | | //网络不稳定,设备列表信息缺损
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //回调函数(接收完成)
|
| | | deviceComingAction?.Invoke(null); |
| | | deviceComingAction = null; |
| | | |
| | | return listDevice; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 创建新设备对象相关_________________ |
| | | |
| | | /// <summary> |
| | | /// 根据设备类型创建设备对象的实例 |
| | | /// </summary> |
| | | /// <param name="deviceType">设备类型</param> |
| | | /// <param name="jobject">主题Data</param> |
| | | /// <param name="zbGateway">网关对象</param> |
| | | /// <returns></returns> |
| | | private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway) |
| | | { |
| | | string gwId = Common.LocalGateway.Current.GetGatewayId(zbGateway); |
| | | |
| | | //根据设备类型创建设备对象的实例 |
| | | CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType); |
| | | if (device == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | //设置设备属性类 |
| | | device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString()); |
| | | if (device.DeviceInfo == null) |
| | | { |
| | | return null; |
| | | } |
| | | this.SetMacName(device, string.Empty); |
| | | this.SetEpointName(device, string.Empty); |
| | | |
| | | //设置设备主键类 |
| | | this.SetNewDeviceMainKeys(device, jobject); |
| | | device.CurrentGateWayId = gwId; |
| | | |
| | | //将DeviceInfo的属性设置到主属性中 |
| | | this.SetDeviceInfoToMain(device, device); |
| | | |
| | | return device; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将DeviceInfo的属性设置到主属性中 |
| | | /// </summary> |
| | | /// <param name="mainDevice">主设备对象</param> |
| | | /// <param name="device">设置源设备对象</param> |
| | | public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device) |
| | | { |
| | | if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false) |
| | | { |
| | | mainDevice.DeviceName = device.DeviceInfo.MacName; |
| | | } |
| | | if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false) |
| | | { |
| | | mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName; |
| | | } |
| | | mainDevice.CurrentGateWayId = device.CurrentGateWayId; |
| | | mainDevice.ImgVersion = device.DeviceInfo.ImgVersion; |
| | | mainDevice.HwVersion = device.DeviceInfo.HwVersion; |
| | | mainDevice.IsOnline = device.DeviceInfo.IsOnline; |
| | | mainDevice.DriveCode = device.DeviceInfo.DriveCode; |
| | | mainDevice.IasDeviceType = device.DeviceInfo.DeviceType; |
| | | mainDevice.Profile = device.DeviceInfo.Profile; |
| | | mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId; |
| | | mainDevice.InClusterList = device.DeviceInfo.InClusterList; |
| | | mainDevice.OutClusterList = device.DeviceInfo.OutClusterList; |
| | | mainDevice.AttributeStatus = device.DeviceInfo.AttributeStatus; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备Type创建对应的设备对象 |
| | | /// </summary> |
| | | /// <param name="deviceType">设备Type</param> |
| | | /// <returns></returns> |
| | | public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType) |
| | | { |
| | | CommonDevice device = null; |
| | | |
| | | //根据设备类型创建设备对象的实例 |
| | | if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); } |
| | | else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); } |
| | | else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); } |
| | | else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); } |
| | | else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); } |
| | | else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); } |
| | | else if (deviceType == DeviceType.IASZone) { device = new IASZone(); } |
| | | else if (deviceType == DeviceType.Repeater) { device = new Repeater(); } |
| | | else if (deviceType == DeviceType.Thermostat) { device = new AC(); } |
| | | else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); } |
| | | else { return null; } |
| | | |
| | | device.DeviceEpointName = string.Empty; |
| | | device.DeviceName = string.Empty; |
| | | |
| | | return device; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 给新设备设置主键属性 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="jobject">主题Data</param> |
| | | public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject) |
| | | { |
| | | //设置设备主键类 |
| | | device.Time = jobject.Value<int>("Time"); |
| | | device.DeviceID = jobject.Value<int>("Device_ID"); |
| | | device.DeviceAddr = jobject.Value<string>("DeviceAddr"); |
| | | device.DeviceEpoint = jobject.Value<int>("Epoint"); |
| | | device.DataID = jobject.Value<int>("Data_ID"); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | //----------------------------------分割线(设备模块ID)--------------------------------------------- |
| | | |
| | | #region ■ 自定义设备模块ID___________________ |
| | | |
| | | /// <summary> |
| | | /// 初始化设备的模块ID的枚举 |
| | | /// </summary> |
| | | private void InitDeviceModelIdEnum() |
| | | { |
| | | if (this.dicDeviceModelIdEnum != null) |
| | | { |
| | | return; |
| | | } |
| | | this.dicDeviceModelIdEnum = new Dictionary<string, string>(); |
| | | |
| | | //定义规则:模块ID(已翻译)=设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以) |
| | | //第一个值是:DeviceConcreteType 第二个值是:DeviceBeloneType |
| | | |
| | | //=========★★开合帘类(100-199)★★========= |
| | | this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//智能开合帘电机 |
| | | this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//智能管状电机 |
| | | |
| | | //=========★★按键面板类(200-1199)★★========= |
| | | this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200";//4按键触摸面板(带4路继电器底座) |
| | | this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200";//3按键触摸面板 |
| | | this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2按键触摸面板 |
| | | this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12按键触摸面板 |
| | | this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4按键触摸面板(只带电源底座) |
| | | |
| | | //=========★★PIR传感器类(1200-1299)★★========= |
| | | this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir传感器220 |
| | | |
| | | //=========★★安防类传感器类(1300-2299)★★========= |
| | | this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1300";//燃气传感器 |
| | | this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300";//门窗磁传感器 |
| | | this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300";//烟雾传感器 |
| | | this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300";//红外传感器 |
| | | this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300";//水浸传感器 |
| | | this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300";//紧急按键 |
| | | |
| | | //=========★★继电器类(2300-2499)★★========= |
| | | this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300";//3路继电器小模块 |
| | | |
| | | //=========★★调光器类(2500-2799)★★========= |
| | | this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500";//1路调光器小模块 |
| | | |
| | | //=========★★空调类(3600-3899)★★========= |
| | | this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee空调网关模块 |
| | | |
| | | //=========★★中继器类(3900-3999)★★========= |
| | | this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee中继器 |
| | | |
| | | //=========★★空气开关类(4100-4199)★★========= |
| | | this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100";//zigbee微断云控制器 |
| | | |
| | | //=========★★转换器类(4200-4699)★★========= |
| | | this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee转485协议转换器 |
| | | this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee转buspro协议转换器 |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 创建新设备对象相关_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据设备类型创建设备对象的实例
|
| | | /// </summary>
|
| | | /// <param name="deviceType">设备类型</param>
|
| | | /// <param name="jobject">主题Data</param>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway)
|
| | | {
|
| | | string gwId = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | |
|
| | | //根据设备类型创建设备对象的实例
|
| | | CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType);
|
| | | if (device == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | //设置设备属性类
|
| | | device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString());
|
| | | if (device.DeviceInfo == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | this.SetMacName(device, string.Empty);
|
| | | this.SetEpointName(device, string.Empty);
|
| | |
|
| | | //设置设备主键类
|
| | | this.SetNewDeviceMainKeys(device, jobject);
|
| | | device.CurrentGateWayId = gwId;
|
| | |
|
| | | //将DeviceInfo的属性设置到主属性中
|
| | | this.SetDeviceInfoToMain(device, device);
|
| | |
|
| | | return device;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将DeviceInfo的属性设置到主属性中
|
| | | /// </summary>
|
| | | /// <param name="mainDevice">主设备对象</param>
|
| | | /// <param name="device">设置源设备对象</param>
|
| | | public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device)
|
| | | {
|
| | | if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false)
|
| | | {
|
| | | mainDevice.DeviceName = device.DeviceInfo.MacName;
|
| | | }
|
| | | if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false)
|
| | | {
|
| | | mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
|
| | | }
|
| | | mainDevice.CurrentGateWayId = device.CurrentGateWayId;
|
| | | mainDevice.IsOnline = device.DeviceInfo.IsOnline;
|
| | | mainDevice.DriveCode = device.DeviceInfo.DriveCode;
|
| | | mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
|
| | | mainDevice.Profile = device.DeviceInfo.Profile;
|
| | |
|
| | | //固件版本
|
| | | mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
|
| | | //硬件版本
|
| | | mainDevice.HwVersion = device.DeviceInfo.HwVersion;
|
| | | //镜像ID
|
| | | mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId;
|
| | | //厂商名称
|
| | | mainDevice.ManufacturerName = device.DeviceInfo.ManufacturerName;
|
| | | //模块ID
|
| | | mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier;
|
| | | //序列号
|
| | | mainDevice.SerialNumber = device.DeviceInfo.ProductCode;
|
| | |
|
| | | mainDevice.InClusterList.Clear();
|
| | | mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
|
| | | mainDevice.OutClusterList.Clear();
|
| | | mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
|
| | | mainDevice.AttributeStatus.Clear();
|
| | | mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据设备Type创建对应的设备对象
|
| | | /// </summary>
|
| | | /// <param name="deviceType">设备Type</param>
|
| | | /// <returns></returns>
|
| | | public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
|
| | | {
|
| | | CommonDevice device = null;
|
| | |
|
| | | //根据设备类型创建设备对象的实例
|
| | | if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
|
| | | else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
|
| | | else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); }
|
| | | else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); }
|
| | | else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); }
|
| | | else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); }
|
| | | else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
|
| | | else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
|
| | | else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
|
| | | else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); }
|
| | | else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
|
| | | else { return null; }
|
| | |
|
| | | device.DeviceEpointName = string.Empty;
|
| | | device.DeviceName = string.Empty;
|
| | |
|
| | | return device;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 给新设备设置主键属性
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="jobject">主题Data</param>
|
| | | public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject)
|
| | | {
|
| | | //设置设备主键类
|
| | | device.Time = jobject.Value<int>("Time");
|
| | | device.DeviceID = jobject.Value<int>("Device_ID");
|
| | | device.DeviceAddr = jobject.Value<string>("DeviceAddr");
|
| | | device.DeviceEpoint = jobject.Value<int>("Epoint");
|
| | | device.DataID = jobject.Value<int>("Data_ID");
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | //----------------------------------分割线(设备模块ID)---------------------------------------------
|
| | |
|
| | | #region ■ 自定义设备模块ID___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化设备的模块ID的枚举
|
| | | /// </summary>
|
| | | private void InitDeviceModelIdEnum()
|
| | | {
|
| | | if (this.dicDeviceModelIdEnum != null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.dicDeviceModelIdEnum = new Dictionary<string, string>();
|
| | |
|
| | | //定义规则:模块ID(已翻译)=设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
|
| | | //第一个值是:DeviceConcreteType 第二个值是:DeviceBeloneType
|
| | |
|
| | | //=========★★开合帘类(100-199)★★=========
|
| | | this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//智能开合帘电机
|
| | | this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//智能管状电机
|
| | |
|
| | | //=========★★按键面板类(200-1199)★★=========
|
| | | this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200";//4按键触摸面板(带4路继电器底座)
|
| | | this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200";//3按键触摸面板
|
| | | this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2按键触摸面板
|
| | | this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12按键触摸面板
|
| | | this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4按键触摸面板(只带电源底座)
|
| | |
|
| | | //=========★★PIR传感器类(1200-1299)★★=========
|
| | | this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir传感器220
|
| | |
|
| | | //=========★★安防类传感器类(1300-2299)★★=========
|
| | | this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1300";//燃气传感器
|
| | | this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300";//门窗磁传感器
|
| | | this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300";//烟雾传感器
|
| | | this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300";//红外传感器
|
| | | this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300";//水浸传感器
|
| | | this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300";//紧急按键
|
| | |
|
| | | //=========★★继电器类(2300-2499)★★=========
|
| | | this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300";//3路继电器小模块
|
| | |
|
| | | //=========★★调光器类(2500-2799)★★=========
|
| | | this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500";//1路调光器小模块
|
| | |
|
| | | //=========★★智能门锁类(2800-????)★★=========
|
| | | this.dicDeviceModelIdEnum["H06C"] = "2800-2800";//智能门锁(H06C)
|
| | |
|
| | | //=========★★空调类(3600-3899)★★=========
|
| | | this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee空调网关模块
|
| | |
|
| | | //=========★★中继器类(3900-3999)★★=========
|
| | | this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee中继器
|
| | |
|
| | | //=========★★空气开关类(4100-4199)★★=========
|
| | | this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100";//zigbee微断云控制器
|
| | |
|
| | | //=========★★转换器类(4200-4699)★★=========
|
| | | this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee转buspro协议转换器
|
| | | this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee转485协议转换器
|
| | |
|
| | | //需要交换的模块ID
|
| | | this.dicDeviceModelIdChanged = new Dictionary<string, string>();
|
| | | //=========★★安防类传感器类★★=========
|
| | | this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//燃气传感器
|
| | | this.dicDeviceModelIdChanged["MULTI-MECI--EA01"] = "MSDC01/M-ZB.10";//门窗磁传感器
|
| | | this.dicDeviceModelIdChanged["MULTI-FIRE--EA05"] = "MSS01/M-ZB.10";//烟雾传感器
|
| | | this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//红外传感器
|
| | | this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//水浸传感器
|
| | | this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//紧急按键
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|