From cc0d80c7d86c6d0167269b3408c4b30c24ce84e9 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 23 三月 2020 16:55:37 +0800 Subject: [PATCH] ??????? --- ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs | 632 ++++++++++++++++++-------------------------------------- 1 files changed, 207 insertions(+), 425 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs index 3ae2a58..1528024 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using Newtonsoft.Json.Linq; @@ -11,6 +10,11 @@ { [Newtonsoft.Json.JsonIgnore] public DateTime LastDateTime = DateTime.MinValue; + /// <summary> + /// 鏄惁宸茬粡璇诲彇浜嗚澶囩姸鎬�(姝ゅ睘鎬ф槸缁欎富椤典娇鐢ㄧ殑) + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public bool HadReadDeviceStatu = false; /// <summary> /// 璋冭瘯鏃舵墦寮�鎵撳嵃淇℃伅锛宼rue:鎵撳嵃锛宖alse:涓嶆墦鍗� @@ -19,13 +23,15 @@ /// <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> @@ -76,7 +82,7 @@ gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId; gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; ZbGateway.GateWayList.Add(gateWay); - } + } return gateWay; } @@ -110,13 +116,13 @@ 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) { @@ -160,6 +166,14 @@ { 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; } @@ -180,8 +194,100 @@ /// </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> @@ -192,7 +298,10 @@ /// 褰撳墠璁惧绫诲瀷 /// </summary> public DeviceType Type = DeviceType.UnKown; - + /// <summary> + /// 璁惧鐨勫姛鑳界被鍨�(姝ょ被鍨嬬洰鍓嶅彧閽堝缁х數鍣ㄥ洖璺湁鏁�,榛樿鏈寚瀹�) + /// </summary> + public DeviceFunctionType DfunctionType = DeviceFunctionType.A鏈畾涔�; /// <summary> /// MAC鍦板潃 /// </summary> @@ -312,7 +421,7 @@ /// <summary> /// 搴忓垪鍙� /// </summary> - public string SerialNumber = string.Empty; + public string SerialNumber = string.Empty; /// <summary> /// 鎵�鏈夋寚瀹歝luster鏄惁閮藉凡缁忔垚鍔熺粦瀹氬崗璋冨櫒 ///<para>0:鏈畬鍏ㄧ粦瀹�</para> @@ -559,6 +668,18 @@ /// 椹卞姩浠g爜銆備负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> @@ -798,7 +919,7 @@ /// 1:璺敱鍣ㄨ澶� /// <para>2:缁堢璁惧</para> /// </summary> - public int ZigbeeType; + public int ZigbeeType; } /// <summary> @@ -886,7 +1007,7 @@ /// <summary> /// 璁惧鎵�鍦ㄧ綉鍏崇殑缃戝叧id /// </summary> - public int GwId; + public string GwId; /// <summary> /// 璁惧鍚� /// </summary> @@ -931,7 +1052,7 @@ /// <summary> /// 搴忓垪鍙� /// </summary> - public string SerialNumber = string.Empty; + public string SerialNumber = string.Empty; /// <summary> /// 杈撳叆绨囧垪琛� /// </summary> @@ -1035,180 +1156,8 @@ 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; @@ -1223,7 +1172,7 @@ 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 { } @@ -1349,7 +1298,7 @@ if (infoToggleLight != null) { infoToggleLight.DeviceName = toggleLight.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.AirSwitch: @@ -1368,7 +1317,7 @@ if (infoAirSwitch != null) { infoAirSwitch.DeviceName = airSwitch.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.OnOffSwitch: @@ -1386,7 +1335,7 @@ if (infoPanel != null) { infoPanel.DeviceName = panelObj.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.WindowCoveringDevice: @@ -1404,7 +1353,7 @@ if (wc != null) { wc.DeviceName = windowCovering.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.IASZone: @@ -1423,7 +1372,7 @@ if (info != null) { info.DeviceName = ias.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.DimmableLight: @@ -1442,7 +1391,7 @@ if (info != null) { info.DeviceName = dimmableLight.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.Repeater: @@ -1461,7 +1410,7 @@ if (info != null) { info.DeviceName = repeater.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.Thermostat: @@ -1502,6 +1451,25 @@ } } 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()); @@ -1536,7 +1504,7 @@ 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 { } @@ -1625,7 +1593,7 @@ 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 { } @@ -1682,191 +1650,6 @@ { 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 { } } } }; @@ -1890,7 +1673,7 @@ { "DeviceAddrList", deviceAddrList } }; jObject.Add("Data", data); - Gateway.Send(("RemoveDevice"), jObject.ToString()); + Gateway.Send(("RemoveDevice"), jObject.ToString()); } } catch { } @@ -2086,7 +1869,7 @@ 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 { } @@ -2179,7 +1962,7 @@ 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 { } @@ -2715,11 +2498,11 @@ { "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()); @@ -2831,7 +2614,7 @@ 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 { } @@ -2951,7 +2734,7 @@ 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()); } @@ -3026,7 +2809,7 @@ 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 { } @@ -3283,7 +3066,7 @@ 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 { } @@ -3457,7 +3240,7 @@ } var data = new JObject { { "DeviceList", deviceList } }; jObject.Add("Data", data); - gateway.Send(("OTA/StartUpdate"), jObject.ToString()); + gateway.Send(("OTA/StartUpdate"), jObject.ToString()); } } catch @@ -3594,28 +3377,28 @@ /// <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 瀹㈡埛绔悜鑺傜偣璁惧閫忎紶鏁版嵁. @@ -3671,7 +3454,6 @@ 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); @@ -3837,7 +3619,7 @@ { "FileName", imageName } }; jObject.Add("Data", data); - gateway.Send("DownloadFile", jObject.ToString()); + gateway.Send("DownloadFile", jObject.ToString()); } catch { @@ -4003,7 +3785,7 @@ 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 { } @@ -4098,12 +3880,12 @@ /// <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 } -- Gitblit v1.8.0