From 0a0d7ec5080cd1f1802d9fcc96b08102b9b551f1 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 29 五月 2020 11:15:19 +0800
Subject: [PATCH] 2020-05-29-2
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 960 ++++++++++++++++++++++-------------------------------------
1 files changed, 360 insertions(+), 600 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index ea5c735..672bc3f 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -142,8 +142,10 @@
List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
foreach (var device in list)
{
- //鍒犻櫎璁惧锛屼笉鍒犻櫎鎴块棿淇℃伅
- Common.LocalDevice.Current.DeleteMemmoryDevice(device, false);
+ //鍒犻櫎涓�鑸澶�
+ Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+ //鍒犻櫎Ota璁惧
+ Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
}
//鍒犻櫎缃戝叧鏂囦欢
this.DeleteGatewayFile(gatewayId);
@@ -178,10 +180,18 @@
/// <returns></returns>
private ZbGateway GetGatewayFromFile(string file)
{
- byte[] filebyte = Global.ReadFileByHomeId(file);
- string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
- var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue);
- return gateway;
+ try
+ {
+ byte[] filebyte = Global.ReadFileByHomeId(file);
+ string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
+ var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue);
+ return gateway;
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex);
+ return null;
+ }
}
#endregion
@@ -194,7 +204,13 @@
/// <param name="zbGateway">缃戝叧</param>
/// <param name="mode">鏄惁鏄剧ず閿欒</param>
public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
- {
+ {
+ //璁剧疆缃戝叧鐨勭粡绾害
+ bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO);
+ if (falge == false)
+ {
+ return falge;
+ }
//鎵ц娣诲姞缃戝叧鍒板唴瀛�
var result = await this.DoAddGatewayToMemory(zbGateway, mode);
//鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
@@ -212,7 +228,7 @@
}
return false;
}
- if (result != 1)
+ if (result == -1)
{
return false;
}
@@ -415,6 +431,7 @@
/// 閲嶆柊缁戝畾缃戝叧(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
/// </summary>
/// <param name="zbGateway">缃戝叧</param>
+ /// <param name="btnMsg">娑堟伅鎺т欢</param>
public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
{
if (zbGateway == null)
@@ -422,6 +439,12 @@
//閿欒:缃戝叧瀵硅薄涓㈠け
string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
this.ShowTipMsg(msg);
+ return -1;
+ }
+ //璁剧疆缃戝叧鐨勭粡绾害
+ bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES);
+ if (falge == false)
+ {
return -1;
}
@@ -461,7 +484,7 @@
btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
});
}
- await System.Threading.Tasks.Task.Delay(8000);
+ await Task.Delay(8000);
//鑾峰彇缃戝叧鐨勪俊鎭�
var result = await zbGateway.GetZbGwInfoAsync();
@@ -473,15 +496,7 @@
return -1;
}
- if (result == null)
- {
- //鑾峰彇缃戝叧淇℃伅澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
- this.ShowTipMsg(msg);
- return -1;
- }
-
- if (result.getGwData == null)
+ if (result == null || result.getGwData == null)
{
//鑾峰彇缃戝叧淇℃伅澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
@@ -596,6 +611,9 @@
}
//鍒囨崲缃戝叧,淇濆瓨缂撳瓨
this.SaveGatewayIdToLocation(gatewayId);
+ //鍒囨崲缃戝叧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
+ UserView.UserPage.Instance.RefreshForm = true;
+
return true;
}
@@ -649,10 +667,10 @@
}
//鑾峰彇鍏ㄩ儴璁惧
- bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
+ int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
//鍏抽棴杩涘害鏉�
ProgressBar.Close();
- if (result == false)
+ if (result == -1)
{
return false;
}
@@ -701,15 +719,15 @@
bool result = await this.SetHomeIdToGateway(realWay, string.Empty);
if (result == false)
{
- //缃戝叧瑙g粦澶辫触
+ //缃戝叧瑙g粦澶辫触 涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
string msg = Language.StringByID(R.MyInternationalizationString.uGatewayUnBindFail);
- this.ShowErrorMsg(msg);
- return false;
+ //this.ShowErrorMsg(msg);
+ //return false;
}
}
//鍒犻櫎浜戠鐨勭綉鍏�
- await Phone.UserCenter.HdlGatewayLogic.Current.DeleteDataBaseGateway(zbGatewayID);
+ await this.DeleteDataBaseGateway(zbGatewayID);
//鍒犻櫎缃戝叧鏂囦欢
this.DeleteGatewayFile(zbGatewayID);
@@ -750,18 +768,21 @@
{
//鍒犻櫎璁惧鏂囦欢
Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+ //鍒犻櫎Ota璁惧
+ Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
}
//濡傛灉鏄富缃戝叧
if (this.IsMainGateway(zbGatewayID) == 1)
{
- foreach (var room in Shared.Common.Room.Lists)
+ var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
+ foreach (var room in listAllRoom)
{
//鍒犻櫎鍦烘櫙鏂囦欢
- foreach (var scene in room.SceneUIFilePathList)
+ foreach (var sceneId in room.ListSceneId)
{
- if (Global.IsExistsByHomeId(scene) == true)
+ if (Global.IsExistsByHomeId($"Scene_{sceneId}.json") == true)
{
- Global.DeleteFilebyHomeId(scene);
+ Global.DeleteFilebyHomeId($"Scene_{sceneId}.json");
}
}
}
@@ -776,9 +797,8 @@
/// 鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�(娉ㄦ剰,鍒锋柊鐨勬槸缂撳瓨,璇疯皟鐢–heckGatewayOnlineByFlag鏉ュ垽鏂槸鍚﹀湪绾�)
/// </summary>
/// <param name="listGateway"></param>
- /// <param name="waitTime">灞�鍩熺綉鐨勬椂鍊�,鏃跺�欑瓑寰�3绉掑欢杩�</param>
/// <returns></returns>
- public void RefreshGatewayOnlineStatu(List<ZbGateway> listGateway, bool waitTime = true)
+ public void RefreshGatewayOnlineStatu(List<ZbGateway> listGateway)
{
var listRealWay = new List<ZbGateway>();
for (int i = 0; i < listGateway.Count; i++)
@@ -793,29 +813,18 @@
{
//铏氭嫙鐗╃悊缃戝叧
listRealWay.Add(listGateway[i]);
- if (waitTime == false)
- {
- //涓嶇瓑寰呯殑璇�,鏍囪瘑鎸囧畾缃戝叧涓轰笉鍦ㄧ嚎
- this.SetGatewayNotOnLineFlag(listRealWay[i]);
- }
}
- if (waitTime == true)
- {
- //鍙湁绛夊緟鐨勬椂鍊�,鎵嶆爣璇嗘寚瀹氱綉鍏充负涓嶅湪绾�
- this.SetGatewayNotOnLineFlag(listRealWay[i]);
- }
+ //鏍囪瘑鎸囧畾缃戝叧涓轰笉鍦ㄧ嚎
+ listRealWay[i].GatewayOnlineFlage = false;
}
- if (waitTime == true)
+ //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟2绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage)
+ System.Threading.Thread.Sleep(2000);
+ //妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
+ if (this.CheckHadGatewayInWifi(listRealWay) == false)
{
- //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟2绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage)
- System.Threading.Thread.Sleep(2000);
- //妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
- if (this.CheckHadGatewayInWifi(listRealWay) == false)
- {
- //绗簩閬撳潕锛氬湪杩滅▼鐨勬儏鍐典笅鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�
- this.RefreshGatewayOnlineOnRemode(listRealWay);
- }
+ //绗簩閬撳潕锛氬湪杩滅▼鐨勬儏鍐典笅鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�
+ this.RefreshGatewayOnlineOnRemode(listRealWay);
}
//鍒锋柊缂撳瓨鐨勫湪绾挎爣璇�
@@ -827,7 +836,6 @@
continue;
}
this.dicGateway[gwID].GatewayOnlineFlage = zbway.GatewayOnlineFlage;
- this.dicGateway[gwID].ReSave();
}
}
@@ -869,26 +877,11 @@
continue;
}
string strId = this.GetGatewayId(way);
- if (dicDbGateway.ContainsKey(strId) == true //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
- && dicDbGateway[strId].MqttOnlineStatus == true //濡傛灉浜戠涓婇潰杩欎釜缃戝叧鏄湪绾跨殑
- )
+ if (dicDbGateway.ContainsKey(strId) == true) //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
{
- way.GatewayOnlineFlage = true;
+ way.GatewayOnlineFlage = dicDbGateway[strId].MqttOnlineStatus;
}
}
- }
-
- /// <summary>
- /// 鏍囪瘑鎸囧畾缃戝叧涓轰笉鍦ㄧ嚎
- /// </summary>
- /// <param name="zbGateway"></param>
- public void SetGatewayNotOnLineFlag(ZbGateway zbGateway)
- {
- if (zbGateway == null)
- {
- return;
- }
- zbGateway.GatewayOnlineFlage = false;
}
/// <summary>
@@ -1382,10 +1375,10 @@
if (mode == GetNameMode.SpecialGateway && localWay.getGwInfo != null)
{
string keyName = Common.LocalDevice.deviceModelIdName + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
- if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
{
- //娌℃湁鍚嶇О鏃讹紝鍒欎娇鐢≧鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
- return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]);
+ //娌℃湁鍚嶇О鏃讹紝鍒欎娇鐢≧鏂囦欢閲岄潰璁剧疆鐨勯粯璁よ澶囧悕绉�
+ return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
}
}
@@ -1424,10 +1417,10 @@
if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
{
string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
- if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
{
//浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
- button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
}
}
else
@@ -1442,10 +1435,10 @@
HdlThreadLogic.Current.RunMain(() =>
{
string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
- if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
{
//浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
- button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
}
});
}
@@ -1455,10 +1448,10 @@
else
{
string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
- if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
+ if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
{
//浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
- button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName];
+ button.TextID = Common.LocalDevice.Current.dicDeviceAllNameID[keyName];
}
}
}
@@ -1551,6 +1544,54 @@
#endregion
+ #region 鈻� 缃戝叧鎴块棿鐩稿叧_______________________
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧鎵�鍦ㄧ殑鎴块棿
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <returns></returns>
+ public Room GetRoomByGateway(ZbGateway zbGateway)
+ {
+ var gatewayId = this.GetGatewayId(zbGateway);
+ return this.GetRoomByGateway(gatewayId);
+ }
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧鎵�鍦ㄧ殑鎴块棿
+ /// </summary>
+ /// <param name="gatewayId">缃戝叧ID</param>
+ /// <returns></returns>
+ public Room GetRoomByGateway(string gatewayId)
+ {
+ var localGateway = this.GetLocalGateway(gatewayId);
+ if (localGateway == null)
+ {
+ return null;
+ }
+ return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
+ }
+
+ /// <summary>
+ /// 鍙樻洿缃戝叧鎴块棿
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="roomId">鎴块棿ID</param>
+ public void ChangedGatewayRoom(ZbGateway zbGateway, string roomId)
+ {
+ var gatewayId = this.GetGatewayId(zbGateway);
+ var localGateway = this.GetLocalGateway(gatewayId);
+ if (localGateway != null)
+ {
+ localGateway.RoomId = roomId;
+ localGateway.ReSave();
+ //娣诲姞澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
+ }
+ }
+
+ #endregion
+
#region 鈻� 娓呯┖鐪熷疄缃戝叧鍒楄〃___________________
/// <summary>
@@ -1619,8 +1660,11 @@
this.GetGwInfoAttribute(localWay, "ZbImageType").ToString(),
Convert.ToInt32(this.GetGwInfoAttribute(localWay, "ZbFWVersion")));
+ var list = new List<FirmwareVersionInfo>();
+ list.Add(gatewayFirmware);
+ list.Add(coordinatorFirmware);
+
//杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈
- FirmwareVersionInfo virtualFirmware = null;
string linImage = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
if (linImage != "6")
{
@@ -1628,28 +1672,32 @@
var listvVode = await HdlGatewayLogic.Current.GetListVDDriveCode(localWay);
if (listvVode != null && listvVode.Count > 0)
{
- //娣诲姞铏氭嫙椹卞姩鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�)
- flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
- listvVode[0].DriveHwVersion.ToString(),
- listvVode[0].DriveImageType.ToString());
-
- //铏氭嫙椹卞姩
- virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
- listvVode[0].DriveHwVersion.ToString(),
- listvVode[0].DriveImageType.ToString(),
- listvVode[0].DriveFwVersion);
-
- if (virtualFirmware != null)
+ foreach (var data in listvVode)
{
- virtualFirmware.VirtualCode = listvVode[0].DriveCode;
+ //娣诲姞铏氭嫙椹卞姩鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�)
+ flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
+ data.DriveHwVersion.ToString(),
+ data.DriveImageType.ToString());
+
+ //铏氭嫙椹卞姩
+ var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
+ data.DriveHwVersion.ToString(),
+ data.DriveImageType.ToString(),
+ data.DriveFwVersion);
+
+ if (virtualFirmware != null)
+ {
+ virtualFirmware.VirtualCode = data.DriveCode;
+ list.Add(virtualFirmware);
+ }
}
}
}
- var list = new List<FirmwareVersionInfo>();
- list.Add(gatewayFirmware);
- list.Add(coordinatorFirmware);
- list.Add(virtualFirmware);
-
+ if (list.Count == 2)
+ {
+ //铏氭嫙椹卞姩濡傛灉娌℃湁鏂扮増鏈殑璇濓紝鍥哄畾娣诲姞涓�涓┖鐨�
+ list.Add(null);
+ }
return list;
}
@@ -1840,274 +1888,16 @@
return;
}
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 85 } };
- realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
- }
-
- #endregion
-
- #region 鈻� 缃戝叧鐩戣___________________________
-
- #region 鈻� 鍙橀噺澹版槑___________________________
-
- /// <summary>
- /// 褰撳墠鐨勭綉缁滆繛鎺ユā寮�
- /// </summary>
- private GatewayConnectMode nowGwConnectMode = GatewayConnectMode.None;
- /// <summary>
- /// 鏄惁瀛樺湪缃戝叧姝e湪鍗囩骇
- /// </summary>
- private bool hadGatewayUpdate = false;
-
- #endregion
-
- #region 鈻� 缃戝叧杩炴帴鏂瑰紡鍙樻洿___________________
-
- /// <summary>
- /// 褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,妫�娴嬬綉鍏�,鐒跺悗鏄剧ず鐗规晥
- /// </summary>
- /// <param name="connectMode">缃戝叧鍙樻洿鍚庣殑杩炴帴鏂瑰紡</param>
- public void CheckGatewayByConnectChanged(GatewayConnectMode connectMode)
- {
- if (this.nowGwConnectMode == connectMode || this.hadGatewayUpdate == true)
+ if (this.IsGatewayExist(zbGateway) == true)
{
- //鐩稿悓鐨勮繛鎺ユā寮�,鎴栬�呮湁缃戝叧姝e湪鍗囩骇,鍒欎笉闇�瑕佹搷浣�
- return;
+ realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
}
-
- //娌℃湁缃戠粶
- if (connectMode == GatewayConnectMode.NoLine)
+ else
{
- nowGwConnectMode = GatewayConnectMode.NoLine;
- //鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- }
- //鍙互鍙�4G
- else if (connectMode == GatewayConnectMode.Remote)
- {
- nowGwConnectMode = GatewayConnectMode.Remote;
- //鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- this.CheckGatewayStatuByRemote();
- }
- //WIFI
- else if (connectMode == GatewayConnectMode.WIFI)
- {
- nowGwConnectMode = GatewayConnectMode.WIFI;
- //鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- this.CheckGatewayStatuByWIFI();
+ //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
+ realWay.SendLocation("GwLinuxLocate_Respon", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
}
}
-
- #endregion
-
- #region 鈻� 妫�鏌ョ綉鍏�(WIFI)_____________________
-
- /// <summary>
- /// 鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- /// </summary>
- private void CheckGatewayStatuByWIFI()
- {
- if (this.dicGateway.Count == 0)
- {
- //濡傛灉鏈湴閮芥病鏈夌綉鍏崇殑璇濓紝涓嶉渶瑕佸鐞�
- return;
- }
-
- HdlThreadLogic.Current.RunThread(() =>
- {
- var dicStatu = this.GetNowOnlineStatuBeforeCheck();
- //绛変釜3绉掞紝鍑嗗涓�涓�
- System.Threading.Thread.Sleep(3000);
- if (nowGwConnectMode != GatewayConnectMode.WIFI)
- {
- //缃戠粶涓存椂鍙樻洿锛燂紵
- return;
- }
-
- //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧
- List<ZbGateway> list = this.GetAllGatewayFromGateway();
- foreach (var way in list)
- {
- string gwId = this.GetGatewayId(way);
- if (this.dicGateway.ContainsKey(gwId) == true)
- {
- //鍒锋柊涓�涓嬬紦瀛�
- this.dicGateway[gwId].GatewayOnlineFlage = way.GatewayOnlineFlage;
- }
- if (this.CheckGatewayOnlineByFlag(way) == true)
- {
- //缃戝叧鍦ㄧ嚎
- dicStatu[gwId] = true;
- }
- }
- //灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
- this.PushGatewayOnlineStatuToForm(dicStatu);
- });
- }
-
- #endregion
-
- #region 鈻� 妫�鏌ョ綉鍏�(4G)_______________________
-
- /// <summary>
- /// 鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- /// </summary>
- private void CheckGatewayStatuByRemote()
- {
- if (this.dicGateway.Count == 0)
- {
- //濡傛灉鏈湴閮芥病鏈夌綉鍏崇殑璇濓紝涓嶉渶瑕佸鐞�
- return;
- }
-
- HdlThreadLogic.Current.RunThread(() =>
- {
- //鍏堣幏鍙栫幇鍦ㄥ叏閮ㄧ殑缃戝叧锛屽垵鏈熷�よ缃负涓嶅湪绾�
- var dicStatu = this.GetNowOnlineStatuBeforeCheck();
-
- //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
- Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
- if (nowGwConnectMode != GatewayConnectMode.Remote || dicDbGateway == null)
- {
- //缃戠粶涓存椂鍙樻洿锛燂紵
- return;
- }
-
- bool hadOnline = false;
- lock (dicGateway)
- {
- foreach (var way in this.dicGateway.Values)
- {
- //寰幆澶勭悊鏈湴鍏ㄩ儴鐨勭綉鍏冲垪琛�
- string gwId = this.GetGatewayId(way);
- if (dicDbGateway.ContainsKey(gwId) == true//濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
- && dicDbGateway[gwId].MqttOnlineStatus == true//濡傛灉浜戠涓婇潰杩欎釜缃戝叧鏄湪绾跨殑
- )
- {
- dicGateway[gwId].GatewayOnlineFlage = true;
- //瀹冩槸鍦ㄧ嚎鐨�
- dicStatu[gwId] = true;
- hadOnline = true;
- }
- }
- }
-
- //灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
- this.PushGatewayOnlineStatuToForm(dicStatu);
-
- //濡傛灉娌℃湁缃戝叧鍦ㄧ嚎
- if (hadOnline == false)
- {
- //杩滅▼杩炴帴瓒呮椂,娌℃湁缃戝叧鍦ㄧ嚎
- string msg = Language.StringByID(R.MyInternationalizationString.uRemoteTimeOutAndNotGatewaiOnline);
- //this.ShowTipMsg(msg);
- }
- });
- }
-
- #endregion
-
- #region 鈻� 妫�鏌ョ綉鍏�(鏃犵綉缁�)___________________
-
- /// <summary>
- /// 鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��(缃戠粶鍙樻洿鏃惰Е鍙�)
- /// </summary>
- private void CheckGatewayStatuByNotNet()
- {
- //褰撳墠鏃犵綉缁滆繛鎺�,璇风‘璁ょ綉缁�
- string msg = Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork);
- this.ShowTipMsg(msg);
- }
-
- #endregion
-
- #region 鈻� 缃戝叧鎺ㄩ�乢__________________________
-
- /// <summary>
- /// 灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
- /// </summary>
- /// <param name="dicStatu"></param>
- private void PushGatewayOnlineStatuToForm(Dictionary<string, bool> dicStatu)
- {
- List<ZbGateway> listChange = new List<ZbGateway>();
- List<bool> listChangeStatu = new List<bool>();
- foreach (string gwid in dicStatu.Keys)
- {
- //缃戝叧涓嶅锛岀洿鎺ユ帹閫�,涓嶅垽鏂槸鍚︽敼鍙樹簡
- ZbGateway zbGateway = this.GetLocalGateway(gwid);
- if (zbGateway != null)
- {
- listChange.Add(zbGateway);
- listChangeStatu.Add(dicStatu[gwid]);
-
- zbGateway.GatewayOnlineFlage = dicStatu[gwid];
- }
- }
-
- if (listChange.Count == 0)
- {
- return;
- }
- //淇濆瓨褰撳墠婵�娲荤殑鐣岄潰ID
- var listId = new List<string>();
- listId.AddRange(UserCenterResourse.listActionFormId);
- for (int i = 0; i < listId.Count; i++)
- {
- if (UserCenterResourse.DicActionForm.ContainsKey(listId[i]) == false)
- {
- continue;
- }
- //缃戝叧鍦ㄧ嚎鎺ㄩ��
- for (int j = 0; j < listChange.Count; j++)
- {
- UserCenterResourse.DicActionForm[listId[i]]?.GatewayOnlinePush(listChange[j], listChangeStatu[j]);
- }
- }
- }
-
- #endregion
-
- #region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <summary>
- /// 璁剧疆瀛樺湪缃戝叧姝e湪鍗囩骇鐨勬爣璇�
- /// </summary>
- /// <param name="update">鏄惁鏈夌綉鍏冲湪鍗囩骇</param>
- public void SetHadGatewayUpdateFlage(bool update)
- {
- this.hadGatewayUpdate = update;
- }
-
- /// <summary>
- /// 鍦ㄧ綉缁滆繛鎺ュ彉鏇翠箣鍚庯紝缃戝叧杩炴帴妫�娴嬩箣鍓嶏紝璁剧疆鍏ㄩ儴缃戝叧涓虹绾跨姸鎬�(浠ユ湰鍦扮綉鍏充负鏍囧噯)
- /// </summary>
- /// <returns></returns>
- private Dictionary<string, bool> GetNowOnlineStatuBeforeCheck()
- {
- //鍏堣幏鍙栫幇鍦ㄥ叏閮ㄧ殑缃戝叧
- List<ZbGateway> listOldGateway = this.GetAllGatewayFromGateway();
- var dicOldZb = new Dictionary<string, ZbGateway>();
- foreach (var zb in listOldGateway)
- {
- string gwID = this.GetGatewayId(zb);
- dicOldZb[gwID] = zb;
- }
-
- var dicStatu = new Dictionary<string, bool>();
- lock (dicGateway)
- {
- foreach (string gwId in this.dicGateway.Keys)
- {
- if (dicOldZb.ContainsKey(gwId) == true)
- {
- //鏍囪涓轰笉鍦ㄧ嚎
- this.SetGatewayNotOnLineFlag(dicOldZb[gwId]);
- }
- dicStatu[gwId] = false;
- }
- }
- return dicStatu;
- }
-
- #endregion
#endregion
@@ -2129,7 +1919,7 @@
bool canBreak = false;
HdlThreadLogic.Current.RunThread(async () =>
{
- List<string> list = new List<string>() { "NotSetAgain" };
+ List<string> list = new List<string>() { "NotSetAgain", "NotCheck" };
//璁剧疆璁块棶鎺ュ彛鐨勫弬鏁�
var pra = new GetGatewayPra();
@@ -2180,15 +1970,19 @@
/// <param name="gateway">缃戝叧瀵硅薄</param>
/// <param name="Longitude">缁忓害</param>
/// <param name="Latitude">缁村害</param>
+ /// <param name="mode">鏄剧ず閿欒</param>
/// <returns></returns>
- public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude)
+ public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
{
ZbGateway realWay = null;
if (this.GetRealGateway(ref realWay, gateway) == false)
{
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
+ if (mode == ShowErrorMode.YES)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ }
return false;
}
@@ -2213,7 +2007,15 @@
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
jObject.Add("Data", data);
- realWay.Send("Logic/SetSite", jObject.ToString());
+ if (this.IsGatewayExist(gateway) == true)
+ {
+ realWay.Send("Logic/SetSite", jObject.ToString());
+ }
+ else
+ {
+ //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
+ realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
+ }
int TimeOut = 0;
while (result == -1 && TimeOut < 30)
@@ -2225,13 +2027,16 @@
realWay.Actions -= action;
if (result != 0)
{
- //璁剧疆缃戝叧缁忕含搴﹀け璐�
- string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
- if (result == -1)
+ if (mode == ShowErrorMode.YES)
{
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ //璁剧疆缃戝叧缁忕含搴﹀け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
+ if (result == -1)
+ {
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ }
+ this.ShowTipMsg(msg);
}
- this.ShowTipMsg(msg);
return false;
}
@@ -2253,7 +2058,7 @@
//鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
- List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord" };
+ List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotSetAgain" };
bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError);
if (result == false)
@@ -2347,13 +2152,13 @@
#region 鈻� 涓婁紶璁惧澶囦唤鍒扮綉鍏砡________________
/// <summary>
- /// 涓婁紶璁惧澶囦唤鍒扮綉鍏�(鏈�濂戒笉瑕佸幓鐞嗗畠鐨勮繑鍥炵粨鏋�)
+ /// 涓婁紶璁惧澶囦唤鍒扮綉鍏�(搴熷純)
/// </summary>
/// <param name="device">璁惧瀵硅薄</param>
/// <param name="backupEnum">澶囦唤绫诲瀷</param>
/// <param name="upLaodData">澶囦唤鐨勬暟鎹�</param>
/// <returns></returns>
- public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData)
+ public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, object upLaodData)
{
//ZbGateway realWay = null;
//if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
@@ -2381,253 +2186,208 @@
#endregion
- #region 鈻� 鎭㈠缃戝叧___________________________
+ #region 鈻� 缃戝叧鐩戣___________________________
/// <summary>
- /// 鎭㈠缃戝叧閰嶇疆
+ /// 褰撳墠鐨勭綉缁滆繛鎺ユā寮�
/// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <param name="listGatewayFile">缃戝叧閲岄潰鎷ユ湁鐨勬枃浠�</param>
- /// <param name="backDirectory">浜戠涓嬭浇鐨勫浠芥暟鎹殑鏂囦欢澶瑰悕瀛�</param>
- /// <returns></returns>
- public async Task<bool> RecoverGatewaySettion(ZbGateway zbGateway, List<string> listGatewayFile, string backDirectory)
+ private GatewayConnectMode nowGwConnectMode = GatewayConnectMode.None;
+ /// <summary>
+ /// 鏄惁瀛樺湪缃戝叧姝e湪鍗囩骇
+ /// </summary>
+ private bool hadGatewayUpdate = false;
+
+ /// <summary>
+ /// 褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
+ /// </summary>
+ /// <param name="connectMode">缃戝叧鍙樻洿鍚庣殑杩炴帴鏂瑰紡</param>
+ public void CheckGatewayByConnectChanged(GatewayConnectMode connectMode)
{
- //鑾峰彇浠庝簯绔偅閲屽緱鏉ョ殑鍏ㄩ儴鏂囦欢
- var listBackFile = HdlAutoBackupLogic.GetFileFromDirectory(UserCenterLogic.CombinePath(backDirectory));
- listBackFile.Sort();
- //娣诲姞闄勫姞鎯呮姤:杩樺師璁惧閰嶇疆
- ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uRecoverDeviceSettion));
- ProgressBar.SetMaxValue(listBackFile.Count);
- ProgressBar.Show();
-
- var listSaveFile = new HashSet<string>();
- foreach (string fileName in listBackFile)
- {
- if (fileName.Length < 10 || fileName.StartsWith("Device_") == false)
- {
- //涓嶆槸璁惧澶囦唤鏂囦欢
- continue;
- }
- //鎭㈠璁惧閰嶇疆
- var result = await this.RecoverDeviceSettion(backDirectory, fileName);
- if (result == -1)
- {
- ProgressBar.Close();
- return false;
- }
- if (result == 1 || result == 2)
- {
- listSaveFile.Add(fileName);
- }
-
- ProgressBar.SetValue(1);
- listGatewayFile.Remove(fileName);
- }
- //娣诲姞闄勫姞鎯呮姤:瑕嗙洊缃戝叧澶囦唤涓�
- ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uGatewayBackupDataIsCovering));
- foreach (var file in listSaveFile)
- {
- //鍒涘缓鏂囦欢瀵硅薄
- var result = await zbGateway.CreateFileAsync(file);
- if (result == null || result.Result != 0)
- {
- Application.RunOnMainThread(() =>
- {
- //瑕嗙洊缃戝叧澶囦唤澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uCoverGatewayBackupDataFail);
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
- });
- ProgressBar.Close();
- return false;
- }
- //鍙戦�佹暟鎹祦
- var byteData = Shared.Common.Global.ReadFileByDirectory(backDirectory, file);
- var result2 = await zbGateway.SendFileAsync(byteData);
- if (result2 == null || result2.Result != 0)
- {
- Application.RunOnMainThread(() =>
- {
- //瑕嗙洊缃戝叧澶囦唤澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uCoverGatewayBackupDataFail);
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
- });
- ProgressBar.Close();
- return false;
- }
- }
- //鍒犻櫎澶氫綑鐨勬枃浠�
- foreach (var deleteFile in listGatewayFile)
- {
- if (deleteFile.Length > 12)
- {
- string deviceFileName = deleteFile.Substring(5);
- if (deviceFileName.StartsWith("Device_") == false)
- {
- //涓嶆槸璁惧鏂囦欢
- continue;
- }
- string[] strArry = deviceFileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
- if (strArry.Length < 4 || listSaveFile.Contains(deleteFile) == true)
- {
- //鎴戜篃涓嶇煡閬撳畠鏄粈涔堟枃浠�,鎴栬�呰繖涓枃浠舵槸瑕嗙洊鐨�
- continue;
- }
- //杩欎釜鎴栬鍙互涓嶇悊浠�
- var result = await zbGateway.DelFileOrDirAsync("/etc/hdlDat/" + deleteFile);
- }
- }
- ProgressBar.Close();
-
- return true;
+ this.nowGwConnectMode = connectMode;
}
/// <summary>
- /// 鎭㈠璁惧閰嶇疆
+ /// 寮�鍚娴嬬綉鍏冲湪绾跨姸鎬佺殑绾跨▼(姝ゆ柟娉曟槸缁欒澶囧垪琛ㄧ晫闈㈢敤鐨�)
/// </summary>
- /// <param name="backDirectory">浜戠涓嬭浇鐨勫浠芥暟鎹殑鏂囦欢澶瑰悕瀛�</param>
- /// <param name="backFileName">缃戝叧鐨勮澶囧浠藉悕瀛�</param>
- /// <returns></returns>
- private async Task<int> RecoverDeviceSettion(string backDirectory, string backFileName)
+ /// <param name="frameLayout">鐣岄潰瀵硅薄</param>
+ public void StartCheckGatewayOnlineThread(EditorCommonForm frameLayout)
{
- string deviceFileName = backFileName.Substring(0, backFileName.Length - 5);
- string[] strArry = deviceFileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
- if (strArry.Length < 4)
+ HdlThreadLogic.Current.RunThread(() =>
{
- //鎴戜篃涓嶇煡閬撳畠鏄粈涔堟枃浠�
- return 0;
- }
- var device = Common.LocalDevice.Current.GetDevice(strArry[2], Convert.ToInt32(strArry[3]));
- if (device == null)
- {
- //杩欎釜璁惧涓嶈浜�
- return 2;
- }
-
- var byteData = Shared.Common.Global.ReadFileByDirectory(backDirectory, backFileName);
- var backType = (GatewayBackupEnum)Convert.ToInt32(backFileName.Substring(backFileName.Length - 5, 5));
-
- bool result = true;
- if (backType == GatewayBackupEnum.AMac鍚嶇О)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await Common.LocalDevice.Current.ReMacName(new List<CommonDevice>() { device }, recoverData);
- }
- else if (backType == GatewayBackupEnum.A绔偣鍚嶇О)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await Common.LocalDevice.Current.ReName(device, recoverData);
- }
- else if (backType == GatewayBackupEnum.APir鐏厜閰嶇疆)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
- }
- else if (backType == GatewayBackupEnum.A骞叉帴鐐归鑹茶皟鑺�)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.KeyColorData>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDevicePanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
- }
- else if (backType == GatewayBackupEnum.A骞叉帴鐐逛寒搴﹁皟鑺�)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
- int directionsLevel = Convert.ToInt32(recoverData["directionsLevel"]);
- int backlightLevel = Convert.ToInt32(recoverData["backlightLevel"]);
- result = await HdlDevicePanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
- }
- else if (backType == GatewayBackupEnum.A骞叉帴鐐硅妭鑳芥ā寮�)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
- bool modeEnable = Convert.ToBoolean(recoverData["modeEnable"]);
- int modeTime = Convert.ToInt32(recoverData["modeTime"]);
- int level = Convert.ToInt32(recoverData["level"]);
- result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
- }
- else if (backType == GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�)
- {
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
- }
- else if (backType == GatewayBackupEnum.A绐楀笜鏂瑰悜)
- {
- var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDeviceCurtainLogic.Current.SetCurtainDirection((Rollershade)device, statu);
- }
- else if (backType == GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗)
- {
- var statu = Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDeviceCurtainLogic.Current.SetHandPullControl((Rollershade)device, statu);
- }
- else if (backType == GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅)
- {
- var curtainDevice = (Rollershade)device;
- var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
- int upLimit = Convert.ToInt32(recoverData["upLimit"]);
- int downLimit = Convert.ToInt32(recoverData["downLimit"]);
- //鍏堥噸缃獥甯�
- result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
- if (result == false) { return -1; }
- await Task.Delay(5000);
- //閲嶇疆涓婇檺浣�
- result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.UpLimit);
- if (result == false) { return -1; }
- //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
- curtainDevice.WcdGoToTiltValue(upLimit);
- await Task.Delay(3000);
- //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
- result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit, -1, -1);
- if (result == false) { return -1; }
-
- await Task.Delay(2000);
- //閲嶇疆涓嬮檺浣�
- result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.DownLimit);
- if (result == false) { return -1; }
- //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
- curtainDevice.WcdGoToTiltValue(downLimit);
- await Task.Delay(3000);
- //鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣
- result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit, -1, -1);
- }
- else if (backType == GatewayBackupEnum.A绌鸿皟鑷畾涔夋ā寮�)
- {
- var data = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
- result = await HdlDeviceAirConditionerLogic.Current.SetAcModeSupport((AC)device, data);
- if (result == true)
+ int waitCount = 0;
+ //濡傛灉浣忓畢ID鍙樻洿浜�,鍒欎笉鍐嶅鐞�
+ while (frameLayout.Parent != null)
{
- //杞崲涓轰簩杩涘埗
- var value = Convert.ToString(data, 2).PadLeft(16, '0');
- //杩欎簲涓缃槸鏀惧湪鍚庨潰鐨�
- var fixValue = value.Substring(0, value.Length - 5);
- var reportValue = value.Substring(fixValue.Length);
- //鏇存敼缂撳瓨
- for (int i = 0; i < reportValue.Length; i++)
+ System.Threading.Thread.Sleep(1000);
+ if (this.hadGatewayUpdate == true)
{
- ((AC)device).listSupportMode[i] = Convert.ToInt32(reportValue[i]);
+ //缃戝叧姝e湪鍗囩骇,涓嶉渶瑕佹搷浣�
+ continue;
}
- device.ReSave();
+
+ waitCount++;
+ if (this.nowGwConnectMode == GatewayConnectMode.Remote)
+ {
+ //杩滅▼姣�20绉掓娴嬩竴娆�
+ if (waitCount < 20) { continue; }
+ }
+ else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
+ {
+ //灞�鍩熺綉姣�5绉掓娴嬩竴娆�
+ if (waitCount < 5) { continue; }
+ }
+ waitCount = 0;
+
+ //鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
+ Dictionary<string, bool> dicOldOnline = this.GetOldGatewayOnlineStatu();
+ if (dicOldOnline == null)
+ {
+ //鍒欎笉澶勭悊
+ continue;
+ }
+ //鍙互鍙�4G
+ if (this.nowGwConnectMode == GatewayConnectMode.Remote)
+ {
+ //鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ this.CheckGatewayStatuByRemote(dicOldOnline);
+ }
+ //WIFI
+ else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
+ {
+ //鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ this.CheckGatewayStatuByWIFI(dicOldOnline);
+ }
+ }
+ }, ShowErrorMode.NO);
+ }
+
+ /// <summary>
+ /// 鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ /// </summary>
+ private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
+ {
+ //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧
+ List<ZbGateway> list = this.GetAllGatewayFromGateway();
+ foreach (var way in list)
+ {
+ //灏嗘爣璇嗙疆涓篺alse
+ way.GatewayOnlineFlage = false;
+ }
+ //绛変釜2绉�
+ System.Threading.Thread.Sleep(2000);
+
+ foreach (var way in list)
+ {
+ string gwId = this.GetGatewayId(way);
+ if (dicOldOnline.ContainsKey(gwId) == true)
+ {
+ //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ�佸惂
+ this.PushGatewayOnlineStatuToForm(gwId, way.GatewayOnlineFlage);
+ }
+ else
+ {
+ //娌℃湁鍖呭惈,榛樿涓篺alse
+ this.PushGatewayOnlineStatuToForm(gwId, false);
}
}
- return result == true ? 1 : -1;
+ }
+
+ /// <summary>
+ /// 鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ /// </summary>
+ private void CheckGatewayStatuByRemote(Dictionary<string, bool> dicOldOnline)
+ {
+ //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
+ Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
+ if (dicDbGateway == null)
+ {
+ //濡傛灉缃戠粶涓嶉��,鍒欎篃寰�涓嬭蛋
+ dicDbGateway = new Dictionary<string, GatewayResult>();
+ }
+
+ foreach (var gwId in dicOldOnline.Keys)
+ {
+ //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
+ if (dicDbGateway.ContainsKey(gwId) == true)
+ {
+ //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ��
+ this.PushGatewayOnlineStatuToForm(gwId, dicDbGateway[gwId].MqttOnlineStatus);
+ }
+ else
+ {
+ //浜戠涓嶅寘鍚殑,褰撲笉鍦ㄧ嚎澶勭悊
+ this.PushGatewayOnlineStatuToForm(gwId, false);
+ }
+ }
+
+
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
+ /// </summary>
+ /// <returns></returns>
+ private Dictionary<string, bool> GetOldGatewayOnlineStatu()
+ {
+ if (this.dicGateway.Count == 0)
+ {
+ //娌℃湁缃戝叧,鍒欎笉澶勭悊
+ return null;
+ }
+
+ try
+ {
+ var dicOldOnline = new Dictionary<string, bool>();
+ //濡傛灉鍦ㄥ惊鐜殑杩囩▼涓�,鍔ㄤ簡閲岄潰鐨勪笢瑗�,鎶ラ敊鍒欎笉鐞嗗畠,涓嬩竴鍥炲悎
+ foreach (var zbway in this.dicGateway.Values)
+ {
+ //鑾峰彇鍓嶅洖鐨勫湪绾跨姸鎬�
+ string gwId = this.GetGatewayId(zbway);
+ dicOldOnline[gwId] = zbway.GatewayOnlineFlage;
+ }
+ return dicOldOnline;
+ }
+ catch { return null; }
+ }
+
+ /// <summary>
+ /// 灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
+ /// </summary>
+ /// <param name="gwId"></param>
+ /// <param name="online"></param>
+ private void PushGatewayOnlineStatuToForm(string gwId, bool online)
+ {
+ try
+ {
+ for (int i = 0; i < UserCenterResourse.listActionFormId.Count; i++)
+ {
+ string formId = UserCenterResourse.listActionFormId[i];
+ if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
+ {
+ continue;
+ }
+ //缃戝叧鍦ㄧ嚎鎺ㄩ��
+ var zbway = this.GetLocalGateway(gwId);
+ zbway.GatewayOnlineFlage = online;
+
+ UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online);
+ }
+ }
+ catch { }
+ }
+
+ /// <summary>
+ /// 璁剧疆瀛樺湪缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+ /// </summary>
+ /// <param name="update">鏄惁鏈夌綉鍏冲湪鍗囩骇</param>
+ public void SetHadGatewayUpdateFlage(bool update)
+ {
+ this.hadGatewayUpdate = update;
}
#endregion
- #region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <summary>
- /// 寮瑰嚭缃戝叧涓嶅湪绾跨殑
- /// </summary>
- private void ShowGatewayNotOnlineMsg()
- {
- Application.RunOnMainThread(() =>
- {
- //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁�
- string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork);
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
- });
- }
+ #region 鈻� 涓�鑸柟娉昣__________________________
/// <summary>
/// 鏄剧ず閿欒淇℃伅绐楀彛
--
Gitblit v1.8.0