From 0bf9e65bc3ba98391e7835c922b15baab3c77876 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 01 六月 2020 14:59:39 +0800
Subject: [PATCH] 上传一个合并的版本
---
ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 109 +++++++++++++++++++++++++++---------------------------
1 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
index 3fd043a..367c79d 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
@@ -22,6 +22,10 @@
/// 鏂板彂鐜扮殑缃戝叧閫氱煡
/// </summary>
public static Action<ZigBee.Device.ZbGateway> NewGateWayAction;
+ /// <summary>
+ /// 涓婁竴娆$殑浣忓畢ID
+ /// </summary>
+ private static string oldHomeID = string.Empty;
public static void Init()
{
@@ -35,7 +39,6 @@
{
var gateWayList = new List<ZbGateway> { };
var searchCount = 6;
- var oldHomeID = string.Empty;
var broadBytes = new byte[44];// byteHomeId[0] ,//H
broadBytes[0] = 0xfe;
broadBytes[1] = 0x29;
@@ -101,21 +104,28 @@
{
searchCount = 6;
ZbGateway.IsRemote = false;
+ //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
+ Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI);
}
else
{
if (searchCount < 0)
{
ZbGateway.IsRemote = true;
+ //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
+ Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
}
}
}
else
{
ZbGateway.IsRemote = true;
+ //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
+ Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
+
for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
{
- ZbGateway.GateWayList[i].DisConnectLocalMqttClient("1");
+ ZbGateway.GateWayList[i].DisConnectLocalMqttClient("1");
}
}
@@ -142,7 +152,11 @@
FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes);
}
}
- catch { }
+ catch
+ {
+ //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴
+ FindGateWaySocket.Stop();
+ }
System.Threading.Thread.Sleep(500);
}
})
@@ -182,7 +196,6 @@
getGatewayBaseInfo = new ZbGateway.GatewayBaseInfo
{
IpAddress = ipAddress,
- Time = time,
GwName = gwName,
HomeId = homeID,
IsMainGateWay = isMainGateWay,
@@ -204,11 +217,11 @@
{
gateWayList.Add(zbGateWay);
}
- //缃戝叧涓埌浣忓畢ID涓虹┖姝ゆ椂涔熼�氳
- else if (homeID == string.Empty)
- {
- gateWayList.Add(zbGateWay);
- }
+ //缃戝叧涓埌浣忓畢ID涓虹┖姝ゆ椂涔熼�氳 2020.01.14鍙樻洿锛氭病杩欎釜蹇呰,涓婇潰閭d釜鍙橀噺灏辫兘澶勭悊
+ //else if (homeID == string.Empty)
+ //{
+ // gateWayList.Add(zbGateWay);
+ //}
}
//缃戝叧鍒楄〃瀛樺偍澶勭悊
var gateWay = ZbGateway.GateWayList.Find(obj => obj.getGatewayBaseInfo != null && obj.getGatewayBaseInfo.gwID == zbGateWay.getGatewayBaseInfo.gwID);
@@ -234,7 +247,6 @@
else
{
gateWay.PubKey = pubKey;
- gateWay.getGatewayBaseInfo.Time = time;
gateWay.getGatewayBaseInfo.GwName = gwName;
gateWay.getGatewayBaseInfo.HomeId = homeID;
await gateWay.StartLocalMqtt(ipAddress);
@@ -255,10 +267,30 @@
//鏍囪褰撳墠缃戝叧鏄富缃戝叧
gateWay.getGatewayBaseInfo.IsMainGateWay = true;
}
+ }
+
+ //娴嬭瘯鑳藉惁骞挎挱寰楀埌缃戝叧,閫氬父鎯呭喌涓嬩笉妫�娴�
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.CheckCanReceiveGateway == 1)
+ {
+ if (Shared.Phone.UserCenter.UserCenterResourse.DicReceiveGatewayTest.ContainsKey(id) == false)
+ {
+ if (gateWay == null)
+ {
+ Shared.Phone.UserCenter.UserCenterResourse.DicReceiveGatewayTest[id] = zbGateWay;
+ }
+ else
+ {
+ Shared.Phone.UserCenter.UserCenterResourse.DicReceiveGatewayTest[id] = gateWay;
+ }
+ }
}
}
}
- catch { }
+ catch
+ {
+ //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴
+ FindGateWaySocket.Stop();
+ }
}
#endregion
}
@@ -276,48 +308,7 @@
try
{
//瀹氭椂妫�娴嬭繙绋嬭繛鎺ユ儏鍐�
- await ZbGateway.StartRemoteMqtt();
- if (!ZbGateway.IsRemote)
- {
- System.Threading.Thread.Sleep(500);
- continue;
- }
- var gateWayList =ZbGateway.GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId);
-
- if (gateWayList.Count == 1)
- {
- gateWayList[0].getGatewayBaseInfo.IsMainGateWay = true;
- }
- else
- {
- if (gateWayList.Find((obj) => obj.getGatewayBaseInfo.IsMainGateWay) == null)
- {
- for (int i = 0; i < gateWayList.Count; i++)
- {
- var gateWay = gateWayList[i];
- var info = await gateWay.GetZbGwInfoAsync();
- if (info == null || info.getGwData == null)
- {
- continue;
- }
- if (info.getGwData.IsDominant == 1)
- {
- for (int j = 0; j < gateWayList.Count; j++)
- {
- if (gateWayList[i].getGatewayBaseInfo.gwID == info.getGwData.GwId)
- {
- gateWayList[i].getGatewayBaseInfo.IsMainGateWay = true;
- }
- else
- {
- gateWayList[i].getGatewayBaseInfo.IsMainGateWay = false;
- }
- }
- break;
- }
- }
- }
- }
+ await ZbGateway.StartRemoteMqtt();
}
catch { }
System.Threading.Thread.Sleep(2000);
@@ -326,6 +317,14 @@
{ IsBackground = true }.Start();
}
+ /// <summary>
+ /// 閲嶆柊鎼滅储,娉ㄦ剰锛氳皟鐢ㄨ鏂规硶,鍒欎績浣垮叏閮ㄧ綉鍏崇殑mqtt鍏ㄩ儴鏂紑,鐒跺悗閲嶆柊鎼滅储(鍙兘浼氭湁1绉掑欢杩�)
+ /// </summary>
+ public static void ReSearch()
+ {
+ //涓轰簡閭d箞澶氬皯涓囧垎涔嬩竴鐨勫嚑鐜�,杩欓噷璁剧疆鎴愬埆鐨勫彟涓�绫荤殑鍊�
+ oldHomeID = "**";
+ }
/// <summary>
/// 鎺ユ敹澶勭悊UDP鏁版嵁鍖�
@@ -334,7 +333,7 @@
public static class FindGateWaySocket
{
//鏈湴Socket
- public static System.Net.Sockets.Socket busSocket;
+ public static Socket busSocket;
/// <summary>
/// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�
@@ -380,7 +379,7 @@
{
get
{
- return null == busSocket ? false : true;
+ return busSocket == null ? false : true;
}
}
--
Gitblit v1.8.0