| | |
| | | #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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 receiptData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceRenameResponseData>(jobject["Data"].ToString());
|
| | | d = new DeviceRenameAllData { deviceRenameData = receiptData }; |
| | | } |
| | | }; |
| | | 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> |
| | | /// 重命名设备,网关反馈具体信息 |
| | |
| | | #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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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");
|
| | | d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RenameDeviceMacNameData>(jobject["Data"].ToString()) }; |
| | | } |
| | | }; |
| | | 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名称数据,网关反馈具体信息 |