| | |
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(gateway, result);
|
| | | }
|
| | | if (gateway.HomeId == string.Empty)
|
| | | {
|
| | | gateway.HomeId = Config.Instance.Home.Id;
|
| | | }
|
| | | return gateway;
|
| | | }
|
| | | catch (Exception ex)
|
| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | /// <param name="logMode">是否写Log</param> |
| | | public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO) |
| | | {
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | | if (falge == false)
|
| | | {
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 设置经纬度失败");
|
| | | }
|
| | | return falge;
|
| | | } |
| | | //执行添加网关到内存 |
| | | var result = await this.DoAddGatewayToMemory(zbGateway, mode); |
| | | var result = this.DoAddGatewayToMemory(zbGateway, mode, logMode); |
| | | //前的网关绑定在了当前账号下的不同住宅里面
|
| | | if (result == 0)
|
| | | {
|
| | |
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 网关绑定在了当前账号下的不同住宅里面,云端不给绑定");
|
| | | }
|
| | | return false;
|
| | | }
|
| | | if (result == -1)
|
| | |
| | | //添加网关的话,强制主页刷新 |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | |
| | | if (Config.Instance.Home.TemplateMode == 2)
|
| | | {
|
| | | //如果这个类型的网关只有一个模板,则自动匹配
|
| | | var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
|
| | | if (dicName.Count == 1)
|
| | | {
|
| | | foreach (var tempId in dicName.Keys)
|
| | | {
|
| | | TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return true; |
| | | }
|
| | |
|
| | |
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <param name="logMode">是否写Log</param>
|
| | | /// <returns></returns>
|
| | | private async Task<int> DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
|
| | | private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO)
|
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | return -1;
|
| | | }
|
| | | //获取网关的信息
|
| | | var result = await zbGateway.GetZbGwInfoAsync();
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | var result = this.GetGatewayInfo(zbGateway, true, mode);
|
| | | if (result == null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | if (result.getGwData == null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | //获取网关信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | | this.ShowTipMsg(msg);
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 获取网关信息失败");
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //设置住宅ID到网关
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | if (flage2 == false)
|
| | | if (result.HomeId != Common.Config.Instance.HomeId)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | if (flage2 == false)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
|
| | | this.ShowTipMsg(msg);
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 向网关设置住宅ID失败");
|
| | | }
|
| | | return -1;
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //更新云端数据库
|
| | |
| | | }
|
| | |
|
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | this.dicGateway[gwID].OnlineTime = DateTime.Now;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | |
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="HomeId"></param>
|
| | | /// <returns></returns> |
| | | public async Task<bool> SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
|
| | | public bool SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | //账号ID
|
| | | string accountId = string.Empty;
|
| | | if (HomeId != string.Empty)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 1)
|
| | | {
|
| | | //主账号
|
| | | accountId = Config.Instance.Guid;
|
| | | }
|
| | | else
|
| | | {
|
| | | accountId = Config.Instance.Home.MainUserDistributedMark;
|
| | | }
|
| | | }
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "HomeId", HomeId }, { "AccountId", accountId } };
|
| | | jObject.Add("Data", data);
|
| | | //住宅ID的设置,固定使用局域网,不存在远程的说法
|
| | | var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
|
| | | if (result.ErrorMsgDiv == -1)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | |
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | var info = await realWay.GwSetHomeIdAsync(HomeId);
|
| | | if (info != null && info.gwSetHomeIdData != null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return true;
|
| | | return false;
|
| | | }
|
| | | return false;
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }); |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false); |
| | | if (result == "Error")
|
| | | {
|
| | | return -1;
|
| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="btnMsg">消息控件</param> |
| | | public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | public int ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //设置住宅ID到网关
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
|
| | | bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
|
| | | if (flage2 == false)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | |
| | | btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
|
| | | });
|
| | | }
|
| | | await Task.Delay(8000);
|
| | | System.Threading.Thread.Sleep(8000);
|
| | |
|
| | | //获取网关的信息
|
| | | ZbGatewayData.GetGwAllData result = null;
|
| | | ZbGatewayData.GetGwData result = null;
|
| | | int count = 5;
|
| | | while (count >= 0)
|
| | | {
|
| | | result = await zbGateway.GetZbGwInfoAsync();
|
| | | if (result != null && result.getGwData != null)
|
| | | result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | break;
|
| | | }
|
| | | count--;
|
| | | //最多再等20秒
|
| | | await Task.Delay(4000);
|
| | | System.Threading.Thread.Sleep(4000);
|
| | | }
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | return -1;
|
| | | }
|
| | |
|
| | | if (result == null || result.getGwData == null)
|
| | | if (result == null)
|
| | | {
|
| | | //获取网关信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | |
| | | }
|
| | |
|
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | this.dicGateway[gwID].OnlineTime = DateTime.Now;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | |
| | |
|
| | | //添加网关的话,强制主页刷新
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | |
|
| | | if (Config.Instance.Home.TemplateMode == 2)
|
| | | {
|
| | | //如果这个类型的网关只有一个模板,则自动匹配
|
| | | var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
|
| | | if (dicName.Count == 1)
|
| | | {
|
| | | foreach (var tempId in dicName.Keys)
|
| | | {
|
| | | TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return 1; |
| | | } |
| | |
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 91 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "GwName", gatewayName } };
|
| | | jObject.Add("Data", data);
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GwReName", jObject.ToString(), "GwReName_Respon");
|
| | | var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GwReName", jObject.ToString(), "GwReName_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | |
| | | /// 执行切换网关操作
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | public async Task<bool> DoSwitchGateway(string gatewayId)
|
| | | public bool DoSwitchGateway(string gatewayId)
|
| | | {
|
| | | var zbGateway = this.GetLocalGateway(gatewayId);
|
| | | if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
|
| | | //重新获取在线网关的信息
|
| | | var result = this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | //重新获取在线网关的信息
|
| | | var result = await this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | //切换网关,保存缓存
|
| | | this.SaveGatewayIdToLocation(gatewayId);
|
| | | //切换网关的话,主页需要重新刷新
|
| | |
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
|
| | | private bool GetOnlineGatewayInfo(string gatewayId)
|
| | | {
|
| | | //显示进度条
|
| | | ProgressBar.Show();
|
| | |
| | | //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
|
| | | if (this.HomeIdIsEmpty(realWay.HomeId) == true)
|
| | | {
|
| | | int result2 = await this.ReBindNewGateway(realWay);
|
| | | int result2 = this.ReBindNewGateway(realWay);
|
| | | if (result2 == 0)
|
| | | {
|
| | | //出现未知错误,请稍后再试
|
| | |
| | | if (getGatewayInfo == true)
|
| | | {
|
| | | //获取网关信息
|
| | | var info = this.GetGatewayInfo(realWay);
|
| | | var info = this.GetGatewayInfo(realWay, false);
|
| | | if (info == null)
|
| | | {
|
| | | //关闭进度条
|
| | |
| | | return false;
|
| | | }
|
| | | }
|
| | | //刷新全部场景
|
| | | if (this.IsMainGateway(realWay) == 1)
|
| | | {
|
| | | HdlSceneLogic.Current.RefreshSceneUIList(false);
|
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false);
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | if (result == -1)
|
| | |
| | | /// <summary> |
| | | /// 删除网关,包括云端和本地(失败时不会显示信息,并且会返回true) |
| | | /// </summary> |
| | | /// <param name="zbGateway"></param> |
| | | public async Task<bool> DeleteGateway(ZbGateway zbGateway) |
| | | { |
| | | //移除本地网关信息 |
| | | return await this.DeleteGateway(zbGateway.GwId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除网关,包括云端和本地(失败时不会显示信息,并且会返回true) |
| | | /// </summary> |
| | | /// <param name="zbGatewayID"></param> |
| | | public async Task<bool> DeleteGateway(string zbGatewayID) |
| | | public bool DeleteGateway(string zbGatewayID) |
| | | {
|
| | | ZbGateway realWay = null;
|
| | | bool hadReal = this.GetRealGateway(ref realWay, zbGatewayID);
|
| | |
|
| | | //暂不支持分享
|
| | | if (hadReal == true && realWay.GatewayOnlineFlage == true)
|
| | | this.GetRealGateway(ref realWay, zbGatewayID);
|
| | | //清空网关的住宅ID 网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | if (realWay != null)
|
| | | {
|
| | | //清空网关的住宅ID
|
| | | bool result = await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | //网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayUnBindFail);
|
| | | //this.ShowErrorMsg(msg);
|
| | | //return false;
|
| | | }
|
| | | this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | //删除云端的网关
|
| | |
| | | //移除 |
| | | ZbGateway.GateWayList.RemoveAll((obj) => obj.GwId == zbGatewayID); |
| | | //断开mqtt连接 |
| | | realWay.DisConnectLocalMqttClient("GD"); |
| | | if (realWay != null)
|
| | | {
|
| | | realWay.CloseLocalConnectionOnForce();
|
| | | } |
| | | |
| | | return true; |
| | | }
|
| | |
| | | //虚拟物理网关
|
| | | listRealWay.Add(listGateway[i]);
|
| | | }
|
| | | //标识指定网关为不在线
|
| | | listRealWay[i].GatewayOnlineFlage = false;
|
| | | }
|
| | |
|
| | | //这是第一道坎,强制检查WIFI:等待2秒(因为wifi的时候,它会自动去刷新flage)
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | //检查是否拥有网关存在于WIFi下
|
| | | if (this.CheckHadGatewayInWifi(listRealWay) == false)
|
| | | {
|
| | | //第二道坎:在远程的情况下刷新网关的在线状态
|
| | | this.RefreshGatewayOnlineOnRemode(listRealWay);
|
| | | }
|
| | |
|
| | | //刷新缓存的在线标识
|
| | | foreach (var zbway in listRealWay)
|
| | | {
|
| | | string gwID = zbway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == false)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbway.GatewayOnlineFlage;
|
| | | }
|
| | | //wifi情况下,由Application自己刷新标识
|
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | {
|
| | | foreach (var zbway in listGateway)
|
| | | {
|
| | | //是否存在网关存在于WIFI下
|
| | | if (zbway.GatewayOnlineFlage == true)
|
| | | //如果广播得到网关,则会刷新OnlineTime,如果与当前时间相差少于指定秒数,则判断为存在网关存在于WIFI下
|
| | | if ((DateTime.Now - zbway.OnlineTime).TotalSeconds <= ZigBee.Common.Application.SendTime * 2)
|
| | | {
|
| | | return true;
|
| | | }
|
| | |
| | | private void RefreshGatewayOnlineOnRemode(List<ZbGateway> listGateway)
|
| | | {
|
| | | //获取云端上面的网关
|
| | | Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
|
| | | Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
|
| | | if (dicDbGateway == null)
|
| | | {
|
| | | return;
|
| | |
| | | continue;
|
| | | }
|
| | | string strId = way.GwId;
|
| | | if (dicDbGateway.ContainsKey(strId) == true) //如果云端上面有这个网关
|
| | | if (dicDbGateway.ContainsKey(strId) == true
|
| | | && dicDbGateway[strId].MqttOnlineStatus == true) //如果云端上面有这个网关
|
| | | {
|
| | | way.GatewayOnlineFlage = dicDbGateway[strId].MqttOnlineStatus;
|
| | | way.OnlineTime = DateTime.Now;
|
| | | }
|
| | | }
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 根据某种标识判断指定网关是否在线
|
| | | /// 根据本地缓存判断指定网关是否在线
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns> |
| | | public bool CheckGatewayOnlineByFlag(ZbGateway zbGateway)
|
| | | public bool CheckGatewayOnlineByMemory(ZbGateway zbGateway)
|
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | string gwID = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == true)
|
| | | {
|
| | | return this.dicGateway[gwID].GatewayOnlineFlage;
|
| | | return this.CheckGatewayOnlineByFlage(dicGateway[gwID]);
|
| | | }
|
| | |
|
| | | return zbGateway.GatewayOnlineFlage;
|
| | | return this.CheckGatewayOnlineByFlage(zbGateway);
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 刷新网关的在线时间点
|
| | | /// </summary>
|
| | | /// <param name="i_gatewayId">网关ID</param> |
| | | public void RefreshGatewayOnlineTime(string i_gatewayId)
|
| | | {
|
| | | try
|
| | | {
|
| | | if (this.dicGateway.ContainsKey(i_gatewayId) == true)
|
| | | {
|
| | | this.dicGateway[i_gatewayId].OnlineTime = DateTime.Now;
|
| | | }
|
| | | }
|
| | | catch { }
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 根据指定标识,判断网关是否在线
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns> |
| | | private bool CheckGatewayOnlineByFlage(ZbGateway zbGateway)
|
| | | {
|
| | | if (this.nowGwConnectMode == GatewayConnectMode.Remote)
|
| | | {
|
| | | //远程每20秒检测一次
|
| | | return (DateTime.Now - zbGateway.OnlineTime).TotalSeconds <= 40;
|
| | | }
|
| | | //如果广播得到网关,则会刷新OnlineTime,如果与当前时间相差少于10秒,则判断为在线
|
| | | return (DateTime.Now - zbGateway.OnlineTime).TotalSeconds <= 15;
|
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// <returns></returns>
|
| | | public string GetGatewayName(ZbGateway zbGateway)
|
| | | {
|
| | | if (zbGateway == null) { return string.Empty; }
|
| | |
|
| | | string gwId = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false)
|
| | | {
|
| | |
| | | return name;
|
| | | }
|
| | |
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + localWay.LinuxImageType;
|
| | | if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //没有名称时,则使用R文件里面设置的默认设备名称
|
| | | return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
|
| | | return nameContent.A备注名字;
|
| | | }
|
| | |
|
| | | return string.Empty;
|
| | |
| | | //如果这个网关没有信息,则从新获取
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | }
|
| | | else
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = Common.LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// 获取网关信息(版本信息,镜像类型,基本信息等。只刷新本地网关的缓存)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | /// <param name="mode"></param>
|
| | | /// <returns></returns>
|
| | | public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //获取网关版本信息
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 95 } };
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon");
|
| | | var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
|
| | |
|
| | | if (result.ErrorMsgDiv != 1)
|
| | | {
|
| | |
| | | localWay.GwSerialNum = data.GWSN;
|
| | | localWay.IsMainGateWay = data.IsDominant == 1 ? true : false;
|
| | | localWay.GwIP = data.GwIP;
|
| | | localWay.GwMac = data.GwMac;
|
| | | localWay.LinuxImageType = data.LinuxImageType;
|
| | | localWay.LinuxHardVersion = data.LinuxHWVersion;
|
| | | localWay.LinuxFirmwareVersion = data.LinuxFWVersion;
|
| | |
| | | localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
|
| | | localWay.CoordinatorImageId = data.ZbImageType;
|
| | | localWay.DriveCodeList = data.DriveCodeList;
|
| | | localWay.GwVersionDate = data.AppVersion;
|
| | | localWay.OnlineTime = DateTime.Now;
|
| | |
|
| | | if (saveFile == true)
|
| | | {
|
| | | localWay.ReSave();
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 网关房间相关_______________________
|
| | | #region ■ 清空真实网关链接___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// 清空全部的真实物理网关的链接
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | /// <param name="roadGateway">是否加载本地的网关对象到真实列表中</param>
|
| | | public void ClearAllRealGatewayConection(bool roadGateway)
|
| | | {
|
| | | return this.GetRoomByGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="gatewayId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(string gatewayId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(gatewayId);
|
| | | if (localGateway == null)
|
| | | //断开mqtt连接(即使保存在内存当中也没问题,因为如果广播不到,则它不会建立链接)
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | | {
|
| | | return null;
|
| | | ZbGateway.GateWayList[i].CloseLocalConnectionOnForce();
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关Id</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(string gwId, string roomId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(gwId);
|
| | | if (localGateway != null)
|
| | | //加载本地网关对象
|
| | | if (roadGateway == true)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | | localGateway.ReSave();
|
| | | //添加备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
|
| | | List<string> listFile = this.GetAllGatewayFile();
|
| | | //反序列化添加到缓存
|
| | | foreach (string file in listFile)
|
| | | {
|
| | | //从文件中反序列化出网关对象
|
| | | var gateway = this.GetGatewayFromFile(file);
|
| | | if (gateway == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var tempWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == gateway.GwId)); |
| | | if (tempWay == null) |
| | | { |
| | | ZbGateway.GateWayList.Add(gateway); |
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 清空真实网关列表___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 清空全部的真实物理网关对象
|
| | | /// </summary>
|
| | | public void ClearAllRealGateway()
|
| | | {
|
| | | //因为那一瞬间,有可能mqtt会加回来,所以先加缓存
|
| | | var list = new List<ZbGateway>();
|
| | | list.AddRange(ZbGateway.GateWayList);
|
| | | //然后清空掉
|
| | | ZbGateway.GateWayList.Clear();
|
| | | //最后再断开mqtt连接
|
| | | for (int i = 0; i < list.Count; i++)
|
| | | {
|
| | | list[i].DisConnectLocalMqttClient("G");
|
| | | }
|
| | | list.Clear();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | public List<FirmwareVersionInfo> GetGatewayAllNewVersion(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //如果是展示模板,或者是虚拟住宅的话,没有什么新版本的说法
|
| | | if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
|
| | | {
|
| | | return new List<FirmwareVersionInfo> { null, null, null };
|
| | | }
|
| | | //获取网关版本信息
|
| | | var result = this.GetGatewayInfo(zbGateway, mode);
|
| | | var result = this.GetGatewayInfo(zbGateway, false, mode);
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | |
| | | if (flage == 1)
|
| | | {
|
| | | //没网的时候不再处理
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Coordinator,
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A协调器,
|
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString());
|
| | | }
|
| | |
| | | localWay.LinuxFirmwareVersion);
|
| | |
|
| | | //协调器版本
|
| | | var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Coordinator,
|
| | | var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A协调器,
|
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString(),
|
| | | localWay.CoordinatorFirmwareVersion);
|
| | |
| | | //添加虚拟驱动的升级固件(成不成功都无所谓) 必须能够联网才行
|
| | | if (flage == 1)
|
| | | {
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A虚拟驱动,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString());
|
| | | }
|
| | |
|
| | | //虚拟驱动
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A虚拟驱动,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString(),
|
| | | data.DriveFwVersion);
|
| | |
| | | /// <returns></returns>
|
| | | public List<ZbGatewayData.DriveCodeObj> GetListVDDriveCode(ZbGateway zbGateway)
|
| | | {
|
| | | //如果是展示模板,或者是虚拟住宅的话,直接取缓存
|
| | | if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
|
| | | {
|
| | | //取本地对象
|
| | | var localgw = this.GetLocalGateway(zbGateway.GwId);
|
| | | return localgw != null ? zbGateway.DriveCodeList : zbGateway.DriveCodeList;
|
| | | }
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 505 } };
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "VirtualDrive/CatDriveCode", jObject.ToString(), "VirtualDrive/CatDriveCode_Respon");
|
| | | var result = this.SendJobjectDataToGateway(zbGateway.GwId, "VirtualDrive/CatDriveCode", jObject.ToString(), "VirtualDrive/CatDriveCode_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | |
| | | /// <returns></returns>
|
| | | public int IsMainGateway(string waiID)
|
| | | {
|
| | | ZbGateway zbGateway = null;
|
| | | if (this.GetRealGateway(ref zbGateway, waiID) == false)
|
| | | var realWay = ZbGateway.GateWayList.Find((obj) =>
|
| | | {
|
| | | return obj.GwId == waiID;
|
| | | });
|
| | | //虚拟网关也返回 0
|
| | | if (realWay == null || realWay.IsVirtual == true)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | return zbGateway.IsMainGateWay == true ? 1 : 2;
|
| | | return realWay.IsMainGateWay == true ? 1 : 2;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | | //获取控制主人账号的Token
|
| | | pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list);
|
| | | var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | canBreak = true;
|
| | |
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
|
| | | {
|
| | | //没有配置过经纬度
|
| | | return true;
|
| | | }
|
| | |
|
| | | int result = -1;
|
| | |
| | |
|
| | | List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
|
| | |
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError);
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | |
| | | /// <summary>
|
| | | /// 重新发送命令去绑定断网情况下备份的网关
|
| | | /// </summary>
|
| | | public void ResetComandToBindBackupGateway()
|
| | | public bool ResetComandToBindBackupGateway()
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData == null)
|
| | | {
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | var listTempId = new List<string>();
|
| | | listTempId.AddRange(this.listBackupGwId);
|
| | | return true;
|
| | | }
|
| | | this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | var listTempId = new List<string>();
|
| | | listTempId.AddRange(this.listBackupGwId);
|
| | |
|
| | | //调用接口,绑定网关
|
| | | var bindGateway = new BindGatewayPra();
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | | //调用接口,绑定网关
|
| | | var bindGateway = new BindGatewayPra();
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | foreach (var gwId in listTempId)
|
| | | foreach (var gwId in listTempId)
|
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
|
| | | if (result == "Success")
|
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" });
|
| | | if (result == "Success")
|
| | | {
|
| | | this.listBackupGwId.Remove(gwId);
|
| | | }
|
| | | if (result == "Error")
|
| | | {
|
| | | break;
|
| | | }
|
| | | this.listBackupGwId.Remove(gwId);
|
| | | }
|
| | | if (result == "Error")
|
| | | {
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | if (this.listBackupGwId.Count == 0)
|
| | | if (this.listBackupGwId.Count == 0)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | System.IO.File.Delete(file);
|
| | | }
|
| | | System.IO.File.Delete(file);
|
| | | }
|
| | | else
|
| | | {
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | }
|
| | | });
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="sendData">需要发送的数据 JObject.ToString()的东西</param>
|
| | | /// <param name="receiptTopic">指定接收哪个主题</param>
|
| | | /// <param name="waitTime">超时时间(秒)</param>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | /// <returns>网关返回的数据</returns>
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5)
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway(string gatewayId, string sendTopic, string sendData, string receiptTopic, int waitTime = 5, bool useLocalConnect = false)
|
| | | {
|
| | | var reResult = new ReceiptGatewayResult();
|
| | |
|
| | | ZbGateway myGateway = null;
|
| | | if (this.GetRealGateway(ref myGateway, gateway) == false)
|
| | | {
|
| | | //获取网关对象失败
|
| | | reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
|
| | | reResult.ErrorMsgDiv = -1;
|
| | | return reResult;
|
| | | }
|
| | | //网关ID
|
| | | string gatewayID = gateway.GwId;
|
| | | //错误主题
|
| | | string errorTopic = gatewayID + "/" + "Error_Respon";
|
| | | string errorTopic = gatewayId + "/" + "Error_Respon";
|
| | | //检测对象的主题
|
| | | string checkTopic = gatewayID + "/" + receiptTopic;
|
| | | string checkTopic = gatewayId + "/" + receiptTopic;
|
| | |
|
| | | Action<string, string> receiptAction = (topic, message) =>
|
| | | HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | |
|
| | |
| | | {
|
| | | reResult.ReceiptData = jobject["Data"].ToString();
|
| | | }
|
| | | };
|
| | | myGateway.Actions += receiptAction;
|
| | | });
|
| | |
|
| | | //发送数据
|
| | | myGateway.Send(sendTopic, sendData);
|
| | | this.SendJobjectData(gatewayId, sendTopic, sendData, useLocalConnect);
|
| | |
|
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | |
| | | System.Threading.Thread.Sleep(50);
|
| | | TimeOut++;
|
| | | }
|
| | | myGateway.Actions -= receiptAction;
|
| | | receiptAction = null;
|
| | | //移除网关监听事件
|
| | | HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
|
| | |
|
| | | if (reResult.ReceiptData == null)
|
| | | {
|
| | | reResult.ErrorMsgDiv = 0;
|
| | | }
|
| | |
|
| | | return reResult;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 单纯执行发送json数据到网关
|
| | | /// </summary>
|
| | | /// <param name="i_gatewayId">网关id</param>
|
| | | /// <param name="topic">主题</param>
|
| | | /// <param name="sendData">发送的json数据</param>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | public void SendJobjectData(string i_gatewayId, string topic, string sendData, bool useLocalConnect = false)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | | {
|
| | | //寻找真实物理网关对象
|
| | | if (ZbGateway.GateWayList[i].GwId == i_gatewayId)
|
| | | {
|
| | | realWay = ZbGateway.GateWayList[i];
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (realWay == null)
|
| | | {
|
| | | //如果网关对象丢失了,则创建个新的
|
| | | realWay = new ZbGateway { IsVirtual = true, }; |
| | | realWay.GwId = i_gatewayId; |
| | | realWay.HomeId = Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(realWay);
|
| | | }
|
| | | if (useLocalConnect == false)
|
| | | {
|
| | | realWay.Send(topic, System.Text.Encoding.UTF8.GetBytes(sendData));
|
| | | }
|
| | | else
|
| | | {
|
| | | //强制使用本地连接
|
| | | realWay.SendLocation(topic, System.Text.Encoding.UTF8.GetBytes(sendData));
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | }
|
| | | else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
|
| | | {
|
| | | //局域网每5秒检测一次
|
| | | if (waitCount < 5) { continue; }
|
| | | //局域网每8秒检测一次
|
| | | if (waitCount < 8) { continue; }
|
| | | }
|
| | | waitCount = 0;
|
| | |
|
| | |
| | | private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
|
| | | {
|
| | | //从网关获取全部的网关
|
| | | List<ZbGateway> list = this.GetAllGatewayFromGateway();
|
| | | foreach (var way in list)
|
| | | {
|
| | | //将标识置为false
|
| | | way.GatewayOnlineFlage = false;
|
| | | }
|
| | | //等个2秒
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | List<ZbGateway> list = this.GetAllLocalGateway();
|
| | |
|
| | | //2020.05.25追加:此住宅是否拥有网关在线
|
| | | var hadGwOnline = false;
|
| | | foreach (var way in list)
|
| | | {
|
| | | if (dicOldOnline.ContainsKey(way.GwId) == true)
|
| | | if (dicOldOnline.ContainsKey(way.GwId) == true
|
| | | && this.CheckGatewayOnlineByFlage(way) == true)
|
| | | {
|
| | | if (way.GatewayOnlineFlage == true)
|
| | | {
|
| | | //有一个网关在线,即在线
|
| | | hadGwOnline = true;
|
| | | break;
|
| | | }
|
| | | //有一个网关在线,即在线
|
| | | hadGwOnline = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | if (dicOldOnline.ContainsKey(gwId) == true)
|
| | | {
|
| | | //网关也不多,直接推送吧
|
| | | this.PushGatewayOnlineStatuToForm(gwId, way.GatewayOnlineFlage, hadGwOnline);
|
| | | bool online = this.CheckGatewayOnlineByFlage(way);
|
| | | this.PushGatewayOnlineStatuToForm(gwId, online, hadGwOnline);
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | private void CheckGatewayStatuByRemote(Dictionary<string, bool> dicOldOnline)
|
| | | {
|
| | | //获取云端上面的网关
|
| | | Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
|
| | | Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
|
| | | if (dicDbGateway == null)
|
| | | {
|
| | | //如果网络不通,则也往下走
|
| | |
| | | foreach (var zbway in this.dicGateway.Values)
|
| | | {
|
| | | //获取前回的在线状态
|
| | | dicOldOnline[zbway.GwId] = zbway.GatewayOnlineFlage;
|
| | | dicOldOnline[zbway.GwId] = this.CheckGatewayOnlineByFlage(zbway);
|
| | | }
|
| | | return dicOldOnline;
|
| | | }
|
| | |
| | | if (zbway != null)
|
| | | {
|
| | | //切换住宅时,这个东西有可能是null
|
| | | zbway.GatewayOnlineFlage = online;
|
| | | if (online == true)
|
| | | {
|
| | | zbway.OnlineTime = DateTime.Now;
|
| | | }
|
| | | UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
|
| | | }
|
| | | }
|