| | |
| | | }
|
| | |
|
| | | //添加设备的缓存
|
| | | var listDriveDevice = new List<CommonDevice>();
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | |
| | | }
|
| | | //获取设备的固定属性
|
| | | HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | | //对未命名的虚拟设备重新命名
|
| | | 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) + ")";
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | this.ReName(device, dName, ShowErrorMode.NO);
|
| | | });
|
| | | listDriveDevice.Add(device);
|
| | | }
|
| | | }
|
| | | if (listDriveDevice.Count > 0)
|
| | | {
|
| | | //如果虚拟设备还没有名字的话
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //如果不这样放在一个线程里,有可能对Dictionary产生影响
|
| | | foreach (var myDevice in listDriveDevice)
|
| | | {
|
| | | //根据设备类型获取名称
|
| | | var dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | this.ReName(myDevice, dName, ShowErrorMode.NO);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | //只有完全获取的时候,才会去处理删除的问题
|
| | |
| | |
|
| | | //获取编辑设备Mac名字的命令字符
|
| | | var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon");
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon", 8);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | |
| | | }
|
| | | //获取编辑设备端点名字的命令字符
|
| | | var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon");
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon", 8);
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | |
| | | public List<CommonDevice> GetMutilfunctionPanelByMac(List<CommonDevice> listDevice, bool sort = true)
|
| | | {
|
| | | //和彪哥、设备和产品部同事确认:
|
| | | //简约多功能面板[不显示多余的回路,只显示携带的2个继电器和1个温湿度传感器
|
| | | //简约多功能面板[不显示多余的回路,只显示携带的2个继电器,1个温度传感器,1个湿度传感器
|
| | | var list = new List<CommonDevice>();
|
| | | foreach (var dev in listDevice)
|
| | | {
|
| | | if (dev.Type == DeviceType.TemperatureSensor)
|
| | | {
|
| | | if (dev.DeviceEpoint == 64)
|
| | | {
|
| | | list.Add(dev);
|
| | | }
|
| | | }
|
| | | else if (dev.Type == DeviceType.FreshAirHumiditySensor)
|
| | | {
|
| | | if (dev.DeviceEpoint == 65)
|
| | | {
|
| | | list.Add(dev);
|
| | | }
|
| | |
| | | return -1;
|
| | | });
|
| | |
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据MAC地址,获取新风、简约环境面板全部回路的设备对象
|
| | | /// </summary>
|
| | | /// <param name="listDevice"></param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetPanelMatchEpointByMac(List<CommonDevice> listDevice, bool sort = true)
|
| | | { |
| | | var list = new List<CommonDevice>();
|
| | | foreach (var dev in listDevice)
|
| | | {
|
| | | if (dev.Type == DeviceType.TemperatureSensor)
|
| | | {
|
| | | list.Add(dev);
|
| | | }
|
| | | else if (dev.Type == DeviceType.FreshAirHumiditySensor)
|
| | | {
|
| | | list.Add(dev);
|
| | | } |
| | | }
|
| | | if (sort == false)
|
| | | {
|
| | | return list;
|
| | | } |
| | | list.Sort((obj1, obj2) => {
|
| | |
|
| | | if (obj1.DeviceEpoint > obj2.DeviceEpoint)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | }); |
| | | return list;
|
| | | }
|
| | |
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备信息_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 读取单个端点回路设备信息
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public CommonDevice.DeviceInfoData ReadDeviceEpointDeviceInfo(CommonDevice device)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } };
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetStatusRecord", jObject.ToString(), "GetStatusRecord_Respon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(result.ReceiptData);
|
| | | return info;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置设备功能类型___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备功能类型到网关
|
| | | /// </summary>
|
| | | /// <param name="device">设备回路</param>
|
| | | /// <param name="functionType">功能类型</param>
|
| | | /// <returns></returns>
|
| | | public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
|
| | | jObject.Add("Data", data);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", jObject.ToString(), "Device/SetEPDeviceFunctionTypeRespon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | var resultData = Newtonsoft.Json.Linq.JObject.Parse(result.ReceiptData);
|
| | | if (resultData.Property("Result") != null)
|
| | | {
|
| | | //0:修改成功 1:修改失败
|
| | | return resultData["Result"].ToString() == "0";
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备名称_______________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | //空调都叫室内机
|
| | | return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
|
| | | }
|
| | | else if (device.Type == DeviceType.FreshAir)
|
| | | {
|
| | | //新风面板中的按键叫新风
|
| | | return Language.StringByID(R.MyInternationalizationString.FreshAir);
|
| | | }
|
| | | else if (device.Type == DeviceType.FreshAirHumiditySensor)
|
| | | {
|
| | | //新风面板湿度传感器
|
| | | return Language.StringByID(R.MyInternationalizationString.HumiditySensor);
|
| | | }
|
| | | } |
| | |
|
| | | //获取设备类型
|
| | | var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
| | |
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo;
|
| | | }
|
| | | }
|
| | | else if (device.Type == DeviceType.FreshAirHumiditySensor)
|
| | | {
|
| | | //新风面板/简约多功能/简约环境面板湿度传感器
|
| | | return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
|
| | | }
|
| | | else if (device.Type == DeviceType.TemperatureSensor)
|
| | | {
|
| | | if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
|
| | | if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir
|
| | | || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment
|
| | | || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
|
| | | {
|
| | | //新风面板中的Thermostat为温度传感器
|
| | | return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
|
| | | //新风面板/简约多功能/简约环境面板 温度传感器
|
| | | return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
|
| | | }
|
| | | else if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
|
| | | {
|
| | |
| | | info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301;
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 541)
|
| | | {
|
| | | //球型移动传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
|
| | | info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1205;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | list.Add(DeviceBeloneType.A未知设备);
|
| | |
|
| | | return list;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备在线状态列表_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备在线状态列表(注意,一个设备只返回一个回路)
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关id</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDeviceOnlineList(string gwId)
|
| | | {
|
| | | var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
|
| | | int statu = 0;
|
| | | var listDevice = this.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
|
| | | if (statu == -1)
|
| | | {
|
| | | //当出现异常时,使用后备操作,直接获取本地的设备列表
|
| | | listDevice = this.GetDeviceByGatewayID(gwId);
|
| | | }
|
| | |
|
| | | var listCheck = new HashSet<string>();
|
| | | var listReturn = new List<CommonDevice>();
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | if (listCheck.Contains(device.DeviceAddr) == false)
|
| | | {
|
| | | listCheck.Add(device.DeviceAddr);
|
| | | listReturn.Add(device);
|
| | | }
|
| | | }
|
| | | return listReturn;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier;
|
| | | //序列号
|
| | | mainDevice.SerialNumber = device.DeviceInfo.ProductCode;
|
| | | //设备功能类型
|
| | | mainDevice.DfunctionType = (DeviceFunctionType)device.DeviceInfo.FunctionType;
|
| | |
|
| | | mainDevice.InClusterList.Clear();
|
| | | mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
|
| | |
| | | else if (mainDevice.Type == DeviceType.DimmableLight)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //调光器固定灯光
|
| | | this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
|
| | | }
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | | {
|
| | | mainDevice.IconPath = "Device/Light.png";
|
| | |
| | | else if (mainDevice.Type == DeviceType.ColorTemperatureLight)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //色温灯固定灯光
|
| | | this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
|
| | | }
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | | {
|
| | | mainDevice.IconPath = "Device/ColorLightTemperature.png";
|
| | |
| | | if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //继电器默认为灯光
|
| | | this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
|
| | | }
|
| | | }
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | | {
|
| | |
| | | if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A开关;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A开关)
|
| | | {
|
| | | //空气开关默认为开关
|
| | | this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A开关);
|
| | | }
|
| | | }
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | | {
|
| | |
| | | else if (mainDevice.Type == DeviceType.ColorDimmableLight)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //彩灯默认为开关
|
| | | this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
|
| | | }
|
| | | if (mainDevice.IsCustomizeImage == false)
|
| | | {
|
| | | mainDevice.IconPath = "Device/ColorLight.png";
|
| | |
| | | //根据设备类型创建设备对象的实例
|
| | | if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
|
| | | else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
|
| | | else if (deviceType == DeviceType.ColorDimmerSwitch) { device = new ColorDimmerSwitch(); }
|
| | | else if (deviceType == DeviceType.LevelControlSwitch) { device = new LevelControlSwitch(); }
|
| | | 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.WindowCoveringController) { device = new WindowCoveringController(); }
|
| | | else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
|
| | | else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
|
| | | else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
|
| | |
| | |
|
| | | //=========★★PIR传感器类(1200-1299)★★=========
|
| | | this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir传感器220
|
| | | this.dicDeviceModelIdEnum["MSPIRB-ZB.10"] = "1205-1200-60000";//球型移动传感器
|
| | |
|
| | | //=========★★安防类传感器类(1300-2299)★★=========
|
| | | //这里是麦乐克的
|
| | |
| | | /// pir传感器220 镜像id:1200
|
| | | /// </summary>
|
| | | Sensor_Pir = 1200,
|
| | | /// <summary>
|
| | | /// 球形移动传感器 镜像id:1205
|
| | | /// </summary>
|
| | | Sensor_SphericalMotion = 1205,
|
| | |
|
| | | //=========★★安防类传感器类(1300-2299)★★=========
|
| | | /// <summary>
|