From 3291885285dfd5d4f665c20676307878dc3163bc Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 20 十二月 2019 16:28:53 +0800
Subject: [PATCH] 请合并最新代码(优化设备不支持的功能)
---
ZigbeeApp/Shared/Common/Device.cs | 700 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 531 insertions(+), 169 deletions(-)
diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 7b123ae..409b460 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -37,18 +37,21 @@
}
}
/// <summary>
- /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨
+ /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(鎺掑簭)
/// </summary>
public List<CommonDevice> listAllDevice
{
get
{
- var list = new List<CommonDevice>();
- foreach (var device in dicAllDevice.Values)
+ lock (dicAllDevice)
{
- list.Add(device);
+ var list = new List<CommonDevice>();
+ foreach (var device in dicAllDevice.Values)
+ {
+ list.Add(device);
+ }
+ return list;
}
- return list;
}
}
@@ -81,13 +84,9 @@
/// </summary>
private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
/// <summary>
- /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧
+ /// 鐗╃悊璁惧灞炰簬鍝釜鎴块棿鐨勮褰�
/// </summary>
- public const string deviceFirstName = "Device_";
- /// <summary>
- /// 閿�
- /// </summary>
- private object objLock = new object();
+ private Dictionary<string, string> dicDeviceRoomId = null;
#endregion
@@ -99,7 +98,7 @@
public void ReFreshByLocal()
{
this.dicAllDevice.Clear();
- this.dicDeviceEpoint.Clear();
+ this.dicDeviceEpoint.Clear();
//鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D
this.InitDeviceDefultNameIDList();
@@ -108,8 +107,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
@@ -172,6 +177,8 @@
}
//鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢
this.DeleteGatewayFileByMemberModel();
+ //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
+ this.InitRealDeviceRoomId();
}
/// <summary>
@@ -184,11 +191,15 @@
return;
}
var listId = new HashSet<string>();
- foreach (var device in this.dicAllDevice.Values)
+
+ lock (dicAllDevice)
{
- if (listId.Contains(device.CurrentGateWayId) == false)
+ foreach (var device in this.dicAllDevice.Values)
{
- listId.Add(device.CurrentGateWayId);
+ if (listId.Contains(device.CurrentGateWayId) == false)
+ {
+ listId.Add(device.CurrentGateWayId);
+ }
}
}
var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
@@ -213,11 +224,11 @@
/// <param name="zbGateway">缃戝叧瀵硅薄</param>
/// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param>
/// <returns>涓�鐩磋繑鍥瀟rue</returns>
- public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
+ public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
{
//浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧
List<CommonDevice> listDevice = new List<CommonDevice>();
- List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction);
+ List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction);
if (list == null)
{
@@ -329,17 +340,20 @@
return;
}
- if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ lock (dicAllDevice)
{
- //浜ゆ崲灞炴��
- var tempDevice = this.dicAllDevice[mainKeys];
- //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
- this.SetDeviceInfoToMain(tempDevice, device);
- device = tempDevice;
- }
- else
- {
- this.dicAllDevice[mainKeys] = device;
+ if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ {
+ //浜ゆ崲灞炴��
+ var tempDevice = this.dicAllDevice[mainKeys];
+ //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
+ this.SetDeviceInfoToMain(tempDevice, device);
+ device = tempDevice;
+ }
+ else
+ {
+ this.dicAllDevice[mainKeys] = device;
+ }
}
//璁惧鍥炶矾鏀堕泦
@@ -446,6 +460,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;
}
@@ -456,16 +475,19 @@
/// <param name="device"></param>
private void BackupDeviceAfterReName(CommonDevice device)
{
- string mainKeys = this.GetDeviceMainKeys(device);
- if (this.dicAllDevice.ContainsKey(mainKeys) == false)
+ lock (dicAllDevice)
{
- return;
- }
- this.dicAllDevice[mainKeys] = device;
- device.ReSave();
+ string mainKeys = this.GetDeviceMainKeys(device);
+ if (this.dicAllDevice.ContainsKey(mainKeys) == false)
+ {
+ return;
+ }
+ this.dicAllDevice[mainKeys] = device;
+ device.ReSave();
- //娣诲姞鑷姩澶囦唤
- HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+ //娣诲姞鑷姩澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+ }
}
#endregion
@@ -501,6 +523,12 @@
{
this.DeleteMemmoryDevice(device);
}
+ if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
+ {
+ //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮�
+ this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
+ this.SaveRealDeviceRoomId(null, null);
+ }
return true;
}
@@ -513,9 +541,12 @@
{
//鍒犻櫎缂撳瓨
string mainKeys = this.GetDeviceMainKeys(device);
- if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ lock (dicAllDevice)
{
- this.dicAllDevice.Remove(mainKeys);
+ if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ {
+ this.dicAllDevice.Remove(mainKeys);
+ }
}
//鍒犻櫎璁惧鏂囦欢
@@ -645,12 +676,15 @@
public List<CommonDevice> GetDeviceByGatewayID(string gwId)
{
List<CommonDevice> list = new List<CommonDevice>();
- //鍚勭綉鍏崇殑鎵�鏈夎澶�
- foreach (CommonDevice device in this.dicAllDevice.Values)
+ lock (dicAllDevice)
{
- if (gwId == device.CurrentGateWayId)
+ //鍚勭綉鍏崇殑鎵�鏈夎澶�
+ foreach (CommonDevice device in this.dicAllDevice.Values)
{
- list.Add(device);
+ if (gwId == device.CurrentGateWayId)
+ {
+ list.Add(device);
+ }
}
}
@@ -664,9 +698,12 @@
/// <returns></returns>
public CommonDevice GetDevice(string mainKeys)
{
- if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ lock (dicAllDevice)
{
- return this.dicAllDevice[mainKeys];
+ if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+ {
+ return this.dicAllDevice[mainKeys];
+ }
}
return null;
}
@@ -716,6 +753,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>
@@ -723,9 +774,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;
@@ -940,6 +992,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;
@@ -947,6 +1004,7 @@
this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
btnIcon.UnSelectedImagePath = unSelectFilePath;
+ btnIcon.SelectedImagePath = selectFilePath;
}
/// <summary>
@@ -1102,14 +1160,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;
}
@@ -1293,7 +1351,7 @@
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9;
info.BeloneType = DeviceBeloneType.A褰╃伅;
- info.ConcreteType = DeviceConcreteType.ColorDimmableLight;
+ info.ConcreteType = DeviceConcreteType.ColorLight;
}
//8绌鸿皟
else if (dicType.ContainsKey(DeviceType.Thermostat) == true)
@@ -1345,7 +1403,7 @@
temperatrue = true;
}
//婀垮害浼犳劅鍣�
- else if(((TemperatureSensor)device).SensorDiv == 2)
+ else if (((TemperatureSensor)device).SensorDiv == 2)
{
humidity = true;
}
@@ -1451,97 +1509,82 @@
#endregion
- #region 鈻� 璁惧鎺掑簭___________________________
+ #region 鈻� 鐗╃悊璁惧鎵�灞炴埧闂確__________________
/// <summary>
- /// 璁惧鎺掑簭
+ /// 鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
/// </summary>
- /// <param name="listDevice">璁惧瀵硅薄</param>
- /// <returns></returns>
- public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice)
+ private void InitRealDeviceRoomId()
{
- List<CommonDevice> listSort = new List<CommonDevice>();
- var list = this.SortDeviceListByRule(listDevice);
- listSort.AddRange(list);
-
- return listSort;
+ this.dicDeviceRoomId = new Dictionary<string, string>();
+ string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
+ var strData = UserCenterLogic.LoadFileContent(fullName);
+ if (strData != null)
+ {
+ this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
+ }
}
/// <summary>
- ///
+ /// 淇濆瓨鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
/// </summary>
- /// <param name="listDevice">璁惧瀵硅薄</param>
- /// <returns></returns>
- private List<CommonDevice> SortDeviceListByRule(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)
{
- //璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒)
- var dic = this.GetDeviceSortRule();
- foreach (CommonDevice device in listDevice)
+ if (listDevice != null)
{
- if (device is IASZone)
- {
- //浼犳劅鍣ㄦ湁寰堝绉�
- var strType = ((IASZone)device).DeviceInfo.DeviceType.ToString();
- if (dic.ContainsKey(strType) == false || dic[strType] == null)
- {
- dic[strType] = new List<CommonDevice>();
- }
- dic[strType].Add(device);
- continue;
- }
- string checkKeys = device.Type.ToString();
- if (dic.ContainsKey(checkKeys) == false || dic[checkKeys] == null)
- {
- dic[checkKeys] = new List<CommonDevice>();
- }
- dic[checkKeys].Add(device);
+ this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
}
- List<CommonDevice> lstSort = new List<CommonDevice>();
- foreach (var list in dic.Values)
+ //淇濆瓨璁板綍
+ string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
+ UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
+
+ //娣诲姞鑷姩澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
+
+ //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜�
+ if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
{
- if (list != null && list.Count > 0)
- {
- lstSort.AddRange(list);
- }
+ Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false);
}
- return lstSort;
}
/// <summary>
- /// 鑾峰彇璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒)
+ /// 鑾峰彇鐪熷疄鐗╃悊璁惧鐨勬埧闂村悕瀛�
/// </summary>
- /// <returns></returns>
- private Dictionary<string, List<CommonDevice>> GetDeviceSortRule()
+ /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param>
+ /// <returns></returns>
+ public string GeteRealDeviceRoomName(CommonDevice device)
{
- var dic = new Dictionary<string, List<CommonDevice>>();
- //鎺у埗闈㈡澘
- dic[DeviceType.OnOffSwitch.ToString()] = null;
- //鍗峰笜
- dic[DeviceType.WindowCoveringDevice.ToString()] = null;
- //璋冨厜鐏�
- dic[DeviceType.ColorDimmableLight.ToString()] = null;
- //缁х數鍣�
- dic[DeviceType.OnOffOutput.ToString()] = null;
- //绌烘皵寮�鍏�
- dic[DeviceType.AirSwitch.ToString()] = null;
- //闂ㄧ獥纾佷紶鎰熷櫒
- dic["21"] = null;
- dic["22"] = null;
- //姘存蹈浼犳劅鍣�
- dic["42"] = null;
- //鐑熼浘浼犳劅鍣�
- dic["40"] = null;
- //绱ф�ユ寜閽�
- dic["44"] = null;
- //鐕冩皵浼犳劅鍣�
- dic["43"] = null;
- //杩愬姩浼犳劅鍣�
- dic["13"] = null;
- //閽ュ寵鎵�
- dic["277"] = null;
+ 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);
+ }
- return dic;
+ /// <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
@@ -1602,16 +1645,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>
@@ -1647,14 +1690,40 @@
#region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________
/// <summary>
- /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚鈽呪槄鈽呪槄鈽呪槄鈽�)
+ /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢鈽呪槄鈽呪槄鈽呪槄鈽�)
/// </summary>
/// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param>
+ /// <param name="ignoreTime">鏄惁鏃犺鏃堕棿,true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param>
+ /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�</param>
/// <param name="mode">鏄惁鏄剧ず閿欒</param>
/// <returns></returns>
- public async Task<List<CommonDevice>> GetDeviceListFromGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES)
+ public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, 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;
+ }
+ }
+ zbGateway.LastDateTime = DateTime.Now;
+
//濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭�
string nowFormId = UserCenterResourse.NowActionFormID;
@@ -1682,61 +1751,74 @@
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)
- {
- //鍥炶皟鍑芥暟
- deviceComingAction?.Invoke(device);
+ TimeOut = 0;
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
+ if (totalNum == 0)
+ {
+ //杩欎釜缃戝叧娌℃湁璁惧
+ canBreak = true;
+ return;
+ }
+ 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)
+ {
+ //鍥炶皟鍑芥暟
+ deviceComingAction?.Invoke(device);
+ 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;
try
{
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
- await realWay.Send("GetDeviceInfo", jObject.ToString());
+ realWay.Send("GetDeviceInfo", jObject.ToString());
}
catch { canBreak = true; }
while (canBreak == false && TimeOut < 60)
{
- await Task.Delay(100);
+ System.Threading.Thread.Sleep(100);
TimeOut++;
}
@@ -1754,7 +1836,7 @@
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);
}
return null;
}
@@ -1769,8 +1851,7 @@
}
}
- //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚)
- deviceComingAction?.Invoke(null);
+ //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚)
deviceComingAction = null;
return listDevice;
@@ -1837,6 +1918,7 @@
mainDevice.DriveCode = device.DeviceInfo.DriveCode;
mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
mainDevice.Profile = device.DeviceInfo.Profile;
+ mainDevice.Type = device.Type;
//鍥轰欢鐗堟湰
mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
@@ -1857,9 +1939,9 @@
mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
mainDevice.AttributeStatus.Clear();
mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
-
+
//濡傛灉鏄俯搴︿紶鎰熷櫒
- if (mainDevice is TemperatureSensor)
+ if (mainDevice.Type == DeviceType.TemperatureSensor)
{
//杈撳嚭鏃� 1026:娓╁害浼犳劅鍣� 1029:婀垮害浼犳劅鍣�
foreach (var data in mainDevice.OutClusterList)
@@ -1872,6 +1954,24 @@
{
((TemperatureSensor)mainDevice).SensorDiv = 1;
}
+ }
+ }
+ //濡傛灉鏄皟鍏夊櫒
+ else if (mainDevice.Type == DeviceType.DimmableLight)
+ {
+ mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+ if (mainDevice.IsCustomizeImage == false)
+ {
+ mainDevice.IconPath = "Device/Light.png";
+ }
+ }
+ //濡傛灉鏄僵鐏殑璇�
+ else if (mainDevice.Type == DeviceType.ColorDimmableLight)
+ {
+ mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+ if (mainDevice.IsCustomizeImage == false)
+ {
+ mainDevice.IconPath = "Device/ColorLight.png";
}
}
}
@@ -1973,7 +2073,7 @@
this.dicDeviceModelIdEnum["H06C"] = "2800-2800";//鏅鸿兘闂ㄩ攣(H06C)
//=========鈽呪槄绌鸿皟绫�(3600-3899)鈽呪槄=========
- this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡
+ this.dicDeviceModelIdEnum["MAC/GW-ZB.10"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡
//=========鈽呪槄涓户鍣ㄧ被(3900-3999)鈽呪槄=========
this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee涓户鍣�
@@ -1998,4 +2098,266 @@
#endregion
}
+
+ #region 鈻� 鑷畾涔夎澶囩被鍨媉________________________
+
+ /// <summary>
+ /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囩殑鍏蜂綋銆愯澶囩被鍨嬨��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��)</para>
+ /// <para>鍙橀噺鍚嶅彲浠ヤ綔涓恒�愯澶囩被鍨嬨�戝浘鐗�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para>
+ /// </summary>
+ public enum DeviceConcreteType
+ {
+ //瀹氫箟瑙勫垯锛氥�愯澶囩被鍨嬨�戝浘鐗囧悕瀛�=LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��
+
+ /// <summary>
+ /// 鏈煡璁惧
+ /// </summary>
+ UnKownDevice = -1,
+
+ //=========鈽呪槄绐楀笜绫�(100-199)鈽呪槄=========
+ /// <summary>
+ /// 绐楀笜
+ /// </summary>
+ Curtain = -100,
+ /// <summary>
+ /// 鏅鸿兘寮�鍚堝笜鐢垫満 闀滃儚id锛�100
+ /// </summary>
+ Curtain_AutoOpen = 100,
+ /// <summary>
+ /// 鏅鸿兘绠$姸鐢垫満 闀滃儚id锛�101
+ /// </summary>
+ Curtain_Siphonate = 101,
+
+ //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄=========
+ /// <summary>
+ /// 鎸夐敭闈㈡澘
+ /// </summary>
+ ButtonPanel = -200,
+ /// <summary>
+ /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�4璺户鐢靛櫒搴曞骇) 闀滃儚id锛�200
+ /// </summary>
+ ButtonPanel_Four = 200,
+ /// <summary>
+ /// 3鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�3璺户鐢靛櫒搴曞骇) 闀滃儚id锛�201
+ /// </summary>
+ ButtonPanel_Three = 201,
+ /// <summary>
+ /// 2鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�2璺户鐢靛櫒搴曞骇) 闀滃儚id锛�202
+ /// </summary>
+ ButtonPanel_Two = 202,
+ /// <summary>
+ /// 12鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�1璺户鐢靛櫒搴曞骇) 闀滃儚id锛�203
+ /// </summary>
+ ButtonPanel_Twelve = 203,
+ /// <summary>
+ /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉匡紙鍙甫鐢垫簮搴曞骇锛� 闀滃儚id锛�210
+ /// </summary>
+ ButtonPanel_FourNotPower = 210,
+
+ //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
+ /// <summary>
+ /// 浼犳劅鍣�
+ /// </summary>
+ Sensor = -1200,
+ /// <summary>
+ /// pir浼犳劅鍣�220 闀滃儚id锛�1200
+ /// </summary>
+ Sensor_Pir = 1200,
+
+ //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
+ /// <summary>
+ /// 鐕冩皵浼犳劅鍣�
+ /// </summary>
+ Sensor_CarbonMonoxide = 1300,
+ /// <summary>
+ /// 闂ㄧ獥浼犳劅鍣�
+ /// </summary>
+ Sensor_DoorWindow = 1301,
+ /// <summary>
+ /// 鐑熼浘浼犳劅鍣�
+ /// </summary>
+ Sensor_Fire = 1302,
+ /// <summary>
+ /// 绾㈠浼犳劅鍣�
+ /// </summary>
+ Sensor_Infrared = 1303,
+ /// <summary>
+ /// 姘翠镜浼犳劅鍣�
+ /// </summary>
+ Sensor_Water = 1304,
+ /// <summary>
+ /// 绱ф�ユ寜閽�
+ /// </summary>
+ Sensor_EmergencyButton = 1305,
+ /// <summary>
+ /// 杩愬姩浼犳劅鍣�
+ /// </summary>
+ Sensor_Motion = -1306,
+ /// <summary>
+ /// 閽ュ寵鎵�
+ /// </summary>
+ Sensor_Keyfob = -1307,
+ /// <summary>
+ /// 娓╂箍搴︿紶鎰熷櫒
+ /// </summary>
+ Sensor_TemperatrueHumidity = -1308,
+ /// <summary>
+ /// 娓╁害浼犳劅鍣�
+ /// </summary>
+ Sensor_Temperatrue = -1309,
+ /// <summary>
+ /// 婀垮害浼犳劅鍣�
+ /// </summary>
+ Sensor_Humidity = -1310,
+
+ //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄=========
+ /// <summary>
+ /// 缁х數鍣�
+ /// </summary>
+ Relay = -2300,
+ /// <summary>
+ /// 涓夎矾缁х數鍣� 闀滃儚id锛�2300
+ /// </summary>
+ Relay_ThreeLoad = 2300,
+
+ //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
+ /// <summary>
+ /// 璋冨厜鍣�
+ /// </summary>
+ DimmableLight = -2500,
+ /// <summary>
+ /// 1璺皟鍏夊櫒灏忔ā鍧�
+ /// </summary>
+ DimmableLight_OneLoad = 2500,
+
+ //=========鈽呪槄鏅鸿兘闂ㄩ攣绫�(2800-????)鈽呪槄=========
+ /// <summary>
+ /// 鏅鸿兘闂ㄩ攣
+ /// </summary>
+ IntelligentLocks = -2800,
+ /// <summary>
+ /// H06C
+ /// </summary>
+ IntelligentLocks_H06C = 2800,
+
+ //=========鈽呪槄褰╃伅绫�(????-????)鈽呪槄=========
+ /// <summary>
+ /// 褰╃伅
+ /// </summary>
+ ColorLight = -10,
+
+ //=========鈽呪槄绌鸿皟(3600-3899)鈽呪槄=========
+ /// <summary>
+ /// 绌鸿皟
+ /// </summary>
+ AirConditioner = -3600,
+ /// <summary>
+ /// zigbee绌鸿皟缃戝叧妯″潡
+ /// </summary>
+ AirConditioner_ZbGateway = 3600,
+
+ //=========鈽呪槄涓户鍣�(3900-3999)鈽呪槄=========
+ /// <summary>
+ /// 涓户鍣�
+ /// </summary>
+ Repeater = -3900,
+ /// <summary>
+ /// zigbee涓户鍣� 闀滃儚id锛�3900
+ /// </summary>
+ Repeater_Zigbee = 3900,
+
+ //=========鈽呪槄绌烘皵寮�鍏崇被(4100-????)鈽呪槄=========
+ /// <summary>
+ /// 鏅鸿兘绌烘皵寮�鍏�
+ /// </summary>
+ AirSwitch = -4100,
+ /// <summary>
+ /// 鏅鸿兘绌哄紑 闀滃儚id锛�4100
+ /// </summary>
+ AirSwitch_CloudContr = 4100,
+
+ //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄=========
+ /// <summary>
+ /// 杞崲鍣�
+ /// </summary>
+ Converter = -4200,
+ /// <summary>
+ /// zigbee杞�485鍗忚杞崲鍣�
+ /// </summary>
+ Converter_Zb485 = 4200,
+ /// <summary>
+ /// zigbee杞琤uspro鍗忚杞崲鍣�
+ /// </summary>
+ Converter_ZbBuspro = 4201,
+ }
+
+ /// <summary>
+ /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囨墍灞炵殑銆愯澶囩绫汇��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��)</para>
+ /// <para>杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para>
+ /// </summary>
+ public enum DeviceBeloneType
+ {
+ /// <summary>
+ /// 鏈煡璁惧
+ /// </summary>
+ A鏈煡璁惧 = 0,
+ /// <summary>
+ /// 绐楀笜(100-199)
+ /// </summary>
+ A绐楀笜 = 100,
+ /// <summary>
+ /// 鎸夐敭闈㈡澘(200-1199)
+ /// </summary>
+ A鎸夐敭闈㈡澘 = 200,
+ /// <summary>
+ /// 浼犳劅鍣�(1200-2299)
+ /// </summary>
+ A浼犳劅鍣� = 1200,
+ /// <summary>
+ /// 缁х數鍣�(2300-2499)
+ /// </summary>
+ A缁х數鍣� = 2300,
+ /// <summary>
+ /// 璋冨厜鍣�(2500-2799)
+ /// </summary>
+ A璋冨厜鍣� = 2500,
+ /// <summary>
+ /// 鏅鸿兘闂ㄩ攣(2800-????)
+ /// </summary>
+ A鏅鸿兘闂ㄩ攣 = 2800,
+ /// <summary>
+ /// 绌鸿皟(3600-3899)
+ /// </summary>
+ A绌鸿皟 = 3600,
+ /// <summary>
+ /// 涓户鍣�(3900-3999)
+ /// </summary>
+ A涓户鍣� = 3900,
+ /// <summary>
+ /// 绌烘皵寮�鍏�(4100-4199)
+ /// </summary>
+ A绌烘皵寮�鍏� = 4100,
+ /// <summary>
+ /// 杞崲鍣�(4200-4699)
+ /// </summary>
+ A杞崲鍣� = 4200,
+ /// <summary>
+ /// 褰╃伅
+ /// </summary>
+ A褰╃伅 = 9,
+ /// <summary>
+ /// 娓╂箍搴︿紶鎰熷櫒
+ /// </summary>
+ A娓╂箍搴︿紶鎰熷櫒 = 10,
+ /// <summary>
+ /// 娓╁害浼犳劅鍣�
+ /// </summary>
+ A娓╁害浼犳劅鍣� = 11,
+ /// <summary>
+ /// 婀垮害浼犳劅鍣�
+ /// </summary>
+ A婀垮害浼犳劅鍣� = 12
+ }
+
+ #endregion
}
--
Gitblit v1.8.0