| | |
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 备份业务的逻辑
|
| | | /// 网关业务的逻辑类
|
| | | /// </summary> |
| | | private static HdlGatewayLogic m_Current = null; |
| | | /// <summary>
|
| | | /// 备份业务的逻辑
|
| | | /// 网关业务的逻辑类
|
| | | /// </summary> |
| | | public static HdlGatewayLogic Current
|
| | | {
|
| | |
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<string> listBackupGwId = new List<string>();
|
| | | var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData != null)
|
| | | {
|
| | | //新增:虽然概率低,但是确实发生了。如果有网络时,App重新绑定记录的网关失败的话
|
| | | //不应该删除它
|
| | | listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | }
|
| | |
|
| | | List<string> listDelete = new List<string>(); |
| | | foreach (var gatewayId in this.dicGateway.Keys)
|
| | | {
|
| | | if (result.ContainsKey(gatewayId) == false)
|
| | | if (result.ContainsKey(gatewayId) == false && listBackupGwId.Contains(gatewayId) == false)
|
| | | {
|
| | | //本地存在云端不存在的网关,则删除
|
| | | listDelete.Add(gatewayId);
|
| | |
| | | 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);
|
| | |
| | | /// <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 |
| | |
| | | #region ■ 添加网关___________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加新网关(仅限追加新的网关 1:正常 -1:异常 0:当前的网关绑定在了当前账号下的不同住宅里面) |
| | | /// 添加新网关(仅限追加新的网关) |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<int> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | { |
| | | //执行添加网关到内存 |
| | | var result = await this.DoAddGatewayToMemory(zbGateway, mode); |
| | | if (result != 1)
|
| | | //前的网关绑定在了当前账号下的不同住宅里面
|
| | | if (result == 0)
|
| | | {
|
| | | return result;
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //网关绑定在当前账号下的其他住宅里\r\n请解除绑定后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
|
| | | if (msg.Contains("{0}") == true)
|
| | | {
|
| | | msg = string.Format(msg, "\r\n");
|
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | if (result == -1)
|
| | | {
|
| | | return false;
|
| | | } |
| | | |
| | | return 1; |
| | | //设置网关的经纬度 |
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude); |
| | | return falge; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// 重新绑定网关(1:正常 -1:异常 0:当前的网关绑定在了当前账号下的不同住宅里面) |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | public async Task<int> ReBindNewGateway(ZbGateway zbGateway) |
| | | /// <param name="btnMsg">消息控件</param> |
| | | public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | 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); |
| | | if (falge == false)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
| | | HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
|
| | | }
|
| | |
|
| | | //网关内部数据变更中,请稍后
|
| | | ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
|
| | |
|
| | | await System.Threading.Tasks.Task.Delay(8000);
|
| | | if (btnMsg == null)
|
| | | {
|
| | | //网关内部数据变更中,请稍后
|
| | | ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
|
| | | }
|
| | | else
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //网关内部数据变更中,请稍后
|
| | | btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
|
| | | });
|
| | | }
|
| | | await Task.Delay(8000);
|
| | |
|
| | | //获取网关的信息
|
| | | var result = await zbGateway.GetZbGwInfoAsync();
|
| | |
| | | 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);
|
| | |
| | | HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | }
|
| | |
|
| | | #endregion |
| | |
|
| | | #region ■ 网关切换___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 执行切换网关操作
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | public async Task<bool> DoSwitchGateway(string gatewayId)
|
| | | {
|
| | | var zbGateway = this.GetLocalGateway(gatewayId);
|
| | | if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
|
| | | {
|
| | | //重新获取在线网关的信息
|
| | | var result = await this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | }
|
| | | //切换网关,保存缓存
|
| | | this.SaveGatewayIdToLocation(gatewayId);
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取在线网关信息
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
|
| | | {
|
| | | //显示进度条
|
| | | ProgressBar.Show();
|
| | |
|
| | | //检测广播到的这个网关是否拥有住宅ID
|
| | | ZbGateway realWay = null;
|
| | | bool getGatewayInfo = true;
|
| | | if (this.GetRealGateway(ref realWay, gatewayId) == true)
|
| | | {
|
| | | //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
|
| | | if (this.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
|
| | | {
|
| | | int result2 = await this.ReBindNewGateway(realWay);
|
| | | if (result2 == 0)
|
| | | {
|
| | | //出现未知错误,请稍后再试
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | }
|
| | | else if (result2 == -1)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | return false;
|
| | | }
|
| | | //重新绑定网关里面已经重新获取了网关信息
|
| | | getGatewayInfo = false;
|
| | | }
|
| | | }
|
| | |
|
| | | if (getGatewayInfo == true)
|
| | | {
|
| | | //获取网关信息
|
| | | var info = await this.GetGatewayNewInfoAsync(realWay);
|
| | | if (info == null)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | if (result == -1)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存选择的网关ID到本地
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | public void SaveGatewayIdToLocation(string gatewayId)
|
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = gatewayId;
|
| | | byte[] data = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
|
| | | Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
|
| | | }
|
| | |
|
| | | #endregion |
| | | |
| | | #region ■ 删除网关___________________________ |
| | |
| | | bool result = await this.SetHomeIdToGateway(realWay, string.Empty);
|
| | | if (result == false)
|
| | | {
|
| | | //网关解绑失败
|
| | | //网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | 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); |
| | |
| | | //移除 |
| | | ZbGateway.GateWayList.RemoveAll((obj) => this.GetGatewayId(obj) == zbGatewayID); |
| | | //断开mqtt连接 |
| | | realWay.DisConnect("GD"); |
| | | realWay.DisConnectLocalMqttClient("GD"); |
| | | |
| | | return true; |
| | | }
|
| | |
| | | {
|
| | | //删除设备文件
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
|
| | | //删除Ota设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | }
|
| | | //如果是主网关
|
| | | if (this.IsMainGateway(zbGatewayID) == 1)
|
| | |
| | |
|
| | | if (waitTime == true)
|
| | | {
|
| | | //这是第一道坎,强制检查WIFI:等待3秒(因为wifi的时候,它会自动去刷新flage)
|
| | | System.Threading.Thread.Sleep(3000);
|
| | | //这是第一道坎,强制检查WIFI:等待2秒(因为wifi的时候,它会自动去刷新flage)
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | //检查是否拥有网关存在于WIFi下
|
| | | if (this.CheckHadGatewayInWifi(listRealWay) == false)
|
| | | {
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取协调器当前信道_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取协调器当前信道(会有等待延迟,返回-1代表错误)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public int GetGatewayChannelId(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return -1;
|
| | | }
|
| | | int data = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | data = Convert.ToInt32(jobject["Data"]["Channel"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 8 } };
|
| | | realWay.Send("ZbGw/GetChannel", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (data == -1 && TimeOut < 30)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (data == -1)
|
| | | {
|
| | | //获取协调器信道失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | | return data;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取协调器MAC______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取协调器MAC地址(会有等待延迟,返回null代表错误)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public string GetGatewayCoordinatorMac(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return null;
|
| | | }
|
| | | string data = null;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | data = jobject["Data"]["MacAddr"].ToString();
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 13 } };
|
| | | realWay.Send("ZbGw/GetMac", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (data == null && TimeOut < 30)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (data == null)
|
| | | {
|
| | | //获取协调器Mac失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | | return data;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取协调器PanID____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取协调器PanID(会有等待延迟,返回-1代表错误)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public int GetGatewayPanId(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return -1;
|
| | | }
|
| | | int panId = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/" + "ZbGw/GetPanId_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 12 } };
|
| | | realWay.Send("ZbGw/GetPanId", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (panId == -1 && TimeOut < 30)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (panId == -1)
|
| | | {
|
| | | //获取协调器PanID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | | return panId;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 网关自动备份设置___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关自动备份设置(-1:异常 0:关闭 1:打开)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public int GetGatewayAutoBackupStatu(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return -1;
|
| | | }
|
| | | int statu = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/GatewayAutoBackup_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | statu = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", 1 } };
|
| | | jObject.Add("Data", data);
|
| | | realWay.Send("GatewayAutoBackup", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (statu == -1 && TimeOut < 60)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (statu == -1)
|
| | | {
|
| | | //获取网关自动备份设置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayAutoBackupStatuFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | | return statu;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置网关自动备份设置
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="statu"></param>
|
| | | /// <returns></returns>
|
| | | public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return false;
|
| | | }
|
| | | int result = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/GatewayAutoBackup_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | result = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", statu == true ? 2 : 3 } };
|
| | | jObject.Add("Data", data);
|
| | | realWay.Send("GatewayAutoBackup", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (result == -1 && TimeOut < 60)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (result == -1)
|
| | | {
|
| | | //设置网关自动备份失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewayAutoBackupStatuFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取网关GwInfo里面的属性___________
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | //获取本地的属性
|
| | | objValue = localWay.getGwInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGwInfo, null);
|
| | | }
|
| | |
|
| | | if (objValue == null)
|
| | | {
|
| | | return defult;
|
| | | }
|
| | | return objValue;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关GatewayBaseInfo里面的属性
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="attributeName">GatewayBaseInfo里面属性的名字</param>
|
| | | /// <param name="defult">如果获取不到时,设置的默认值</param>
|
| | | /// <returns></returns>
|
| | | public object GetGatewayBaseInfoAttribute(ZbGateway zbGateway, string attributeName, string defult = "")
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | var localWay = this.GetLocalGateway(gwID);
|
| | |
|
| | | object objValue = null;
|
| | | if (localWay == null || localWay.getGatewayBaseInfo == null)
|
| | | {
|
| | | //本地没有记录有这个东西,则直接返回参数的数据
|
| | | if (zbGateway.getGatewayBaseInfo != null)
|
| | | {
|
| | | objValue = zbGateway.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, zbGateway.getGatewayBaseInfo, null);
|
| | | }
|
| | | else
|
| | | {
|
| | | return defult;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | //获取本地属性 |
| | | objValue = localWay.getGatewayBaseInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGatewayBaseInfo, null);
|
| | | }
|
| | |
|
| | | if (objValue == null)
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关镜像类型的翻译名字
|
| | | /// 设置网关镜像类型的翻译名字
|
| | | /// </summary>
|
| | | /// <param name="button"></param>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public string GetGatewayImageText(ZbGateway zbGateway)
|
| | | public void SetGatewayImageText(Button button, ZbGateway zbGateway)
|
| | | {
|
| | | //初始值:无法识别的网关设备
|
| | | button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
|
| | |
|
| | | string gwId = this.GetGatewayId(zbGateway);
|
| | | int imageType = -1;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false || this.dicGateway[gwId].getGwInfo == null)
|
| | | {
|
| | | //如果这个网关没有信息,则从新获取
|
| | | var result = this.GetGatewayNewInfo(zbGateway, ShowErrorMode.NO);
|
| | | if (result == null)
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | {
|
| | | //无法识别的网关设备
|
| | | return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | }
|
| | | }
|
| | | imageType = result.LinuxImageType;
|
| | | else
|
| | | {
|
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | zbGateway.getGwInfo = result;
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | }
|
| | | });
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | imageType = Convert.ToInt32(this.GetGwInfoAttribute(this.dicGateway[gwId], "LinuxImageType"));
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | }
|
| | | }
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + imageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]);
|
| | | }
|
| | |
|
| | | //无法识别的网关设备
|
| | | return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | //最后再断开mqtt连接
|
| | | for (int i = 0; i < list.Count; i++)
|
| | | {
|
| | | list[i].DisConnect("G");
|
| | | list[i].DisConnectLocalMqttClient("G");
|
| | | }
|
| | | list.Clear();
|
| | | }
|
| | |
| | | #region ■ 主网关判定_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
|
| | | /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
|
| | | /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
|
| | | /// </summary>
|
| | | /// <param name="waiID">网关id</param>
|
| | | /// <returns></returns>
|
| | |
| | | {
|
| | | return 0;
|
| | | }
|
| | | return zbGateway.IsMainGateWay == true ? 1 : 0;
|
| | | return zbGateway.IsMainGateWay == true ? 1 : 2;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | #region ■ 设置网关图片_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置真实网关的图片,规格:915X492
|
| | | /// 设置真实网关的图片
|
| | | /// </summary>
|
| | | /// <param name="button"></param>
|
| | | /// <param name="zbGateway"></param>
|
| | |
| | | var localWay = this.GetLocalGateway(gwID);
|
| | | if (localWay == null || localWay.getGwInfo == null)
|
| | | {
|
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | {
|
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.getGwInfo.LinuxImageType + ".png";
|
| | | }
|
| | | else
|
| | | {
|
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | if (button != null)
|
| | | zbGateway.getGwInfo = result;
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
|
| | | }
|
| | | });
|
| | | }
|
| | | });
|
| | | });
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString() + ".png";
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.getGwInfo.LinuxImageType + ".png";
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置网关图标,规格:110X110
|
| | | /// 设置网关图标
|
| | | /// </summary>
|
| | | /// <param name="button"></param>
|
| | | /// <param name="zbGateway"></param>
|
| | |
| | | var localWay = this.GetLocalGateway(gwID);
|
| | | if (localWay == null || localWay.getGwInfo == null)
|
| | | {
|
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | {
|
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.getGwInfo.LinuxImageType + ".png";
|
| | | }
|
| | | else
|
| | | {
|
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | if (button != null)
|
| | | zbGateway.getGwInfo = result;
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
|
| | | button.SelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + "Selected.png";
|
| | | }
|
| | | });
|
| | | }
|
| | | });
|
| | | });
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | string linType = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + linType + ".png";
|
| | | button.SelectedImagePath = "Gateway/GatewayIcon" + linType + "Selected.png";
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.getGwInfo.LinuxImageType + ".png";
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 测试网关___________________________
|
| | | #region ■ 网关定位___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 发送测试指令到设备(网关LED闪烁识别)
|
| | | /// 发送指令到网关进行定位(网关LED闪烁识别)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | public void SetTestCommand(ZbGateway zbGateway)
|
| | | public void SetFixedPositionCommand(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | |
| | | return;
|
| | | }
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 85 } }; |
| | | realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________ |
| | |
|
| | | /// <summary>
|
| | | /// 弹出网关不在线的
|
| | | /// </summary> |
| | | private void ShowGatewayNotOnlineMsg()
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | if (this.IsGatewayExist(zbGateway) == true)
|
| | | {
|
| | | //网关连接失败,请确认网络
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示错误信息窗口
|
| | | /// </summary>
|
| | | /// <param name="msg"></param>
|
| | | private void ShowErrorMsg(string msg)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
|
| | | }
|
| | | else
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Error, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示Tip信息窗口
|
| | | /// </summary>
|
| | | /// <param name="msg"></param>
|
| | | private void ShowTipMsg(string msg)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | contr.Show();
|
| | | });
|
| | | //如果这个网关还没有绑定的话,则强制使用本地连接
|
| | | realWay.SendLocation("GwLinuxLocate_Respon", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion |
| | |
| | | {
|
| | | return;
|
| | | }
|
| | | //获取当前接受在线状态推送的界面
|
| | | var listForm = new List<CommonFormBase>();
|
| | | listForm.AddRange(UserCenterResourse.listGatewayOnlinePushForm);
|
| | | if (listForm.Count > 0)
|
| | | //保存当前激活的界面ID
|
| | | var listId = new List<string>();
|
| | | listId.AddRange(UserCenterResourse.listActionFormId);
|
| | | for (int i = 0; i < listId.Count; i++)
|
| | | {
|
| | | for (int i = 0; i < listChange.Count; i++)
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(listId[i]) == false)
|
| | | {
|
| | | foreach (var form in listForm)
|
| | | {
|
| | | form?.GatewayOnlinePush(listChange[i], listChangeStatu[i]);
|
| | | }
|
| | | continue;
|
| | | }
|
| | | //网关在线推送
|
| | | for (int j = 0; j < listChange.Count; j++)
|
| | | {
|
| | | UserCenterResourse.DicActionForm[listId[i]]?.GatewayOnlinePush(listChange[j], listChangeStatu[j]);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | 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();
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置网关经纬度_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置网关经纬度
|
| | | /// </summary>
|
| | | /// <param name="gateway">网关对象</param>
|
| | | /// <param name="Longitude">经度</param>
|
| | | /// <param name="Latitude">维度</param>
|
| | | /// <returns></returns>
|
| | | public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, gateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | int result = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | | //两位小数
|
| | | Longitude = Math.Round(Longitude, 2);
|
| | | Latitude = Math.Round(Latitude, 2);
|
| | |
|
| | | int intLongitude = Convert.ToInt32(Longitude.ToString().Replace(".", string.Empty));
|
| | | int intLatitude = Convert.ToInt32(Latitude.ToString().Replace(".", string.Empty));
|
| | |
|
| | | 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);
|
| | | 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)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (result != 0)
|
| | | {
|
| | | //设置网关经纬度失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
|
| | | if (result == -1)
|
| | | {
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 解绑云端网关_______________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | //获取控制主人账号的Token
|
| | | 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)
|
| | |
| | | {
|
| | | //获取从云端那里得来的全部文件
|
| | | var listBackFile = HdlAutoBackupLogic.GetFileFromDirectory(UserCenterLogic.CombinePath(backDirectory));
|
| | | listBackFile.Sort();
|
| | | //添加附加情报:还原设备配置
|
| | | ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uRecoverDeviceSettion));
|
| | | ProgressBar.SetMaxValue(listBackFile.Count);
|
| | |
| | | var listSaveFile = new HashSet<string>();
|
| | | foreach (string fileName in listBackFile)
|
| | | {
|
| | | if (fileName.Length < 10 || fileName.StartsWith(Common.LocalDevice.deviceFirstName) == false)
|
| | | if (fileName.Length < 10 || fileName.StartsWith("Device_") == false)
|
| | | {
|
| | | //不是设备备份文件
|
| | | continue;
|
| | |
| | | if (deleteFile.Length > 12)
|
| | | {
|
| | | string deviceFileName = deleteFile.Substring(5);
|
| | | if (deviceFileName.StartsWith(Common.LocalDevice.deviceFirstName) == false)
|
| | | if (deviceFileName.StartsWith("Device_") == false)
|
| | | {
|
| | | //不是设备文件
|
| | | continue;
|
| | |
| | | else if (backType == GatewayBackupEnum.APir灯光配置)
|
| | | {
|
| | | var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData));
|
| | | result = await HdlPirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
|
| | | result = await HdlDevicePirSensorLogic.Current.SetPirSensorSettion((IASZone)device, recoverData);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A干接点颜色调节)
|
| | | {
|
| | | var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.KeyColorData>(System.Text.Encoding.UTF8.GetString(byteData));
|
| | | result = await HdlPanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
|
| | | 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 HdlPanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
|
| | | result = await HdlDevicePanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A干接点节能模式)
|
| | | {
|
| | |
| | | bool modeEnable = Convert.ToBoolean(recoverData["modeEnable"]);
|
| | | int modeTime = Convert.ToInt32(recoverData["modeTime"]);
|
| | | int level = Convert.ToInt32(recoverData["level"]);
|
| | | result = await HdlPanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
|
| | | result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A干接点私有属性)
|
| | | else if (backType == GatewayBackupEnum.A干接点第三级别私有属性)
|
| | | {
|
| | | var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
|
| | | result = await HdlPanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
|
| | | result = await HdlDevicePanelLogic.Current.EditorDryContactThirdFunction((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)
|
| | | {
|
| | | //转换为二进制
|
| | | 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++)
|
| | | {
|
| | | ((AC)device).listSupportMode[i] = Convert.ToInt32(reportValue[i]);
|
| | | }
|
| | | device.ReSave();
|
| | | }
|
| | | }
|
| | | return result == true ? 1 : -1;
|
| | | }
|
| | |
|
| | | #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();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示错误信息窗口
|
| | | /// </summary>
|
| | | /// <param name="msg"></param>
|
| | | private void ShowErrorMsg(string msg)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Error, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示Tip信息窗口
|
| | | /// </summary>
|
| | | /// <param name="msg"></param>
|
| | | private void ShowTipMsg(string msg)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|