| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | |
| | | { |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime LastDateTime = DateTime.MinValue; |
| | | /// <summary>
|
| | | /// 是否已经读取了设备状态(此属性是给主页使用的)
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool HadReadDeviceStatu = false; |
| | | |
| | | /// <summary> |
| | | /// 调试时打开打印信息,true:打印,false:不打印 |
| | |
| | | /// <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);
|
| | | //} |
| | | if (msg.Contains("DeviceStatusReport") == false)
|
| | | {
|
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
|
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId; |
| | | gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(gateWay); |
| | | } |
| | | } |
| | | |
| | | return gateWay; |
| | | } |
| | |
| | | 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> |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 由设备字符串比特恢复设备对象
|
| | | /// </summary>
|
| | | /// <param name="strDeviceType">设备DeviceType的字符串类型</param>
|
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
|
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) |
| | | { |
| | |
| | | { |
| | | 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> |
| | | public void ReSave() |
| | | { |
| | | //Console.WriteLine(FilePath); |
| | | 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> |
| | | /// 设备图片 |
| | | /// </summary> |
| | | public string IconPath = string.Empty; |
| | | /// <summary> |
| | | /// 设备图片--在线或者选中状态 |
| | | /// </summary> |
| | | /// <value>The online icon path.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string OnlineIconPath |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(IconPath)) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | var pathArr = IconPath.Split('.'); |
| | | if (pathArr == null || string.IsNullOrEmpty(pathArr[0])) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | return $"{pathArr[0]}Selected.png"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 当前设备类型 |
| | | /// </summary> |
| | | public DeviceType Type = DeviceType.UnKown; |
| | | |
| | | /// <summary>
|
| | | /// 设备的功能类型(此类型目前只针对继电器回路有效,默认未指定)
|
| | | /// </summary> |
| | | public DeviceFunctionType DfunctionType = DeviceFunctionType.A未定义; |
| | | /// <summary> |
| | | /// MAC地址 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 序列号 |
| | | /// </summary> |
| | | public string SerialNumber = string.Empty; |
| | | public string SerialNumber = string.Empty; |
| | | /// <summary> |
| | | /// 所有指定cluster是否都已经成功绑定协调器 |
| | | ///<para>0:未完全绑定</para> |
| | |
| | | /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备 |
| | | /// </summary> |
| | | public int DriveCode; |
| | | /// <summary>
|
| | | /// 厂商名称
|
| | | /// </summary> |
| | | public string ManufacturerName = string.Empty; |
| | | /// <summary>
|
| | | /// 模块ID
|
| | | /// </summary> |
| | | public string ModelIdentifier = string.Empty; |
| | | /// <summary>
|
| | | /// 好像是序列号
|
| | | /// </summary> |
| | | public string ProductCode = string.Empty; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | |
| | | /// 1:路由器设备 |
| | | /// <para>2:终端设备</para> |
| | | /// </summary> |
| | | public int ZigbeeType; |
| | | public int ZigbeeType; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <summary> |
| | | /// 设备所在网关的网关id |
| | | /// </summary> |
| | | public int GwId; |
| | | public string GwId; |
| | | /// <summary> |
| | | /// 设备名 |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 序列号 |
| | | /// </summary> |
| | | public string SerialNumber = string.Empty; |
| | | public string SerialNumber = string.Empty; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | |
| | | |
| | | 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; |
| | | } |
| | | var receiptData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceRenameResponseData>(jobject["Data"].ToString());
|
| | | d = new DeviceRenameAllData { deviceRenameData = receiptData }; |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | |
| | | 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()); |
| | | Gateway?.Send(("DeviceRename"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | if (infoToggleLight != null) |
| | | { |
| | | infoToggleLight.DeviceName = toggleLight.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | |
| | | if (infoAirSwitch != null) |
| | | { |
| | | infoAirSwitch.DeviceName = airSwitch.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | |
| | | if (infoPanel != null) |
| | | { |
| | | infoPanel.DeviceName = panelObj.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | |
| | | if (wc != null) |
| | | { |
| | | wc.DeviceName = windowCovering.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.IASZone: |
| | |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = ias.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DimmableLight: |
| | |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = dimmableLight.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | |
| | | if (info != null) |
| | | { |
| | | info.DeviceName = repeater.renameDeviceMacNameData.MacName; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | |
| | | } |
| | | } |
| | | 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()); |
| | |
| | | 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()); |
| | | Gateway?.Send(("MacRename"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 97 } }; |
| | | Gateway.Send("FactoryReset", jObject.ToString()); |
| | | Gateway.Send("FactoryReset", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | { |
| | | d = new RemoveDeviceResponseAllData { removeDeviceResponseData = gatewayTemp.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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | } |
| | | }; |
| | |
| | | { "DeviceAddrList", deviceAddrList } |
| | | }; |
| | | jObject.Add("Data", data); |
| | | Gateway.Send(("RemoveDevice"), jObject.ToString()); |
| | | Gateway.Send(("RemoveDevice"), jObject.ToString()); |
| | | } |
| | | } |
| | | catch { } |
| | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 81 } }; |
| | | var data = new JObject { { "GwId", gwId } }; |
| | | jObject.Add("Data", data); |
| | | Gateway.Send(("RemoveEqOfGw"), jObject.ToString()); |
| | | Gateway.Send(("RemoveEqOfGw"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 3 }, { "Command", 0 }, { "SendMode", 2 } }; |
| | | var data = new JObject { { "Time", time } }; |
| | | jObject.Add("Data", data); |
| | | Gateway.Send(("Identify"), jObject.ToString()); |
| | | Gateway.Send(("Identify"), jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | { "AttriButeId", (int)attriButeId} |
| | | } |
| | | }; |
| | | var data = new JObject { { "AttriBute", attriBute } }; |
| | | JObject.Add("Data", data); |
| | | var data = new JObject { { "AttriBute", attriBute } }; |
| | | JObject.Add("Data", data); |
| | | Gateway?.Send(("GetDeviceStatus"), JObject.ToString()); |
| | | } |
| | | catch { } |
| | | } |
| | | catch { } |
| | | |
| | | // Gateway.Actions -= action; |
| | | System.Console.WriteLine("GetDeviceStatus_Actions 退出" + System.DateTime.Now.ToString()); |
| | |
| | | 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 { } |
| | | |
| | |
| | | try |
| | | { |
| | | var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 6 }, { "Command", command }, { "SendMode", 2 } }; |
| | | Gateway?.Send(("DeviceControl"), jobject.ToString()); |
| | | Gateway?.Send(("DeviceControl"), jobject.ToString()); |
| | | System.Console.WriteLine("SwitchControl_发送数据" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | } |
| | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 301 } }; |
| | | gateway.Send("Cluster/OwnAttributes", jObject.ToString()); |
| | | gateway.Send("Cluster/OwnAttributes", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | var jObject = new JObject { { "Cluster_ID", 25 }, { "Command", 30 } }; |
| | | var data = new JObject { { "OTAImageName", oTAImageName }, { "OTAImagePath", "/tmp" } }; |
| | | jObject.Add("Data", data); |
| | | gateway.Send(("OTA/SetImage"), jObject.ToString()); |
| | | gateway.Send(("OTA/SetImage"), jObject.ToString()); |
| | | } |
| | | catch |
| | | { } |
| | |
| | | } |
| | | var data = new JObject { { "DeviceList", deviceList } }; |
| | | jObject.Add("Data", data); |
| | | gateway.Send(("OTA/StartUpdate"), jObject.ToString()); |
| | | gateway.Send(("OTA/StartUpdate"), jObject.ToString()); |
| | | } |
| | | } |
| | | catch |
| | |
| | | /// <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()); |
| | | //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 { } |
| | | // 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()); |
| | | } |
| | | // Gateway.Actions -= action; |
| | | // System.Console.WriteLine("OnZbDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | //} |
| | | #endregion |
| | | |
| | | #region 客户端向节点设备透传数据. |
| | |
| | | |
| | | try |
| | | { |
| | | OpenPassthroughControl(gateway); |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; |
| | | var data = new JObject { { "PassData", passData } }; |
| | | jObject.Add("Data", data); |
| | |
| | | { "FileName", imageName } |
| | | }; |
| | | jObject.Add("Data", data); |
| | | gateway.Send("DownloadFile", jObject.ToString()); |
| | | gateway.Send("DownloadFile", jObject.ToString()); |
| | | } |
| | | catch |
| | | { |
| | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 25 }, { "Command", 5 } }; |
| | | gateway.Send("OTA/KillUpdate", jObject.ToString()); |
| | | gateway.Send("OTA/KillUpdate", jObject.ToString()); |
| | | } |
| | | catch |
| | | { } |
| | |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command=-1; |
| | | public int command = -1; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>0--成功 1--失败 ff--无效</para> |
| | | /// </summary> |
| | | public int status=-1; |
| | | public int status = -1; |
| | | } |
| | | #endregion |
| | | } |