From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs | 546 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 377 insertions(+), 169 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs index da81728..5bb5fac 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Newtonsoft.Json.Linq; +using Shared; namespace ZigBee.Device { @@ -10,8 +11,8 @@ { #region 闇�瑕佷繚瀛樼殑鍙橀噺 - /// <summary> - /// 鏄惁鏄嚜瀹氫箟鍥剧墖 + /// <summary> + /// 鏄惁鏄嚜瀹氫箟鍥剧墖 /// </summary> public bool IsCustomizeImage = false; /// <summary> @@ -27,9 +28,9 @@ { get { - if (string.IsNullOrEmpty(IconPath)) - { - return string.Empty; + if (string.IsNullOrEmpty(IconPath)) + { + return string.Empty; } var pathArr = IconPath.Split('.'); if (pathArr == null || string.IsNullOrEmpty(pathArr[0])) @@ -61,7 +62,7 @@ /// </summary> public int DeviceEpoint; /// <summary> - /// 璁惧id + /// 瀹為檯鐨勮澶噄d /// <para>258:color dimmable light,璋冨叧鐏� </para> /// <para>10:Door lock,闂ㄩ攣</para> /// <para>514:Window covering device,绐楀笜</para> @@ -73,6 +74,16 @@ /// <para>1026:sensor,浼犳劅鍣紝鍏蜂綋绫诲瀷鐨勪紶鎰熷櫒DeviceType鏉ュ尯鍒�</para> /// </summary> public int DeviceID; + /// <summary> + /// <para>2020.09.21杩藉姞:涓轰簡瀵瑰簲绗笁鏂硅澶�,浠ュ強涔嬪悗鐨勫璁惧ID闂,杩藉姞鐨勫彉閲�</para> + /// <para>杩欐槸涓壒娈婄殑,骞朵笖涓嶄繚瀛樺湪鏂囦欢褰撲腑鐨処D, DeviceType鐢辨鍊兼槧灏勫嚭鏉�</para> + /// <para>褰撹澶囨槸娌充笢璁惧鏃�,瀹冧笌DeviceID鐩哥瓑</para> + /// <para>褰撴槸鐪熸鐨勭涓夋柟璁惧鏃�,瀹冩湁鍙兘涓嶥eviceID涓嶇浉绛�</para> + /// <para>姣斿锛�2鍜�256閮芥槸缁х數鍣�,閭d箞銆怐eviceID涓�2 鎴栬�� DeviceID涓�256銆� 鑰� 銆怑xDeviceID鍥哄畾涓�2銆�,銆怐eviceType涓篛nOffOutput銆�</para> + /// <para>閫氫織鏉ヨ锛欴eviceID鏄疄闄呮纭殑ID,鑰屻�怑xDeviceID鏄竴绉嶆墍灞炴蹇电殑ID銆�</para> + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public int ExDeviceID; /// <summary> /// 璇ュ瓧娈典富瑕侀拡瀵笽AS瀹夐槻璁惧璁剧珛銆傛墍鏈塈AS瀹夐槻璁惧鍏辩敤涓�涓狣eviceID涓�1026銆傛墍浠ヨ鍖哄垎瀛愯澶囩被鍨嬶紝闇�瑕佽瀛楁銆� /// 鐬棿鏁版嵁涓婃姤鐨勪紶鎰熷櫒 (MomentStatus=1 TriggerZoneStatus>=1锛滄姤璀︼紴) @@ -108,14 +119,14 @@ /// 0锛氳澶囦笉鍦ㄧ嚎 /// <para>1锛氳澶囧湪绾�</para> /// </summary> - public int IsOnline; - /// <summary> - /// 1锛氳矾鐢辫澶� - /// <para>2锛氱粓绔澶囷紝鐢垫睜璁惧</para> - /// </summary> + public int IsOnline; + /// <summary> + /// 1锛氳矾鐢辫澶� + /// <para>2锛氱粓绔澶囷紝鐢垫睜璁惧</para> + /// </summary> public int ZigbeeType; /// <summary> - /// 褰撳墠杩愯绋嬪簭鐗堟湰淇℃伅銆� 鏈�澶�64瀛楄妭 + /// 鍥轰欢鐗堟湰 /// </summary> public int ImgVersion; /// <summary> @@ -158,6 +169,10 @@ /// 杈撳嚭绨囧垪琛� /// </summary> public List<OutClusterObj> OutClusterList = new List<OutClusterObj>(); + /// <summary> + /// 鐢ㄤ簬璁板綍璁惧鏈�鏂颁笂鎶ョ殑灞炴�х姸鎬佷俊鎭� + /// </summary> + public List<AttributeStatusObj> AttributeStatus = new List<AttributeStatusObj>(); [Newtonsoft.Json.JsonIgnore] public DateTime LastDateTime = DateTime.MinValue; @@ -166,6 +181,12 @@ /// </summary> [Newtonsoft.Json.JsonIgnore] public bool HadReadDeviceStatu = false; + + /// <summary> + /// 鏄惁鏄綆鐢甸噺(杩欎釜鍙橀噺鐩墠鏄粰浼犳劅鍣ㄧ敤鐨�) + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public bool IsBatteryDown = false; /// <summary> /// 绛夊緟浠庣綉鍏虫帴鏀舵暟鎹殑鏃堕棿 @@ -220,114 +241,145 @@ { get { - var deviceType = Type.ToString(); - var fileName = "Device_" + deviceType + "_" + DeviceAddr; - fileName += "_" + (DeviceEpoint.ToString().Length < 2 ? "0" + DeviceEpoint.ToString() : DeviceEpoint.ToString()); - return fileName; + //2020.09.21 瀵瑰簲绗笁鏂硅澶囧彲浠ュ叆缃�,璁惧鏂囦欢鍚嶅瓧,鍘绘帀 deviceType + return "Device_" + DeviceAddr + "_" + DeviceEpoint.ToString().PadLeft(2, '0'); } } #endregion #region 璁惧淇濆瓨鍙婄敓鎴� - - /// <summary> - /// 鐢辫澶囧瓧绗︿覆姣旂壒鎭㈠璁惧瀵硅薄 - /// </summary> - /// <param name="strDeviceType">璁惧DeviceType鐨勫瓧绗︿覆绫诲瀷</param> - /// <param name="strDeviceByte">璁惧Json鏂囦欢杞负姣旂壒鍚庡啀杞负鐨勫瓧绗︿覆</param> - /// <returns></returns> - public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) - { - CommonDevice device = null; - if (strDeviceType == ZigBee.Device.DeviceType.DimmableLight.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.OnOffOutput.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.IASZone.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.OtaDevice.ToString() || strDeviceType == ZigBee.Device.DeviceType.OtaPanelDevice.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.AirSwitch.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.Repeater.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.Thermostat.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.Transverter.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.TemperatureSensor.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.FreshAirHumiditySensor.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.FreshAir.ToString()) - { - device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.PMSensor.ToString()) - { - return Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString()) - { - return Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte); - } - else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString()) - { - return Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte); - } - else { return null; } - //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓� - device.Type = (DeviceType)device.DeviceID; - - return device; - } /// <summary> - /// 鐢辫澶囪矾寰勬仮澶嶈澶囧璞� + /// 鐢辫澶囧瓧绗︿覆姣旂壒鎭㈠璁惧瀵硅薄 /// </summary> - /// <returns>The device by file path.</returns> - /// <param name="deviceFilePath">Device file path.</param> - public static CommonDevice CommonDeviceByFilePath(string deviceFilePath) + /// <param name="intDeviceType">璁惧DeviceType鐨勬暣鍨嬪��</param> + /// <param name="strDeviceByte">璁惧Json鏂囦欢杞负姣旂壒鍚庡啀杞负鐨勫瓧绗︿覆</param> + /// <returns></returns> + public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte) { - var v = deviceFilePath.Split('_'); - if (v.Length < 3) + //杩欐槸娌充笢鐨勭壒娈婄鐐�,涓嶉渶瑕佸鐞� + if (intDeviceType == 49408) { return null; } - return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath))); + + CommonDevice device = null; + if (intDeviceType == (int)DeviceType.DimmableLight || intDeviceType == 3) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); + device.ExDeviceID = (int)DeviceType.DimmableLight; + } + else if (intDeviceType == (int)DeviceType.OnOffOutput || intDeviceType == 256) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); + device.ExDeviceID = (int)DeviceType.OnOffOutput; + } + else if (intDeviceType == (int)DeviceType.ColorDimmerSwitch) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.LevelControlSwitch) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.WindowCoveringDevice) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.WindowCoveringController) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.OnOffSwitch) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.IASZone) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.OtaDevice || intDeviceType == (int)DeviceType.OtaPanelDevice) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.AirSwitch) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.Repeater) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.Thermostat) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.Transverter) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.DoorLock) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.TemperatureSensor) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.FreshAirHumiditySensor) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.FreshAir) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.PMSensor) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.ColorTemperatureLight) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.Buzzer) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.ColorDimmableLight) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmableLight>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.DimmerSwitch) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte); + } + else if (intDeviceType == (int)DeviceType.Airer) + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<Airer>(strDeviceByte); + } + else + { + device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte); + } + + //杩欐槸娌充笢鐨勭壒娈婄鐐�,涓嶉渶瑕佸鐞� + if (device.DeviceEpoint == 242 && intDeviceType == 97) + { + return null; + } + + if (device.ExDeviceID == 0) + { + //璧嬪垵濮嬪�� + device.ExDeviceID = device.DeviceID; + } + + //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓� + device.Type = (DeviceType)device.ExDeviceID; + + return device; } /// <summary> @@ -347,15 +399,57 @@ /// </summary> public void ReSave() { - if (IconPath == string.Empty) - { - //淇濆瓨璁惧鍥炬爣(杩欓噷浼氫繚瀛樹竴娆�,涓嬮潰灏变笉鐢ㄤ繚瀛樹簡) - this.SaveDeviceIcon(); - return; + if (Shared.Common.Config.Instance.Home.IsShowTemplate == true) + { + //灞曠ず妯℃澘鏃�,涓嶅厑璁镐繚瀛樻枃浠�(闃叉灞炴�т笂鎶ョ敤鐨�) + return; + } + if (IconPath == string.Empty) + { + //淇濆瓨璁惧鍥炬爣(杩欓噷浼氫繚瀛樹竴娆�,涓嬮潰灏变笉鐢ㄤ繚瀛樹簡) + this.SaveDeviceIcon(); + return; } Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); - } - + } + + /// <summary> + /// 鍒ゆ柇鏄惁鏄┖姘旇川閲忎紶鎰熷櫒 + /// </summary> + /// <param name="dev"></param> + /// <returns></returns> + public bool isAirQualitySensor(CommonDevice dev) + { + bool hasT = false; + bool hasH = false; + bool hasPM = false; + bool hasCo2 = false; + foreach (var clu in dev.InClusterList) + { + switch (clu.InCluster) + { + case 1026: + hasT = true; + break; + case 1029: + hasH = true; + break; + case 1037: + hasCo2 = true; + break; + case 1066: + hasPM = true; + break; + } + } + + if (hasT == true && hasH == true && hasPM == true && hasCo2 == true) + { + return true; + } + return false; + } + /// <summary> /// 淇濆瓨璁惧鍥炬爣 /// </summary> @@ -363,25 +457,25 @@ { if (IconPath == string.Empty) { - //骞叉帴鐐� - if (this.Type == DeviceType.OnOffSwitch) - { - IconPath = "Device/DryContact.png"; - } + //骞叉帴鐐� + if (this.Type == DeviceType.OnOffSwitch) + { + IconPath = "Device/DryContact.png"; + } else if (this.Type == DeviceType.ColorDimmableLight) { //褰╃伅 IconPath = "Device/ColorLight.png"; - } + } else if (this.Type == DeviceType.DimmableLight) { //璋冨厜鍣� IconPath = "Device/Light.png"; - } - else if (this.Type == DeviceType.ColorTemperatureLight) - { - //鑹叉俯鐏� - IconPath = "Device/ColorLightTemperature.png"; + } + else if (this.Type == DeviceType.ColorTemperatureLight) + { + //鑹叉俯鐏� + IconPath = "Device/ColorLightTemperature.png"; } else if (this.Type == DeviceType.OnOffOutput) { @@ -408,31 +502,39 @@ //婀垮害浼犳劅鍣� IconPath = "Device/SensorHumidity.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.TemperatureSensor) + { + if (isAirQualitySensor(this)) + { + //绌烘皵璐ㄩ噺浼犳劅鍣� + IconPath = "Device/AirQualitySensorEpoint.png"; + } + else + { + if (((TemperatureSensor)this).SensorDiv == 1) + { + //娓╁害浼犳劅鍣� + IconPath = "Device/SensorTemperature.png"; + } + else if (((TemperatureSensor)this).SensorDiv == 2) + { + //婀垮害浼犳劅鍣� + IconPath = "Device/SensorHumidity.png"; + } + } } - else if (this.Type != DeviceType.UnKown) - { - //鍏朵粬鐨勫浘鏍囨湁鐐圭壒娈� - string unSelectPic = string.Empty; - string selectPic = string.Empty; - Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic); - IconPath = unSelectPic; - } + else if (this.Type != DeviceType.UnKown) + { + //鍏朵粬鐨勫浘鏍囨湁鐐圭壒娈� + string unSelectPic = string.Empty; + string selectPic = string.Empty; + Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic); + IconPath = unSelectPic; + } Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); } - } - + } + #endregion #region 杈撳叆杈撳嚭闀炲畾涔� @@ -452,7 +554,7 @@ /// </summary> public int AttributeId; /// <summary> - /// 灞炴�у�硷紝鏈�澶у崰鐢�4涓瓧鑺� + /// 灞炴�у�硷紝杩欎釜涓滆タ涓嶉渶瑕佷粈涔堥珮浣嶅湪鍚庝綆浣嶅湪鍓�,瀹冨凡缁忔槸杞负浜�10杩涘埗 /// </summary> public int AttributeData; /// <summary> @@ -663,18 +765,22 @@ /// 椹卞姩浠g爜銆備负0鏃讹紝琛ㄧずzigbee鍗忚皟鍣ㄨ澶囥�傚叾浠栧�艰〃绀轰负铏氭嫙椹卞姩璁惧 /// </summary> public int DriveCode; - /// <summary> - /// 鍘傚晢鍚嶇О + /// <summary> + /// 鍘傚晢鍚嶇О /// </summary> public string ManufacturerName = string.Empty; - /// <summary> - /// 妯″潡ID + /// <summary> + /// 妯″潡ID /// </summary> public string ModelIdentifier = string.Empty; - /// <summary> - /// 濂藉儚鏄簭鍒楀彿 + /// <summary> + /// 濂藉儚鏄簭鍒楀彿 /// </summary> public string ProductCode = string.Empty; + /// <summary> + /// 璁惧鍔熻兘绫诲瀷(绌烘皵寮�鍏冲拰缁х數鍣ㄤ笓鐢�) + /// </summary> + public int FunctionType = -1; /// <summary> /// 杈撳叆绨囧垪琛� /// </summary> @@ -833,6 +939,109 @@ } #endregion + #region 涓�閿洿鏂板洓瀵稿睆鎸夐敭灞炴�� + /// <summary> + /// 鍚屾璁惧鍔熻兘 + /// </summary> + /// <returns></returns> + public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint) + { + if (Gateway == null) + { + return null; + } + + return await System.Threading.Tasks.Task.Run(async () => + { + SynchronizationDeviceResponseAllData resContent = null; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + + if (topic == gatewayID + "/" + "Error_Respon") + { + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); + + if (temp == null) + { + resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + else + { + resContent = new SynchronizationDeviceResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + + if (topic == gatewayID + "/" + "Bind/SyncMsgToBindSourceRespon") + { + var res = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); + if (res == null) + { + resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + resContent = new SynchronizationDeviceResponseAllData { result = res }; + System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); + } + } + }; + Gateway.Actions = action; + DebugPrintLog("Bind/SyncMsgToBindSourceRespon_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); + + try + { + var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5010 } }; + Gateway.Send("Bind/SyncMsgToBindSource", jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (resContent != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) + { + resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("Bind/SyncMsgToBindSource_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return resContent; + }); + + } + + /// <summary> + /// 鍚屾璁惧,缃戝叧鍙嶉鍏蜂綋淇℃伅 + /// </summary> + [System.Serializable] + public class SynchronizationDeviceResponseAllData + { + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string errorMessageBase; + /// <summary> + /// 缃戝叧淇℃伅閿欒鍙嶉 + /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + /// </summary> + public ErrorResponData errorResponData; + /// <summary> + /// 鍚屾缁撴灉 + /// 0:鎴愬姛锛氱綉鍏冲唴閮ㄨ嚜鍔ㄥ啓鍏ヨ澶囩洰鏍囧悕瀛椼�佽澶囩洰鏍囧姛鑳界被鍨嬨�佸満鏅洰鏍囧悕瀛椼�乽tc鏃堕棿鍐欏叆4瀵稿睆 + /// 1:澶辫触 + /// </summary> + public int result; + } + #endregion + #region 鍒犻櫎璁惧锛堜娇璁惧绂荤綉锛� /// <summary> /// 鍒犻櫎璁惧锛堜娇璁惧绂荤綉锛� @@ -883,7 +1092,7 @@ } }; Gateway.Actions += action; - System.Console.WriteLine("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); + DebugPrintLog("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); try { @@ -921,7 +1130,7 @@ d = new RemoveDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; } Gateway.Actions -= action; - System.Console.WriteLine("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + DebugPrintLog("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString()); return d; }); @@ -1143,12 +1352,11 @@ /// 璁剧疆鍙啓灞炴�х殑鍊� /// </summary> /// <returns>The writable value async.</returns> - /// <param name="gateway">Gateway.</param> /// <param name="clusterID">瑕侀厤缃殑灞炴�ф墍鍦ㄧ殑cluster.</param> /// <param name="setWritableValue">璁剧疆鍙啓灞炴�х殑鏁版嵁</param> - public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(ZigBee.Device.ZbGateway gateway, int clusterID, SetWritableValueData setWritableValue) + public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(int clusterID, SetWritableValueData setWritableValue) { - if (gateway == null || setWritableValue == null) + if (Gateway == null || setWritableValue == null) { return null; } @@ -1189,7 +1397,7 @@ } } }; - gateway.Actions += action; + Gateway.Actions += action; System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); try @@ -1197,7 +1405,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 { } @@ -1214,7 +1422,7 @@ { d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; } - gateway.Actions -= action; + Gateway.Actions -= action; System.Console.WriteLine("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString()); return d; @@ -2291,13 +2499,13 @@ public static void DebugPrintLog(string msg, bool flage = true) { #if DEBUG - if (flage == true) - { - if (msg.Contains("DeviceStatusReport") == false) - { - System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); - } - } + if (flage == true) + { + if (msg.Contains("DeviceStatusReport") == false) + { + System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); + } + } #endif } -- Gitblit v1.8.0