From 0d9f64668fd7350d6a21fd157e32009a96d98134 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 16 十二月 2020 13:09:08 +0800 Subject: [PATCH] 新云端代码Ver1.2 --- ZigbeeApp/Shared/Phone/Common/Logic/HdlDeviceCommonLogic.cs | 874 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 638 insertions(+), 236 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlDeviceCommonLogic.cs similarity index 82% rename from ZigbeeApp/Shared/Common/Device.cs rename to ZigbeeApp/Shared/Phone/Common/Logic/HdlDeviceCommonLogic.cs index 78875ab..cfa7c87 100644 --- a/ZigbeeApp/Shared/Common/Device.cs +++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlDeviceCommonLogic.cs @@ -1,33 +1,33 @@ -锘縰sing Shared.Phone.UserCenter; -using System; +锘縰sing System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using ZigBee.Device; +using Shared.Common; -namespace Shared.Common +namespace Shared.Phone { /// <summary> - /// 鏈湴璁惧 + /// 璁惧鐨勫叡閫氶�昏緫 /// </summary> - public class LocalDevice + public class HdlDeviceCommonLogic { #region 鈻� 鍙橀噺澹版槑___________________________ /// <summary> - /// 鏈湴璁惧 + /// 璁惧鐨勫叡閫氶�昏緫 /// </summary> - private static LocalDevice m_Current = null; + private static HdlDeviceCommonLogic m_Current = null; /// <summary> - /// 鏈湴璁惧 + /// 璁惧鐨勫叡閫氶�昏緫 /// </summary> - public static LocalDevice Current + public static HdlDeviceCommonLogic Current { get { if (m_Current == null) { - m_Current = new LocalDevice(); + m_Current = new HdlDeviceCommonLogic(); } return m_Current; } @@ -106,7 +106,7 @@ try { //璇诲彇瀹冪殑鍐呭 - var fileData = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(Config.Instance.FullPath, file)); + var fileData = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(Common.Config.Instance.FullPath, file)); var jobject = Newtonsoft.Json.Linq.JObject.Parse(fileData); if (jobject.Property("DeviceID") == null) { @@ -125,7 +125,7 @@ //濡傛灉杩欎釜璁惧鐨勭綉鍏矷D涓嶅瓨鍦ㄧ殑璇� if (HdlGatewayLogic.Current.IsGatewayExist(device.CurrentGateWayId) == false) { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) { //濡傛灉浠栨槸鎴愬憳鐨勮瘽,甯粬鏂板缓涓�涓綉鍏� HdlGatewayLogic.Current.AddVirtualGateway(device.CurrentGateWayId); @@ -145,14 +145,6 @@ this.dicOTADevice[mainKey] = (OTADevice)device; continue; } - //濡傛灉璁惧鏄櫨琛f灦,鍒欎竴绔偣锛屽叾浠栫鐐癸紙2锝�5锛夎繃婊�, - //鍥犱负鍏朵粬绔偣鍙湁鎺у埗浣滅敤锛岋紙2:鎺у埗鐓ф槑锛�3:鎺у埗椋庡共锛�4:鎺у埗鐑樺共锛�5:鎺у埗娑堟瘨锛� - //浜у搧缁忕悊涓嶈鏄剧ず - if (device is Airer) - { - if (device.DeviceEpoint == 2 || device.DeviceEpoint == 3 || device.DeviceEpoint == 4 || device.DeviceEpoint == 5) - continue; - } //娣诲姞缂撳瓨 this.dicAllDevice[mainKey] = device; @@ -168,7 +160,7 @@ if (bolSave == true) { //鍒犳帀杩欎釜鏂囦欢,閲嶆柊鐢熸垚 - HdlAutoBackupLogic.DeleteFile(file); + HdlBackupLogic.Current.DeleteAutoBackFileStatu(file); Global.DeleteFilebyHomeId(file); } @@ -178,7 +170,7 @@ //涓嶅瓨鍦ㄧ殑璇濓紝閲嶆柊鐢熸垚 device.IconPath = string.Empty; device.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); bolSave = false; } @@ -186,16 +178,14 @@ if (bolSave == true) { device.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } } //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 this.DeleteGatewayFileByMemberModel(); - //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍 - HdlRoomLogic.Current.InitRealDeviceRoomId(); #if DEBUG - if (UserCenterResourse.HideOption.CenterHideMenu == 1) + if (HdlUserCenterResourse.HideOption.CenterHideMenu == 1) { //妫�娴嬩竴浜涗唬鐮侀厤缃�(debug) this.CheckOhtherSettion(); @@ -208,7 +198,7 @@ /// </summary> private void DeleteGatewayFileByMemberModel() { - if (UserCenterResourse.UserInfo.AuthorityNo != 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3) { return; } @@ -327,7 +317,7 @@ dicExist.Remove(maikey); } //鑾峰彇璁惧鐨勫浐瀹氬睘鎬� - if (HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device) == true) + if (HdlDeviceAttributeLogic.Current.ReadDeviceAllFixedAttribute(device) == true) { System.Threading.Thread.Sleep(200); } @@ -403,18 +393,9 @@ if (exists == false) { //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } return; - } - - //濡傛灉璁惧鏄櫨琛f灦,鍒欎竴绔偣锛屽叾浠栫鐐癸紙2锝�5锛夎繃婊�, - //鍥犱负鍏朵粬绔偣鍙湁鎺у埗浣滅敤锛岋紙2:鎺у埗鐓ф槑锛�3:鎺у埗椋庡共锛�4:鎺у埗鐑樺共锛�5:鎺у埗娑堟瘨锛� - //浜у搧缁忕悊涓嶈鏄剧ず - if (device is Airer) - { - if (device.DeviceEpoint == 2 || device.DeviceEpoint == 3 || device.DeviceEpoint == 4 || device.DeviceEpoint == 5) - return; } lock (dicAllDevice) @@ -450,7 +431,7 @@ if (exists2 == false) { //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } } @@ -466,14 +447,6 @@ this.dicOTADevice[mainKeys] = (OTADevice)device; device.ReSave(); return; - } - //濡傛灉璁惧鏄櫨琛f灦,鍒欎竴绔偣锛屽叾浠栫鐐癸紙2锝�5锛夎繃婊�, - //鍥犱负鍏朵粬绔偣鍙湁鎺у埗浣滅敤锛岋紙2:鎺у埗鐓ф槑锛�3:鎺у埗椋庡共锛�4:鎺у埗鐑樺共锛�5:鎺у埗娑堟瘨锛� - //浜у搧缁忕悊涓嶈鏄剧ず - if (device is Airer) - { - if (device.DeviceEpoint == 2 || device.DeviceEpoint == 3 || device.DeviceEpoint == 4 || device.DeviceEpoint == 5) - return; } this.dicAllDevice[mainKeys] = device; @@ -516,7 +489,7 @@ //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� - if (UserCenterResourse.UserInfo.AuthorityNo != 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3) { var result = this.RenameDeviceNameAsync(device, newName); if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) @@ -524,7 +497,7 @@ //璁惧鍚嶇О淇敼澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, result); if (mode == ShowErrorMode.YES) { @@ -569,7 +542,7 @@ CommonDevice device = listDevice[0]; //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� - if (UserCenterResourse.UserInfo.AuthorityNo != 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3) { //淇敼鐗╃悊鍚嶅瓧 var result = this.RenameDeviceMacNameAsync(device, newMacName); @@ -578,7 +551,7 @@ //璁惧鍚嶇О淇敼澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, result); if (mode == ShowErrorMode.YES) { this.ShowErrorMsg(msg); @@ -658,7 +631,7 @@ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� if (Common.Config.Instance.Home.IsVirtually == true) { - return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); + return Phone.HdlTemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); } //鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗� @@ -669,7 +642,7 @@ return null; } //鍔犵紦瀛� - Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); + Phone.HdlTemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RenameDeviceMacNameData>(result.ReceiptData); return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData }; @@ -686,7 +659,7 @@ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� if (Common.Config.Instance.Home.IsVirtually == true) { - return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); + return Phone.HdlTemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); } //鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗� var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName); @@ -696,7 +669,7 @@ return null; } //鍔犵紦瀛� - Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); + Phone.HdlTemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceRenameResponseData>(result.ReceiptData); return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData }; @@ -759,7 +732,7 @@ device.ReSave(); //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } else if (this.dicOTADevice.ContainsKey(mainKeys) == true) { @@ -768,7 +741,7 @@ device.ReSave(); //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } } @@ -799,7 +772,7 @@ //璁惧鍒犻櫎澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, result); this.ShowErrorMsg(msg); return false; @@ -852,13 +825,13 @@ } } //鍒犻櫎妯℃澘鏁版嵁 - Phone.TemplateData.TemplateCommonLogic.Current.DeleteDevice(device); + Phone.HdlTemplateCommonLogic.Current.DeleteDevice(device); //鍒犻櫎璁惧鏂囦欢 string filePath = device.FilePath; if (Global.IsExistsByHomeId(filePath) == true) { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) { //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� Global.DeleteFilebyHomeId(filePath); @@ -868,7 +841,7 @@ //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� Global.DeleteFilebyHomeId(filePath); //鍒犻櫎鑷姩澶囦唤 - HdlAutoBackupLogic.DeleteFile(device.FilePath); + HdlBackupLogic.Current.DeleteAutoBackFileStatu(device.FilePath); } } } @@ -887,7 +860,7 @@ string otaFile = this.dicOTADevice[otaKeys].FilePath; if (Global.IsExistsByHomeId(otaFile) == true) { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) + if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) { //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� Global.DeleteFilebyHomeId(otaFile); @@ -897,7 +870,7 @@ //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� Global.DeleteFilebyHomeId(otaFile); //鍒犻櫎鑷姩澶囦唤 - HdlAutoBackupLogic.DeleteFile(otaFile); + HdlBackupLogic.Current.DeleteAutoBackFileStatu(otaFile); } } this.dicOTADevice.Remove(otaKeys); @@ -914,7 +887,7 @@ public async Task<bool> SynchronizationDevice(List<CommonDevice> listdevice) { //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧 - if (Config.Instance.Home.IsVirtually == false) + if (Common.Config.Instance.Home.IsVirtually == false) { //鍚屾 var result = await listdevice[0].SyncMsgToBindSource(listdevice[0].DeviceAddr, listdevice[0].DeviceEpoint); @@ -923,7 +896,7 @@ //鍚屾鍒犻櫎澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.SynchronizationFailed); //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, result); this.ShowErrorMsg(msg); return false; @@ -967,9 +940,9 @@ /// <returns></returns> public bool DeviceIsCanFixedPosition(CommonDevice device) { - if (device.Type == DeviceType.DoorLock || device.Type == DeviceType.Airer || device.Type == DeviceType.PMSensor) + if (device.Type == DeviceType.DoorLock || device.Type == DeviceType.PMSensor) { - //闂ㄩ攣鍜屾櫨琛f灦娌℃湁瀹氫綅鍔熻兘锛� + //闂ㄩ攣娌℃湁瀹氫綅鍔熻兘 return false; } var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); @@ -1012,7 +985,7 @@ public bool DeviceIsCanSynchronization(CommonDevice device) { //鑾峰彇璁惧绫诲瀷鐨� - var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + var deviceEnumInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction) { return true; @@ -1495,7 +1468,7 @@ { //閲嶆柊鐢熸垚缂撳瓨 tempDevice.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(tempDevice.FilePath); //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂� Phone.UserView.UserPage.Instance.RefreshAllForm = true; } @@ -1747,7 +1720,7 @@ device.IsCustomizeImage = true; device.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(device.FilePath); } /// <summary> @@ -2399,22 +2372,6 @@ info.ConcreteType = DeviceConcreteType.ColorLight_Temperature; info.ObjectTypeName = this.dicDeviceModelIdEnum["A420"].A绫诲瀷鍚嶅瓧;//璋冨厜妯″潡 } - //17鏅捐。鏋� - else if (dicType.ContainsKey(DeviceType.Airer) == true) - { - info.ConcreteText = this.dicDeviceModelIdEnum["A421"].A瀹樻柟鍚嶅瓧; - info.BeloneType = DeviceBeloneType.A鏅捐。鏋�; - info.ConcreteType = DeviceConcreteType.Airer; - info.ObjectTypeName = this.dicDeviceModelIdEnum["A421"].A绫诲瀷鍚嶅瓧; - } - //18绌烘皵璐ㄩ噺浼犳劅鍣� - else if (dicType.ContainsKey(DeviceType.AirQualitySensor) == true) - { - info.ConcreteText = this.dicDeviceModelIdEnum["A422"].A瀹樻柟鍚嶅瓧; - info.BeloneType = DeviceBeloneType.A绌烘皵璐ㄩ噺; - info.ConcreteType = DeviceConcreteType.AirQualitySensor; - info.ObjectTypeName = this.dicDeviceModelIdEnum["A422"].A绫诲瀷鍚嶅瓧; - } //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 info.BeloneText = info.ConcreteText; @@ -2561,73 +2518,346 @@ #endregion - #region 鈻� 鏅捐。鏋惰澶囨椂闂撮厤缃甠__________________________ + #region 鈻� 鑾峰彇涓婚〉璁惧鐘舵�佺殑缈昏瘧鏂囨湰_________ + /// <summary> - /// 璁剧疆鏅捐。鏋堕骞诧紝鐑樺共鍜屾秷姣掓椂闂�(璁剧疆澶辫触鏃讹紝浼氭樉绀轰俊鎭�) - /// time:璁剧疆鐨勫垎閽� + /// 鑾峰彇涓婚〉璁惧鐘舵�佺殑缈昏瘧鏂囨湰 /// </summary> - /// <param name="litdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param> - public async Task<bool> SetAirerTimeDevice(List<CommonDevice> listdevice, Airer airer, int time, int controlEpoint) + /// <returns></returns> + public string GetMainPageDeviceStatuText(CommonDevice device) { - //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕� - if (Config.Instance.Home.IsVirtually == false) + if (device.Type == DeviceType.OnOffOutput) { - foreach (var dev in listdevice) + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) { - //璁剧疆灞炴�т俊鎭� - CommonDevice.SetWritableValueData dataT = new CommonDevice.SetWritableValueData(); - dataT.Undivided = 0; - dataT.AttributeId = 16385; - dataT.AttributeDataType = 33; - dataT.AttributeData = time; - dev.DeviceEpoint = controlEpoint;//鏆傛椂鎹㈡垚鏅捐。鏋跺搴旂殑鎺у埗绔偣 - var result = await dev.SetWritableValueAsync(6, dataT); - if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0) + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + if ((device as ToggleLight).OnOffStatus == 1) + { + return Language.StringByID(R.MyInternationalizationString.uOpen1); + } + return Language.StringByID(R.MyInternationalizationString.Close); + } + else if (device.Type == DeviceType.AirSwitch) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + if ((device as AirSwitch).OnOffStatus == 1) + { + return Language.StringByID(R.MyInternationalizationString.uOpen1); + } + return Language.StringByID(R.MyInternationalizationString.Close); + } + else if (device.Type == DeviceType.DimmableLight) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + if ((device as DimmableLight).OnOffStatus == 0) + { + return Language.StringByID(R.MyInternationalizationString.Close); + } + return $"{(int)((device as DimmableLight).Level * 1.0 / 254 * 100)}%"; + } + else if (device.Type == DeviceType.ColorTemperatureLight) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + if ((device as ColorTemperatureLight).OnOffStatus == 0) + { + return Language.StringByID(R.MyInternationalizationString.Close); + } + return $"{(int)((device as ColorTemperatureLight).Level * 1.0 / 254 * 100)}%"; + } + else if (device.Type == DeviceType.WindowCoveringDevice) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + if ((device as Rollershade).WcdCurrentPositionLiftPercentage == 0) + { + return Language.StringByID(R.MyInternationalizationString.Close); + } + return $"{(device as Rollershade).WcdCurrentPositionLiftPercentage}%"; + } + else if (device.Type == DeviceType.FreshAir) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + + //妯″紡 + string wind = string.Empty; + var freshAir = device as FreshAir; + if (freshAir.currentFanStatus == 0) + { + return Language.StringByID(R.MyInternationalizationString.Close); + } + if (freshAir.currentFanSpeed == 1) + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Low); + } + else if (freshAir.currentFanSpeed == 2) + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Middle); + } + else if (freshAir.currentFanSpeed == 3) + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Height); + } + return $"{wind}"; + } + else if (device.Type == DeviceType.PMSensor) + { + //绌烘皵璐ㄩ噺 + string curQuality = ""; + //娓╁害 + string temperature = string.Empty; + //婀垮害 + string humidity = string.Empty; + //PM2.5 + string pm = string.Empty; + var pMSensor = device as PMSensor; + if (pMSensor.currentPmData <= 35 && pMSensor.currentPmData >= 0) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else if (pMSensor.currentPmData <= 75 && pMSensor.currentPmData > 35) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else if (pMSensor.currentPmData <= 115 && pMSensor.currentPmData > 75) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else if (pMSensor.currentPmData <= 150 && pMSensor.currentPmData > 115) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else if (pMSensor.currentPmData <= 250 && pMSensor.currentPmData > 150) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else if (pMSensor.currentPmData > 250) + { + curQuality = Language.StringByID(R.MyInternationalizationString.ExcellentAirQuality); + } + else + { + curQuality = "--"; + } + + humidity = $"{pMSensor.currentHumidity}%"; + temperature = $"{pMSensor.currentTemperature}鈩�"; + pm = $"{pMSensor.currentPmData}渭g/m鲁"; + return $"{curQuality},{pm},{temperature},{humidity}"; + + } + else if (device.Type == DeviceType.Thermostat) + { + //鍦ㄧ綉鍏虫病鏈夊洖澶嶄箣鍓�,榛樿绂荤嚎 + if (device.HadReadDeviceStatu == false) + { + return Language.StringByID(R.MyInternationalizationString.uOffLine); + } + //娓╁害锛屾ā寮忥紝椋庨�� + string tempareture = string.Empty; + string model = string.Empty; + string wind = string.Empty; + + var ac = device as AC; + + if (ac.currentSystemMode == 0) + { + return Language.StringByID(R.MyInternationalizationString.Close); + } + else if (ac.currentSystemMode == 1) + { + model = Language.StringByID(R.MyInternationalizationString.Mode_Auto); + tempareture = $"{ac.currentAutoSetpoint} 鈩�"; + } + else if (ac.currentSystemMode == 3) + { + model = Language.StringByID(R.MyInternationalizationString.Mode_Cool); + tempareture = $"{ac.currentCoolingSetpoint} 鈩�"; + } + else if (ac.currentSystemMode == 4) + { + model = Language.StringByID(R.MyInternationalizationString.Mode_Heat); + tempareture = $"{ac.currentHeatingSetpoint} 鈩�"; + } + else if (ac.currentSystemMode == 7) + { + model = Language.StringByID(R.MyInternationalizationString.Mode_FanOnly); + } + else if (ac.currentSystemMode == 8) + { + model = Language.StringByID(R.MyInternationalizationString.Mode_Dry); + tempareture = $"{ac.currentCoolingSetpoint} 鈩�"; + } + + if (ac.currentFanMode == 1) + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Low); + } + else if (ac.currentFanMode == 2) + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Middle); + } + else + { + wind = Language.StringByID(R.MyInternationalizationString.Fan_Height); + } + + if (string.IsNullOrEmpty(tempareture)) + { + return $"{model},{wind}"; + } + return $"{model},{wind},{tempareture}"; + } + else if (device.Type == DeviceType.IASZone) + { + var ias = device as IASZone; + //鍖哄垎浼犳劅鍣ㄥ叿浣撶被鍨� + var info = HdlDeviceCommonLogic.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice> { device }); + if (info.ConcreteType == DeviceConcreteType.Sensor_Infrared) + { + //绾㈠ + if (ias.iASInfo?.Alarm1 == 1) { - //璁剧疆澶辫触 - if (dev.DeviceEpoint == 3) - { - if (airer.WindTime != 0) - { - airer.WindTime = 0; - } - string msg = Language.StringByID(R.MyInternationalizationString.AirerWindTimeFailed); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); - dev.DeviceEpoint = 1;//灏嗘櫨琛f灦瀵瑰簲鐨勬帶鍒剁鐐硅繕鍘熸垚1绔偣 - this.ShowErrorMsg(msg); - return false; - } - if (dev.DeviceEpoint == 4) - { - if (airer.DryTime != 0) - { - airer.DryTime = 0; - } - string msg = Language.StringByID(R.MyInternationalizationString.AirerDryTimeFailed); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); - dev.DeviceEpoint = 1;//灏嗘櫨琛f灦瀵瑰簲鐨勬帶鍒剁鐐硅繕鍘熸垚1绔偣 - this.ShowErrorMsg(msg); - return false; - } - if (dev.DeviceEpoint == 5) - { - if (airer.DisinfectTime != 0) - { - airer.DisinfectTime = 0; - } - string msg = Language.StringByID(R.MyInternationalizationString.AirerDisinfectTimeFailed); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); - this.ShowErrorMsg(msg); - dev.DeviceEpoint = 1;//灏嗘櫨琛f灦瀵瑰簲鐨勬帶鍒剁鐐硅繕鍘熸垚1绔偣 - return false; - } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HavePerson); } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_NoPerson); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_Water) + { + //姘存蹈 + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HaveWater); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_DoorWindow) + { + //闂ㄧ獥 + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Open); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Close); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_CarbonMonoxide) + { + //鐕冩皵 + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.uGasLeakage); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_Fire) + { + //鐑熼浘 + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.uSmogAlarm); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Safe); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_Pir) + { + //pir + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HavePerson); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_NoPerson); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_Keyfob) + { + //閽ュ寵鎵� + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_Motion) + { + //杩愬姩浼犳劅鍣� + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HavePerson); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_NoPerson); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_EmergencyButton) + { + //绱ф�ユ寜閽� + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal); + } + else if (info.ConcreteType == DeviceConcreteType.Sensor_SphericalMotion) + { + //鐞冨瀷绉诲姩浼犳劅鍣� + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HavePerson); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_NoPerson); + } + else + { + //鍏朵粬浼犳劅鍣� + if (ias.iASInfo?.Alarm1 == 1) + { + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm); + } + return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal); } } - return true; + else if (device.Type == DeviceType.TemperatureSensor) + { + var tempera = device as TemperatureSensor; + if (tempera.SensorDiv == 1) + { + if (tempera.currentTemperature == 0) + { + return "0.0鈩�"; + } + return $"{tempera.currentTemperature}鈩�"; + } + else if (tempera.SensorDiv == 2) + { + if (tempera.currentHumidity == 0) + { + return "--%"; + } + return $"{tempera.currentHumidity}%"; + } + return null; + } + else + { + return null; + } } #endregion @@ -2684,7 +2914,7 @@ //2020.03.30杩藉姞寮忔牱:濡傛灉鏄潰鏉跨殑娓╁害鎺㈠ご,涓嶆樉绀� else if (i_device.Type == DeviceType.TemperatureSensor && ((TemperatureSensor)i_device).SensorDiv == 1) { - var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); + var myInfoType = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); if (myInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) { return false; @@ -2702,7 +2932,7 @@ } //濡傛灉鏄柊椋庨潰鏉挎垨鐜闈㈡澘,鍒欓兘涓嶆樉绀轰换浣曞洖璺� - var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); + var myInfoTypeTemp = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment) { return false; @@ -2940,7 +3170,7 @@ { //閲嶆柊鐢熸垚缂撳瓨 tempDevice.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath); + HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(tempDevice.FilePath); //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂� Phone.UserView.UserPage.Instance.RefreshAllForm = true; } @@ -2992,7 +3222,7 @@ { msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(localGw).ToString() + "]"; } - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false); + msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false); this.ShowTipMsg(msg); } statu = -1; @@ -3081,7 +3311,7 @@ private bool ReNewDeviceOnTypeIsChanged(CommonDevice oldLocalDevice, DeviceType newDeviceType) { //鍏堣幏鍙栨湰鍦拌繖涓棫璁惧瀵硅薄鐨刯son - string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, oldLocalDevice.FilePath); + string oldFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, oldLocalDevice.FilePath); var deviceData = HdlFileLogic.Current.ReadFileTextContent(oldFile); if (deviceData == null) { @@ -3097,7 +3327,7 @@ } //鍒犻櫎鏈湴鏂囦欢 HdlFileLogic.Current.DeleteFile(oldFile); - HdlAutoBackupLogic.DeleteFile(oldLocalDevice.FilePath); + HdlBackupLogic.Current.DeleteAutoBackFileStatu(oldLocalDevice.FilePath); //閲嶆柊鐢熸垚鏂囦欢 if (newDevice.IsCustomizeImage == false) @@ -3431,7 +3661,7 @@ } this.dicDeviceModelIdEnum = new Dictionary<string, DeviceNameContent>(); - var listText = this.GetDeviceNameFileContent(); + var listText = HdlCommonLogic.Current.GetInitFileContent("DeviceName.ini"); foreach (var dataText in listText) { if (dataText == string.Empty || dataText.StartsWith(";") == true) @@ -3478,63 +3708,279 @@ this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭闈㈡澘 娌跨敤 4鎸夐敭鐨勫浘鏍� this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//绠�绾�3鎸夐敭闈㈡澘 娌跨敤 3鎸夐敭鐨勫浘鏍� this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//绠�绾�2鎸夐敭闈㈡澘 娌跨敤 2鎸夐敭鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-One Pro鐨勯棬閿佸浘鐗� 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_AT1TF"] = "IntelligentLocks_H06C";//鍏ㄨ嚜鍔ㄦ櫤鑳介棬閿� AT-1TF鍥剧墖 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_AT1F"] = "IntelligentLocks_H06C";//鍏ㄨ嚜鍔ㄦ櫤鑳介棬閿� AT-1F鍥剧墖 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_AT1T"] = "IntelligentLocks_H06C";//鍏ㄨ嚜鍔ㄦ櫤鑳介棬閿� AT-1T鍥剧墖 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_HAT1B"] = "IntelligentLocks_H06C";//鏅鸿兘闂ㄩ攣 HAT-1B鍥剧墖 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_HAT1T"] = "IntelligentLocks_H06C";//鏅鸿兘闂ㄩ攣 HAT-1T鍥剧墖 娌跨敤 H06C鐨勫浘鏍� - this.dicPictrueShard["IntelligentLocks_ATFT"] = "IntelligentLocks_H06C";//鏅鸿兘闂ㄩ攣 HAT-1T鍥剧墖 娌跨敤 H06C鐨勫浘鏍� + this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one鐨勯棬閿佸浘鐗� 娌跨敤 H06C鐨勫浘鏍� this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//鏂规偊鏂伴灏忔ā鍧楀浘鐗� 娌跨敤 3璺户鐢靛櫒鐨勫浘鏍� this.dicPictrueShard["ButtonPanel_FourButtonScene"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭鍦烘櫙闈㈡澘 娌跨敤 4鎸夐敭闈㈡澘鐨勫浘鏍� } + #endregion + + #region 鈻� 鍙戦�佹暟鎹甠__________________________ + /// <summary> - /// 鑾峰彇璁惧鍚嶅瓧鏂囦欢鐨勫唴瀹� + /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(闈為�忎紶,ReceiptData涓鸿繑鍥炲��) /// </summary> - /// <returns></returns> - private List<string> GetDeviceNameFileContent() + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="sendTopic">鍙戦�佺殑涓婚</param> + /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param> + /// <param name="receiptTopic">鎸囧畾鎺ユ敹鍝釜涓婚</param> + /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param> + /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns> + public ReceiptGatewayResult SendJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, string receiptTopic, int waitTime = 5) { - System.IO.StreamReader streamReader = null; - var listText = new List<string>(); - try + //鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹� + return this.SendJobjectDataToGateway(device, sendTopic, sendData, new List<string>() { receiptTopic }, waitTime); + } + + /// <summary> + /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(闈為�忎紶),listReceiptData涓鸿繑鍥炲��(鍏ㄩ儴涓婚鍏ㄩ儴鎺ユ敹寰楀埌,鎵嶄細杩斿洖,涓嶇劧浼氳繑鍥炶秴鏃�) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="sendTopic">鍙戦�佺殑涓婚</param> + /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param> + /// <param name="listReceiptTopic">鎸囧畾鎺ユ敹鍝簺涓婚</param> + /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param> + /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns> + public ReceiptGatewayResult SendJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 5) + { + var reResult = new ReceiptGatewayResult(); + reResult.listReceiptData = new string[listReceiptTopic.Count]; + reResult.JsonData = new string[listReceiptTopic.Count]; + + var myGateway = device.Gateway; + if (myGateway == null) { -#if iOS - string textFile = Foundation.NSBundle.MainBundle.PathForResource("DeviceName.ini", null); - streamReader = new System.IO.StreamReader(textFile, Encoding.UTF8); - string text; - while ((text = streamReader.ReadLine()) != null) - { - listText.Add(text.Trim()); - } - return listText; -#endif -#if Android - var stream = Application.Activity.Assets.Open("DeviceName.ini"); - streamReader = new System.IO.StreamReader(stream, Encoding.UTF8); - string text; - while ((text = streamReader.ReadLine()) != null) - { - listText.Add(text.Trim()); - } - stream.Close(); - return listText; -#endif + //鑾峰彇缃戝叧瀵硅薄澶辫触 + reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail); + reResult.ErrorMsgDiv = -1; + return reResult; } - catch + //缃戝叧ID + string gatewayID = device.Gateway.GwId; + //閿欒涓婚 + string errorTopic = gatewayID + "/" + "Error_Respon"; + //妫�娴嬪璞$殑涓婚 + for (int i = 0; i < listReceiptTopic.Count; i++) { - return listText; + listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i]; } - finally + + //钃濇墠鍒氭暣浜嗕釜鍚屼竴涓富棰樺彲鑳戒細鎺ㄩ�佸涓繃鏉ョ殑鏈鸿兘 + var listCheckTopic = new HashSet<string>(); + Action<string, string> receiptAction = (topic, message) => { - try + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + + //缃戝叧鍥炲閿欒 + if (topic == errorTopic) { - streamReader?.Close(); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); + reResult.ErrorMsg = HdlCheckLogic.Current.CheckGatewayErrorCode(temp.Error); } - catch + //濡傛灉鏄寚瀹氱殑涓婚 + for (int i = 0; i < listReceiptTopic.Count; i++) { + if (topic == listReceiptTopic[i]) + { + if (listCheckTopic.Contains(topic) == true) + { + //杩欓噷鍐欒繖涓笢瑗挎槸鏈夌偣鐢ㄥ鐨� + continue; + } + string deviceMac = jobject["DeviceAddr"].ToString(); + int deviceEpoint = 200; + if (jobject.Property("Epoint") != null) + { + //鎷ユ湁姝ら敭鍊� + deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString()); + } + if (device.DeviceAddr != deviceMac) + { + //涓嶆槸鍚屼竴涓笢瑗縈ac + return; + } + if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200) + { + //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣 + return; + } + reResult.listReceiptData[i] = jobject["Data"].ToString(); + if (jobject.Property("Time") != null) + { + //闇�瑕佺Щ闄ime杩欎釜瀛楁 + jobject.Remove("Time"); + } + reResult.JsonData[i] = jobject.ToString(); + if (listCheckTopic.Contains(topic) == false) + { + //鍔犲埌妫�娴嬩富棰樺璞′腑 + listCheckTopic.Add(topic); + } + } + } + + }; + myGateway.Actions += receiptAction; + //鍙戦�佹暟鎹� + myGateway.Send(sendTopic, sendData); + + //瓒呮椂鏃堕棿 + int TimeOut = 0; + waitTime = 20 * waitTime; + while (listCheckTopic.Count != listReceiptTopic.Count && TimeOut < waitTime) + { + //鍏ㄩ儴鎺ユ敹鎵嶉��鍑� + System.Threading.Thread.Sleep(50); + TimeOut++; + } + myGateway.Actions -= receiptAction; + receiptAction = null; + + int receveCount = listCheckTopic.Count; + if (receveCount > 1) + { + //鐪嬬湅閲岄潰鏈夋病鏈夐噸澶嶇殑 + var listTemp = new HashSet<string>(); + foreach (var value in listCheckTopic) + { + if (listTemp.Contains(value) == false) + { + listTemp.Add(value); + } + } + receveCount = listTemp.Count; + } + if (receveCount != listReceiptTopic.Count) + { + reResult.ErrorMsgDiv = 0; + } + else + { + //姝e父鎺ユ敹鍒扮綉鍏宠繑鍥炵殑鏁版嵁 + if (reResult.listReceiptData.Length == 1) + { + //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲� + reResult.ReceiptData = reResult.listReceiptData[0]; } } + + return reResult; + } + + /// <summary> + /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(閫忎紶涓撶敤) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param> + /// <param name="receiptCommand">鎸囧畾鎺ユ敹鍛戒护绗�</param> + /// <param name="receiptDataLength">鎸囧畾鎺ユ敹鏁版嵁鐨勯暱搴�</param> + /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param> + /// <param name="listReceiptLength">闄勫姞妫�娴嬫暟鎹帴鏀堕暱搴�,褰撴帴鏀剁殑闀垮害鍦ㄨ繖鍒楄〃閲岄潰鏃�,浠h〃鎺ユ敹鎴愬姛(鏃ㄥ湪瀵瑰簲鏂版棫璁惧,閫忎紶鍥炲鐨勯暱搴﹀彲鑳戒笉鍚�)</param> + /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns> + public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength, + int waitTime = 5, List<int> listReceiptLength = null) + { + var reResult = new ReceiptGatewayResult(); + var myGateway = device.Gateway; + if (myGateway == null) + { + //鑾峰彇缃戝叧瀵硅薄澶辫触 + reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail); + reResult.ErrorMsgDiv = -1; + return reResult; + } + //缃戝叧ID + string gatewayID = device.Gateway.GwId; + //閿欒涓婚 + string errorTopic = gatewayID + "/" + "Error_Respon"; + //妫�娴嬪璞$殑涓婚 + string checkTopic = gatewayID + "/ZbDataPassthrough"; + + Action<string, string> receiptAction = (topic, message) => + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + + //缃戝叧鍥炲閿欒 + if (topic == errorTopic) + { + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); + reResult.ErrorMsg = HdlCheckLogic.Current.CheckGatewayErrorCode(temp.Error); + } + //濡傛灉鏄寚瀹氱殑涓婚 + if (topic == checkTopic) + { + string deviceMac = jobject["DeviceAddr"].ToString(); + int deviceEpoint = 200; + if (jobject.Property("Epoint") != null) + { + //鎷ユ湁姝ら敭鍊� + deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString()); + } + if (device.DeviceAddr != deviceMac) + { + //涓嶆槸鍚屼竴涓笢瑗縈ac + return; + } + if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200) + { + //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣 + return; + } + + var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + //闀垮害涓嶄竴鑷� + if (responseData.PassData.Length != receiptDataLength) + { + if (listReceiptLength == null) + { + //濡傛灉娌℃湁闄勫姞妫�娴嬮暱搴�,鍒欑洿鎺ヨ繑鍥� + return; + } + if (listReceiptLength.Contains(responseData.PassData.Length) == false) + { + //濡傛灉闄勫姞鐨勬娴嬮暱搴﹂噷闈�,杩樹笉瀛樺湪鐨勮瘽,鐩存帴杩斿洖 + return; + } + } + + var command = responseData.PassData[4].ToString() + + responseData.PassData[5].ToString() + + responseData.PassData[2].ToString() + + responseData.PassData[3].ToString(); + //骞朵笖鏄繖涓懡浠� + if (command == receiptCommand) + { + reResult.ReceiptData = responseData.PassData; + reResult.JsonData = new string[1]; + if (jobject.Property("Time") != null) + { + //闇�瑕佺Щ闄ime杩欎釜瀛楁 + jobject.Remove("Time"); + } + reResult.JsonData[0] = jobject.ToString(); + } + } + }; + myGateway.Actions += receiptAction; + //鍙戦�佹暟鎹� + myGateway.Send("ClientDataPassthrough", sendData); + + //瓒呮椂鏃堕棿 + int TimeOut = 0; + waitTime = 20 * waitTime; + while (reResult.ReceiptData == null && TimeOut < waitTime) + { + System.Threading.Thread.Sleep(50); + TimeOut++; + } + myGateway.Actions -= receiptAction; + receiptAction = null; + if (reResult.ReceiptData == null) + { + //瓒呮椂 + reResult.ErrorMsgDiv = 0; + } + return reResult; } #endregion @@ -3759,33 +4205,9 @@ /// </summary> IntelligentLocks_H06C = 2800, /// <summary> - /// S-One Pro + /// S-one /// </summary> IntelligentLocks_Sone = 2802, - /// <summary> - /// AT-1TF - /// </summary> - IntelligentLocks_AT1TF = 2803, - /// <summary> - /// AT-1F - /// </summary> - IntelligentLocks_AT1F = 2804, - /// <summary> - /// AT-1T - /// </summary> - IntelligentLocks_AT1T = 2805, - /// <summary> - /// HAT-1B - /// </summary> - IntelligentLocks_HAT1B = 2806, - /// <summary> - /// HAT-1T - /// </summary> - IntelligentLocks_HAT1T = 2807, - /// <summary> - /// AT-FT - /// </summary> - IntelligentLocks_ATFT = 2808, //=========鈽呪槄褰╃伅绫�(????-????)鈽呪槄========= /// <summary> @@ -3840,18 +4262,6 @@ /// zigbee杞琤uspro鍗忚杞崲鍣� /// </summary> Converter_ZbBuspro = 4201, - - //=========鈽呪槄鏅捐。鏋剁被(5000-5199)鈽呪槄========= - /// <summary> - /// 鏅捐。鏋� - /// </summary> - Airer = 5000, - - //=========鈽呪槄绌烘皵璐ㄩ噺浼犳劅鍣ㄧ被(5200-5399)鈽呪槄========= - /// <summary> - /// 绌烘皵璐ㄩ噺浼犳劅鍣� - /// </summary> - AirQualitySensor = 5200, //=========鈽呪槄鍏朵粬绫�(????-????)鈽呪槄========= /// <summary> @@ -3929,14 +4339,6 @@ /// 杞崲鍣�(4200-4699) /// </summary> A杞崲鍣� = 4200, - /// <summary> - /// 鏅捐。鏋�(4200-4699) - /// </summary> - A鏅捐。鏋� = 5000, - /// <summary> - /// 绌烘皵璐ㄩ噺浼犳劅鍣�(5200-5399) - /// </summary> - A绌烘皵璐ㄩ噺 = 5200, /// <summary> /// 褰╃伅 /// </summary> -- Gitblit v1.8.0