From dc6493db59dcb0893eac50b72122f94c24056b3f Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 12 十月 2020 14:35:39 +0800
Subject: [PATCH] 新版本
---
ZigbeeApp/Shared/Common/Device.cs | 504 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 350 insertions(+), 154 deletions(-)
diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 5628cbf..4d1050a 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -245,7 +245,7 @@
{
continue;
}
- var device = this.NewDeviceObjectByDeviceId((DeviceType)itemValue);
+ var device = this.NewDeviceObjectByDeviceId((DeviceType)itemValue, 1);
string strMsg = string.Empty;
if (device == null)
{
@@ -272,14 +272,14 @@
/// <para>灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚)</para>
/// <para>-1:寮傚父 1:姝e父 2:璁惧淇℃伅缂烘崯</para>
/// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="gatewayId">缃戝叧Id</param>
/// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
- public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway, bool useLocalConnect)
+ public int SetDeviceToMemmoryByGateway(string gatewayId, bool useLocalConnect)
{
//浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧
int statu = 0;
List<CommonDevice> listDevice = new List<CommonDevice>();
- List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, useLocalConnect);
+ List<CommonDevice> list = this.GetDeviceListFromGateway(gatewayId, ref statu, useLocalConnect);
if (list == null)
{
return -1;
@@ -287,12 +287,11 @@
listDevice.AddRange(list);
//鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶�
- string gwID = zbGateway.GwId;
- List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
+ List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gatewayId);
//鑾峰彇ota璁惧
foreach (var ota in this.dicOTADevice.Values)
{
- if (ota.CurrentGateWayId == gwID)
+ if (ota.CurrentGateWayId == gatewayId)
{
listLocalDevices.Add(ota);
}
@@ -1187,7 +1186,7 @@
/// <param name="listDevice"></param>
/// <returns></returns>
public List<CommonDevice> GetPanelMatchEpointByMac(List<CommonDevice> listDevice, bool sort = true)
- {
+ {
var list = new List<CommonDevice>();
foreach (var dev in listDevice)
{
@@ -1198,7 +1197,7 @@
else if (dev.Type == DeviceType.FreshAirHumiditySensor)
{
list.Add(dev);
- }
+ }
}
if (sort == false)
{
@@ -1212,7 +1211,7 @@
return 1;
}
return -1;
- });
+ });
return list;
}
@@ -1334,7 +1333,7 @@
#region 鈻� 鑾峰彇璁惧淇℃伅_______________________
/// <summary>
- /// 璇诲彇鍗曚釜绔偣鍥炶矾璁惧淇℃伅
+ /// 浠庣綉鍏宠鍙栧崟涓鐐瑰洖璺澶囦俊鎭�
/// </summary>
/// <param name="device">璁惧瀵硅薄</param>
/// <returns></returns>
@@ -1348,6 +1347,145 @@
}
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(result.ReceiptData);
return info;
+ }
+
+ /// <summary>
+ /// 浠庣綉鍏宠鍙栨寚瀹歁ac涓嬬殑璁惧鍒楄〃(杩斿洖鐨勬槸缃戝叧鍥炲鐨勮澶嘕son,璋冪敤ConvertJObjectToDevice鏂规硶杞负Device瀵硅薄)
+ /// </summary>
+ /// <param name="realGateway">鐪熷疄缃戝叧瀵硅薄</param>
+ /// <param name="i_deviceMac">璁惧Mac</param>
+ /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
+ /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+ /// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param>
+ /// <returns></returns>
+ public List<Newtonsoft.Json.Linq.JObject> ReadDeviceListByMacFromGateway(string gatewayId, string i_deviceMac, bool useLocalConnect, ref int statu)
+ {
+ //鏄惁杈炬垚涓柇鐨勬椂鏈�
+ bool canBreak = false;
+ //瓒呮椂鏃堕棿
+ int TimeOut = 0;
+ //璁惧鎬绘暟
+ int deviceCount = -1;
+ //鎺ユ敹鏁�
+ int receiveCount = 0;
+ //璁惧鍒楄〃
+ var listDeviceJson = new List<Newtonsoft.Json.Linq.JObject>();
+
+ HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+ {
+ if (topic == gatewayId + "/GetStatusRecord_Respon")
+ {
+ lock (listDeviceJson)
+ {
+ //璁惧鎺ユ敹鏁�
+ receiveCount++;
+ 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;
+ }
+ listDeviceJson.Add(jobject);
+ }
+
+ if (receiveCount == deviceCount && deviceCount != -1)
+ {
+ //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
+ canBreak = true;
+ }
+ }
+ });
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", i_deviceMac }, { "Epoint", 255 }, { "Cluster_ID", 0 }, { "Command", 80 } };
+ HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetStatusRecord", jObject.ToString(), useLocalConnect);
+
+ while (canBreak == false && TimeOut <= 150)
+ {
+ System.Threading.Thread.Sleep(20);
+ TimeOut++;
+ }
+ //绉婚櫎鐩戝惉
+ HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+ if (TimeOut > 150)
+ {
+ statu = listDeviceJson.Count == 0 ? -1 : 2;
+ }
+ else
+ {
+ statu = 1;
+ }
+ return listDeviceJson;
+ }
+
+ /// <summary>
+ /// 灏嗚澶囩殑Json杞崲涓鸿澶囧璞�
+ /// </summary>
+ /// <param name="listIObjects">璁惧Json</param>
+ /// <param name="gwId">缃戝叧id</param>
+ /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+ /// <returns></returns>
+ public List<CommonDevice> ConvertJObjectToDevice(List<Newtonsoft.Json.Linq.JObject> listIObjects, string gwId, ref List<CommonDevice> listFucDevice)
+ {
+ //璁惧鍒楄〃
+ var listDevice = new List<CommonDevice>();
+ //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+ var listCheck = new HashSet<string>();
+
+ foreach (var jobject in listIObjects)
+ {
+ var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
+ //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
+ var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, gwId);
+ if (device != null)
+ {
+ string mainkeys = this.GetDeviceMainKeys(device);
+ //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+ if (listCheck.Contains(mainkeys) == false)
+ {
+ listDevice.Add(device);
+ listCheck.Add(mainkeys);
+ //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
+ var localDevice = this.GetDevice(mainkeys);
+ var tempDevice = localDevice == null ? device : localDevice;
+
+ //濡傛灉杩欎釜璁惧ID鍙樻洿浜嗙殑璇�
+ bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
+ if (typeNotEquals == true)
+ {
+ //閲嶆柊New杩欎釜瀵硅薄
+ typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
+ //閲嶆柊鍐嶆鑾峰彇瀵硅薄
+ tempDevice = this.GetDevice(mainkeys);
+ }
+
+ //鍒锋柊灞炴��
+ this.SetDeviceInfoToMain(tempDevice, device);
+ if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
+ {
+ //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
+ listFucDevice.Add(tempDevice);
+ }
+ if (typeNotEquals == true)
+ {
+ //閲嶆柊鐢熸垚缂撳瓨
+ tempDevice.ReSave();
+ HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
+ //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂�
+ Phone.UserView.UserPage.Instance.RefreshAllForm = true;
+ }
+ }
+ }
+ }
+ return listDevice;
}
#endregion
@@ -1444,7 +1582,7 @@
}
if (device.Type == DeviceType.OnOffOutput
- || device.Type == DeviceType.DimmableLight
+ || device.Type == DeviceType.DimmableLight
|| device.Type == DeviceType.ColorDimmableLight
|| device.Type == DeviceType.ColorTemperatureLight)
{
@@ -1455,7 +1593,7 @@
{
//绌鸿皟閮藉彨瀹ゅ唴鏈�
return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
- }
+ }
//鑾峰彇璁惧绫诲瀷
var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
@@ -2554,7 +2692,7 @@
//鍏朵粬鐨勭湅鐫�鍔炲憲,閮芥槸鎺掑湪鍚庨潰鐨�,閮藉綊涓鸿繖涓睘鎬�
list.Add(DeviceBeloneType.A鏈煡璁惧);
-
+
return list;
}
@@ -2631,7 +2769,7 @@
}
//濡傛灉鏄柊椋庨潰鏉挎垨鐜闈㈡澘,鍒欓兘涓嶆樉绀轰换浣曞洖璺�
- var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
+ var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
{
return false;
@@ -2775,182 +2913,157 @@
#region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________
/// <summary>
- /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�)</para>
+ /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�),涓�娆℃�у叏閮ㄨ幏鍙�</para>
/// <para>statu鐘舵�� -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</para>
/// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="gatewayId">缃戝叧id</param>
/// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param>
/// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
/// <param name="mode">鏄惁鏄剧ず閿欒</param>
/// <returns></returns>
- public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
+ public List<CommonDevice> GetDeviceListFromGateway(string gatewayId, ref int statu, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
{
- //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭�
- string nowFormId = UserCenterResourse.NowActionFormID;
-
- ZbGateway realWay = null;
- if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == false)
- {
- if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
- }
- statu = -1;
- return null;
- }
//闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾
var listFucDevice = new List<CommonDevice>();
//鏄惁杈炬垚涓柇鐨勬椂鏈�
bool canBreak = false;
- //缃戝叧ID
- string gatewayID = zbGateway.GwId;
//瓒呮椂鏃堕棿
int TimeOut = 0;
+ //褰撳墠璁惧鎺ユ敹鏁�
+ int nowReceiveCount = 0;
//璁惧鎬绘暟
int deviceCount = -1;
- //鎺ユ敹鏁�
- int receiveCount = 0;
//璁惧鍒楄〃
var listDevice = new List<CommonDevice>();
//缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
var listCheck = new HashSet<string>();
- Action<string, string> getDeviceAction = (topic, message) =>
+ ///Mac鐨勭鐐规�绘暟
+ var dicMacPointCount = new Dictionary<string, int>();
+
+ HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
{
- if (topic == gatewayID + "/DeviceInfoRespon")
+ if (topic == gatewayId + "/DeviceInfoRespon")
{
- try
+ lock (listDevice)
{
- lock (listDevice)
+ TimeOut = 0;
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ var totalNum = Convert.ToInt32(jobject["Data"]["TotalNum"].ToString());
+ if (totalNum == 0)
{
- //璁惧鎺ユ敹鏁�
- receiveCount++;
+ //杩欎釜缃戝叧娌℃湁璁惧
+ canBreak = true;
+ return;
+ }
+ if (deviceCount == -1)
+ {
+ //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
+ deviceCount = totalNum;
+ }
+ nowReceiveCount++;
- 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;
- }
+ //璁惧鍥炶矾鏁版敹闆�
+ string deviceMac = jobject.Value<string>("DeviceAddr");
+ if (dicMacPointCount.ContainsKey(deviceMac) == false)
+ {
+ dicMacPointCount[deviceMac] = 0;
+ }
+ dicMacPointCount[deviceMac]++;
- var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
- //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
- var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
- if (device != null)
+ var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
+ //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
+ var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, gatewayId);
+ if (device != null)
+ {
+ string mainkeys = this.GetDeviceMainKeys(device);
+ //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+ if (listCheck.Contains(mainkeys) == false)
{
- string mainkeys = this.GetDeviceMainKeys(device);
- //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
- if (listCheck.Contains(mainkeys) == false)
+ listDevice.Add(device);
+ listCheck.Add(mainkeys);
+ //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
+ var localDevice = this.GetDevice(mainkeys);
+ var tempDevice = localDevice == null ? device : localDevice;
+
+ //濡傛灉杩欎釜璁惧ID鍙樻洿浜嗙殑璇�
+ bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
+ if (typeNotEquals == true)
{
- listDevice.Add(device);
- listCheck.Add(mainkeys);
- //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
- var localDevice = this.GetDevice(mainkeys);
- var tempDevice = localDevice == null ? device : localDevice;
+ //閲嶆柊New杩欎釜瀵硅薄
+ typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
+ //閲嶆柊鍐嶆鑾峰彇瀵硅薄
+ tempDevice = this.GetDevice(mainkeys);
+ }
- //濡傛灉杩欎釜璁惧ID鍙樻洿浜嗙殑璇�
- bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
- if (typeNotEquals == true)
- {
- //閲嶆柊New杩欎釜瀵硅薄
- typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
- //閲嶆柊鍐嶆鑾峰彇瀵硅薄
- tempDevice = this.GetDevice(mainkeys);
- }
-
- //鍒锋柊灞炴��
- this.SetDeviceInfoToMain(tempDevice, device);
- if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
- {
- //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
- listFucDevice.Add(tempDevice);
- }
- if (typeNotEquals == true)
- {
- //閲嶆柊鐢熸垚缂撳瓨
- tempDevice.ReSave();
- HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
- //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂�
- Phone.UserView.UserPage.Instance.RefreshAllForm = true;
- }
+ //鍒锋柊灞炴��
+ this.SetDeviceInfoToMain(tempDevice, device);
+ if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
+ {
+ //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
+ listFucDevice.Add(tempDevice);
+ }
+ if (typeNotEquals == true)
+ {
+ //閲嶆柊鐢熸垚缂撳瓨
+ tempDevice.ReSave();
+ HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
+ //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂�
+ Phone.UserView.UserPage.Instance.RefreshAllForm = true;
}
}
}
}
- //Log鍑哄姏
- catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
- if (receiveCount == deviceCount && deviceCount != -1)
+ if (nowReceiveCount >= deviceCount)
{
//璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
canBreak = true;
}
}
- else if (topic == gatewayID + "/DeviceInfoResponEnd")
- {
- }
- };
+ });
+ //鍙戦�佸懡浠�
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
+ HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDeviceInfo", jObject.ToString(), useLocalConnect);
- realWay.Actions += getDeviceAction;
- try
- {
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
- if (useLocalConnect == false)
- {
- realWay.Send("GetDeviceInfo", jObject.ToString());
- }
- else
- {
- //寮哄埗浣跨敤鏈湴杩炴帴
- realWay.SendLocation("GetDeviceInfo", Encoding.UTF8.GetBytes(jObject.ToString()));
- }
- }
- catch { canBreak = true; }
-
- while (canBreak == false && TimeOut < 60)
+ while (canBreak == false && TimeOut <= 30)
{
System.Threading.Thread.Sleep(100);
TimeOut++;
}
+ //绉婚櫎缃戝叧鐩戝惉浜嬩欢
+ HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
- realWay.Actions -= getDeviceAction;
- getDeviceAction = null;
-
- if (TimeOut >= 60)
+ if (TimeOut > 30)
{
- if (listDevice.Count == 0)
+ if (listDevice.Count > 0)
{
- if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
- {
- //鑾峰彇璁惧鍒楄〃澶辫触
- //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇�
- string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
- msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false);
- this.ShowTipMsg(msg);
- }
- statu = -1;
- return null;
- }
- else
- {
- if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
+ //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯,鍒欓噰鐢ㄦ寜搴忓彿鑾峰彇璁惧
+ statu = this.GetDeviceListFromGatewayByMac(gatewayId, ref listDevice, ref listFucDevice, dicMacPointCount, useLocalConnect);
+ if (statu == 2)
{
//缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯
string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
this.ShowTipMsg(msg);
}
- statu = 2;
+ }
+ else
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //鑾峰彇璁惧鍒楄〃澶辫触
+ //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇�
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
+ var localGw = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
+ if (localGw != null)
+ {
+ msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(localGw).ToString() + "]";
+ }
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false);
+ this.ShowTipMsg(msg);
+ }
+ statu = -1;
+ return null;
}
}
else
@@ -2971,6 +3084,60 @@
}
return listDevice;
+ }
+
+ /// <summary>
+ /// 鏍规嵁搴忓彿鑾峰彇璁惧鍒楄〃淇℃伅(鍙湁鍦ㄨ澶囩己鎹熺殑鏃跺�欐墠璋冪敤杩欎釜鍑芥暟) 1:姝e父 2:璁惧缂烘崯
+ /// </summary>
+ /// <param name="gatewayId">缃戝叧id</param>
+ /// <param name="listDevice">瀛樺偍鐨勮澶囧璞¢泦鍚�</param>
+ /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+ /// <param name="dicNowPointCount">褰撳墠宸茬粡鑾峰彇鐨凪ac鐨勭鐐规�绘暟</param>
+ /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
+ /// <returns></returns>
+ public int GetDeviceListFromGatewayByMac(string gatewayId, ref List<CommonDevice> listDevice, ref List<CommonDevice> listFucDevice, Dictionary<string, int> dicNowPointCount, bool useLocalConnect)
+ {
+ //棣栧厛鍏堣幏鍙栬澶囩殑mac鍒楄〃
+ var jObject33 = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 87 } };
+ var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(gatewayId, "GetStatusRecord", jObject33.ToString(), "DeviceMACDeviceListRespon", 3, useLocalConnect);
+ if (result.ErrorMsgDiv == -1 || result.ErrorMsgDiv == 0)
+ {
+ //濡傛灉缃戝叧娌℃湁瀵硅繖涓富棰樺仛鍑哄洖搴旂殑璇�,鍒欒鏄庡畠鏄竴涓棫缃戝叧
+ return 2;
+ }
+ var resultMac = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiptMacResult>(result.ReceiptData);
+
+ //璁惧鍒楄〃
+ var listDeviceJson = new List<Newtonsoft.Json.Linq.JObject>();
+
+ int statu = 0;
+ foreach (var macInfo in resultMac.MACDeviceList)
+ {
+ if (dicNowPointCount.ContainsKey(macInfo.MacAddr) == true
+ && dicNowPointCount[macInfo.MacAddr] == macInfo.EPTotalNum)
+ {
+ //濡傛灉杩欎釜mac鐨勭鐐规暟涓�鑷�,鍒欒鏄庡凡缁忔帴鏀堕綈浜�,涓嶉渶瑕佸啀娆℃帴鏀�
+ continue;
+ }
+ //浠庣綉鍏宠鍙栨寚瀹歁ac涓嬬殑璁惧鍒楄〃
+ var jsonData = this.ReadDeviceListByMacFromGateway(gatewayId, macInfo.MacAddr, useLocalConnect, ref statu);
+ foreach (var myData in jsonData)
+ {
+ listDeviceJson.Add(myData);
+ }
+ if (statu != 1)
+ {
+ //娌℃湁姝e父瀹屾垚,鍒欎腑鏂�
+ break;
+ }
+ }
+ //杞寲涓鸿澶囧垪琛�
+ var listTempDevice = this.ConvertJObjectToDevice(listDeviceJson, gatewayId, ref listFucDevice);
+ for (int i = 0; i < listTempDevice.Count; i++)
+ {
+ listDevice.Add(listTempDevice[i]);
+ }
+ return statu == 1 ? 1 : 2;
}
/// <summary>
@@ -3012,6 +3179,36 @@
return true;
}
+ /// <summary>
+ /// 鎺ユ敹璁惧Mac鍒楄〃鐨勭被
+ /// </summary>
+ private class ReceiptMacResult
+ {
+ /// <summary>
+ /// mac鎬绘暟
+ /// </summary>
+ public int MACDeviceTotalNum = 0;
+ /// <summary>
+ /// 璁惧mac鍒楄〃
+ /// </summary>
+ public List<MacResult> MACDeviceList = new List<MacResult>();
+ }
+
+ /// <summary>
+ /// 璁惧Mac鐨勫唴瀹�
+ /// </summary>
+ private class MacResult
+ {
+ /// <summary>
+ /// 璁惧Mac
+ /// </summary>
+ public string MacAddr = string.Empty;
+ /// <summary>
+ /// mac绔偣鐨勬�绘暟
+ /// </summary>
+ public int EPTotalNum = 0;
+ }
+
#endregion
#region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________
@@ -3021,14 +3218,12 @@
/// </summary>
/// <param name="deviceType">璁惧绫诲瀷</param>
/// <param name="jobject">涓婚Data</param>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="gwid">缃戝叧id</param>
/// <returns></returns>
- private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway)
+ private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, string gwid)
{
- string gwId = zbGateway.GwId;
-
//鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
- CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType);
+ CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType, jobject.Value<int>("Epoint"));
if (device == null)
{
return null;
@@ -3043,7 +3238,7 @@
//璁剧疆璁惧涓婚敭绫�
this.SetNewDeviceMainKeys(device, jobject);
- device.CurrentGateWayId = gwId;
+ device.CurrentGateWayId = gwid;
return device;
}
@@ -3115,11 +3310,12 @@
/// 鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞�
/// </summary>
/// <param name="deviceType">璁惧Type</param>
+ /// <param name="DeviceEpoint">璁惧绔偣(娌℃湁浠�涔堢壒娈婇渶姹傜殑璇�,濉�0鍗冲彲)</param>
/// <returns></returns>
- public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
+ public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, int DeviceEpoint)
{
//鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
- var device = CommonDevice.CommonDeviceByByteString((int)deviceType, "{\"DeviceID\":" + (int)deviceType + "}");
+ var device = CommonDevice.CommonDeviceByByteString((int)deviceType, "{\"DeviceID\":" + (int)deviceType + ",\"DeviceEpoint\":" + DeviceEpoint + "}");
if (device == null)
{
return null;
@@ -3326,7 +3522,7 @@
content.ConcreteTypeValue = Convert.ToInt32(strArry2[0].Trim());
content.A瀹樻柟鍚嶅瓧 = strArry2[1].Trim();
content.A澶囨敞鍚嶅瓧 = strArry2[2].Trim();
- content.BeloneTypeValue= Convert.ToInt32(strArry2[3].Trim());
+ content.BeloneTypeValue = Convert.ToInt32(strArry2[3].Trim());
content.A鎵�灞炲悕瀛� = strArry2[4].Trim();
content.A绫诲瀷鍚嶅瓧 = strArry2[5].Trim();
this.dicDeviceModelIdEnum[strArry1[0].Trim()] = content;
@@ -3592,17 +3788,17 @@
/// </summary>
Relay_FangyueFreshAirModul = 2310,
/// <summary>
- /// 鍥芥爣3璺�10A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2311(涓存椂)
+ /// 鍥芥爣3璺�10A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2301
/// </summary>
- Relay_NationalThreeLoadTenA = 2311,
+ Relay_NationalThreeLoadTenA = 2301,
/// <summary>
- /// 娆ф爣2璺�5A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2312(涓存椂)
+ /// 娆ф爣2璺�5A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2315
/// </summary>
- Relay_EuropeanTwoLoadFiveA = 2312,
+ Relay_EuropeanTwoLoadFiveA = 2315,
/// <summary>
- /// 娆ф爣14璺共鎺ョ偣灏忔ā鍧� 闀滃儚id锛�2313(涓存椂)
+ /// 7璺共鎺ョ偣杈撳叆杈撳嚭妯″潡 闀滃儚id锛�2320
/// </summary>
- Relay_EuropeanFourteenLoadDryContact = 2313,
+ Relay_SevenLoadInOutPutDryContact = 2320,
//=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
/// <summary>
--
Gitblit v1.8.0