| | |
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存(排序)
|
| | | /// 本地所有设备的缓存
|
| | | /// </summary>
|
| | | public List<CommonDevice> listAllDevice
|
| | | {
|
| | |
| | | #region ■ 添加设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 将指定网关的设备存入缓存中(从新获取镜像)
|
| | | /// <para>将指定网关的设备存入缓存中(从新获取镜像)</para>
|
| | | /// <para>-1:异常 1:正常 2:设备信息缺损</para>
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="deviceComingAction">接收到设备时的事件,设备对象为null时,代表接收完成</param>
|
| | | /// <returns>一直返回true</returns>
|
| | | public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
|
| | | public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | //从网关获取全部的设备
|
| | | int statu = 0;
|
| | | List<CommonDevice> listDevice = new List<CommonDevice>();
|
| | | List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction);
|
| | |
|
| | | List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, true);
|
| | | if (list == null)
|
| | | {
|
| | | return false;
|
| | | return -1;
|
| | | }
|
| | | listDevice.AddRange(list);
|
| | |
|
| | | //获取这个网关的本地所有设备
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
|
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID, true);
|
| | | Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>();
|
| | | foreach (var device in listLocalDevices)
|
| | | {
|
| | |
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | | //对未命名的设备重新命名
|
| | | if (this.GetSimpleEpointName(device) == string.Empty)
|
| | | //对未命名的虚拟设备重新命名
|
| | | if (device.DriveCode > 0 && 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) + ")";
|
| | | }
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | //如果本地和网关的设备不一致的时候,暂时删除本地的设备
|
| | | //注意:只是删除设备文件,房间内容什么的还存在着
|
| | | foreach (var device in dicExist.Values)
|
| | | //只有完全获取的时候,才会去处理删除的问题
|
| | | if (statu != 1)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device, false);
|
| | | return statu;
|
| | | }
|
| | |
|
| | | return true;
|
| | | //如果本地和网关的设备不一致的时候,删除本地的设备
|
| | | foreach (var device in dicExist.Values)
|
| | | {
|
| | | if (device is OTADevice)
|
| | | {
|
| | | this.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | }
|
| | | else
|
| | | {
|
| | | this.DeleteMemmoryDevice(device, true);
|
| | | }
|
| | | }
|
| | |
|
| | | return statu;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | lock (dicAllDevice)
|
| | | {
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == false)
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | device.ReSave();
|
| | | //一般设备
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | device.ReSave();
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | | else if (this.dicOTADevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | //Ota设备
|
| | | this.dicOTADevice[mainKeys] = (OTADevice)device;
|
| | | device.ReSave();
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | //删除缓存的Ota设备
|
| | | this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr);
|
| | | //删除一般设备文件
|
| | | foreach (CommonDevice device in listdevice)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device);
|
| | | }
|
| | |
|
| | | if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
|
| | | {
|
| | | //移除真实设备的房间索引
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除缓存的设备
|
| | | /// 删除缓存的一般设备
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="deleteRoom">是否从房间删除</param>
|
| | |
| | | {
|
| | | this.dicAllDevice.Remove(mainKeys);
|
| | | }
|
| | | if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
|
| | | {
|
| | | //变更端点数
|
| | | this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
|
| | | }
|
| | | }
|
| | |
|
| | | //删除设备文件
|
| | |
| | | HdlAutoBackupLogic.DeleteFile(device.FilePath);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除缓存的Ota设备
|
| | | /// </summary>
|
| | | /// <param name="macAdrr"></param>
|
| | | /// <param name="ePoint"></param>
|
| | | public void DeleteMemmoryOtaDevice(string macAdrr, int ePoint = 200)
|
| | | {
|
| | | //删除200端口文件
|
| | | string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200);
|
| | | string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint);
|
| | | if (this.dicOTADevice.ContainsKey(otaKeys) == true)
|
| | | {
|
| | | string otaFile = this.dicOTADevice[otaKeys].FilePath;
|
| | |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //成员的话,直接删除,没有商量的余地
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | Global.DeleteFilebyHomeId(otaFile);
|
| | | }
|
| | | else
|
| | | {
|
| | | //变更:搞掉它,不留了
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | Global.DeleteFilebyHomeId(otaFile);
|
| | | //删除自动备份
|
| | | HdlAutoBackupLogic.DeleteFile(otaFile);
|
| | | }
|
| | |
| | | /// 根据网关ID获取所有的设备
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关ID</param>
|
| | | /// <param name="getOtaDevice">是否获取ota设备</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId)
|
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId, bool getOtaDevice = false)
|
| | | {
|
| | | List<CommonDevice> list = new List<CommonDevice>();
|
| | | lock (dicAllDevice)
|
| | |
| | | if (gwId == device.CurrentGateWayId)
|
| | | {
|
| | | list.Add(device);
|
| | | }
|
| | | }
|
| | | if (getOtaDevice == true)
|
| | | {
|
| | | //获取ota设备
|
| | | foreach (var ota in this.dicOTADevice.Values)
|
| | | {
|
| | | if (ota.CurrentGateWayId == gwId)
|
| | | {
|
| | | list.Add(ota);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | return this.dicOTADevice[mainkeys];
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取特殊的,没有其他回路,单纯只有200端点的OTA设备
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public List<OTADevice> GetSpecialOtaDevice(string gwId)
|
| | | {
|
| | | var list = new List<OTADevice>();
|
| | | foreach (var ota in this.dicOTADevice.Values)
|
| | | {
|
| | | if (ota.CurrentGateWayId != gwId)
|
| | | {
|
| | | //不是同一个网关
|
| | | continue;
|
| | | }
|
| | | if (dicDeviceEpoint.ContainsKey(ota.DeviceAddr) == false
|
| | | || dicDeviceEpoint[ota.DeviceAddr].Count == 0)
|
| | | {
|
| | | list.Add(ota);
|
| | | }
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备名称_______________________
|
| | |
| | | return dName;
|
| | | }
|
| | | //根据设备类型获取名称
|
| | | dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
|
| | | var tempValue = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
|
| | | var arry = tempValue.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | dName = arry[0].Trim();
|
| | |
|
| | | //如果是虚拟设备
|
| | | if (device.DriveCode > 0
|
| | | || (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1))
|
| | | if (device.DriveCode > 0)
|
| | | {
|
| | | var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | dName = arry[0].Trim();
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | return dName;
|
| | | }
|
| | |
|
| | | //获取设备类型
|
| | | var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
| | | if (deviceInfoType.BeloneType == Common.DeviceBeloneType.A按键面板 && device.Type == DeviceType.TemperatureSensor)
|
| | | {
|
| | | //面板的最后一个回路是温度传感器
|
| | | dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId11);
|
| | | }
|
| | | else if (deviceInfoType.ConcreteType == Common.DeviceConcreteType.Sensor_Pir)
|
| | | {
|
| | | //pir传感器,它又搞特殊东西,传感器自身用自己的名字,继电器回路的话……
|
| | | if (device.Type == DeviceType.OnOffOutput)
|
| | | {
|
| | | dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2300);
|
| | | }
|
| | | }
|
| | | else if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1)
|
| | | {
|
| | | //XXXXX(N回路)
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | }
|
| | |
|
| | | return dName;
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | //不存在则使用共通图片
|
| | | string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None);
|
| | | if (arry.Length == 1)
|
| | | //如果它自己就是共通图片的话,不再处理
|
| | | if (arry.Length > 1)
|
| | | {
|
| | | //如果它自己就是共通图片的话,不再处理
|
| | | return;
|
| | | imageFilePath = "Device/" + arry[0] + ".png";
|
| | | imageSelectFilePath = "Device/" + arry[0] + "Selected.png";
|
| | | }
|
| | | imageFilePath = "Device/" + arry[0] + ".png";
|
| | | imageSelectFilePath = "Device/" + arry[0] + "Selected.png";
|
| | | }
|
| | | //如果那款设备连共通图片都没有的话
|
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
|
| | | {
|
| | | imageFilePath = "Device/ThirdPartyDevice.png";
|
| | | imageSelectFilePath = "Device/ThirdPartyDeviceSelected.png";
|
| | | }
|
| | | //设置图片
|
| | | unSelectPath = imageFilePath;
|
| | |
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
|
| | | {
|
| | | if (listDevice[0] is OTADevice)
|
| | | {
|
| | | //单纯只是Ota设备则不处理
|
| | | return;
|
| | | }
|
| | | Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | }
|
| | |
| | | #region ■ 获取设备列表的接口_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 从网关重新获取设备列表(★★★★★★★接收到设备时的事件★★★★★★★)
|
| | | /// <para>从网关重新获取设备列表(返回的设备为虚拟出来的)</para>
|
| | | /// <para>statu状态 -1:异常,会返回null, 1:没有异常, 2:数据接收不全</para>
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="ignoreTime">是否无视时间,true:每次调用都去网关获取,false:3分钟内返回的是本地的设备</param>
|
| | | /// <param name="deviceComingAction">接收到设备时的事件</param>
|
| | | /// <param name="statu">状态-> -1:异常,会返回null, 1:没有异常, 2:数据接收不全</param>
|
| | | /// <param name="ignoreTime">是否无视时间(此变量是给获取在线状态用的),true:每次调用都去网关获取,false:3分钟内返回的是本地的设备</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <returns></returns> |
| | | public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) |
| | | public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, ShowErrorMode mode = ShowErrorMode.YES) |
| | | {
|
| | | if (ignoreTime == false)
|
| | | {
|
| | | if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000)
|
| | | {
|
| | | //不无视时间,返回本地设备列表
|
| | | var listTemp = this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
|
| | | if (deviceComingAction != null)
|
| | | {
|
| | | for (int i = 0; i < listTemp.Count; i++)
|
| | | {
|
| | | try
|
| | | {
|
| | | //回调函数
|
| | | deviceComingAction.Invoke(listTemp[i]);
|
| | | }
|
| | | //Log出力
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | | }
|
| | | }
|
| | | deviceComingAction = null;
|
| | | return listTemp;
|
| | | statu = 1;
|
| | | return this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
|
| | | }
|
| | | }
|
| | | zbGateway.LastDateTime = DateTime.Now;
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | statu = -1;
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | //网关里面有可能会有重复的回路
|
| | | if (listCheck.Contains(mainkeys) == false)
|
| | | {
|
| | | //回调函数
|
| | | deviceComingAction?.Invoke(device);
|
| | | listDevice.Add(device);
|
| | |
|
| | | listCheck.Add(mainkeys);
|
| | |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时", false);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | statu = -1;
|
| | | return null;
|
| | | }
|
| | | else
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | statu = 2;
|
| | | }
|
| | | }
|
| | |
|
| | | //回调函数(接收完成) |
| | | deviceComingAction = null; |
| | | |
| | | } |
| | | return listDevice; |
| | | }
|
| | |
|
| | |
| | | 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按键面板
|
| | | this.dicDeviceModelIdEnum["MPT4R4L/S-ZB.18"] = "220-200";//简约4按键面板
|
| | | this.dicDeviceModelIdEnum["MPT3R3L/S-ZB.18"] = "221-200";//简约3按键面板
|
| | | this.dicDeviceModelIdEnum["MPT2R2L/S-ZB.18"] = "222-200";//简约2按键面板
|
| | |
|
| | | //=========★★PIR传感器类(1200-1299)★★=========
|
| | | this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir传感器220
|
| | |
| | | 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-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>();
|
| | |
| | |
|
| | | //=========★★其他类(????-????)★★=========
|
| | | /// <summary>
|
| | | /// 干接点
|
| | | /// 干接点(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | DryContact = -10000,
|
| | | /// <summary>
|
| | | /// 灯光(注意,它输入其他类,不是设备类型)
|
| | | /// 灯光(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Light = -10001,
|
| | | /// <summary>
|
| | | /// 插座
|
| | | /// 插座(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Socket1 = -10002,
|
| | | /// <summary>
|
| | | /// 开关
|
| | | /// 开关(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Switch = -10003,
|
| | | }
|