From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期五, 28 二月 2020 15:25:13 +0800 Subject: [PATCH] 2020.2.28 --- ZigbeeApp/Shared/Common/Device.cs | 855 ++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 570 insertions(+), 285 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs old mode 100755 new mode 100644 index 15b7c71..32b497d --- a/ZigbeeApp/Shared/Common/Device.cs +++ b/ZigbeeApp/Shared/Common/Device.cs @@ -43,16 +43,15 @@ { get { - var list = new List<CommonDevice>(); - foreach (var listMac in this.dicDeviceSort.Values) + lock (dicAllDevice) { - foreach (var strMac in listMac) + var list = new List<CommonDevice>(); + foreach (var device in dicAllDevice.Values) { - var listTemp = this.GetDevicesByMac(strMac); - list.AddRange(listTemp); + list.Add(device); } + return list; } - return list; } } @@ -73,6 +72,10 @@ /// </summary> private Dictionary<string, string> dicDeviceModelIdChanged = null; /// <summary> + /// 鍥剧墖鍏辨湁(keys:鎸囧畾璁惧鐨勫叿浣撶被鍨� value:鎸囧畾鍏辨湁瀵硅薄鐨勫叿浣撶被鍨�) + /// </summary> + private Dictionary<string, string> dicPictrueShard = null; + /// <summary> /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(闈炲叕寮�) /// </summary> private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>(); @@ -85,13 +88,9 @@ /// </summary> private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>(); /// <summary> - /// 璁惧Mac椤哄簭(閲岄潰鏄疢ac鍦板潃) + /// 鐗╃悊璁惧灞炰簬鍝釜鎴块棿鐨勮褰� /// </summary> - private Dictionary<string, List<string>> dicDeviceSort = null; - /// <summary> - /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧 - /// </summary> - public const string deviceFirstName = "Device_"; + private Dictionary<string, string> dicDeviceRoomId = null; #endregion @@ -112,8 +111,14 @@ List<string> listFile = this.GetAllDeviceFile(); foreach (string file in listFile) { + CommonDevice device = null; //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞� - var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file); + try + { + device = CommonDevice.CommonDeviceByFilePath(file); + } + catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } + if (device == null || device.CurrentGateWayId == null) { #if DEBUG @@ -175,9 +180,9 @@ } } //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 - this.DeleteGatewayFileByMemberModel(); - //鍒濆鍖栬澶囬『搴� - this.InitDeviceSort(); + this.DeleteGatewayFileByMemberModel(); + //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍 + this.InitRealDeviceRoomId(); } /// <summary> @@ -218,26 +223,25 @@ #region 鈻� 娣诲姞璁惧___________________________ /// <summary> - /// 灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚) + /// <para>灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚)</para> + /// <para>-1:寮傚父 1:姝e父 2:璁惧淇℃伅缂烘崯</para> /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param> - /// <returns>涓�鐩磋繑鍥瀟rue</returns> - public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null) + public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway) { //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧 + int statu = 0; List<CommonDevice> listDevice = new List<CommonDevice>(); - List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction); - + List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, true); if (list == null) { - return false; + return -1; } listDevice.AddRange(list); //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶� string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); - List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID); + List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID, true); Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>(); foreach (var device in listLocalDevices) { @@ -256,7 +260,7 @@ //娣诲姞缂撳瓨 this.AddDeviceToMemory(ref device); - //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� + //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� string maikey = this.GetDeviceMainKeys(device); if (dicExist.ContainsKey(maikey) == true) { @@ -269,25 +273,13 @@ for (int i = 0; i < listDevice.Count; i++) { var device = listDevice[i]; - //瀵规湭鍛藉悕鐨勮澶囬噸鏂板懡鍚� - if (this.GetSimpleEpointName(device) == string.Empty) + //瀵规湭鍛藉悕鐨勮櫄鎷熻澶囬噸鏂板懡鍚� + if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty) { //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); - //铏氭嫙璁惧鐨勮瘽锛岄檮鍔犲洖璺彿 - if (device.DriveCode > 0) - { - //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� - dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; - } - //澶氬洖璺澶囩殑璇濓紝闄勫姞鍥炶矾鍙� - else if (dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && dicDeviceEpoint[device.DeviceAddr].Count > 1) - { - var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); - dName = arry[0].Trim(); - //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� - dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; - } + //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� + dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; HdlThreadLogic.Current.RunThread(async () => { @@ -296,14 +288,26 @@ } } - //濡傛灉鏈湴鍜岀綉鍏崇殑璁惧涓嶄竴鑷寸殑鏃跺�欙紝鏆傛椂鍒犻櫎鏈湴鐨勮澶� - //娉ㄦ剰锛氬彧鏄垹闄よ澶囨枃浠讹紝鎴块棿鍐呭浠�涔堢殑杩樺瓨鍦ㄧ潃 - foreach (var device in dicExist.Values) + //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂 + if (statu != 1) { - this.DeleteMemmoryDevice(device, false); + return statu; } - return true; + //濡傛灉鏈湴鍜岀綉鍏崇殑璁惧涓嶄竴鑷寸殑鏃跺�欙紝鍒犻櫎鏈湴鐨勮澶� + foreach (var device in dicExist.Values) + { + if (device is OTADevice) + { + this.DeleteMemmoryOtaDevice(device.DeviceAddr); + } + else + { + this.DeleteMemmoryDevice(device, true); + } + } + + return statu; } /// <summary> @@ -312,16 +316,6 @@ /// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param> public void AddDeviceToMemory(ref CommonDevice device) { - if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false) - { - dicDeviceSort[device.CurrentGateWayId] = new List<string>(); - } - if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false) - { - //淇濆瓨椤哄簭 - dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr); - UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort); - } string mainKeys = this.GetDeviceMainKeys(device); //濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠� if (device is OTADevice) @@ -469,6 +463,11 @@ } //澶囦唤鏁版嵁 await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName); + //濡傛灉瀹冨彧鏈変竴涓洖璺�,鍒欐洿鏀圭鐐瑰悕瀛� + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count == 1) + { + return await this.ReName(device, newMacName); + } } return true; } @@ -482,15 +481,25 @@ lock (dicAllDevice) { string mainKeys = this.GetDeviceMainKeys(device); - if (this.dicAllDevice.ContainsKey(mainKeys) == false) + if (this.dicAllDevice.ContainsKey(mainKeys) == true) { - return; - } - this.dicAllDevice[mainKeys] = device; - device.ReSave(); + //涓�鑸澶� + this.dicAllDevice[mainKeys] = device; + device.ReSave(); - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + else if (this.dicOTADevice.ContainsKey(mainKeys) == true) + { + //Ota璁惧 + this.dicOTADevice[mainKeys] = (OTADevice)device; + device.ReSave(); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + + } } } @@ -521,29 +530,39 @@ this.ShowErrorMsg(msg); return false; } - if (dicDeviceSort.ContainsKey(listdevice[0].CurrentGateWayId) == true && - dicDeviceSort[listdevice[0].CurrentGateWayId].Contains(info.DeviceAddr) == true) - { - //淇濆瓨椤哄簭 - dicDeviceSort[listdevice[0].CurrentGateWayId].Remove(info.DeviceAddr); - UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort); - } - //鍒犻櫎鏂囦欢 + //鍒犻櫎缂撳瓨鐨凮ta璁惧 + this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr); + //鍒犻櫎涓�鑸澶囨枃浠� foreach (CommonDevice device in listdevice) { this.DeleteMemmoryDevice(device); + } + + if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true) + { + //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮� + this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr); + this.SaveRealDeviceRoomId(null, null); } return true; } /// <summary> - /// 鍒犻櫎缂撳瓨鐨勮澶� + /// 鍒犻櫎缂撳瓨鐨勪竴鑸澶� /// </summary> /// <param name="device">璁惧瀵硅薄</param> /// <param name="deleteRoom">鏄惁浠庢埧闂村垹闄�</param> public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) { + if (deleteRoom == true && Room.CurrentRoom != null) + { + //浠庢埧闂翠腑鍒犻櫎 + Room.CurrentRoom.DeleteDevice(device); + //鍒犻櫎鎴戠殑鍠滅埍鐨勮澶� + Room.CurrentRoom.DeleteLoveDevice(device); + } + //鍒犻櫎缂撳瓨 string mainKeys = this.GetDeviceMainKeys(device); lock (dicAllDevice) @@ -551,6 +570,11 @@ if (this.dicAllDevice.ContainsKey(mainKeys) == true) { this.dicAllDevice.Remove(mainKeys); + } + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true) + { + //鍙樻洿绔偣鏁� + this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint); } } @@ -571,9 +595,17 @@ HdlAutoBackupLogic.DeleteFile(device.FilePath); } } + } + /// <summary> + /// 鍒犻櫎缂撳瓨鐨凮ta璁惧 + /// </summary> + /// <param name="macAdrr"></param> + /// <param name="ePoint"></param> + public void DeleteMemmoryOtaDevice(string macAdrr, int ePoint = 200) + { //鍒犻櫎200绔彛鏂囦欢 - string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200); + string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint); if (this.dicOTADevice.ContainsKey(otaKeys) == true) { string otaFile = this.dicOTADevice[otaKeys].FilePath; @@ -582,23 +614,17 @@ if (UserCenterResourse.UserInfo.AuthorityNo == 3) { //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� - Global.DeleteFilebyHomeId(filePath); + Global.DeleteFilebyHomeId(otaFile); } else { //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� - Global.DeleteFilebyHomeId(filePath); + Global.DeleteFilebyHomeId(otaFile); //鍒犻櫎鑷姩澶囦唤 HdlAutoBackupLogic.DeleteFile(otaFile); } } this.dicOTADevice.Remove(otaKeys); - } - - if (deleteRoom == true && Room.CurrentRoom != null) - { - //浠庢埧闂翠腑鍒犻櫎 - Room.CurrentRoom.DeleteDevice(device); } } @@ -677,38 +703,32 @@ /// 鏍规嵁缃戝叧ID鑾峰彇鎵�鏈夌殑璁惧 /// </summary> /// <param name="gwId">缃戝叧ID</param> + /// <param name="getOtaDevice">鏄惁鑾峰彇ota璁惧</param> /// <returns></returns> - public List<CommonDevice> GetDeviceByGatewayID(string gwId) + public List<CommonDevice> GetDeviceByGatewayID(string gwId, bool getOtaDevice = false) { List<CommonDevice> list = new List<CommonDevice>(); lock (dicAllDevice) { - List<string> listSort = null; - if (dicDeviceSort.ContainsKey(gwId) == false) - { - dicDeviceSort[gwId] = new List<string>(); - } - listSort = dicDeviceSort[gwId]; - //鍚勭綉鍏崇殑鎵�鏈夎澶� foreach (CommonDevice device in this.dicAllDevice.Values) { if (gwId == device.CurrentGateWayId) { - if (listSort.Contains(device.DeviceAddr) == false) + list.Add(device); + } + } + if (getOtaDevice == true) + { + //鑾峰彇ota璁惧 + foreach (var ota in this.dicOTADevice.Values) + { + if (ota.CurrentGateWayId == gwId) { - listSort.Add(device.DeviceAddr); + list.Add(ota); } } } - //鎺掑簭 - foreach (var strMac in listSort) - { - var listTemp = this.GetDevicesByMac(strMac); - list.AddRange(listTemp); - } - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort); } return list; @@ -744,11 +764,12 @@ } /// <summary> - /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(宸茬粡鎺掑簭) + /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞� /// </summary> /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <param name="sort">鏄惁鎺掑簭</param> /// <returns></returns> - public List<CommonDevice> GetDevicesByMac(string DeviceAddr) + public List<CommonDevice> GetDevicesByMac(string DeviceAddr, bool sort = true) { var list = new List<CommonDevice>(); if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false) @@ -763,6 +784,11 @@ list.Add(device); } } + if (sort == false) + { + return list; + } + //鎺掑簭 list.Sort((obj1, obj2) => { @@ -776,6 +802,20 @@ } /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勬暟閲� + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <returns></returns> + public int GetDevicesCountByMac(string DeviceAddr) + { + if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false) + { + return 0; + } + return dicDeviceEpoint[DeviceAddr].Count; + } + + /// <summary> /// 鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� /// </summary> /// <returns></returns> @@ -783,9 +823,10 @@ { List<string> listDeviceFile = new List<string>(); List<string> listAllFile = Global.FileListByHomeId(); + foreach (string file in listAllFile) { - if (file.StartsWith(deviceFirstName) == false) + if (file.StartsWith("Device_") == false) { //濡傛灉涓嶆槸璁惧鏂囦欢 continue; @@ -811,6 +852,30 @@ return this.dicOTADevice[mainkeys]; } + /// <summary> + /// 鑾峰彇鐗规畩鐨�,娌℃湁鍏朵粬鍥炶矾,鍗曠函鍙湁200绔偣鐨凮TA璁惧 + /// </summary> + /// <param name="gwId">缃戝叧ID</param> + /// <returns></returns> + public List<OTADevice> GetSpecialOtaDevice(string gwId) + { + var list = new List<OTADevice>(); + foreach (var ota in this.dicOTADevice.Values) + { + if (ota.CurrentGateWayId != gwId) + { + //涓嶆槸鍚屼竴涓綉鍏� + continue; + } + if (dicDeviceEpoint.ContainsKey(ota.DeviceAddr) == false + || dicDeviceEpoint[ota.DeviceAddr].Count == 0) + { + list.Add(ota); + } + } + return list; + } + #endregion #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________ @@ -828,16 +893,39 @@ return dName; } //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О - dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); + var tempValue = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); + var arry = tempValue.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); + dName = arry[0].Trim(); + //濡傛灉鏄櫄鎷熻澶� - if (device.DriveCode > 0 - || (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1)) + if (device.DriveCode > 0) { - var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); - dName = arry[0].Trim(); //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; + return dName; } + + //鑾峰彇璁惧绫诲瀷 + var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (deviceInfoType.BeloneType == Common.DeviceBeloneType.A鎸夐敭闈㈡澘 && device.Type == DeviceType.TemperatureSensor) + { + //闈㈡澘鐨勬渶鍚庝竴涓洖璺槸娓╁害浼犳劅鍣� + dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId11); + } + else if (deviceInfoType.ConcreteType == Common.DeviceConcreteType.Sensor_Pir) + { + //pir浼犳劅鍣�,瀹冨張鎼炵壒娈婁笢瑗�,浼犳劅鍣ㄨ嚜韬敤鑷繁鐨勫悕瀛�,缁х數鍣ㄥ洖璺殑璇濃�︹�� + if (device.Type == DeviceType.OnOffOutput) + { + dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2300); + } + } + else if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1) + { + //XXXXX(N鍥炶矾) + dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; + } + return dName; } @@ -1000,6 +1088,11 @@ /// <returns></returns> public void SetDeviceIconToControl(Button btnIcon, CommonDevice device) { + if (device == null) + { + btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png"; + return; + } string unSelectFilePath = string.Empty; string selectFilePath = string.Empty; @@ -1039,9 +1132,27 @@ /// <param name="listdevice">璁惧瀵硅薄</param> public void SetRealDeviceIconToControl(Button btnIcon, List<CommonDevice> listdevice) { + //鑾峰彇璁惧鐨勭湡瀹炲浘鐗� + string imagePath = this.GetRealDeviceIcon(listdevice); + btnIcon.UnSelectedImagePath = imagePath; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勭湡瀹炲浘鐗� + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + public string GetRealDeviceIcon(List<CommonDevice> listdevice) + { //鑾峰彇瀹冨睘浜庝粈涔堢被鍨嬬殑璁惧 var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); + + //鍥剧墖鍏辨湁 + if (this.dicPictrueShard.ContainsKey(strConcrete) == true) + { + strConcrete = this.dicPictrueShard[strConcrete]; + } + string strType = strConcrete.Replace("_", string.Empty); //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� string imageFilePath = "RealDevice/" + strType + ".png"; @@ -1053,7 +1164,7 @@ if (arry.Length == 1) { //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 - return; + return "RealDevice/CommonDevice.png"; } imageFilePath = "RealDevice/" + arry[0] + ".png"; //濡傛灉瀹冭嚜宸辩殑鍏遍�氬浘鐗囪繕鏄笉瀛樺湪鐨勮瘽,鍒欑洿鎺ヤ娇鐢ㄦ墍鏈夎澶囩殑鍏遍�氬浘鐗� @@ -1062,16 +1173,16 @@ imageFilePath = "RealDevice/CommonDevice.png"; } } - btnIcon.UnSelectedImagePath = imageFilePath; + return imageFilePath; } /// <summary> - /// 璁剧疆銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣鍒版寚瀹氱殑鎺т欢 + /// 璁剧疆銆愯澶囩被鍨嬨�戠殑鍥炬爣鍒版寚瀹氱殑鎺т欢 /// </summary> /// <param name="btnIcon">鎺т欢瀵硅薄</param> /// <param name="listdevice">璁惧瀵硅薄</param> /// <returns></returns> - public void SetDeviceBeloneIconToControl(Button btnIcon, List<CommonDevice> listdevice) + public void SetDeviceObjectIconToControl(Button btnIcon, List<CommonDevice> listdevice) { //鑾峰彇鑷畾涔夎澶囩被鍨� var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); @@ -1079,8 +1190,8 @@ string imageUnSelectFilePath = string.Empty; string imageSelectFilePath = string.Empty; - //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); + //鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); //璁剧疆鍥剧墖 btnIcon.UnSelectedImagePath = imageUnSelectFilePath; @@ -1088,32 +1199,38 @@ } /// <summary> - /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + /// 鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 /// </summary> /// <param name="listdevice">璁惧瀵硅薄</param> /// <param name="unSelectPath">鍥剧墖鍦板潃</param> /// <param name="selectPath">鍥剧墖鍦板潃</param> /// <returns></returns> - public void GetDeviceBeloneIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) + public void GetDeviceObjectIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) { //鑾峰彇鑷畾涔夎澶囩被鍨� var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); - //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); + //鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); } /// <summary> - /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + /// 鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 /// </summary> /// <param name="specificType">鑷畾涔夎澶囩被鍨�</param> /// <param name="unSelectPath">鍥剧墖鍦板潃</param> /// <param name="selectPath">鍥剧墖鍦板潃</param> /// <returns></returns> - public void GetDeviceBeloneIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) + public void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) { //灏嗗叿浣撶被鍨嬭浆瀛楃涓� string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType); + //鍥剧墖鍏辨湁 + if (this.dicPictrueShard.ContainsKey(strSpecific) == true) + { + strSpecific = this.dicPictrueShard[strSpecific]; + } + string strType = strSpecific.Replace("_", string.Empty); //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� string imageFilePath = "Device/" + strType + ".png"; @@ -1124,13 +1241,18 @@ { //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None); - if (arry.Length == 1) + //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 + if (arry.Length > 1) { - //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 - return; + imageFilePath = "Device/" + arry[0] + ".png"; + imageSelectFilePath = "Device/" + arry[0] + "Selected.png"; } - imageFilePath = "Device/" + arry[0] + ".png"; - imageSelectFilePath = "Device/" + arry[0] + "Selected.png"; + } + //濡傛灉閭f璁惧杩炲叡閫氬浘鐗囬兘娌℃湁鐨勮瘽 + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + imageFilePath = "Device/ThirdPartyDevice.png"; + imageSelectFilePath = "Device/ThirdPartyDeviceSelected.png"; } //璁剧疆鍥剧墖 unSelectPath = imageFilePath; @@ -1163,14 +1285,14 @@ public DeviceUI GetDeviceUI(string filePath) { string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); - if (arry.Length != 5) + if (arry.Length != 4) { return null; } //鍒涘缓涓�涓柊鐨勪笢瑗跨粰杩囧幓 var deviceUi = new DeviceUI(); - deviceUi.DeviceAddr = arry[3]; - deviceUi.DeviceEpoint = Convert.ToInt32(arry[4]); + deviceUi.DeviceAddr = arry[2]; + deviceUi.DeviceEpoint = Convert.ToInt32(arry[3]); return deviceUi; } @@ -1202,7 +1324,7 @@ return info; } //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� - return this.GetNotHdlMyDeviceEnumInfo(listdevice); + return this.GetNotHdlMyDeviceEnumInfo(listdevice, false); } /// <summary> @@ -1232,7 +1354,7 @@ else { //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� - var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice); + var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice, false); strName = Language.StringByID(myDeviceType.ConcreteTextId); } if (ApendFalge == true && listDevice[0].DriveCode > 0) @@ -1298,11 +1420,68 @@ #region 鈻� 鑾峰彇绗笁鏂硅澶囩殑璁惧绫诲瀷___________ /// <summary> - /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� + /// 鑾峰彇璁惧鐨勩�愭墍灞炵被鍨嬩俊鎭��,姝ゆ柟娉曚細鎶婃墍鏈夌殑浼犳劅鍣ㄩ兘褰掍负銆愪紶鎰熷櫒銆�(鍖呮嫭娓╂箍搴︿紶鎰熷櫒) /// </summary> - /// <param name="listdevice"></param> + /// <param name="device">璁惧鍥炶矾</param> /// <returns></returns> - public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice) + public DeviceEnumInfo GetDeviceBelongEnumInfo(CommonDevice device) + { + var info = this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (info.BeloneType == DeviceBeloneType.A璋冨厜鍣� + || info.BeloneType == DeviceBeloneType.A褰╃伅) + { + //褰掍负鐏厜 + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.ConcreteType = DeviceConcreteType.Light; + + int value = (int)info.BeloneType; + if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value]; + } + } + else if (info.BeloneType == DeviceBeloneType.A浼犳劅鍣� + || device.Type == DeviceType.TemperatureSensor) + { + //浼犳劅鍣ㄥ悎骞� + info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; + info.ConcreteType = DeviceConcreteType.Sensor; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; + + int value = (int)info.BeloneType; + if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value]; + } + } + + return info; + } + + /// <summary> + /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨��(涓嶅缓璁娇鐢�) + /// </summary> + /// <param name="listdevice">Mac閮戒竴鏍风殑璁惧鍒楄〃</param> + /// <returns></returns> + public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(CommonDevice device, bool margeSensor = true) + { + return this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }, margeSensor); + } + + /// <summary> + /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨��(涓嶅缓璁娇鐢�) + /// </summary> + /// <param name="listdevice">Mac閮戒竴鏍风殑璁惧鍒楄〃</param> + /// <param name="margeSensor"> + /// <para>鏄惁灏嗘墍鏈夌被鍨嬬殑浼犳劅鍣ㄩ兘褰掍负銆愪紶鎰熷櫒銆�,</para> + /// <para>false鐨勬椂鍊欙細銆怌oncreteType銆戝拰銆怌oncreteTextId銆戝彲鑳戒細鏈変笉鍚岀殑鍊�</para> + /// <para>true鐨勬椂鍊欙細銆怌oncreteType銆戠粺涓�涓篠ensor,銆怌oncreteTextId銆戠粺涓�涓轰紶鎰熷櫒</para> + /// </param> + /// <returns></returns> + public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice, bool margeSensor = true) { var dicType = new Dictionary<DeviceType, CommonDevice>(); foreach (CommonDevice device in listdevice) @@ -1317,9 +1496,18 @@ //1鍖呭惈闈㈡澘鐨勮瘽,褰撻潰鏉垮鐞� if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200; - info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; - info.ConcreteType = DeviceConcreteType.ButtonPanel; + if (listdevice.Count > 1) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200; + info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; + info.ConcreteType = DeviceConcreteType.ButtonPanel; + } + else + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16; + info.BeloneType = DeviceBeloneType.A骞叉帴鐐�; + info.ConcreteType = DeviceConcreteType.DryContact; + } } //3鍖呭惈绐楀笜鐨勮瘽,褰撶獥甯樺鐞� else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) @@ -1331,16 +1519,56 @@ //4绌烘皵寮�鍏� else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) { + //榛樿鍊� info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100; - info.BeloneType = DeviceBeloneType.A绌烘皵寮�鍏�; + info.BeloneType = DeviceBeloneType.A鏅鸿兘绌哄紑; info.ConcreteType = DeviceConcreteType.AirSwitch; + + if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A寮�鍏�) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.BeloneType = DeviceBeloneType.A寮�鍏�; + info.ConcreteType = DeviceConcreteType.Switch; + } + else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鎻掑骇) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.BeloneType = DeviceBeloneType.A鎻掑骇; + info.ConcreteType = DeviceConcreteType.Socket1; + } + else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鐏厜) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.ConcreteType = DeviceConcreteType.Light; + } } //5缁х數鍣� else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) { + //榛樿鍊� info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300; info.BeloneType = DeviceBeloneType.A缁х數鍣�; info.ConcreteType = DeviceConcreteType.Relay; + + if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A寮�鍏�) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.BeloneType = DeviceBeloneType.A寮�鍏�; + info.ConcreteType = DeviceConcreteType.Switch; + } + else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鎻掑骇) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.BeloneType = DeviceBeloneType.A鎻掑骇; + info.ConcreteType = DeviceConcreteType.Socket1; + } + else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鐏厜) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.ConcreteType = DeviceConcreteType.Light; + } } //6璋冨厜鍣� else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) @@ -1387,8 +1615,10 @@ //12鍖呭惈浼犳劅鍣ㄧ殑璇�,褰撲紶鎰熷櫒澶勭悊 else if (dicType.ContainsKey(DeviceType.IASZone) == true) { - //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; + info.ConcreteType = DeviceConcreteType.Sensor; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 this.SetSensorDeviceSpecificType(ref info, listdevice); } //13鍖呭惈娓╁害浼犳劅鍣ㄧ殑璇� @@ -1396,7 +1626,9 @@ { bool temperatrue = false; bool humidity = false; - foreach (var device in listdevice) + //鑾峰彇鍏ㄩ儴鐨勫洖璺� + var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false); + foreach (var device in listTemp) { if (device is TemperatureSensor) { @@ -1406,7 +1638,7 @@ temperatrue = true; } //婀垮害浼犳劅鍣� - else if(((TemperatureSensor)device).SensorDiv == 2) + else if (((TemperatureSensor)device).SensorDiv == 2) { humidity = true; } @@ -1417,14 +1649,14 @@ //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A娓╂箍搴︿紶鎰熷櫒; info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10; - info.ConcreteType = DeviceConcreteType.Sensor_TemperatrueHumidity; + info.ConcreteType = DeviceConcreteType.Sensor_TemperatureHumidity; } else if (temperatrue == true && humidity == false) { //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A娓╁害浼犳劅鍣�; info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11; - info.ConcreteType = DeviceConcreteType.Sensor_Temperatrue; + info.ConcreteType = DeviceConcreteType.Sensor_Temperature; } else if (temperatrue == false && humidity == true) { @@ -1456,10 +1688,6 @@ /// <param name="listdevice">璁惧瀵硅薄</param> private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice) { - //榛樿鍚嶅瓧:浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.Sensor; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; - //濡傛灉杩欎釜璁惧鎷ユ湁澶氫釜鍥炶矾鐨勮瘽,鎴戜篃涓嶇煡閬撴�庝箞鍛藉悕,鍙兘缁欎釜榛樿鍚嶅瓧 if (listdevice.Count > 1) { @@ -1512,89 +1740,87 @@ #endregion - #region 鈻� 璁惧鎺掑簭___________________________ + #region 鈻� 鐗╃悊璁惧鎵�灞炴埧闂確__________________ /// <summary> - /// 鍒濆鍖栬澶囬『搴� + /// 鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍 /// </summary> - private void InitDeviceSort() + private void InitRealDeviceRoomId() { - //璇诲彇璁惧椤哄簭 - this.dicDeviceSort = new Dictionary<string, List<string>>(); - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile); + this.dicDeviceRoomId = new Dictionary<string, string>(); + string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); var strData = UserCenterLogic.LoadFileContent(fullName); if (strData != null) { - this.dicDeviceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); + this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData); } - foreach (var device in dicAllDevice.Values) - { - if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false) - { - dicDeviceSort[device.CurrentGateWayId] = new List<string>(); - } - if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false) - { - //鏂版坊鍔犵殑璁惧 - dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr); - } - } - foreach (var keys in dicDeviceSort.Keys) - { - var list = dicDeviceSort[keys]; - for (int i = 0; i < list.Count; i++) - { - if (this.dicDeviceEpoint.ContainsKey(list[i]) == false) - { - //杩欎釜涓滆タ鑾悕鐨勪笉瑙佷簡锛熷拰璁惧鍒楄〃鍖归厤涓嶄笂? - list.RemoveAt(i); - i--; - } - } - } - - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, dicDeviceEpoint); } /// <summary> - /// 璁惧鎺掑簭 + /// 淇濆瓨鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍 /// </summary> - /// <param name="listDevice">闇�瑕佹帓搴忕殑璁惧鍒楄〃</param> - /// <returns></returns> - public List<CommonDevice> SortDevice(List<CommonDevice> listDevice) + /// <param name="listDevice">闇�瑕佷繚瀛樼殑璁惧瀵硅薄</param> + /// <param name="roomId">闇�瑕佷繚瀛樼殑鍝釜璁惧鐨勬埧闂碔D</param> + /// <param name="saveRoadDevice">濡傛灉鍙湁涓�涓洖璺�,鏄惁鎶婂洖璺殑鎴块棿涓�璧蜂慨鏀�</param> + public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true) { - var dic = new Dictionary<string, List<CommonDevice>>(); - for (int i = 0; i < listDevice.Count; i++) + if (listDevice != null) { - if (dic.ContainsKey(listDevice[i].DeviceAddr) == false) - { - dic[listDevice[i].DeviceAddr] = new List<CommonDevice>(); - } - dic[listDevice[i].DeviceAddr].Add(listDevice[i]); + this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId; } - var list = new List<CommonDevice>(); - var listCheck = new HashSet<string>(); - foreach (var listSort in this.dicDeviceSort.Values) + + //淇濆瓨璁板綍 + string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); + UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); + + //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜� + if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1) { - for (int i = 0; i < listSort.Count; i++) + if (listDevice[0] is OTADevice) { - if (dic.ContainsKey(listSort[i]) == true && listCheck.Contains(listSort[i]) == false) - { - listCheck.Add(listSort[i]); - dic[listSort[i]].Sort((obj1, obj2) => - { - if (obj1.DeviceEpoint > obj2.DeviceEpoint) - { - return 1; - } - return -1; - }); - list.AddRange(dic[listSort[i]]); - } + //鍗曠函鍙槸Ota璁惧鍒欎笉澶勭悊 + return; } + Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false); } - return list; + } + + /// <summary> + /// 鑾峰彇鐪熷疄鐗╃悊璁惧鐨勬埧闂村悕瀛� + /// </summary> + /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param> + /// <returns></returns> + public string GeteRealDeviceRoomName(CommonDevice device) + { + if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false) + { + //鏈垎閰嶅尯鍩� + return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); + } + var room = Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]); + if (room != null) + { + return room.Name; + } + //鏈垎閰嶅尯鍩� + return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); + } + + /// <summary> + /// 鑾峰彇鐪熷疄鐗╃悊璁惧灞炰簬鍝釜鎴块棿 + /// </summary> + /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param> + /// <returns></returns> + public Room GeteRealDeviceRoom(CommonDevice device) + { + if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false) + { + return null; + } + return Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]); } #endregion @@ -1655,16 +1881,16 @@ /// <returns></returns> public string AppendVersion(int versionValue) { - //杞负16杩涘埗 - string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0'); + //鐩存帴鏄�10杩涘埗 + string txt10 = Convert.ToString(versionValue).PadLeft(4, '0'); //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫�� - int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16); + int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2)); //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫�� - int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16); + int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2)); //Ver. string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); - return ver + value1 + "." + value2.ToString().PadLeft(3, '0'); + return ver + value1 + "." + value2.ToString().PadLeft(2, '0'); } /// <summary> @@ -1700,36 +1926,23 @@ #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________ /// <summary> - /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢鈽呪槄鈽呪槄鈽呪槄鈽�) + /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�)</para> + /// <para>statu鐘舵�� -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</para> /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <param name="ignoreTime">鏄惁鏃犺鏃堕棿,true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param> - /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�</param> + /// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param> + /// <param name="ignoreTime">鏄惁鏃犺鏃堕棿(姝ゅ彉閲忔槸缁欒幏鍙栧湪绾跨姸鎬佺敤鐨�),true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> /// <returns></returns> - public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) + public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, ShowErrorMode mode = ShowErrorMode.YES) { if (ignoreTime == false) { if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000) { //涓嶆棤瑙嗘椂闂�,杩斿洖鏈湴璁惧鍒楄〃 - var listTemp = this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway)); - if (deviceComingAction != null) - { - for (int i = 0; i < listTemp.Count; i++) - { - try - { - //鍥炶皟鍑芥暟 - deviceComingAction.Invoke(listTemp[i]); - } - //Log鍑哄姏 - catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } - } - } - deviceComingAction = null; - return listTemp; + statu = 1; + return this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway)); } } zbGateway.LastDateTime = DateTime.Now; @@ -1746,6 +1959,7 @@ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); this.ShowTipMsg(msg); } + statu = -1; return null; } @@ -1761,53 +1975,59 @@ int receiveCount = 0; //璁惧鍒楄〃 var listDevice = new List<CommonDevice>(); - + //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾 + var listCheck = new HashSet<string>(); Action<string, string> getDeviceAction = (topic, message) => { - try + if (topic == gatewayID + "/" + "DeviceInfoRespon") { - if (topic == gatewayID + "/" + "DeviceInfoRespon") + try { - TimeOut = 0; - var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); - var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); - if (totalNum == 0) + lock (listDevice) { - //杩欎釜缃戝叧娌℃湁璁惧 - canBreak = true; - return; - } - if (deviceCount == -1) - { - //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧 - deviceCount = totalNum; - } - //璁惧鎺ユ敹鏁� - receiveCount++; + //璁惧鎺ユ敹鏁� + receiveCount++; - var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); - //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); - if (device != null) - { - try + TimeOut = 0; + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); + if (totalNum == 0) { - //鍥炶皟鍑芥暟 - deviceComingAction?.Invoke(device); + //杩欎釜缃戝叧娌℃湁璁惧 + canBreak = true; + return; } - //Log鍑哄姏 - catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } + if (deviceCount == -1) + { + //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧 + deviceCount = totalNum; + } - listDevice.Add(device); - } - if (deviceCount == receiveCount) - { - //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚 - canBreak = true; + var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); + if (device != null) + { + string mainkeys = this.GetDeviceMainKeys(device); + //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾 + if (listCheck.Contains(mainkeys) == false) + { + listDevice.Add(device); + + listCheck.Add(mainkeys); + } + } } } + //Log鍑哄姏 + catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } + + if (receiveCount == deviceCount && deviceCount != -1) + { + //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚 + canBreak = true; + } } - catch { } }; realWay.Actions += getDeviceAction; @@ -1838,8 +2058,9 @@ string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]"; msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false); - this.ShowErrorMsg(msg); + this.ShowTipMsg(msg); } + statu = -1; return null; } else @@ -1850,12 +2071,9 @@ string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); this.ShowTipMsg(msg); } + statu = 2; } - } - - //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚) - deviceComingAction = null; - + } return listDevice; } @@ -1959,7 +2177,7 @@ } } //濡傛灉鏄皟鍏夊櫒 - else if (mainDevice.Type == DeviceType.DimmableLight ) + else if (mainDevice.Type == DeviceType.DimmableLight) { mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; if (mainDevice.IsCustomizeImage == false) @@ -1968,7 +2186,7 @@ } } //濡傛灉鏄僵鐏殑璇� - else if ( mainDevice.Type == DeviceType.ColorDimmableLight) + else if (mainDevice.Type == DeviceType.ColorDimmableLight) { mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; if (mainDevice.IsCustomizeImage == false) @@ -2043,6 +2261,14 @@ //瀹氫箟瑙勫垯锛氭ā鍧桰D(宸茬炕璇�)=璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) //绗竴涓�兼槸:DeviceConcreteType 绗簩涓�兼槸:DeviceBeloneType + //********************************************************************* + //鏂拌澶囨坊鍔犳柟娉曪細 + //1銆佸湪杩欓噷濉啓涓婃ā鍧桰D锛岀劧鍚庢槸 DeviceConcreteType 锛岀劧鍚庢槸 DeviceBeloneType + //2銆佺劧鍚庡湪鏈�涓嬮潰娣诲姞銆愯澶囩殑鍏蜂綋绫诲瀷銆戯紝銆愯澶囩殑鎵�灞炵被鍨嬨�� + //3銆佸凡璁惧鐨勫叿浣撶被鍨嬩负鍚嶅瓧(鍘绘帀銆�-銆�)娣诲姞璁惧鐨勩�愭墍灞炲浘鐗囥�戯紝銆愮湡瀹炵墿鐞嗗浘鐗囥�戙�傚洖璺浘鐗囬渶瑕佺壒娈婂鐞� + //4銆佹坊鍔燫鏂囦欢,娣诲姞Language鏂囦欢 + //********************************************************************* + //=========鈽呪槄寮�鍚堝笜绫�(100-199)鈽呪槄========= this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//鏅鸿兘寮�鍚堝笜鐢垫満 this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//鏅鸿兘绠$姸鐢垫満 @@ -2053,6 +2279,9 @@ this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2鎸夐敭瑙︽懜闈㈡澘 this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12鎸夐敭瑙︽懜闈㈡澘 this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4鎸夐敭瑙︽懜闈㈡澘(鍙甫鐢垫簮搴曞骇) + this.dicDeviceModelIdEnum["MPT4R4L/S-ZB.18"] = "220-200";//绠�绾�4鎸夐敭闈㈡澘 + this.dicDeviceModelIdEnum["MPT3R3L/S-ZB.18"] = "221-200";//绠�绾�3鎸夐敭闈㈡澘 + this.dicDeviceModelIdEnum["MPT2R2L/S-ZB.18"] = "222-200";//绠�绾�2鎸夐敭闈㈡澘 //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir浼犳劅鍣�220 @@ -2087,7 +2316,9 @@ this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee杞琤uspro鍗忚杞崲鍣� this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee杞�485鍗忚杞崲鍣� - //闇�瑕佷氦鎹㈢殑妯″潡ID + + + //鉁┾湬鉁┾湬鉁╅渶瑕佷氦鎹㈢殑妯″潡ID鉁┾湬鉁┾湬鉁� this.dicDeviceModelIdChanged = new Dictionary<string, string>(); //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫烩槄鈽�========= this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//鐕冩皵浼犳劅鍣� @@ -2096,6 +2327,14 @@ this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//绾㈠浼犳劅鍣� this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//姘存蹈浼犳劅鍣� this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//绱ф�ユ寜閿� + + + + //鉁┾湬鉁┾湬鉁╅渶瑕佸叡鏈夌殑鍥剧墖瀵硅薄鉁┾湬鉁┾湬鉁� + this.dicPictrueShard = new Dictionary<string, string>(); + this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭闈㈡澘 娌跨敤 4鎸夐敭鐨勫浘鏍� + this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//绠�绾�3鎸夐敭闈㈡澘 娌跨敤 3鎸夐敭鐨勫浘鏍� + this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//绠�绾�2鎸夐敭闈㈡澘 娌跨敤 2鎸夐敭鐨勫浘鏍� } #endregion @@ -2155,6 +2394,18 @@ /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉匡紙鍙甫鐢垫簮搴曞骇锛� 闀滃儚id锛�210 /// </summary> ButtonPanel_FourNotPower = 210, + /// <summary> + /// 绠�绾�4鎸夐敭闈㈡澘 闀滃儚id锛�220 + /// </summary> + ButtonPanel_SimpleFour = 220, + /// <summary> + /// 绠�绾�3鎸夐敭闈㈡澘 闀滃儚id锛�221 + /// </summary> + ButtonPanel_SimpleThree = 221, + /// <summary> + /// 绠�绾�2鎸夐敭闈㈡澘 闀滃儚id锛�222 + /// </summary> + ButtonPanel_SimpleTwo = 222, //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= /// <summary> @@ -2202,11 +2453,11 @@ /// <summary> /// 娓╂箍搴︿紶鎰熷櫒 /// </summary> - Sensor_TemperatrueHumidity = -1308, + Sensor_TemperatureHumidity = -1308, /// <summary> /// 娓╁害浼犳劅鍣� /// </summary> - Sensor_Temperatrue = -1309, + Sensor_Temperature = -1309, /// <summary> /// 婀垮害浼犳劅鍣� /// </summary> @@ -2270,11 +2521,11 @@ //=========鈽呪槄绌烘皵寮�鍏崇被(4100-????)鈽呪槄========= /// <summary> - /// 鏅鸿兘绌烘皵寮�鍏� + /// 鏅鸿兘绌哄紑 /// </summary> AirSwitch = -4100, /// <summary> - /// 寰柇浜戞帶鍒跺櫒 闀滃儚id锛�4100 + /// 鏅鸿兘绌哄紑 闀滃儚id锛�4100 /// </summary> AirSwitch_CloudContr = 4100, @@ -2291,6 +2542,24 @@ /// zigbee杞琤uspro鍗忚杞崲鍣� /// </summary> Converter_ZbBuspro = 4201, + + //=========鈽呪槄鍏朵粬绫�(????-????)鈽呪槄========= + /// <summary> + /// 骞叉帴鐐�(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + DryContact = -10000, + /// <summary> + /// 鐏厜(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Light = -10001, + /// <summary> + /// 鎻掑骇(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Socket1 = -10002, + /// <summary> + /// 寮�鍏�(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Switch = -10003, } /// <summary> @@ -2336,9 +2605,9 @@ /// </summary> A涓户鍣� = 3900, /// <summary> - /// 绌烘皵寮�鍏�(4100-4199) + /// 鏅鸿兘绌哄紑(4100-4199) /// </summary> - A绌烘皵寮�鍏� = 4100, + A鏅鸿兘绌哄紑 = 4100, /// <summary> /// 杞崲鍣�(4200-4699) /// </summary> @@ -2358,7 +2627,23 @@ /// <summary> /// 婀垮害浼犳劅鍣� /// </summary> - A婀垮害浼犳劅鍣� = 12 + A婀垮害浼犳劅鍣� = 12, + /// <summary> + /// 寮�鍏� + /// </summary> + A寮�鍏� = 13, + /// <summary> + /// 鎻掑骇 + /// </summary> + A鎻掑骇 = 14, + /// <summary> + /// 鐏厜 + /// </summary> + A鐏厜 = 15, + /// <summary> + /// 骞叉帴鐐� + /// </summary> + A骞叉帴鐐� = 16 } #endregion -- Gitblit v1.8.0