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 | 104 +++++++++++++++++++++++++++++----------------------
1 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 7259cdb..409b460 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -107,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
@@ -1397,7 +1403,7 @@
temperatrue = true;
}
//婀垮害浼犳劅鍣�
- else if(((TemperatureSensor)device).SensorDiv == 2)
+ else if (((TemperatureSensor)device).SensorDiv == 2)
{
humidity = true;
}
@@ -1639,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>
@@ -1745,53 +1751,61 @@
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)
+ {
+ //鍥炶皟鍑芥暟
+ 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;
@@ -1943,7 +1957,7 @@
}
}
//濡傛灉鏄皟鍏夊櫒
- else if (mainDevice.Type == DeviceType.DimmableLight )
+ else if (mainDevice.Type == DeviceType.DimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
if (mainDevice.IsCustomizeImage == false)
@@ -1952,7 +1966,7 @@
}
}
//濡傛灉鏄僵鐏殑璇�
- else if ( mainDevice.Type == DeviceType.ColorDimmableLight)
+ else if (mainDevice.Type == DeviceType.ColorDimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
if (mainDevice.IsCustomizeImage == false)
@@ -2258,7 +2272,7 @@
/// </summary>
AirSwitch = -4100,
/// <summary>
- /// 寰柇浜戞帶鍒跺櫒 闀滃儚id锛�4100
+ /// 鏅鸿兘绌哄紑 闀滃儚id锛�4100
/// </summary>
AirSwitch_CloudContr = 4100,
--
Gitblit v1.8.0