| | |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | |
| | | { |
| | | #region 需要保存的变量 |
| | | |
| | | /// <summary>
|
| | | /// 是否是自定义图片
|
| | | /// <summary> |
| | | /// 是否是自定义图片 |
| | | /// </summary> |
| | | public bool IsCustomizeImage = false; |
| | | /// <summary> |
| | |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(IconPath))
|
| | | {
|
| | | return string.Empty;
|
| | | if (string.IsNullOrEmpty(IconPath)) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | var pathArr = IconPath.Split('.'); |
| | | if (pathArr == null || string.IsNullOrEmpty(pathArr[0])) |
| | |
| | | /// </summary> |
| | | public int DeviceEpoint; |
| | | /// <summary> |
| | | /// 设备id |
| | | /// 实际的设备id |
| | | /// <para>258:color dimmable light,调关灯 </para> |
| | | /// <para>10:Door lock,门锁</para> |
| | | /// <para>514:Window covering device,窗帘</para> |
| | |
| | | /// <para>1026:sensor,传感器,具体类型的传感器DeviceType来区分</para> |
| | | /// </summary> |
| | | public int DeviceID; |
| | | /// <summary> |
| | | /// <para>2020.09.21追加:为了对应第三方设备,以及之后的多设备ID问题,追加的变量</para> |
| | | /// <para>这是个特殊的,并且不保存在文件当中的ID, DeviceType由此值映射出来</para> |
| | | /// <para>当设备是河东设备时,它与DeviceID相等</para> |
| | | /// <para>当是真正的第三方设备时,它有可能与DeviceID不相等</para> |
| | | /// <para>比如:2和256都是继电器,那么【DeviceID为2 或者 DeviceID为256】 而 【ExDeviceID固定为2】,【DeviceType为OnOffOutput】</para> |
| | | /// <para>通俗来说:DeviceID是实际正确的ID,而【ExDeviceID是一种所属概念的ID】</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int ExDeviceID; |
| | | /// <summary> |
| | | /// 该字段主要针对IAS安防设备设立。所有IAS安防设备共用一个DeviceID为1026。所以要区分子设备类型,需要该字段。 |
| | | /// 瞬间数据上报的传感器 (MomentStatus=1 TriggerZoneStatus>=1<报警>) |
| | |
| | | /// 0:设备不在线 |
| | | /// <para>1:设备在线</para> |
| | | /// </summary> |
| | | public int IsOnline;
|
| | | /// <summary>
|
| | | /// 1:路由设备
|
| | | /// <para>2:终端设备,电池设备</para>
|
| | | /// </summary>
|
| | | public int IsOnline; |
| | | /// <summary> |
| | | /// 1:路由设备 |
| | | /// <para>2:终端设备,电池设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | /// <summary> |
| | | /// 当前运行程序版本信息。 最大64字节 |
| | | /// 固件版本 |
| | | /// </summary> |
| | | public int ImgVersion; |
| | | /// <summary> |
| | |
| | | /// 输出簇列表 |
| | | /// </summary> |
| | | public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); |
| | | /// <summary> |
| | | /// 用于记录设备最新上报的属性状态信息 |
| | | /// </summary> |
| | | public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime LastDateTime = DateTime.MinValue; |
| | |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool HadReadDeviceStatu = false; |
| | | |
| | | /// <summary> |
| | | /// 是否是低电量(这个变量目前是给传感器用的) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsBatteryDown = false; |
| | | |
| | | /// <summary> |
| | | /// 等待从网关接收数据的时间 |
| | |
| | | { |
| | | get |
| | | { |
| | | var deviceType = Type.ToString(); |
| | | var fileName = "Device_" + deviceType + "_" + DeviceAddr; |
| | | fileName += "_" + (DeviceEpoint.ToString().Length < 2 ? "0" + DeviceEpoint.ToString() : DeviceEpoint.ToString()); |
| | | return fileName; |
| | | //2020.09.21 对应第三方设备可以入网,设备文件名字,去掉 deviceType |
| | | return "Device_" + DeviceAddr + "_" + DeviceEpoint.ToString().PadLeft(2, '0'); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 设备保存及生成 |
| | |
|
| | | /// <summary>
|
| | | /// 由设备字符串比特恢复设备对象
|
| | | /// </summary>
|
| | | /// <param name="strDeviceType">设备DeviceType的字符串类型</param>
|
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
|
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) |
| | | { |
| | | CommonDevice device = null; |
| | | if (strDeviceType == ZigBee.Device.DeviceType.DimmableLight.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffOutput.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.IASZone.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OtaDevice.ToString() || strDeviceType == ZigBee.Device.DeviceType.OtaPanelDevice.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.AirSwitch.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Repeater.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Thermostat.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Transverter.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); |
| | | }
|
| | | else if (strDeviceType == ZigBee.Device.DeviceType.TemperatureSensor.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.FreshAirHumiditySensor.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.FreshAir.ToString()) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.PMSensor.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte); |
| | | }
|
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte); |
| | | } |
| | | else { return null; } |
| | | //能少存一个变量就少存一个 |
| | | device.Type = (DeviceType)device.DeviceID; |
| | | |
| | | return device; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 由设备路径恢复设备对象 |
| | | /// 由设备字符串比特恢复设备对象 |
| | | /// </summary> |
| | | /// <returns>The device by file path.</returns> |
| | | /// <param name="deviceFilePath">Device file path.</param> |
| | | public static CommonDevice CommonDeviceByFilePath(string deviceFilePath) |
| | | /// <param name="intDeviceType">设备DeviceType的整型值</param> |
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param> |
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte) |
| | | { |
| | | var v = deviceFilePath.Split('_'); |
| | | if (v.Length < 3) |
| | | //这是河东的特殊端点,不需要处理 |
| | | if (intDeviceType == 49408) |
| | | { |
| | | return null; |
| | | } |
| | | return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath))); |
| | | |
| | | CommonDevice device = null; |
| | | if (intDeviceType == (int)DeviceType.DimmableLight || intDeviceType == 3) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); |
| | | device.ExDeviceID = (int)DeviceType.DimmableLight; |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.OnOffOutput || intDeviceType == 256) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); |
| | | device.ExDeviceID = (int)DeviceType.OnOffOutput; |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.ColorDimmerSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.LevelControlSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.WindowCoveringDevice) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.WindowCoveringController) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.OnOffSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.IASZone) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.OtaDevice || intDeviceType == (int)DeviceType.OtaPanelDevice) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.AirSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.Repeater) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.Thermostat) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.Transverter) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.DoorLock) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.TemperatureSensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.FreshAirHumiditySensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.FreshAir) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.PMSensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.ColorTemperatureLight) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.Buzzer) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.ColorDimmableLight) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmableLight>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.DimmerSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte); |
| | | } |
| | | else if (intDeviceType == (int)DeviceType.Airer) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Airer>(strDeviceByte); |
| | | } |
| | | else |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte); |
| | | } |
| | | |
| | | //这是河东的特殊端点,不需要处理 |
| | | if (device.DeviceEpoint == 242 && intDeviceType == 97) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if (device.ExDeviceID == 0) |
| | | { |
| | | //赋初始值 |
| | | device.ExDeviceID = device.DeviceID; |
| | | } |
| | | |
| | | //能少存一个变量就少存一个 |
| | | device.Type = (DeviceType)device.ExDeviceID; |
| | | |
| | | return device; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void ReSave() |
| | | { |
| | | if (IconPath == string.Empty)
|
| | | {
|
| | | //保存设备图标(这里会保存一次,下面就不用保存了)
|
| | | this.SaveDeviceIcon();
|
| | | return;
|
| | | if (Shared.Common.Config.Instance.Home.IsShowTemplate == true) |
| | | { |
| | | //展示模板时,不允许保存文件(防止属性上报用的) |
| | | return; |
| | | } |
| | | if (IconPath == string.Empty) |
| | | { |
| | | //保存设备图标(这里会保存一次,下面就不用保存了) |
| | | this.SaveDeviceIcon(); |
| | | return; |
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | }
|
| | |
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否是空气质量传感器 |
| | | /// </summary> |
| | | /// <param name="dev"></param> |
| | | /// <returns></returns> |
| | | public bool isAirQualitySensor(CommonDevice dev) |
| | | { |
| | | bool hasT = false; |
| | | bool hasH = false; |
| | | bool hasPM = false; |
| | | bool hasCo2 = false; |
| | | foreach (var clu in dev.InClusterList) |
| | | { |
| | | switch (clu.InCluster) |
| | | { |
| | | case 1026: |
| | | hasT = true; |
| | | break; |
| | | case 1029: |
| | | hasH = true; |
| | | break; |
| | | case 1037: |
| | | hasCo2 = true; |
| | | break; |
| | | case 1066: |
| | | hasPM = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (hasT == true && hasH == true && hasPM == true && hasCo2 == true) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存设备图标 |
| | | /// </summary> |
| | |
| | | { |
| | | if (IconPath == string.Empty) |
| | | { |
| | | //干接点
|
| | | if (this.Type == DeviceType.OnOffSwitch)
|
| | | {
|
| | | IconPath = "Device/DryContact.png";
|
| | | }
|
| | | //干接点 |
| | | if (this.Type == DeviceType.OnOffSwitch) |
| | | { |
| | | IconPath = "Device/DryContact.png"; |
| | | } |
| | | else if (this.Type == DeviceType.ColorDimmableLight) |
| | | { |
| | | //彩灯 |
| | | IconPath = "Device/ColorLight.png"; |
| | | }
|
| | | } |
| | | else if (this.Type == DeviceType.DimmableLight) |
| | | { |
| | | //调光器 |
| | | IconPath = "Device/Light.png"; |
| | | }
|
| | | else if (this.Type == DeviceType.ColorTemperatureLight)
|
| | | {
|
| | | //色温灯
|
| | | IconPath = "Device/ColorLightTemperature.png";
|
| | | } |
| | | else if (this.Type == DeviceType.ColorTemperatureLight) |
| | | { |
| | | //色温灯 |
| | | IconPath = "Device/ColorLightTemperature.png"; |
| | | } |
| | | else if (this.Type == DeviceType.OnOffOutput) |
| | | { |
| | |
| | | //湿度传感器 |
| | | IconPath = "Device/SensorHumidity.png"; |
| | | } |
| | | else if (this.Type == DeviceType.TemperatureSensor)
|
| | | {
|
| | | if (((TemperatureSensor)this).SensorDiv == 1)
|
| | | {
|
| | | //温度传感器
|
| | | IconPath = "Device/SensorTemperature.png";
|
| | | }
|
| | | else if (((TemperatureSensor)this).SensorDiv == 2)
|
| | | {
|
| | | //湿度传感器
|
| | | IconPath = "Device/SensorHumidity.png";
|
| | | }
|
| | | else if (this.Type == DeviceType.TemperatureSensor) |
| | | { |
| | | if (isAirQualitySensor(this)) |
| | | { |
| | | //空气质量传感器 |
| | | IconPath = "Device/AirQualitySensorEpoint.png"; |
| | | } |
| | | else |
| | | { |
| | | if (((TemperatureSensor)this).SensorDiv == 1) |
| | | { |
| | | //温度传感器 |
| | | IconPath = "Device/SensorTemperature.png"; |
| | | } |
| | | else if (((TemperatureSensor)this).SensorDiv == 2) |
| | | { |
| | | //湿度传感器 |
| | | IconPath = "Device/SensorHumidity.png"; |
| | | } |
| | | } |
| | | } |
| | | else if (this.Type != DeviceType.UnKown)
|
| | | {
|
| | | //其他的图标有点特殊
|
| | | string unSelectPic = string.Empty;
|
| | | string selectPic = string.Empty;
|
| | | Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
|
| | | IconPath = unSelectPic;
|
| | | }
|
| | | else if (this.Type != DeviceType.UnKown) |
| | | { |
| | | //其他的图标有点特殊 |
| | | string unSelectPic = string.Empty; |
| | | string selectPic = string.Empty; |
| | | Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic); |
| | | IconPath = unSelectPic; |
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | } |
| | | }
|
| | |
|
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 输入输出镞定义 |
| | |
| | | /// </summary> |
| | | public int AttributeId; |
| | | /// <summary> |
| | | /// 属性值,最大占用4个字节 |
| | | /// 属性值,这个东西不需要什么高位在后低位在前,它已经是转为了10进制 |
| | | /// </summary> |
| | | public int AttributeData; |
| | | /// <summary> |
| | |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary>
|
| | | /// 厂商名称
|
| | | /// <summary> |
| | | /// 厂商名称 |
| | | /// </summary> |
| | | public string ManufacturerName = string.Empty; |
| | | /// <summary>
|
| | | /// 模块ID
|
| | | /// <summary> |
| | | /// 模块ID |
| | | /// </summary> |
| | | public string ModelIdentifier = string.Empty; |
| | | /// <summary>
|
| | | /// 好像是序列号
|
| | | /// <summary> |
| | | /// 好像是序列号 |
| | | /// </summary> |
| | | public string ProductCode = string.Empty; |
| | | /// <summary> |
| | | /// 设备功能类型(空气开关和继电器专用) |
| | | /// </summary> |
| | | public int FunctionType = -1; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 一键更新四寸屏按键属性 |
| | | /// <summary> |
| | | /// 同步设备功能 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | SynchronizationDeviceResponseAllData resContent = null; |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | resContent = new SynchronizationDeviceResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Bind/SyncMsgToBindSourceRespon") |
| | | { |
| | | var res = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | if (res == null) |
| | | { |
| | | resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | resContent = new SynchronizationDeviceResponseAllData { result = res }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions = action; |
| | | DebugPrintLog("Bind/SyncMsgToBindSourceRespon_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5010 } }; |
| | | Gateway.Send("Bind/SyncMsgToBindSource", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (resContent != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("Bind/SyncMsgToBindSource_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return resContent; |
| | | }); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 同步设备,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SynchronizationDeviceResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 同步结果 |
| | | /// 0:成功:网关内部自动写入设备目标名字、设备目标功能类型、场景目标名字、utc时间写入4寸屏 |
| | | /// 1:失败 |
| | | /// </summary> |
| | | public int result; |
| | | } |
| | | #endregion |
| | | |
| | | #region 删除设备(使设备离网) |
| | | /// <summary> |
| | | /// 删除设备(使设备离网) |
| | |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("RemoveDevice_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("RemoveDevice_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | |
| | | d = new RemoveDeviceResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("RemoveDevice_Actions 退出" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("RemoveDevice_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | |
| | | /// 设置可写属性的值 |
| | | /// </summary> |
| | | /// <returns>The writable value async.</returns> |
| | | /// <param name="gateway">Gateway.</param> |
| | | /// <param name="clusterID">要配置的属性所在的cluster.</param> |
| | | /// <param name="setWritableValue">设置可写属性的数据</param> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(ZigBee.Device.ZbGateway gateway, int clusterID, SetWritableValueData setWritableValue) |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(int clusterID, SetWritableValueData setWritableValue) |
| | | { |
| | | if (gateway == null || setWritableValue == null) |
| | | if (Gateway == null || setWritableValue == null) |
| | | { |
| | | return null; |
| | | } |
| | |
| | | } |
| | | } |
| | | }; |
| | | gateway.Actions += action; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", setWritableValue.Undivided }, { "AttributeId", setWritableValue.AttributeId }, { "AttributeDataType", setWritableValue.AttributeDataType }, { "AttributeData", setWritableValue.AttributeData } }; |
| | | jObject.Add("Data", data); |
| | | gateway.Send("SetWritableValue", jObject.ToString()); |
| | | Gateway.Send("SetWritableValue", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | gateway.Actions -= action; |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | |
| | | public static void DebugPrintLog(string msg, bool flage = true) |
| | | { |
| | | #if DEBUG |
| | | if (flage == true) |
| | | { |
| | | if (msg.Contains("DeviceStatusReport") == false) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | | } |
| | | if (flage == true) |
| | | { |
| | | if (msg.Contains("DeviceStatusReport") == false) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |