| | |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | | [System.Serializable] |
| | | public class CommonDevice |
| | | { |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime LastDateTime = DateTime.MinValue; |
| | | #region 需要保存的变量 |
| | | |
| | | /// <summary> |
| | | /// 调试时打开打印信息,true:打印,false:不打印 |
| | | /// </summary> |
| | | /// <param name="msg">Message.</param> |
| | | /// <param name="flage">If set to <c>true</c> flage.</param> |
| | | 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);
|
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 等待从网关接收数据的时间 |
| | | /// </summary> |
| | | /// <value>The wait receive data time.</value> |
| | | public virtual int WaitReceiveDataTime |
| | | { |
| | | get |
| | | { |
| | | if (Device.ZbGateway.RemoteMqttClient != null && Device.ZbGateway.RemoteMqttClient.IsConnected) |
| | | { |
| | | return 10000; |
| | | } |
| | | else |
| | | { |
| | | return 3000; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsValid |
| | | { |
| | | get |
| | | { |
| | | return (DateTime.Now - LastDateTime).TotalSeconds < 10; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过设备调用网关 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public ZbGateway Gateway |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(CurrentGateWayId)) |
| | | { |
| | | return null; |
| | | } |
| | | var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.getGatewayBaseInfo != null) && (obj.getGatewayBaseInfo.gwID == CurrentGateWayId)); |
| | | if (gateWay == null) |
| | | { |
| | | gateWay = new ZbGateway { IsVirtual = true, }; |
| | | gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId; |
| | | gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(gateWay); |
| | | } |
| | | |
| | | return gateWay; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存设备数据的文件名 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public virtual string FilePath |
| | | { |
| | | get |
| | | { |
| | | var deviceType = Type.ToString(); |
| | | var fileName = "Device_" + deviceType + "_" + DeviceAddr; |
| | | fileName += "_" + (DeviceEpoint.ToString().Length < 2 ? "0" + DeviceEpoint.ToString() : DeviceEpoint.ToString()); |
| | | return fileName; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 由设备路径恢复设备对象 |
| | | /// </summary> |
| | | /// <returns>The device by file path.</returns> |
| | | /// <param name="deviceFilePath">Device file path.</param> |
| | | public static CommonDevice CommonDeviceByFilePath(string deviceFilePath) |
| | | { |
| | | var v = deviceFilePath.Split('_'); |
| | | if (v.Length < 3) |
| | | { |
| | | return null; |
| | | } |
| | | return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath))); |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 由设备字符串比特恢复设备对象
|
| | | /// </summary>
|
| | | /// <param name="strDeviceType">设备DeviceType的字符串类型</param>
|
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
|
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) |
| | | { |
| | | if (strDeviceType == ZigBee.Device.DeviceType.DimmableLight.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffOutput.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.IASZone.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OtaDevice.ToString() || strDeviceType == ZigBee.Device.DeviceType.OtaPanelDevice.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.AirSwitch.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Repeater.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Thermostat.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Transverter.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); |
| | | }
|
| | | else if (strDeviceType == ZigBee.Device.DeviceType.TemperatureSensor.ToString()) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存设备 |
| | | /// </summary> |
| | | public void Save() |
| | | { |
| | | if (Shared.Common.Global.IsExistsByHomeId(FilePath)) |
| | | { |
| | | return; |
| | | } |
| | | ReSave(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重新保存设备 |
| | | /// </summary> |
| | | public void ReSave() |
| | | { |
| | | if (IconPath == string.Empty)
|
| | | {
|
| | | //保存设备图标(这里会保存一次,下面就不用保存了)
|
| | | this.SaveDeviceIcon();
|
| | | return;
|
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 保存设备图标 |
| | | /// </summary> |
| | | private void SaveDeviceIcon() |
| | | { |
| | | if (IconPath == string.Empty) |
| | | { |
| | | //干接点
|
| | | 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.OnOffOutput) |
| | | { |
| | | //继电器 |
| | | IconPath = "Device/RelayEpoint.png"; |
| | | } |
| | | else if (this.Type == DeviceType.Thermostat) |
| | | { |
| | | //空调 |
| | | IconPath = "Device/AirConditionerEpoint.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.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))); |
| | | } |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 是否是自定义图片
|
| | | /// 是否是自定义图片 |
| | | /// </summary> |
| | | public bool IsCustomizeImage = false; |
| | | /// <summary> |
| | |
| | | return $"{pathArr[0]}Selected.png"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 当前网关的ID |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 当前设备类型 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DeviceType Type = DeviceType.UnKown; |
| | | /// <summary>
|
| | | /// 设备的功能类型(此类型目前只针对继电器回路有效,默认未指定)
|
| | | /// <summary> |
| | | /// 设备的功能类型(此类型目前只针对继电器回路有效,默认未指定) |
| | | /// </summary> |
| | | public DeviceFunctionType DfunctionType = DeviceFunctionType.A未定义; |
| | | /// <summary> |
| | | /// MAC地址 |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | |
| | | /// <summary> |
| | | /// 设备端口号 |
| | | /// </summary> |
| | | public int DeviceEpoint; |
| | | |
| | | /// <summary> |
| | | /// 设备命令格式:Mac+端口 |
| | | /// </summary> |
| | | /// <value>The common device address epoint.</value> |
| | | public string CommonDeviceAddrEpoint |
| | | { |
| | | get |
| | | { |
| | | return DeviceAddr + "_" + DeviceEpoint.ToString(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关反馈的时间戳 |
| | | /// </summary> |
| | | public int Time; |
| | | |
| | | /// <summary> |
| | | /// 网关回复的数据ID |
| | | /// </summary> |
| | | public int DataID; |
| | | |
| | | /// <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<报警>) |
| | |
| | | /// <para>22:Door/Window 门窗传感器(有21和22,这里没有写错</para> |
| | | /// </summary> |
| | | public int IasDeviceType; |
| | | |
| | | /// <summary> |
| | | /// 设备名称,以设备的MAC命名 |
| | | /// </summary> |
| | | public string DeviceName = "UnKown"; |
| | | |
| | | /// <summary> |
| | | /// 设备端点名称,以设备端点名称命名 |
| | | /// </summary> |
| | | public string DeviceEpointName = "UnKown"; |
| | | |
| | | /// <summary> |
| | | /// 用于判断设备的zigbee协议版本。 |
| | | ///<para>49246:ZLL1.0标准设备。</para> |
| | |
| | | ///<para>41440:ZGP3.0标准设备。</para> |
| | | ///<para>265:ZSE1.4标准设备。</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int Profile; |
| | | /// <summary> |
| | | /// 0:设备不在线 |
| | |
| | | /// </summary> |
| | | public int IsOnline; |
| | | /// <summary> |
| | | /// 当前运行程序版本信息。 最大64字节 |
| | | /// 1:路由设备 |
| | | /// <para>2:终端设备,电池设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | /// <summary> |
| | | /// 固件版本 |
| | | /// </summary> |
| | | public int ImgVersion; |
| | | /// <summary> |
| | |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary>
|
| | | /// <summary> |
| | | /// 生产商名字 |
| | | /// </summary> |
| | | public string ManufacturerName = string.Empty; |
| | |
| | | /// </summary> |
| | | public string SerialNumber = string.Empty; |
| | | /// <summary> |
| | | /// 所有指定cluster是否都已经成功绑定协调器 |
| | | ///<para>0:未完全绑定</para> |
| | | ///<para>1:已经绑定</para> |
| | | /// </summary> |
| | | public int ClusterBindZbSuccess = -1; |
| | | /// <summary> |
| | | /// 是否获取所有默认绑定信息 |
| | | ///<para>0:否</para> |
| | | ///<para>1:是</para> |
| | | /// </summary> |
| | | public int IsGetAllDefaultBind = -1; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | | public List<InClusterObj> InClusterList = new List<InClusterObj>(); |
| | |
| | | /// </summary> |
| | | public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); |
| | | /// <summary> |
| | | /// 用于记录设备最新上报的属性状态信息。最大支持记录16个属性状态,且只记录属性值长度不大于4字节的数据。 |
| | | /// 用于记录设备最新上报的属性状态信息 |
| | | /// </summary> |
| | | public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime LastDateTime = DateTime.MinValue; |
| | | /// <summary> |
| | | /// 是否已经读取了设备状态(此属性是给主页使用的) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool HadReadDeviceStatu = false; |
| | | |
| | | /// <summary> |
| | | /// 是否是低电量(这个变量目前是给传感器用的) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsBatteryDown = false; |
| | | |
| | | /// <summary> |
| | | /// 等待从网关接收数据的时间 |
| | | /// </summary> |
| | | /// <value>The wait receive data time.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public virtual int WaitReceiveDataTime |
| | | { |
| | | get |
| | | { |
| | | if (Device.ZbGateway.RemoteMqttClient != null && Device.ZbGateway.RemoteMqttClient.IsConnected) |
| | | { |
| | | return 10000; |
| | | } |
| | | else |
| | | { |
| | | return 3000; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过设备调用网关 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public ZbGateway Gateway |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(CurrentGateWayId)) |
| | | { |
| | | return null; |
| | | } |
| | | var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == CurrentGateWayId)); |
| | | if (gateWay == null) |
| | | { |
| | | gateWay = new ZbGateway { IsVirtual = true, }; |
| | | gateWay.GwId = CurrentGateWayId; |
| | | gateWay.HomeId = Shared.Common.Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(gateWay); |
| | | } |
| | | |
| | | return gateWay; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存设备数据的文件名 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public virtual string FilePath |
| | | { |
| | | get |
| | | { |
| | | //2020.09.21 对应第三方设备可以入网,设备文件名字,去掉 deviceType |
| | | return "Device_" + DeviceAddr + "_" + DeviceEpoint.ToString().PadLeft(2, '0'); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 设备保存及生成 |
| | | |
| | | /// <summary> |
| | | /// 由设备字符串比特恢复设备对象 |
| | | /// </summary> |
| | | /// <param name="intDeviceType">设备DeviceType的整型值</param> |
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param> |
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte) |
| | | { |
| | | //这是河东的特殊端点,不需要处理 |
| | | if (intDeviceType == 49408) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | 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 Save() |
| | | { |
| | | if (Shared.Common.Global.IsExistsByHomeId(FilePath)) |
| | | { |
| | | return; |
| | | } |
| | | ReSave(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重新保存设备 |
| | | /// </summary> |
| | | public void ReSave() |
| | | { |
| | | 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> |
| | | private void SaveDeviceIcon() |
| | | { |
| | | if (IconPath == string.Empty) |
| | | { |
| | | //干接点 |
| | | 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.OnOffOutput) |
| | | { |
| | | //继电器 |
| | | IconPath = "Device/RelayEpoint.png"; |
| | | } |
| | | else if (this.Type == DeviceType.Thermostat) |
| | | { |
| | | //空调 |
| | | IconPath = "Device/AirConditionerEpoint.png"; |
| | | } |
| | | else if (this.Type == DeviceType.FreshAir) |
| | | { |
| | | //新风 |
| | | IconPath = "Device/FreshAirEpoint.png"; |
| | | } |
| | | else if (this.Type == DeviceType.PMSensor) |
| | | { |
| | | //PM2.5空气质量传感器 |
| | | IconPath = "Device/AirQualitySensorEpoint.png"; |
| | | } |
| | | else if (this.Type == DeviceType.FreshAirHumiditySensor) |
| | | { |
| | | //湿度传感器 |
| | | 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; |
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 输入输出镞定义 |
| | | |
| | | /// <summary> |
| | | /// 设备最新上报的属性状态信息 |
| | |
| | | /// </summary> |
| | | public int AttributeId; |
| | | /// <summary> |
| | | /// 属性值,最大占用4个字节 |
| | | /// 属性值,这个东西不需要什么高位在后低位在前,它已经是转为了10进制 |
| | | /// </summary> |
| | | public int AttributeData; |
| | | /// <summary> |
| | |
| | | /// 温度测量功能的设备如:温度传感器。。。 |
| | | /// <para>1029:Relative Humidity Measurement,设备支持“湿度测量功能”</para> |
| | | /// 湿度测量功能的设备如:湿度传感器。。。 |
| | | /// <para>1066:Pm2.5 Measurement,设备支持“pm2.5测量功能”</para> |
| | | /// Pm2.5测量功能的设备如:Pm2.5传感器。。。 |
| | | /// </summary> |
| | | public int InCluster; |
| | | } |
| | |
| | | public int commandId; |
| | | } |
| | | |
| | | #region 二、获取已入网设备信息 |
| | | #endregion |
| | | |
| | | #region 获取已入网设备信息 |
| | | |
| | | /// <summary> |
| | | /// 网关中的设备信息 |
| | | /// </summary> |
| | | public DeviceInfoData DeviceInfo = new DeviceInfoData(); |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DeviceInfoData DeviceInfo = null; |
| | | /// <summary> |
| | | /// 网关中的设备信息 |
| | | /// </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> |
| | | public List<InClusterObj> InClusterList = new List<InClusterObj>(); |
| | |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 错误结果定义 |
| | | |
| | | /// <summary> |
| | | /// 获取所有网关的节点设备信息(用于主网关) |
| | | /// </summary> |
| | | public AllGatewayDeviceInfo getAllGatewayDeviceInfo; |
| | | /// <summary> |
| | | /// 获取所有网关的节点设备信息(用于主网关) |
| | | /// 网关信息错误反馈共通 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class AllGatewayDeviceInfo |
| | | { |
| | | /// <summary> |
| | | /// 入网设备总数。等于0时,表示没有设备信息,下面字段将不存在。 |
| | | /// </summary> |
| | | public int TotalNum; |
| | | /// <summary> |
| | | /// 标识当前设备是发送的是第几个设备。DeviceNum从1开始每发送一个设备信息,下一个设备信息的DeviceNum将加1。直到DeviceNum等于TotalNum说明所有设备信息发送完毕。 |
| | | /// </summary> |
| | | public int DeviceNum; |
| | | /// <summary> |
| | | /// 设备所在网关的网关id |
| | | /// </summary> |
| | | public string GwId; |
| | | /// <summary> |
| | | /// 入网的utc时间戳 |
| | | /// </summary> |
| | | public int JoinTime; |
| | | /// <summary> |
| | | /// 1:路由器设备 |
| | | /// <para>2:终端设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | /// <summary> |
| | | /// 设备网络地址 |
| | | /// </summary> |
| | | public int NwkAddr; |
| | | /// <summary> |
| | | /// 该字段主要针对IAS安防设备设立。所有IAS安防设备共用一个DeviceID为1026。所以要区分子设备类型,需要该字段。 |
| | | /// <para>13:Motion sensor (运动传感器)</para> |
| | | /// <para>43:Carbon Monoxide sensor (一氧化碳传感器)</para> |
| | | /// <para>44:Personal emergency device (紧急按钮)</para> |
| | | /// </summary> |
| | | public int DeviceType; |
| | | /// <summary> |
| | | /// 用于判断设备的zigbee协议版本。 |
| | | /// <para>49246:ZLL1.0标准设备。</para> |
| | | /// <para>260: ZHA1.2标准设备、 Z3.0标准设备。</para> |
| | | /// <para>41440:ZGP3.0标准设备。</para> |
| | | /// <para>265:ZSE1.4标准设备。</para> |
| | | /// </summary> |
| | | public int Profile; |
| | | /// <summary> |
| | | /// 设备端点名 |
| | | /// </summary> |
| | | public string DeviceName; |
| | | /// <summary> |
| | | /// 设备名 |
| | | /// </summary> |
| | | public string MacName; |
| | | /// <summary> |
| | | /// 0:设备不在线 |
| | | /// <para>1:设备在线</para> |
| | | /// </summary> |
| | | public int IsOnline; |
| | | /// <summary> |
| | | /// 当前运行程序版本信息。 最大64字节 |
| | | /// </summary> |
| | | public int ImgVersion; |
| | | /// <summary> |
| | | /// 硬件版本 |
| | | /// </summary> |
| | | public int HwVersion; |
| | | /// <summary> |
| | | /// 当前镜像类型id |
| | | /// </summary> |
| | | public int ImgTypeId; |
| | | /// <summary> |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | | public List<InClusterObj> InClusterList = new List<InClusterObj>(); |
| | | |
| | | /// <summary> |
| | | /// 输出簇列表 |
| | | /// </summary> |
| | | public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); |
| | | /// <summary> |
| | | /// 用于记录设备最新上报的属性状态信息。最大支持记录16个属性状态,且只记录属性值长度不大于4字节的数据。 |
| | | /// </summary> |
| | | public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取网关记录的设备属性状态 |
| | | /// </summary> |
| | | public GetStatusRecordAllInfo getStatusRecordAllInfo; |
| | | /// <summary> |
| | | /// 获取网关记录的设备属性状态 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetStatusRecordAllInfo |
| | | public class ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 设备名称修改 |
| | | /// </summary> |
| | | public GetStatusRecordInfo getStatusRecordInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取所有网关的节点设备信息(用于主网关) |
| | | /// </summary> |
| | | public GetStatusRecordInfo getStatusRecordInfo; |
| | | /// <summary> |
| | | /// 获取所有网关的节点设备信息(用于主网关) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetStatusRecordInfo |
| | | { |
| | | /// <summary> |
| | | /// 设备所在网关的网关id |
| | | /// </summary> |
| | | public string GwId; |
| | | /// <summary> |
| | | /// 入网的utc时间戳 |
| | | /// </summary> |
| | | public int JoinTime; |
| | | /// <summary> |
| | | /// 1:路由器设备 |
| | | /// <para>2:终端设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | /// <summary> |
| | | /// 设备网络地址 |
| | | /// </summary> |
| | | public int NwkAddr; |
| | | /// <summary> |
| | | /// 该字段主要针对IAS安防设备设立。所有IAS安防设备共用一个DeviceID为1026。所以要区分子设备类型,需要该字段。 |
| | | /// <para>13:Motion sensor (运动传感器)</para> |
| | | /// <para>43:Carbon Monoxide sensor (一氧化碳传感器)</para> |
| | | /// <para>44:Personal emergency device (紧急按钮)</para> |
| | | /// </summary> |
| | | public int DeviceType; |
| | | /// <summary> |
| | | /// 用于判断设备的zigbee协议版本。 |
| | | /// <para>49246:ZLL1.0标准设备。</para> |
| | | /// <para>260: ZHA1.2标准设备、 Z3.0标准设备。</para> |
| | | /// <para>41440:ZGP3.0标准设备。</para> |
| | | /// <para>265:ZSE1.4标准设备。</para> |
| | | /// </summary> |
| | | public int Profile; |
| | | /// <summary> |
| | | /// 设备端点名 |
| | | /// </summary> |
| | | public string DeviceName; |
| | | /// <summary> |
| | | /// 设备名 |
| | | /// </summary> |
| | | public string MacName; |
| | | /// <summary> |
| | | /// 0:设备不在线 |
| | | /// <para>1:设备在线</para> |
| | | /// </summary> |
| | | public int IsOnline; |
| | | /// <summary> |
| | | /// 当前运行程序版本信息。 最大64字节 |
| | | /// </summary> |
| | | public int ImgVersion; |
| | | /// <summary> |
| | | /// 硬件版本 |
| | | /// </summary> |
| | | public int HwVersion; |
| | | /// <summary> |
| | | /// 当前镜像类型id |
| | | /// </summary> |
| | | public int ImgTypeId; |
| | | /// <summary> |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | | public List<InClusterObj> InClusterList = new List<InClusterObj>(); |
| | | /// <summary> |
| | | /// 输出簇列表 |
| | | /// </summary> |
| | | public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); |
| | | /// <summary> |
| | | /// 用于记录设备最新上报的属性状态信息。最大支持记录16个属性状态,且只记录属性值长度不大于4字节的数据。 |
| | | /// </summary> |
| | | public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 有新设备加入zigbee网络的信息 |
| | | /// </summary> |
| | | public DeviceDeviceJoinZbNetResponData deviceDeviceJoinZbNetResponData; |
| | | /// <summary> |
| | | /// 有新设备加入zigbee网络的信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceDeviceJoinZbNetResponData |
| | | { |
| | | /// <summary> |
| | | /// 设备网络地址 |
| | | /// </summary> |
| | | public int NwkAddr; |
| | | /// <summary> |
| | | /// 1:路由器设备 |
| | | /// <para>2:终端设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取新设备所有端点信息是否成功信息 |
| | | /// </summary> |
| | | public DeviceIsGetEpointInfoResponData deviceIsGetEpointInfoResponData; |
| | | /// <summary> |
| | | /// 获取新设备所有端点信息是否成功信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceIsGetEpointInfoResponData |
| | | { |
| | | /// <summary> |
| | | /// 0:成功获取所有端点信息 |
| | | ///<para>1:获取失败</para> |
| | | /// </summary> |
| | | public int Result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关中新搜索出的设备信息 |
| | | /// </summary> |
| | | public NewDeviceInfoData getNewDeviceInfo; |
| | | /// <summary> |
| | | /// 网关中新搜索出的设备信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class NewDeviceInfoData |
| | | { |
| | | /// <summary> |
| | | /// 入网的utc时间戳 |
| | | /// </summary> |
| | | public int JoinTime; |
| | | /// <summary> |
| | | /// 1:路由器设备 |
| | | /// <para>2:终端设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | /// <summary> |
| | | /// 设备网络地址 |
| | | /// </summary> |
| | | public int NwkAddr; |
| | | /// <summary> |
| | | /// 该字段主要针对IAS安防设备设立。所有IAS安防设备共用一个DeviceID为1026。所以要区分子设备类型,需要该字段。 |
| | | /// <para>13:Motion sensor (运动传感器)</para> |
| | | /// <para>43:Carbon Monoxide sensor (一氧化碳传感器)</para> |
| | | /// <para>44:Personal emergency device (紧急按钮)</para> |
| | | /// </summary> |
| | | public int DeviceType; |
| | | /// <summary> |
| | | /// 用于判断设备的zigbee协议版本。区分3.0设备和ZHA设备 |
| | | /// <para>49246:ZLL1.0标准设备。</para> |
| | | /// <para>260: ZHA1.2标准设备、 Z3.0标准设备。</para> |
| | | /// <para>41440:ZGP3.0标准设备。</para> |
| | | /// <para>265:ZSE1.4标准设备。</para> |
| | | /// </summary> |
| | | public int Profile; |
| | | /// <summary> |
| | | /// 是否是新入网设备。 |
| | | /// <para>如果网关储存的设备列表中原来是没有该设备则为新入网设备。</para> |
| | | /// <para>如果网关储存的设备列表中有该设备则为旧设备。</para> |
| | | /// <para>如果重入网后设备信息已经改变(如设备的网络地址,设备ID,cluster列表)则也视为新设备入网。</para> |
| | | /// <para>该字段用来判别用户可能通过节点的实体按键将设备恢复出厂设备后节点设备重新入网的情况或节点设备重启主动发送入网信息的情况。</para> |
| | | /// <para>0:旧设备入网</para> |
| | | /// <para>1:新设备入网</para> |
| | | /// <para>2:设备为新设备,并在上报该信息前已经退网,即设备入网后网关还来不及上报该设备信息设备便已经退网。(设备入网,到网关上报设备信息有一段延时,如果在此期间如果设备已经退网,将反馈该值。该值为异常情况,当收到该值时候说明设备并没入网,可丢弃这个入网信息)</para> |
| | | /// </summary> |
| | | public int IsNewDev; |
| | | /// <summary> |
| | | /// 当前运行程序版本信息。 最大64字节 |
| | | /// </summary> |
| | | public int ImgVersion; |
| | | /// <summary> |
| | | /// 硬件版本 |
| | | /// </summary> |
| | | public int HwVersion; |
| | | /// <summary> |
| | | /// 当前镜像类型id |
| | | /// </summary> |
| | | public int ImgTypeId; |
| | | /// <summary> |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary> |
| | | /// 设备所在网关的网关id |
| | | /// </summary> |
| | | public string GwId; |
| | | /// <summary> |
| | | /// 设备名 |
| | | /// </summary> |
| | | public string MacName; |
| | | /// <summary> |
| | | /// 设备端点名 |
| | | /// </summary> |
| | | public string DeviceName; |
| | | /// <summary> |
| | | /// 0:设备不在线 |
| | | /// <para>1:设备在线</para> |
| | | /// </summary> |
| | | public int IsOnline; |
| | | /// <summary> |
| | | /// 所有指定cluster是否都已经成功绑定协调器 |
| | | ///<para>0:未完全绑定</para> |
| | | ///<para>1:已经绑定</para> |
| | | /// </summary> |
| | | public int ClusterBindZbSuccess = -1; |
| | | /// <summary> |
| | | /// 是否获取所有默认绑定信息 |
| | | ///<para>0:否</para> |
| | | ///<para>1:是</para> |
| | | /// </summary> |
| | | public int IsGetAllDefaultBind = -1; |
| | | /// <summary> |
| | | /// 生产商名字 |
| | | /// </summary> |
| | | public string ManufacturerName = string.Empty; |
| | | /// <summary> |
| | | /// 模块ID(这个东西也叫【型号码】) |
| | | /// </summary> |
| | | public string ModelIdentifier = string.Empty; |
| | | /// <summary> |
| | | /// 生产日期 |
| | | /// </summary> |
| | | public string ProductionDate = string.Empty; |
| | | /// <summary> |
| | | /// 电源 |
| | | /// </summary> |
| | | public int PowerSource = -1; |
| | | /// <summary> |
| | | /// 序列号 |
| | | /// </summary> |
| | | public string SerialNumber = string.Empty; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | | public List<InClusterObj> InClusterList = new List<InClusterObj>(); |
| | | /// <summary> |
| | | /// 输出簇列表 |
| | | /// </summary> |
| | | public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); |
| | | /// <summary> |
| | | /// 用于记录设备最新上报的属性状态信息。最大支持记录16个属性状态,且只记录属性值长度不大于4字节的数据。 |
| | | /// </summary> |
| | | public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | |
| | | return message; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 修改设备端口名称 |
| | | ///<summary > |
| | | /// 修改设备端口(按键)名称 |
| | | /// <para>Gateway:设备所属网关(调用方法:device.Gateway)</para> |
| | | /// <para>deviceName:按键名称</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<DeviceRenameAllData> RenameDeviceNameAsync(string deviceAddr, int deviceEpoint, string deviceName) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | DeviceRenameAllData d = 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 gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "DeviceRenameRespon") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | toggleLight.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (toggleLight.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = toggleLight.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var infoToggleLight = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); |
| | | if (infoToggleLight != null) |
| | | { |
| | | infoToggleLight.DeviceEpointName = toggleLight.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | airSwitch.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (airSwitch.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = airSwitch.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var infoAirSwitch = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); |
| | | if (infoAirSwitch != null) |
| | | { |
| | | infoAirSwitch.DeviceEpointName = airSwitch.renameDeviceData.DeviceName; |
| | | //infoAirSwitch.ReSave(); |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panelObj = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | panelObj.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (panelObj.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = panelObj.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var infoPanel = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == panelObj.DeviceID && obj.DeviceAddr == panelObj.DeviceAddr && obj.DeviceEpoint == panelObj.DeviceEpoint); |
| | | if (infoPanel != null) |
| | | { |
| | | infoPanel.DeviceEpointName = panelObj.renameDeviceData.DeviceName; |
| | | //infoPanel.ReSave(); |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | windowCovering.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (windowCovering.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = windowCovering.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{topic}"); |
| | | var wc = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint); |
| | | if (wc != null) |
| | | { |
| | | wc.DeviceEpointName = windowCovering.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | ias.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (ias.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = ias.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{topic}"); |
| | | |
| | | var zone = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); |
| | | if (zone != null) |
| | | { |
| | | zone.DeviceEpointName = ias.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | dimmableLight.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (dimmableLight.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = dimmableLight.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceEpointName = dimmableLight.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | repeater.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (repeater.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = repeater.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr && obj.DeviceEpoint == repeater.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceEpointName = repeater.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | ac.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (ac.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = ac.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr && obj.DeviceEpoint == ac.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceEpointName = ac.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Transverter: |
| | | var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | transverter.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (transverter.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = transverter.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceEpointName = transverter.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | doorLock.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | if (doorLock.renameDeviceData == null) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DeviceRenameAllData { deviceRenameData = doorLock.renameDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceEpointName = doorLock.renameDeviceData.DeviceName; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("DeviceRename_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var bytes = new byte[64]; |
| | | var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName); |
| | | System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length); |
| | | deviceName = Encoding.UTF8.GetString(bytes); |
| | | |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } }; |
| | | var data = new JObject { { "DeviceName", deviceName } }; |
| | | jObject.Add("Data", data); |
| | | Gateway?.Send(("DeviceRename"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new DeviceRenameAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("DeviceRename_Actions退出" + System.DateTime.Now.ToString()); |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重命名设备,网关反馈具体信息 |
| | | /// </summary> |
| | | public DeviceRenameAllData renameDeviceAllData; |
| | | /// <summary> |
| | | /// 重命名设备,网关反馈具体信息 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 设备名称修改 |
| | | /// </summary> |
| | | public DeviceRenameResponseData renameDeviceData; |
| | | /// <summary> |
| | | /// 设备名称修改 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceRenameResponseData |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region 修改设备mac名称 |
| | | ///<summary > |
| | | /// 修改设备mac名称 |
| | | /// <para>macName:设备名称</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<RenameDeviceMacNameAllData> RenameDeviceMacNameAsync(string deviceAddr, int deviceEpoint, string macName) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | RenameDeviceMacNameAllData d = 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 gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "MacRename_Respon") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | toggleLight.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (toggleLight.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = toggleLight.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var infoToggleLight = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); |
| | | if (infoToggleLight != null) |
| | | { |
| | | infoToggleLight.DeviceName = toggleLight.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | airSwitch.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (airSwitch.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = airSwitch.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | var infoAirSwitch = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); |
| | | if (infoAirSwitch != null) |
| | | { |
| | | infoAirSwitch.DeviceName = airSwitch.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panelObj = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | panelObj.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | if (panelObj.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = panelObj.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{topic}"); |
| | | var infoPanel = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == panelObj.DeviceID && obj.DeviceAddr == panelObj.DeviceAddr && obj.DeviceEpoint == panelObj.DeviceEpoint); |
| | | if (infoPanel != null) |
| | | { |
| | | infoPanel.DeviceName = panelObj.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | windowCovering.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | if (windowCovering.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = windowCovering.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var wc = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint); |
| | | if (wc != null) |
| | | { |
| | | wc.DeviceName = windowCovering.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | ias.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (ias.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = ias.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = ias.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | dimmableLight.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (dimmableLight.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = dimmableLight.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = dimmableLight.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | repeater.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (repeater.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = repeater.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr && obj.DeviceEpoint == repeater.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = repeater.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | ac.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (ac.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = ac.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr && obj.DeviceEpoint == ac.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = ac.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Transverter: |
| | | var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | transverter.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (transverter.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = transverter.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = transverter.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | doorLock.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.RenameDeviceMacNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (doorLock.renameDeviceMacNameData == null) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = doorLock.renameDeviceMacNameData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}"); |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = doorLock.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | break; |
| | | //case DeviceType.TemperatureSensor: |
| | | // var temperatureSensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | // temperatureSensor.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceRenameResponseData>(jobject["Data"].ToString()); |
| | | // if (temperatureSensor.renameDeviceData == null) |
| | | // { |
| | | // d.errorMessageBase = "网关返回的数据为空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.deviceRenameData = temperatureSensor.renameDeviceData; |
| | | // } |
| | | // var ts = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == temperatureSensor.DeviceID && obj.DeviceEpoint == temperatureSensor.DeviceEpoint && obj.DeviceEpoint == temperatureSensor.DeviceEpoint); |
| | | // if (ts == null) |
| | | // { |
| | | // ts.DeviceName = temperatureSensor.renameDeviceData.DeviceName; |
| | | // IO.LocalFileUtils.SaveDeviceInfo(ts, ts.DeviceEpoint.ToString()); |
| | | |
| | | // } |
| | | // break; |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("MacRename_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var bytes = new byte[64]; |
| | | var reamarkGwBytes = Encoding.UTF8.GetBytes(macName); |
| | | System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length); |
| | | macName = Encoding.UTF8.GetString(bytes); |
| | | |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } }; |
| | | var data = new JObject { { "MacName", macName } }; |
| | | jObject.Add("Data", data); |
| | | Gateway?.Send(("MacRename"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new RenameDeviceMacNameAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("MacRename_Action退出" + System.DateTime.Now.ToString()); |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改设备mac名称数据,网关反馈具体信息 |
| | | /// </summary> |
| | | public RenameDeviceMacNameAllData renameDeviceMacNameAllData; |
| | | /// <summary> |
| | | /// 修改设备mac名称数据,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RenameDeviceMacNameAllData |
| | | public class RenameDeviceMacNameAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 修改设备mac名称数据 |
| | | /// </summary> |
| | | public RenameDeviceMacNameData renameDeviceMacNameData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改设备mac名称数据 |
| | | /// </summary> |
| | | public RenameDeviceMacNameData renameDeviceMacNameData; |
| | | /// <summary> |
| | | /// 修改设备mac名称数据 |
| | | /// </summary> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 设备恢复出厂设置与出网 |
| | | ///<summary > |
| | | /// 使设备恢复出厂设置 |
| | | /// <para>仅恢复出厂设置,不离网。但有些不标准的3.0设备,恢复出厂设置就会离网。 客户端或云端到网关</para> |
| | | #region 一键更新四寸屏按键属性 |
| | | /// <summary> |
| | | /// 同步设备功能 |
| | | /// </summary> |
| | | public async void ResetDeviceFactoryAsync(string deviceAddr, int deviceEpoint) |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return; |
| | | return null; |
| | | } |
| | | //Action<string, string> action = (topic, message) => { }; |
| | | //Gateway.Actions += action; |
| | | System.Console.WriteLine("FactoryResete_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 97 } }; |
| | | Gateway.Send("FactoryReset", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | //Gateway.Actions -= action; |
| | | System.Console.WriteLine("FactoryReset_Action退出" + System.DateTime.Now.ToString()); |
| | | 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 |
| | | |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "RemoveDeviceRespon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | var removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.removeDeviceResponseData == null) |
| | | if (removeDeviceResponseData == null) |
| | | { |
| | | d = new RemoveDeviceResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveDeviceResponseAllData { removeDeviceResponseData = gatewayTemp.removeDeviceResponseData }; |
| | | d = new RemoveDeviceResponseAllData { removeDeviceResponseData = removeDeviceResponseData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | try |
| | | { |
| | | if (gatewayTemp.removeDeviceResponseData.Result == 0) |
| | | { |
| | | foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList) |
| | | { |
| | | var deviceID = delD.Device_ID; |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | toggleLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (toggleLight.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (toggleLight.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoToggleLight = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); |
| | | if (infoToggleLight != null) |
| | | { |
| | | Gateway.DeviceList.Remove(infoToggleLight); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | airSwitch.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (airSwitch.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (airSwitch.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoAirSwitch = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); |
| | | if (infoAirSwitch != null) |
| | | { |
| | | Gateway.DeviceList.Remove(infoAirSwitch); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panelObj = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | panelObj.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (panelObj.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (panelObj.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoPanel = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == panelObj.DeviceID && obj.DeviceAddr == panelObj.DeviceAddr && obj.DeviceEpoint == panelObj.DeviceEpoint); |
| | | if (infoPanel != null) |
| | | { |
| | | Gateway.DeviceList.Remove(infoPanel); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var rollershade = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | rollershade.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (rollershade.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (rollershade.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoRoller = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == rollershade.DeviceID && obj.DeviceAddr == rollershade.DeviceAddr && obj.DeviceEpoint == rollershade.DeviceEpoint); |
| | | if (infoRoller != null) |
| | | { |
| | | Gateway.DeviceList.Remove(infoRoller); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | ias.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (ias.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (ias.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | dimmableLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (dimmableLight.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (dimmableLight.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | repeater.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (repeater.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (repeater.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr && obj.DeviceEpoint == repeater.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | ac.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (ac.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (ac.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr && obj.DeviceEpoint == ac.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Transverter: |
| | | var transverter = new Transverter() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | transverter.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (transverter.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (transverter.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | doorLock.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (doorLock.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (doorLock.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | Gateway.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | } |
| | | }; |
| | | 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> |
| | | /// 需要删除设备的数据 |
| | | /// </summary> |
| | | public RemoveDeviceData removeDeviceData; |
| | | /// <summary> |
| | | /// 需要删除设备的数据 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 移除设备,网关反馈具体信息 |
| | | /// </summary> |
| | | public RemoveDeviceResponseAllData removeDeviceResponseAllData; |
| | | /// <summary> |
| | | /// 移除设备,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveDeviceResponseAllData |
| | | { |
| | |
| | | public RemoveDeviceResponseData removeDeviceResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除设备回复数据 |
| | | /// </summary> |
| | | public RemoveDeviceResponseData removeDeviceResponseData; |
| | | /// <summary> |
| | | /// 删除设备回复数据 |
| | | /// <para>返回结果Resul=,删除成功</para> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 从总设备列表中移除一个网关的所有节点设备(用于主网关) |
| | | ///<summary > |
| | | /// 从总设备列表中移除一个网关的所有节点设备(用于主网关) |
| | | /// <para>GwId:要移除节点设备的网关id</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<RemoveGatewayDeviceListAllData> RemoveGatewayDeviceListAsync(string gwId) |
| | | { |
| | | if (Gateway == null || gwId == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | RemoveGatewayDeviceListAllData d = 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 gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new RemoveGatewayDeviceListAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveGatewayDeviceListAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "RemoveEqOfGw_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.removeGatewayDeviceListData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveGatewayDeviceListData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.removeGatewayDeviceListData == null) |
| | | { |
| | | d = new RemoveGatewayDeviceListAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveGatewayDeviceListAllData { removeGatewayDeviceListData = gatewayTemp.removeGatewayDeviceListData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | //for (int listCount = 0; listCount < Gateway.AllGatewayDeviceList.Count; listCount++) |
| | | //{ |
| | | // var dev = Gateway.AllGatewayDeviceList[listCount]; |
| | | // if (gatewayTemp.removeGatewayDeviceListData.GwId == dev.Gateway.CurrentGateWayId) |
| | | // { |
| | | // ZigBee.Device.ZbGateway.LogicList.RemoveAt(listCount); |
| | | // listCount--; |
| | | // } |
| | | //} |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("RemoveEqOfGw_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 81 } }; |
| | | var data = new JObject { { "GwId", gwId } }; |
| | | jObject.Add("Data", data); |
| | | Gateway.Send(("RemoveEqOfGw"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new RemoveGatewayDeviceListAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("RemoveEqOfGw_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除设备,网关反馈具体信息 |
| | | /// </summary> |
| | | public RemoveGatewayDeviceListAllData removeGatewayDeviceListAllData; |
| | | /// <summary> |
| | | /// 移除设备,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveGatewayDeviceListAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 设备名称修改 |
| | | /// </summary> |
| | | public RemoveGatewayDeviceListData removeGatewayDeviceListData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从总设备列表中移除一个网关的所有节点设备(用于主网关) |
| | | /// </summary> |
| | | public RemoveGatewayDeviceListData removeGatewayDeviceListData; |
| | | /// <summary> |
| | | /// 从总设备列表中移除一个网关的所有节点设备(用于主网关) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveGatewayDeviceListData |
| | | { |
| | | /// <summary> |
| | | /// 要移除节点设备的网关id |
| | | /// </summary> |
| | | public string GwId; |
| | | /// <summary> |
| | | /// 被删除设备的数量 |
| | | /// </summary> |
| | | public int RemoveNum; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 识别设备 |
| | | ///<summary > |
| | | /// 识别设备 |
| | |
| | | System.Console.WriteLine("Identify_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 设备上报返回数据,网关回复信息 |
| | | ///// <summary> |
| | | ///// 设备上报返回数据,网关回复信息 |
| | | ///// </summary> |
| | | //public DeviceReportResponAllData deviceReportResponAllData; |
| | | ///// <summary> |
| | | ///// 网关恢复出厂设置返回数据 |
| | | ///// </summary> |
| | | //[System.Serializable] |
| | | //public class DeviceReportResponAllData |
| | | //{ |
| | | // /// <summary> |
| | | // /// 错误信息 |
| | | // /// </summary> |
| | | // public string errorMessageBase; |
| | | // /// <summary> |
| | | // /// 网关信息错误反馈 |
| | | // /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | // /// </summary> |
| | | // public ErrorResponData errorResponData; |
| | | // ///<summary > |
| | | // ///设备数据 |
| | | // /// </summary> |
| | | // public DeviceStatusReportData deviceStatusReportData; |
| | | //} |
| | | |
| | | ///// <summary> |
| | | ///// 读取报告属性配置,异步获取数据 |
| | | ///// </summary> |
| | | ///// <param name="clusterID">Cluster identifier.</param> |
| | | ///// <param name="attriButeId">Attri bute identifier.</param> |
| | | //public async System.Threading.Tasks.Task<DeviceReportResponAllData> ReadAttriAsync(Cluster_ID clusterID, AttriButeId attriButeId) |
| | | //{ |
| | | //if (Gateway == null) |
| | | //{ |
| | | // return null; |
| | | //} |
| | | ////string result = null; |
| | | |
| | | //return await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | | //var d = new DeviceReportResponAllData(); |
| | | //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 gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | // var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | // if (temp == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.errorResponData = temp; |
| | | // d.errorMessageBase = ErrorMess(temp.Error); |
| | | // } |
| | | //} |
| | | |
| | | //if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + DeviceAddr + "/" + DeviceEpoint + "/" + (int)clusterID + "/" + (int)attriButeId) |
| | | //{ |
| | | //var deviceID = jobject.Value<int>("Device_ID"); |
| | | //var deviceAddr = jobject.Value<string>("DeviceAddr"); |
| | | //var ep = jobject.Value<int>("Epoint"); |
| | | |
| | | //var device = Gateway.DeviceList.Find((obj) => obj.DeviceID == deviceID && obj.DeviceAddr == deviceAddr && obj.DeviceEpoint == ep); |
| | | //if (device == null) |
| | | //{ |
| | | // return; |
| | | //} |
| | | |
| | | //switch ((DeviceType)(deviceID)) |
| | | //{ |
| | | // case DeviceType.ColorDimmableLight: |
| | | // device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmableLight.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | // if (device.DeviceStatusReport == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.deviceStatusReportData = device.DeviceStatusReport; |
| | | // System.Console.WriteLine($"收到通知后的主题_{ topic}"); |
| | | // var light = device as ColorDimmableLight; |
| | | // if (device.DeviceStatusReport.CluterID == 8) |
| | | // { |
| | | // var attriButeList = device.DeviceStatusReport.AttriBute; |
| | | // foreach (var attriBute1 in attriButeList) |
| | | // { |
| | | // light.Level = attriBute1.AttriButeData; |
| | | // } |
| | | // light.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(light); |
| | | // } |
| | | // else if (device.DeviceStatusReport.CluterID == 6) |
| | | // { |
| | | // var attriButeList = device.DeviceStatusReport.AttriBute; |
| | | // foreach (var attriBute1 in attriButeList) |
| | | // { |
| | | // light.OnOffStatus = attriBute1.AttriButeData; |
| | | |
| | | // var key = light.DeviceAddr + "_" + light.DeviceEpoint; |
| | | // Gateway.sceneTaskInfoList.Remove(key); |
| | | // var st = new Scene.TaskListInfo() |
| | | // { |
| | | // TaskType = 1, |
| | | // Data1 = attriBute1.AttriButeData, |
| | | // Data2 = 0, |
| | | // }; |
| | | // Gateway.sceneTaskInfoList.Add(key, st); |
| | | // } |
| | | // light.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(light); |
| | | // } |
| | | // else if (device.DeviceStatusReport.CluterID == 768) |
| | | // { |
| | | // var attriButeList = device.DeviceStatusReport.AttriBute; |
| | | // //foreach (var attriBute1 in attriButeList) |
| | | // //{ |
| | | // // if (attriBute1.AttriButeId == 0) |
| | | // // { |
| | | // // light.Hue = attriBute1.AttriButeData.ToString(); |
| | | // // } |
| | | // // else if ((attriBute1.AttriButeId == 1)) |
| | | // // { |
| | | // // light.Saturation = attriBute1.AttriButeData.ToString(); |
| | | |
| | | // // } |
| | | // // else if ((attriBute1.AttriButeId == 16394)) |
| | | // // { |
| | | // // light.ColorCapabilities = attriBute1.AttriButeData.ToString(); |
| | | // // } |
| | | // // else if ((attriBute1.AttriButeId == 16384)) |
| | | // // { |
| | | // // light.EnhancedCurrentHue = attriBute1.AttriButeData.ToString(); |
| | | // // } |
| | | // //} |
| | | // light.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(light); |
| | | // } |
| | | // } |
| | | // break; |
| | | // case DeviceType.OnOffSwitch: |
| | | // device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | // if (device.DeviceStatusReport == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.deviceStatusReportData = device.DeviceStatusReport; |
| | | // System.Console.WriteLine($"收到通知后的主题_{ topic}"); |
| | | |
| | | // var panelObj = device as Panel; |
| | | // foreach (var common in Gateway.DeviceList) |
| | | // { |
| | | // if (common.DeviceAddr != panelObj.DeviceAddr || common.DeviceEpoint != panelObj.DeviceEpoint) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // if (common.Type == DeviceType.OnOffSwitch) |
| | | // { |
| | | // if (device.DeviceStatusReport.CluterID == 6) |
| | | // { |
| | | // var attriButeList = device.DeviceStatusReport.AttriBute; |
| | | // foreach (var attriBute1 in attriButeList) |
| | | // { |
| | | // panelObj.panelMode = attriBute1.AttriButeData; |
| | | // } |
| | | |
| | | // } |
| | | // } |
| | | // panelObj.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(panelObj); |
| | | // } |
| | | // } |
| | | // break; |
| | | //case DeviceType.OnOffOutput: |
| | | // device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | // //if (device.DeviceStatusReport != null) |
| | | // //{ |
| | | // // result = "成功"; |
| | | // //} |
| | | // if (device.DeviceStatusReport == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.deviceStatusReportData = device.DeviceStatusReport; |
| | | // System.Console.WriteLine($"收到通知后的主题_{ topic}"); |
| | | |
| | | // var lighttoggle = device as ToggleLight; |
| | | // foreach (var common in Gateway.DeviceList) |
| | | // { |
| | | // if (common.DeviceAddr != lighttoggle.DeviceAddr || common.DeviceEpoint != lighttoggle.DeviceEpoint) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // if (common.Type == DeviceType.OnOffOutput) |
| | | // { |
| | | // if (device.DeviceStatusReport.CluterID == 6) |
| | | // { |
| | | // var attriButeList = device.DeviceStatusReport.AttriBute; |
| | | // foreach (var attriBute1 in attriButeList) |
| | | // { |
| | | // lighttoggle.OnOffStatus = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("当前开关状态" + "_" + attriBute1.AttriButeData.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // } |
| | | // } |
| | | // } |
| | | // lighttoggle.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(lighttoggle); |
| | | // } |
| | | // } |
| | | // break; |
| | | |
| | | //case DeviceType.WindowCoveringDevice: |
| | | // device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | // if (device.DeviceStatusReport == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.deviceStatusReportData = device.DeviceStatusReport; |
| | | // System.Console.WriteLine($"收到通知后的主题_{ topic}"); |
| | | // var curtain = device as Rollershade; |
| | | // foreach (var common in Gateway.DeviceList) |
| | | // { |
| | | // if (common.DeviceAddr != curtain.DeviceAddr || common.DeviceEpoint != curtain.DeviceEpoint) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // if (common.Type == DeviceType.WindowCoveringDevice) |
| | | // { |
| | | // if (device.DeviceStatusReport.CluterID == 258) |
| | | // { |
| | | // foreach (var attriBute1 in curtain.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // switch (attriBute1.AttributeId) |
| | | // { |
| | | // case 0: |
| | | // curtain.WcdType = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("当前窗帘的类型" + "_" + curtain.WcdType.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 3: |
| | | // curtain.WcdCurrentPositionLift = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘当前高度" + "_" + curtain.WcdCurrentPositionLift.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 8: |
| | | // curtain.WcdCurrentPositionLiftPercentage = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("当前窗帘所在的进度(百分)位置" + "_" + curtain.WcdCurrentPositionLiftPercentage.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 16: |
| | | // curtain.WcdInstalledOpenLimitLift = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘全开所在的位置" + "_" + curtain.WcdInstalledOpenLimitLift.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 17: |
| | | // curtain.WcdInstalledClosedLimitLift = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘全关所在的位置" + "_" + curtain.WcdCurrentPositionLift.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 18: |
| | | // curtain.WcdInstalledOpenLimitTilt = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘全开所在的角度" + "_" + curtain.WcdCurrentPositionLift.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 19: |
| | | // curtain.WcdInstalledClosedLimitTilt = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘全关所在的角度" + "_" + curtain.WcdCurrentPositionLift.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // case 23: |
| | | // curtain.WcdCurrentMode = attriBute1.AttriButeData; |
| | | // System.Console.WriteLine("窗帘当前模式" + "_" + curtain.WcdCurrentMode.ToString() + "_" + Gateway.getGatewayBaseInfo.gwID + "_" + System.DateTime.Now.ToString()); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // curtain.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(curtain); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // break; |
| | | //case DeviceType.IASZone: |
| | | //device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | //var ias = device as IASZone; |
| | | //foreach (var common in Gateway.DeviceList) |
| | | //{ |
| | | // if (common.DeviceAddr != ias.DeviceAddr || common.DeviceEpoint != ias.DeviceEpoint) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // if (common.Type == DeviceType.IASZone) |
| | | // { |
| | | // ias.ReSave(); |
| | | // ZigBee.Device.ZbGateway.UpdateDeviceStatus(ias); |
| | | // } |
| | | //} |
| | | //ias.ReSave(); |
| | | //break; |
| | | //case DeviceType.Thermostat: |
| | | //device.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<ThermostatObj.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | //var ther = device as ThermostatObj; |
| | | //if (ther.DeviceStatusReport.CluterID == 514) |
| | | //{ |
| | | // foreach (var attriBute1 in ther.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // ther.CurentFanControlMode = attriBute1.AttriButeData; |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | //if (ther.DeviceStatusReport.CluterID == 513) |
| | | //{ |
| | | // foreach (var attriBute1 in ther.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // ther.LocalThermostat = attriBute1.AttriButeData / 100; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 17) |
| | | // { |
| | | // ther.CurentCoolingSetpoint = attriBute1.AttriButeData / 100; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 18) |
| | | // { |
| | | // ther.CurentHeatingSetpoint = attriBute1.AttriButeData / 100; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 28) |
| | | // { |
| | | // ther.CurentSystemMode = attriBute1.AttriButeData; |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | //ZigBee.Device.ZbGateway.UpdateDeviceStatus(ther); |
| | | //break; |
| | | //case DeviceType.TemperatureSensor: |
| | | //var sensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId }; |
| | | //sensor.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | //ZigBee.Device.ZbGateway.UpdateDeviceStatus(sensor); |
| | | |
| | | //if (sensor.DeviceStatusReport.CluterID == 1026) |
| | | //{ |
| | | // foreach (var attriBute1 in sensor.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // sensor.CurentTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 1) |
| | | // { |
| | | // sensor.MaxTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 2) |
| | | // { |
| | | // sensor.MinTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 3) |
| | | // { |
| | | // sensor.TorleranceTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // IO.LocalFileUtils.SaveDeviceInfo(sensor, sensor.DeviceEpoint.ToString()); |
| | | // } |
| | | //} |
| | | //else if (sensor.DeviceStatusReport.CluterID == 1029) |
| | | //{ |
| | | // foreach (var attriBute1 in sensor.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // sensor.CurentHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 1) |
| | | // { |
| | | // sensor.MaxHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 2) |
| | | // { |
| | | // sensor.MinHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 3) |
| | | // { |
| | | // sensor.ToleranceHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // IO.LocalFileUtils.SaveDeviceInfo(sensor, sensor.DeviceEpoint.ToString()); |
| | | // } |
| | | //} |
| | | |
| | | //var sen = Gateway.SensorInfoList.Find(obj => obj.DeviceAddr == sensor.DeviceAddr && obj.DeviceEpoint == sensor.DeviceEpoint); |
| | | //if (sen == null) |
| | | //{ |
| | | // Gateway.SensorInfoList.Add(sensor); |
| | | //} |
| | | //else |
| | | //{ |
| | | // if (sensor.DeviceStatusReport.CluterID == 1026) |
| | | // { |
| | | // foreach (var attriBute1 in sensor.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // sen.CurentTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 1) |
| | | // { |
| | | // sen.MaxTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 2) |
| | | // { |
| | | // sen.MinTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 3) |
| | | // { |
| | | // sen.TorleranceTemperature = attriBute1.AttriButeData; |
| | | // } |
| | | // IO.LocalFileUtils.SaveDeviceInfo(sensor, sensor.DeviceEpoint.ToString()); |
| | | // } |
| | | // } |
| | | // else if (sensor.DeviceStatusReport.CluterID == 1029) |
| | | // { |
| | | // foreach (var attriBute1 in sensor.DeviceStatusReport.AttriBute) |
| | | // { |
| | | // if (attriBute1.AttributeId == 0) |
| | | // { |
| | | // sen.CurentHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 1) |
| | | // { |
| | | // sen.MaxHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 2) |
| | | // { |
| | | // sen.MinHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // else if (attriBute1.AttributeId == 3) |
| | | // { |
| | | // sen.ToleranceHumidity = attriBute1.AttriButeData; |
| | | // } |
| | | // IO.LocalFileUtils.SaveDeviceInfo(sensor, sensor.DeviceEpoint.ToString()); |
| | | // } |
| | | // } |
| | | //} |
| | | //break; |
| | | // } |
| | | // } |
| | | // }; |
| | | |
| | | // Gateway.Actions += action; |
| | | |
| | | // var JObject = new JObject { |
| | | // { "DeviceAddr",DeviceAddr }, |
| | | // { "Epoint", DeviceEpoint }, |
| | | // { "Cluster_ID", (int)clusterID }, |
| | | // { "Command", 108 } |
| | | // }; |
| | | // var attriBute = new JArray{ |
| | | // new JObject { |
| | | // { "AttriButeId", (int)attriButeId} |
| | | // } |
| | | // }; |
| | | // var data = new JObject { { "AttriBute", attriBute } }; |
| | | // JObject.Add("Data", data); |
| | | // Gateway?.Send(("GetDeviceStatus"), Common.SecuritySet.Encryption((JObject.ToString()))); |
| | | |
| | | // var dateTime = DateTime.Now; |
| | | // while ((DateTime.Now - dateTime).TotalMilliseconds < 5000) |
| | | // { |
| | | // await System.Threading.Tasks.Task.Delay(10); |
| | | // if (d.deviceStatusReportData != null) |
| | | // { |
| | | // break; |
| | | // } |
| | | // } |
| | | // if ((DateTime.Now - dateTime).TotalMilliseconds > 10000) |
| | | // { |
| | | // d.errorMessageBase = " 回复超时,请重新操作"; |
| | | // } |
| | | // Gateway.Actions -= action; |
| | | // return d; |
| | | |
| | | // }); |
| | | |
| | | //} |
| | | #endregion |
| | | |
| | | #region 设备属性状态上报 |
| | |
| | | /// <summary> |
| | | /// 设备属性状态上报 |
| | | /// </summary> |
| | | public DeviceStatusReportData DeviceStatusReport = new DeviceStatusReportData { }; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DeviceStatusReportData DeviceStatusReport = new DeviceStatusReportData(); |
| | | /// <summary> |
| | | /// 设备属性状态上报 |
| | | /// </summary> |
| | |
| | | /// 设置可写属性的值 |
| | | /// </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; |
| | | } |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "SetWritableValue_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == 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; |
| | |
| | | /// <summary> |
| | | /// 网关版本信息,网关反馈信息 |
| | | /// </summary> |
| | | public SetWritableValueResponAllData setWritableValueResponAllData; |
| | | /// <summary> |
| | | /// 网关版本信息,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SetWritableValueResponAllData |
| | | public class SetWritableValueResponAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 网关版本信息 |
| | | /// </summary> |
| | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置可写属性的值的数据 |
| | | /// </summary> |
| | | public SetWritableValueData setWritableValueData; |
| | | /// <summary> |
| | | /// 设置可写属性的值的数据 |
| | | /// </summary> |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Cluster/OwnAttributes_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.clusterOwnAttributesResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ClusterOwnAttributesResponData>(jobject["Data"].ToString()); |
| | | var clusterOwnAttributesResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClusterOwnAttributesResponData>(jobject["Data"].ToString()); |
| | | var tempAttributes = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["Attribute"].ToString()); |
| | | for (int m = 0; tempAttributes != null && m < tempAttributes.Count; m++) |
| | | { |
| | | var tempAttribute = tempAttributes[m]; |
| | | gatewayTemp.clusterOwnAttributesResponData.AttributeList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AttributeObj>(tempAttribute.ToString())); |
| | | clusterOwnAttributesResponData.AttributeList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AttributeObj>(tempAttribute.ToString())); |
| | | } |
| | | |
| | | if (gatewayTemp.clusterOwnAttributesResponData == null) |
| | | if (clusterOwnAttributesResponData == null) |
| | | { |
| | | d = new ClusterOwnAttributesResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new ClusterOwnAttributesResponAllData { clusterOwnAttributesResponData = gatewayTemp.clusterOwnAttributesResponData }; |
| | | d = new ClusterOwnAttributesResponAllData { clusterOwnAttributesResponData = clusterOwnAttributesResponData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | |
| | | /// <summary> |
| | | /// 发现属性,网关反馈信息 |
| | | /// </summary> |
| | | public ClusterOwnAttributesResponAllData clusterOwnAttributesResponAllData; |
| | | /// <summary> |
| | | /// 发现属性,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ClusterOwnAttributesResponAllData |
| | | public class ClusterOwnAttributesResponAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 网关版本信息 |
| | | /// </summary> |
| | | public ClusterOwnAttributesResponData clusterOwnAttributesResponData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发现属性数据 |
| | | /// </summary> |
| | | public ClusterOwnAttributesResponData clusterOwnAttributesResponData; |
| | | [System.Serializable] |
| | | public class ClusterOwnAttributesResponData |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Cluster/OwnCommand_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.clusterOwnCommandResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClusterOwnCommandResponData>(jobject["Data"].ToString()); |
| | | var clusterOwnCommandResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClusterOwnCommandResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.clusterOwnCommandResponData == null) |
| | | if (clusterOwnCommandResponData == null) |
| | | { |
| | | d = new ClusterOwnCommandResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | |
| | | } |
| | | else |
| | | { |
| | | d = new ClusterOwnCommandResponAllData { clusterOwnCommandResponData = gatewayTemp.clusterOwnCommandResponData }; |
| | | d = new ClusterOwnCommandResponAllData { clusterOwnCommandResponData = clusterOwnCommandResponData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// 设备某cluster所支持的Command数据,网关反馈信息 |
| | | /// </summary> |
| | | public ClusterOwnCommandResponAllData clusterOwnCommandResponAllData; |
| | | /// <summary> |
| | | /// 设备某cluster所支持的Command数据,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ClusterOwnCommandResponAllData |
| | | public class ClusterOwnCommandResponAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 网设备某cluster所支持的Command数据 |
| | | /// </summary> |
| | | public ClusterOwnCommandResponData clusterOwnCommandResponData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设备某cluster所支持的Command数据 |
| | | /// </summary> |
| | | public ClusterOwnCommandResponData clusterOwnCommandResponData; |
| | | /// <summary> |
| | | /// 设备某cluster所支持的Command数据 |
| | | /// </summary> |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "OTA/SetImage_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.oTASetImageData = Newtonsoft.Json.JsonConvert.DeserializeObject<OTASetImageData>(jobject["Data"].ToString()); |
| | | var oTASetImageData = Newtonsoft.Json.JsonConvert.DeserializeObject<OTASetImageData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.oTASetImageData == null) |
| | | if (oTASetImageData == null) |
| | | { |
| | | d = new OTASetImageResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new OTASetImageResponseAllData { otaSetImageData = gatewayTemp.oTASetImageData }; |
| | | d = new OTASetImageResponseAllData { otaSetImageData = oTASetImageData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// 设备进行OTA升级,网关反馈具体信息 |
| | | /// </summary> |
| | | public OTASetImageResponseAllData otaSetImageResponseAllData; |
| | | /// <summary> |
| | | /// 设备进行OTA升级,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class OTASetImageResponseAllData |
| | | public class OTASetImageResponseAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 保存zigbee协调器组网信息 |
| | | /// </summary> |
| | | public OTASetImageData otaSetImageData; |
| | | } |
| | | /// <summary> |
| | | /// 设备进行OTA升级 |
| | | /// </summary> |
| | | public OTASetImageData oTASetImageData; |
| | | |
| | | [System.Serializable] |
| | | public class OTASetImageData |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "OTA/StartUpdate_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.startUpdateDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<StartDeviceUpdateData>(jobject["Data"].ToString()); |
| | | var startUpdateDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<StartDeviceUpdateData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.startUpdateDeviceData == null) |
| | | if (startUpdateDeviceData == null) |
| | | { |
| | | d = new StartDeviceUpdateResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new StartDeviceUpdateResponseAllData { startUpdateDeviceData = gatewayTemp.startUpdateDeviceData }; |
| | | d = new StartDeviceUpdateResponseAllData { startUpdateDeviceData = startUpdateDeviceData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// 启动升级,网关反馈具体信息 |
| | | /// </summary> |
| | | public StartDeviceUpdateResponseAllData startUpdateDeviceResponseAllData; |
| | | /// <summary> |
| | | /// 启动升级,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class StartDeviceUpdateResponseAllData |
| | | { |
| | |
| | | /// </summary> |
| | | public StartDeviceUpdateData startUpdateDeviceData; |
| | | } |
| | | /// <summary> |
| | | /// 启动升级 |
| | | /// </summary> |
| | | public StartDeviceUpdateData startUpdateDeviceData; |
| | | |
| | | [System.Serializable] |
| | | public class StartDeviceUpdateData |
| | | { |
| | |
| | | /// <summary> |
| | | /// 启动升级 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public OTAScheduleResponData oTAScheduleResponData; |
| | | |
| | | [System.Serializable] |
| | | public class OTAScheduleResponData |
| | | { |
| | |
| | | public int Percent = 999; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 启动升级的数据 |
| | | /// </summary> |
| | | public StartUpdateData startUpdateData; |
| | | [System.Serializable] |
| | | public class StartUpdateData |
| | | { |
| | |
| | | public List<OTADeviceList> DeviceList = new List<OTADeviceList>(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 启用或关闭节点设备透传数据上传接口 |
| | | /// <summary> |
| | | /// 节点设备透传数据到客户端 |
| | | /// <para>网关程序默认是关闭透传数据上传的,可以通过以下指令开启透传数据上传。透传数据上传开启后,重启网关程序透传数据上传将还原成关闭状态</para> |
| | | /// <para>isOn 0:关闭透传数据上传</para> |
| | | /// <para>isOn 1:开启透传数据上传</para> |
| | | /// </summary> |
| | | //public void OpenPassthroughControl(ZigBee.Device.ZbGateway gateway, int isOn = 1) |
| | | //{ |
| | | // if (Gateway == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // Action<string, string> action = (topic, message) => { }; |
| | | // Gateway.Actions += action; |
| | | // System.Console.WriteLine("OnZbDataPassthrough_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | // try |
| | | // { |
| | | // var jObject = new JObject { { "Cluster_ID", 64513 }, { "Command", 1 } }; |
| | | // var data = new JObject { { "IsOn", isOn } }; |
| | | // jObject.Add("Data", data); |
| | | // gateway.Send(("OnZbDataPassthrough"), jObject.ToString()); |
| | | // } |
| | | // catch { } |
| | | |
| | | // Gateway.Actions -= action; |
| | | // System.Console.WriteLine("OnZbDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | //} |
| | | #endregion |
| | | |
| | | #region 客户端向节点设备透传数据. |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | d = new ClientDataPassthroughResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new ClientDataPassthroughResponseAllData { clientDataPassthroughResponseData = gatewayTemp.clientDataPassthroughResponseData }; |
| | | d = new ClientDataPassthroughResponseAllData { clientDataPassthroughResponseData = clientDataPassthroughResponseData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// 客户端向节点设备透传数据,网关反馈具体信息 |
| | | /// </summary> |
| | | public ClientDataPassthroughResponseAllData clientDataPassthroughResponseAllData; |
| | | /// <summary> |
| | | /// 客户端向节点设备透传数据,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ClientDataPassthroughResponseAllData |
| | | public class ClientDataPassthroughResponseAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 客户端向节点设备透传数据 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 客户端向节点设备透传数据 |
| | | /// </summary> |
| | | public ClientDataPassthroughResponseData clientDataPassthroughResponseData = new ClientDataPassthroughResponseData { }; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public ClientDataPassthroughResponseData clientDataPassthroughResponseData = new ClientDataPassthroughResponseData(); |
| | | |
| | | [System.Serializable] |
| | | public class ClientDataPassthroughResponseData |
| | | { |
| | |
| | | /// <summary> |
| | | /// 启用或关闭节点设备透传数据上传接口,网关反馈具体信息 |
| | | /// </summary> |
| | | public OnZbDataPassthroughResponseAllData onZbDataPassthroughResponseAllData; |
| | | /// <summary> |
| | | /// 启用或关闭节点设备透传数据上传接口,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class OnZbDataPassthroughResponseAllData |
| | | public class OnZbDataPassthroughResponseAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 启用或关闭节点设备透传数据上传接口 |
| | | /// </summary> |
| | | public OnZbDataPassthroughData onZbDataPassthroughData; |
| | | } |
| | | /// <summary> |
| | | /// 启用或关闭节点设备透传数据上传接口 |
| | | /// </summary> |
| | | public OnZbDataPassthroughData onZbDataPassthroughData; |
| | | |
| | | [System.Serializable] |
| | | public class OnZbDataPassthroughData |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "DownloadFile_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileResponData>(jobject["Data"].ToString()); |
| | | var downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.downloadFileResponData == null) |
| | | if (downloadFileResponData == null) |
| | | { |
| | | d = new DownloadFileResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DownloadFileResponAllData { downloadFileResponData = gatewayTemp.downloadFileResponData }; |
| | | d = new DownloadFileResponAllData { downloadFileResponData = downloadFileResponData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 网关系统升级,网关反馈具体信息 |
| | | /// </summary> |
| | | public DownloadFileResponAllData downloadFileResponAllData; |
| | | |
| | | /// <summary> |
| | | /// 网关系统升级,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DownloadFileResponAllData |
| | | public class DownloadFileResponAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 下载云端固件 |
| | | /// </summary> |
| | | public DownloadFileResponData downloadFileResponData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载云端固件 |
| | | /// </summary> |
| | | public DownloadFileResponData downloadFileResponData; |
| | | /// <summary> |
| | | /// 下载云端固件 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 下载进度 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DownloadFileProgressResponData downloadFileProgressResponData; |
| | | /// <summary> |
| | | /// 下载进度 |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "OTA/KillUpdate_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.killUpdateData = Newtonsoft.Json.JsonConvert.DeserializeObject<KillUpdateData>(jobject["Data"].ToString()); |
| | | var killUpdateData = Newtonsoft.Json.JsonConvert.DeserializeObject<KillUpdateData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.killUpdateData == null) |
| | | if (killUpdateData == null) |
| | | { |
| | | d = new KillUpdateResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new KillUpdateResponseAllData { killUpdateData = gatewayTemp.killUpdateData }; |
| | | d = new KillUpdateResponseAllData { killUpdateData = killUpdateData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// 终止设备升级,网关反馈具体信息 |
| | | /// </summary> |
| | | public KillUpdateResponseAllData killUpdateResponseAllData; |
| | | /// <summary> |
| | | /// 终止设备升级,网关反馈具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class KillUpdateResponseAllData |
| | | public class KillUpdateResponseAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 终止设备升级 |
| | | /// </summary> |
| | | public KillUpdateData killUpdateData; |
| | | } |
| | | /// <summary> |
| | | /// 终止设备升级 |
| | | /// </summary> |
| | | public KillUpdateData killUpdateData; |
| | | |
| | | [System.Serializable] |
| | | public class KillUpdateData |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region 私有协议网关和设备的默认回复 |
| | | /// <summary> |
| | | /// 私有协议网关和设备的默认回复 |
| | | /// </summary> |
| | | public ResponseAllData keyColorDataResponseAllData; |
| | | |
| | | [System.Serializable] |
| | | public class ResponseAllData |
| | | public class ResponseAllData : ErrorResponCommon |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 按键指示灯颜色信息 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command = -1; |
| | | public string command; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>0--成功 1--失败 ff--无效</para> |
| | |
| | | public int status = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region ■ 调试打印 |
| | | |
| | | /// <summary> |
| | | /// 调试时打开打印信息,true:打印,false:不打印 |
| | | /// </summary> |
| | | /// <param name="msg">Message.</param> |
| | | /// <param name="flage">If set to <c>true</c> flage.</param> |
| | | 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); |
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |