old mode 100755
new mode 100644
| | |
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存
|
| | | /// 本地所有设备的缓存(排序)
|
| | | /// </summary>
|
| | | public List<CommonDevice> listAllDevice
|
| | | {
|
| | | get
|
| | | {
|
| | | var list = new List<CommonDevice>();
|
| | | foreach (var listMac in this.dicDeviceSort.Values)
|
| | | lock (dicAllDevice)
|
| | | {
|
| | | foreach (var strMac in listMac)
|
| | | var list = new List<CommonDevice>();
|
| | | foreach (var device in dicAllDevice.Values)
|
| | | {
|
| | | var listTemp = this.GetDevicesByMac(strMac);
|
| | | list.AddRange(listTemp);
|
| | | list.Add(device);
|
| | | }
|
| | | return list;
|
| | | }
|
| | | return list;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceModelIdChanged = null;
|
| | | /// <summary>
|
| | | /// 图片共有(keys:指定设备的具体类型 value:指定共有对象的具体类型)
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicPictrueShard = null;
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存(非公开)
|
| | | /// </summary>
|
| | | private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>();
|
| | |
| | | /// </summary>
|
| | | private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
|
| | | /// <summary>
|
| | | /// 设备Mac顺序
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, List<string>> dicDeviceSort = null;
|
| | | /// <summary>
|
| | | /// 设备文件的前缀名字
|
| | | /// </summary>
|
| | | public const string deviceFirstName = "Device_";
|
| | | private Dictionary<string, string> dicDeviceRoomId = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | List<string> listFile = this.GetAllDeviceFile(); |
| | | foreach (string file in listFile)
|
| | | {
|
| | | CommonDevice device = null;
|
| | | //反序列化为指定的类,不然数据会丢失而导致无法强转
|
| | | var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file);
|
| | | try |
| | | {
|
| | | device = CommonDevice.CommonDeviceByFilePath(file);
|
| | | }
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | |
|
| | | if (device == null || device.CurrentGateWayId == null)
|
| | | {
|
| | | #if DEBUG
|
| | |
| | | }
|
| | | } |
| | | //成员身份的时候,删除掉非法的网关文件 |
| | | this.DeleteGatewayFileByMemberModel();
|
| | | //初始化设备顺序
|
| | | this.InitDeviceSort(); |
| | | this.DeleteGatewayFileByMemberModel(); |
| | | //初始化物理设备所属房间的记录 |
| | | this.InitRealDeviceRoomId(); |
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param>
|
| | | /// <returns>一直返回true</returns>
|
| | | public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
|
| | | public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
|
| | | {
|
| | | //从网关获取全部的设备
|
| | | List<CommonDevice> listDevice = new List<CommonDevice>();
|
| | | List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction);
|
| | | List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction);
|
| | |
|
| | | if (list == null)
|
| | | {
|
| | |
| | | /// <param name="device">设备对象(这个东西有可能会被更改)</param>
|
| | | public void AddDeviceToMemory(ref CommonDevice device)
|
| | | {
|
| | | if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
|
| | | {
|
| | | dicDeviceSort[device.CurrentGateWayId] = new List<string>();
|
| | | }
|
| | | if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
|
| | | {
|
| | | //保存顺序
|
| | | dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
|
| | | UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
|
| | | }
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | //如果它是升级的顶端端点,则不能让它加入到缓存,但是可以让他生成文件
|
| | | if (device is OTADevice)
|
| | |
| | | }
|
| | | //备份数据
|
| | | await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac名称, newMacName);
|
| | | //如果它只有一个回路,则更改端点名字
|
| | | if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
|
| | | {
|
| | | return await this.ReName(device, newMacName);
|
| | | }
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
| | | this.ShowErrorMsg(msg);
|
| | | return false;
|
| | | }
|
| | | if (dicDeviceSort.ContainsKey(listdevice[0].CurrentGateWayId) == true &&
|
| | | dicDeviceSort[listdevice[0].CurrentGateWayId].Contains(info.DeviceAddr) == true)
|
| | | {
|
| | | //保存顺序
|
| | | dicDeviceSort[listdevice[0].CurrentGateWayId].Remove(info.DeviceAddr);
|
| | | UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | foreach (CommonDevice device in listdevice)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device);
|
| | | }
|
| | | if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
|
| | | {
|
| | | //移除真实设备的房间索引
|
| | | this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
|
| | | this.SaveRealDeviceRoomId(null, null);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
| | | /// <param name="deleteRoom">是否从房间删除</param>
|
| | | public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
|
| | | {
|
| | | if (deleteRoom == true && Room.CurrentRoom != null)
|
| | | {
|
| | | //从房间中删除
|
| | | Room.CurrentRoom.DeleteDevice(device);
|
| | | }
|
| | |
|
| | | //删除缓存
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | lock (dicAllDevice)
|
| | |
| | | }
|
| | | }
|
| | | this.dicOTADevice.Remove(otaKeys);
|
| | | }
|
| | |
|
| | | if (deleteRoom == true && Room.CurrentRoom != null)
|
| | | {
|
| | | //从房间中删除
|
| | | Room.CurrentRoom.DeleteDevice(device);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | List<CommonDevice> list = new List<CommonDevice>();
|
| | | lock (dicAllDevice)
|
| | | {
|
| | | List<string> listSort = null;
|
| | | if (dicDeviceSort.ContainsKey(gwId) == false)
|
| | | {
|
| | | dicDeviceSort[gwId] = new List<string>();
|
| | | }
|
| | | listSort = dicDeviceSort[gwId];
|
| | |
|
| | | //各网关的所有设备
|
| | | foreach (CommonDevice device in this.dicAllDevice.Values)
|
| | | {
|
| | | if (gwId == device.CurrentGateWayId)
|
| | | {
|
| | | if (listSort.Contains(device.DeviceAddr) == false)
|
| | | {
|
| | | listSort.Add(device.DeviceAddr);
|
| | | }
|
| | | list.Add(device);
|
| | | }
|
| | | }
|
| | | //排序
|
| | | foreach (var strMac in listSort)
|
| | | {
|
| | | var listTemp = this.GetDevicesByMac(strMac);
|
| | | list.AddRange(listTemp);
|
| | | }
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
|
| | | }
|
| | |
|
| | | return list;
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据MAC地址,获取全部回路的设备对象(已经排序)
|
| | | /// 根据MAC地址,获取全部回路的设备对象
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">Mac地址</param>
|
| | | /// <param name="sort">是否排序</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDevicesByMac(string DeviceAddr)
|
| | | public List<CommonDevice> GetDevicesByMac(string DeviceAddr, bool sort = true)
|
| | | {
|
| | | var list = new List<CommonDevice>();
|
| | | if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
|
| | |
| | | list.Add(device);
|
| | | }
|
| | | }
|
| | | if (sort == false)
|
| | | {
|
| | | return list;
|
| | | }
|
| | |
|
| | | //排序
|
| | | list.Sort((obj1, obj2) =>
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据MAC地址,获取全部回路的数量
|
| | | /// </summary>
|
| | | /// <param name="DeviceAddr">Mac地址</param>
|
| | | /// <returns></returns>
|
| | | public int GetDevicesCountByMac(string DeviceAddr)
|
| | | {
|
| | | if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | return dicDeviceEpoint[DeviceAddr].Count;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取本地全部的设备文件
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | |
| | | {
|
| | | List<string> listDeviceFile = new List<string>();
|
| | | List<string> listAllFile = Global.FileListByHomeId(); |
| | | |
| | | foreach (string file in listAllFile)
|
| | | {
|
| | | if (file.StartsWith(deviceFirstName) == false)
|
| | | if (file.StartsWith("Device_") == false)
|
| | | {
|
| | | //如果不是设备文件
|
| | | continue;
|
| | |
| | | /// <returns></returns>
|
| | | public void SetDeviceIconToControl(Button btnIcon, CommonDevice device)
|
| | | {
|
| | | if (device == null)
|
| | | {
|
| | | btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
|
| | | return;
|
| | | }
|
| | | string unSelectFilePath = string.Empty;
|
| | | string selectFilePath = string.Empty;
|
| | |
|
| | |
| | | this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
|
| | |
|
| | | btnIcon.UnSelectedImagePath = unSelectFilePath;
|
| | | btnIcon.SelectedImagePath = selectFilePath;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | //获取它属于什么类型的设备
|
| | | var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
|
| | | string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType);
|
| | | string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); |
| | | |
| | | //图片共有 |
| | | if (this.dicPictrueShard.ContainsKey(strConcrete) == true)
|
| | | {
|
| | | strConcrete = this.dicPictrueShard[strConcrete];
|
| | | }
|
| | |
|
| | | string strType = strConcrete.Replace("_", string.Empty);
|
| | | //将类型转为图片地址
|
| | | string imageFilePath = "RealDevice/" + strType + ".png";
|
| | |
| | | {
|
| | | //将具体类型转字符串
|
| | | string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
|
| | | //图片共有
|
| | | if (this.dicPictrueShard.ContainsKey(strSpecific) == true)
|
| | | {
|
| | | strSpecific = this.dicPictrueShard[strSpecific];
|
| | | }
|
| | |
|
| | | string strType = strSpecific.Replace("_", string.Empty);
|
| | | //将类型转为图片地址
|
| | | string imageFilePath = "Device/" + strType + ".png";
|
| | |
| | | public DeviceUI GetDeviceUI(string filePath)
|
| | | {
|
| | | string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | if (arry.Length != 5)
|
| | | if (arry.Length != 4)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //创建一个新的东西给过去
|
| | | var deviceUi = new DeviceUI();
|
| | | deviceUi.DeviceAddr = arry[3];
|
| | | deviceUi.DeviceEpoint = Convert.ToInt32(arry[4]);
|
| | | deviceUi.DeviceAddr = arry[2];
|
| | | deviceUi.DeviceEpoint = Convert.ToInt32(arry[3]);
|
| | | return deviceUi;
|
| | | }
|
| | |
|
| | |
| | | return info;
|
| | | }
|
| | | //获取第三方设备的【设备类型】
|
| | | return this.GetNotHdlMyDeviceEnumInfo(listdevice);
|
| | | return this.GetNotHdlMyDeviceEnumInfo(listdevice, false);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | else
|
| | | {
|
| | | //获取第三方设备的【设备类型】
|
| | | var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice);
|
| | | var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice, false);
|
| | | strName = Language.StringByID(myDeviceType.ConcreteTextId);
|
| | | }
|
| | | if (ApendFalge == true && listDevice[0].DriveCode > 0)
|
| | |
| | | /// <summary>
|
| | | /// 获取第三方设备的【设备类型】
|
| | | /// </summary>
|
| | | /// <param name="listdevice"></param>
|
| | | /// <param name="device">设备回路</param>
|
| | | /// <param name="margeSensor">
|
| | | /// <para>是否将所有类型的传感器都归为【传感器】,</para> |
| | | /// <para>false的时候:【ConcreteType】和【ConcreteTextId】可能会有不同的值</para> |
| | | /// <para>true的时候:【ConcreteType】统一为Sensor,【ConcreteTextId】统一为传感器</para> |
| | | /// </param>
|
| | | /// <returns></returns>
|
| | | public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice)
|
| | | public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(CommonDevice device, bool margeSensor = true)
|
| | | {
|
| | | return this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }, margeSensor);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取第三方设备的【设备类型】(不建议使用)
|
| | | /// </summary>
|
| | | /// <param name="listdevice">Mac都一样的设备列表</param>
|
| | | /// <param name="margeSensor">
|
| | | /// <para>是否将所有类型的传感器都归为【传感器】,</para> |
| | | /// <para>false的时候:【ConcreteType】和【ConcreteTextId】可能会有不同的值</para> |
| | | /// <para>true的时候:【ConcreteType】统一为Sensor,【ConcreteTextId】统一为传感器</para> |
| | | /// </param>
|
| | | /// <returns></returns>
|
| | | public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice, bool margeSensor = true)
|
| | | {
|
| | | var dicType = new Dictionary<DeviceType, CommonDevice>();
|
| | | foreach (CommonDevice device in listdevice)
|
| | |
| | | //1包含面板的话,当面板处理
|
| | | if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
|
| | | info.BeloneType = DeviceBeloneType.A按键面板;
|
| | | info.ConcreteType = DeviceConcreteType.ButtonPanel;
|
| | | if (listdevice.Count > 1)
|
| | | {
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
|
| | | info.BeloneType = DeviceBeloneType.A按键面板;
|
| | | info.ConcreteType = DeviceConcreteType.ButtonPanel;
|
| | | }
|
| | | else
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16;
|
| | | info.BeloneType = DeviceBeloneType.A干接点;
|
| | | info.ConcreteType = DeviceConcreteType.DryContact;
|
| | | }
|
| | | }
|
| | | //3包含窗帘的话,当窗帘处理
|
| | | else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true)
|
| | |
| | | //4空气开关
|
| | | else if (dicType.ContainsKey(DeviceType.AirSwitch) == true)
|
| | | {
|
| | | //默认值
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100;
|
| | | info.BeloneType = DeviceBeloneType.A空气开关;
|
| | | info.BeloneType = DeviceBeloneType.A智能空开;
|
| | | info.ConcreteType = DeviceConcreteType.AirSwitch;
|
| | |
|
| | | if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A开关)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
|
| | | info.BeloneType = DeviceBeloneType.A开关;
|
| | | info.ConcreteType = DeviceConcreteType.Switch;
|
| | | }
|
| | | else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A插座)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
|
| | | info.BeloneType = DeviceBeloneType.A插座;
|
| | | info.ConcreteType = DeviceConcreteType.Socket1;
|
| | | }
|
| | | else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A灯光)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
|
| | | info.BeloneType = DeviceBeloneType.A灯光;
|
| | | info.ConcreteType = DeviceConcreteType.Light;
|
| | | }
|
| | | }
|
| | | //5继电器
|
| | | else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true)
|
| | | {
|
| | | //默认值
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300;
|
| | | info.BeloneType = DeviceBeloneType.A继电器;
|
| | | info.ConcreteType = DeviceConcreteType.Relay;
|
| | |
|
| | | if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A开关)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
|
| | | info.BeloneType = DeviceBeloneType.A开关;
|
| | | info.ConcreteType = DeviceConcreteType.Switch;
|
| | | }
|
| | | else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A插座)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
|
| | | info.BeloneType = DeviceBeloneType.A插座;
|
| | | info.ConcreteType = DeviceConcreteType.Socket1;
|
| | | }
|
| | | else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A灯光)
|
| | | {
|
| | | //info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
|
| | | info.BeloneType = DeviceBeloneType.A灯光;
|
| | | info.ConcreteType = DeviceConcreteType.Light;
|
| | | }
|
| | | }
|
| | | //6调光器
|
| | | else if (dicType.ContainsKey(DeviceType.DimmableLight) == true)
|
| | |
| | | //12包含传感器的话,当传感器处理
|
| | | else if (dicType.ContainsKey(DeviceType.IASZone) == true)
|
| | | {
|
| | | //设置传感器具体的类型
|
| | | info.BeloneType = DeviceBeloneType.A传感器;
|
| | | this.SetSensorDeviceSpecificType(ref info, listdevice);
|
| | | info.ConcreteType = DeviceConcreteType.Sensor;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
|
| | | if (margeSensor == false)
|
| | | {
|
| | | //设置传感器具体的类型
|
| | | this.SetSensorDeviceSpecificType(ref info, listdevice);
|
| | | }
|
| | | }
|
| | | //13包含温度传感器的话
|
| | | else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true)
|
| | | {
|
| | | bool temperatrue = false;
|
| | | bool humidity = false;
|
| | | foreach (var device in listdevice)
|
| | | //获取全部的回路
|
| | | var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false);
|
| | | foreach (var device in listTemp)
|
| | | {
|
| | | if (device is TemperatureSensor)
|
| | | {
|
| | |
| | | temperatrue = true;
|
| | | }
|
| | | //湿度传感器
|
| | | else if(((TemperatureSensor)device).SensorDiv == 2)
|
| | | else if (((TemperatureSensor)device).SensorDiv == 2)
|
| | | {
|
| | | humidity = true;
|
| | | }
|
| | |
| | | /// <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)
|
| | | {
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设备排序___________________________
|
| | | #region ■ 物理设备所属房间___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化设备顺序
|
| | | /// 初始化物理设备所属房间的记录
|
| | | /// </summary>
|
| | | private void InitDeviceSort()
|
| | | private void InitRealDeviceRoomId()
|
| | | {
|
| | | //读取设备顺序
|
| | | this.dicDeviceSort = new Dictionary<string, List<string>>();
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile);
|
| | | this.dicDeviceRoomId = new Dictionary<string, string>();
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
|
| | | var strData = UserCenterLogic.LoadFileContent(fullName);
|
| | | if (strData != null)
|
| | | {
|
| | | this.dicDeviceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
|
| | | this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
|
| | | }
|
| | | foreach (var device in dicAllDevice.Values)
|
| | | {
|
| | | if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
|
| | | {
|
| | | dicDeviceSort[device.CurrentGateWayId] = new List<string>();
|
| | | }
|
| | | if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
|
| | | {
|
| | | //新添加的设备
|
| | | dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
|
| | | }
|
| | | }
|
| | | foreach (var keys in dicDeviceSort.Keys)
|
| | | {
|
| | | var list = dicDeviceSort[keys];
|
| | | for (int i = 0; i < list.Count; i++)
|
| | | {
|
| | | if (this.dicDeviceEpoint.ContainsKey(list[i]) == false)
|
| | | {
|
| | | //这个东西莫名的不见了?和设备列表匹配不上?
|
| | | list.RemoveAt(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, dicDeviceEpoint);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设备排序
|
| | | /// 保存物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <param name="listDevice">需要排序的设备列表</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> SortDevice(List<CommonDevice> listDevice)
|
| | | /// <param name="listDevice">需要保存的设备对象</param>
|
| | | /// <param name="roomId">需要保存的哪个设备的房间ID</param>
|
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | var dic = new Dictionary<string, CommonDevice>();
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | if (listDevice != null)
|
| | | {
|
| | | dic[(this.GetDeviceMainKeys(listDevice[i]))] = listDevice[i];
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | }
|
| | | var list = new List<CommonDevice>();
|
| | | foreach (var listSort in this.dicDeviceSort.Values)
|
| | |
|
| | | //保存记录
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
|
| | | UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | |
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
|
| | | {
|
| | | for (int i = 0; i < listSort.Count; i++)
|
| | | {
|
| | | if (dic.ContainsKey(listSort[i]) == true)
|
| | | {
|
| | | list.Add(dic[listSort[i]]);
|
| | | }
|
| | | }
|
| | | Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备的房间名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public string GeteRealDeviceRoomName(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | }
|
| | | var room = Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | if (room != null)
|
| | | {
|
| | | return room.Name;
|
| | | }
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备属于哪个房间
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public Room GeteRealDeviceRoom(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | public string AppendVersion(int versionValue)
|
| | | {
|
| | | //转为16进制
|
| | | string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0');
|
| | | //直接是10进制
|
| | | string txt10 = Convert.ToString(versionValue).PadLeft(4, '0');
|
| | | //这个是小数点前面的值
|
| | | int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16);
|
| | | int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2));
|
| | | //这个是小数点后面的值
|
| | | int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16);
|
| | | int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2));
|
| | |
|
| | | //Ver.
|
| | | string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
|
| | | return ver + value1 + "." + value2.ToString().PadLeft(3, '0');
|
| | | return ver + value1 + "." + value2.ToString().PadLeft(2, '0');
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="deviceComingAction">接收到设备时的事件</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <returns></returns> |
| | | public async Task<List<CommonDevice>> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) |
| | | public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) |
| | | {
|
| | | if (ignoreTime == false)
|
| | | {
|
| | |
| | | int receiveCount = 0;
|
| | | //设备列表
|
| | | var listDevice = new List<CommonDevice>();
|
| | |
|
| | | //网关里面有可能会有重复的回路
|
| | | var listCheck = new HashSet<string>();
|
| | | Action<string, string> getDeviceAction = (topic, message) =>
|
| | | {
|
| | | try
|
| | | if (topic == gatewayID + "/" + "DeviceInfoRespon")
|
| | | {
|
| | | if (topic == gatewayID + "/" + "DeviceInfoRespon")
|
| | | try
|
| | | {
|
| | | TimeOut = 0;
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
|
| | | if (totalNum == 0)
|
| | | lock (listDevice)
|
| | | {
|
| | | //这个网关没有设备
|
| | | canBreak = true;
|
| | | return;
|
| | | }
|
| | | if (deviceCount == -1)
|
| | | {
|
| | | //设置需要接收多少个设备
|
| | | deviceCount = totalNum;
|
| | | }
|
| | | //设备接收数
|
| | | receiveCount++;
|
| | | //设备接收数
|
| | | receiveCount++;
|
| | |
|
| | | var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
|
| | | //根据设备类型创建设备对象的实例
|
| | | var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
|
| | | if (device != null)
|
| | | {
|
| | | try
|
| | | TimeOut = 0;
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
|
| | | if (totalNum == 0)
|
| | | {
|
| | | //回调函数
|
| | | deviceComingAction?.Invoke(device);
|
| | | //这个网关没有设备
|
| | | canBreak = true;
|
| | | return;
|
| | | }
|
| | | //Log出力
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | | if (deviceCount == -1)
|
| | | {
|
| | | //设置需要接收多少个设备
|
| | | deviceCount = totalNum;
|
| | | }
|
| | |
|
| | | listDevice.Add(device);
|
| | | }
|
| | | if (deviceCount == receiveCount)
|
| | | {
|
| | | //设备全部接收完成
|
| | | canBreak = true;
|
| | | var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
|
| | | //根据设备类型创建设备对象的实例
|
| | | var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
|
| | | if (device != null)
|
| | | {
|
| | | string mainkeys = this.GetDeviceMainKeys(device);
|
| | | //网关里面有可能会有重复的回路
|
| | | if (listCheck.Contains(mainkeys) == false)
|
| | | {
|
| | | //回调函数
|
| | | deviceComingAction?.Invoke(device);
|
| | | listDevice.Add(device);
|
| | |
|
| | | listCheck.Add(mainkeys);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | //Log出力
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | |
|
| | | if (receiveCount == deviceCount && deviceCount != -1)
|
| | | {
|
| | | //设备全部接收完成
|
| | | 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());
|
| | | realWay.Send("GetDeviceInfo", jObject.ToString());
|
| | | }
|
| | | catch { canBreak = true; }
|
| | |
|
| | | while (canBreak == false && TimeOut < 60)
|
| | | {
|
| | | await Task.Delay(100);
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
|
| | | msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时", false);
|
| | | this.ShowErrorMsg(msg);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | //如果是调光器
|
| | | else if (mainDevice.Type == DeviceType.DimmableLight )
|
| | | else if (mainDevice.Type == DeviceType.DimmableLight)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | |
| | | }
|
| | | }
|
| | | //如果是彩灯的话
|
| | | else if ( mainDevice.Type == DeviceType.ColorDimmableLight)
|
| | | else if (mainDevice.Type == DeviceType.ColorDimmableLight)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | |
| | | //定义规则:模块ID(已翻译)=设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
|
| | | //第一个值是:DeviceConcreteType 第二个值是:DeviceBeloneType
|
| | |
|
| | | //*********************************************************************
|
| | | //新设备添加方法:
|
| | | //1、在这里填写上模块ID,然后是 DeviceConcreteType ,然后是 DeviceBeloneType
|
| | | //2、然后在最下面添加【设备的具体类型】,【设备的所属类型】
|
| | | //3、已设备的具体类型为名字(去掉【-】)添加设备的【所属图片】,【真实物理图片】。回路图片需要特殊处理
|
| | | //4、添加R文件,添加Language文件
|
| | | //*********************************************************************
|
| | |
|
| | | //=========★★开合帘类(100-199)★★=========
|
| | | this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//智能开合帘电机
|
| | | this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//智能管状电机
|
| | |
| | | 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按键触摸面板(只带电源底座)
|
| | | this.dicDeviceModelIdEnum["MPT4R4L/S-ZB1.8"] = "220-200";//简约4按键面板
|
| | | this.dicDeviceModelIdEnum["MPT3R3L/S-ZB1.8"] = "221-200";//简约3按键面板
|
| | | this.dicDeviceModelIdEnum["MPT2R2L/S-ZB1.8"] = "222-200";//简约2按键面板
|
| | |
|
| | | //=========★★PIR传感器类(1200-1299)★★=========
|
| | | this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir传感器220
|
| | |
| | | this.dicDeviceModelIdEnum["H06C"] = "2800-2800";//智能门锁(H06C)
|
| | |
|
| | | //=========★★空调类(3600-3899)★★=========
|
| | | this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee空调网关模块
|
| | | this.dicDeviceModelIdEnum["MAC/GW-ZB.10"] = "3600-3600";//zigbee空调网关模块
|
| | |
|
| | | //=========★★中继器类(3900-3999)★★=========
|
| | | this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee中继器
|
| | |
| | | this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee转buspro协议转换器
|
| | | this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee转485协议转换器
|
| | |
|
| | | //需要交换的模块ID
|
| | | //✩✩✩✩✩需要交换的模块ID✩✩✩✩✩
|
| | | this.dicDeviceModelIdChanged = new Dictionary<string, string>();
|
| | | //=========★★安防类传感器类★★=========
|
| | | this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/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";//紧急按键
|
| | |
|
| | | //✩✩✩✩✩需要共有的图片对象✩✩✩✩✩
|
| | | this.dicPictrueShard = new Dictionary<string, string>();
|
| | | this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//简约4按键面板 沿用 4按键的图标
|
| | | this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//简约3按键面板 沿用 3按键的图标
|
| | | this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//简约2按键面板 沿用 2按键的图标
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// 4按键多功能触摸面板(只带电源底座) 镜像id:210
|
| | | /// </summary>
|
| | | ButtonPanel_FourNotPower = 210,
|
| | | /// <summary>
|
| | | /// 简约4按键面板 镜像id:220
|
| | | /// </summary>
|
| | | ButtonPanel_SimpleFour = 220,
|
| | | /// <summary>
|
| | | /// 简约3按键面板 镜像id:221
|
| | | /// </summary>
|
| | | ButtonPanel_SimpleThree = 221,
|
| | | /// <summary>
|
| | | /// 简约2按键面板 镜像id:222
|
| | | /// </summary>
|
| | | ButtonPanel_SimpleTwo = 222,
|
| | |
|
| | | //=========★★PIR传感器类(1200-1299)★★=========
|
| | | /// <summary>
|
| | |
| | |
|
| | | //=========★★空气开关类(4100-????)★★=========
|
| | | /// <summary>
|
| | | /// 智能空气开关
|
| | | /// 智能空开
|
| | | /// </summary>
|
| | | AirSwitch = -4100,
|
| | | /// <summary>
|
| | | /// 微断云控制器 镜像id:4100
|
| | | /// 智能空开 镜像id:4100
|
| | | /// </summary>
|
| | | AirSwitch_CloudContr = 4100,
|
| | |
|
| | |
| | | /// zigbee转buspro协议转换器
|
| | | /// </summary>
|
| | | Converter_ZbBuspro = 4201,
|
| | |
|
| | | //=========★★其他类(????-????)★★=========
|
| | | /// <summary>
|
| | | /// 干接点
|
| | | /// </summary>
|
| | | DryContact = -10000,
|
| | | /// <summary>
|
| | | /// 灯光(注意,它输入其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Light = -10001,
|
| | | /// <summary>
|
| | | /// 插座
|
| | | /// </summary>
|
| | | Socket1 = -10002,
|
| | | /// <summary>
|
| | | /// 开关
|
| | | /// </summary>
|
| | | Switch = -10003,
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// </summary>
|
| | | A中继器 = 3900,
|
| | | /// <summary>
|
| | | /// 空气开关(4100-4199)
|
| | | /// 智能空开(4100-4199)
|
| | | /// </summary>
|
| | | A空气开关 = 4100,
|
| | | A智能空开 = 4100,
|
| | | /// <summary>
|
| | | /// 转换器(4200-4699)
|
| | | /// </summary>
|
| | |
| | | /// <summary>
|
| | | /// 湿度传感器
|
| | | /// </summary>
|
| | | A湿度传感器 = 12
|
| | | A湿度传感器 = 12,
|
| | | /// <summary>
|
| | | /// 开关
|
| | | /// </summary>
|
| | | A开关 = 13,
|
| | | /// <summary>
|
| | | /// 插座
|
| | | /// </summary>
|
| | | A插座 = 14,
|
| | | /// <summary>
|
| | | /// 灯光
|
| | | /// </summary>
|
| | | A灯光 = 15,
|
| | | /// <summary>
|
| | | /// 干接点
|
| | | /// </summary>
|
| | | A干接点 = 16
|
| | | }
|
| | |
|
| | | #endregion
|