| | |
| | | { |
| | | //if (msg.Contains("DeviceStatusReport") == false)
|
| | | //{
|
| | | System.Console.WriteLine(msg);
|
| | | System.Console.WriteLine(msg);
|
| | | //} |
| | | } |
| | | } |
| | |
| | | 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); |
| | | } |
| | | 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/ColorDimmableLight.png"; |
| | | }
|
| | | else if (this.Type == DeviceType.DimmableLight) |
| | | { |
| | | //调光器 |
| | | IconPath = "Device/ColorDimmableLight.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.UnKown)
|
| | | {
|
| | | //其他的图标有点特殊
|
| | | string unSelectPic = string.Empty;
|
| | | string selectPic = string.Empty;
|
| | | Shared.Common.LocalDevice.Current.GetDeviceBeloneIcon(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> |
| | | /// 序列号 |
| | | /// </summary> |
| | | public string SerialNumber = string.Empty; |
| | | public string SerialNumber = string.Empty; |
| | | /// <summary> |
| | | /// 输入簇列表 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | }; |
| | |
| | | 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 { } |
| | | |
| | |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | |
| | | { "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 |
| | | } |