using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone
|
{
|
/// <summary>
|
/// 网关备份业务的逻辑
|
/// </summary>
|
public class HdlGatewayBackupLogic
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 备份业务的逻辑
|
/// </summary>
|
private static HdlGatewayBackupLogic m_Current = null;
|
/// <summary>
|
/// 备份业务的逻辑
|
/// </summary>
|
public static HdlGatewayBackupLogic Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
m_Current = new HdlGatewayBackupLogic();
|
}
|
return m_Current;
|
}
|
}
|
|
#endregion
|
|
#region ■ 网关备份___________________________
|
|
/// <summary>
|
/// 网关执行备份
|
/// </summary>
|
/// <param name="gatewayId">网关ID</param>
|
/// <param name="backupName">需要创建的备份的名字</param>
|
public void DoBackupGateway(string gatewayId, string backupName)
|
{
|
//展开进度条
|
ProgressFormBar.Current.Start();
|
//创建备份文件
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uCreatBackupFile));
|
System.Threading.Thread.Sleep(1000);
|
|
//创建一个备份
|
string backupClassId = this.CreatGatewayBackup(gatewayId, backupName);
|
if (backupClassId == null)
|
{
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return;
|
}
|
|
//保存协调器的nv分区组网信息
|
//bool result = this.SaveNVFile(realGateway);
|
//if (result == false)
|
//{
|
// //如果上传失败的话,就把它删除
|
// await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
|
// //关闭进度条
|
// ProgressFormBar.Current.Close();
|
// return;
|
//}
|
|
//打开协调器串口发送功能
|
//result = this.OpenZbMsComSend(realGateway);
|
//if (result == false)
|
//{
|
// //如果上传失败的话,就把它删除
|
// await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
|
// //关闭进度条
|
// ProgressFormBar.Current.Close();
|
// return;
|
//}
|
|
//开始上传数据
|
bool result = this.StartUpLoadData(gatewayId, backupClassId);
|
if (result == false)
|
{
|
//如果上传失败的话,就把它删除
|
this.DeleteGatewayBackup(gatewayId, backupClassId);
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return;
|
}
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
}
|
|
/// <summary>
|
/// 删除网关备份
|
/// </summary>
|
/// <param name="i_gwId">网关id</param>
|
/// <param name="i_backupId">备份的主键</param>
|
/// <param name="mode">失败时是否显示tip消息</param>
|
/// <returns></returns>
|
public bool DeleteGatewayBackup(string i_gwId, string i_backupId, ShowNetCodeMode mode = ShowNetCodeMode.YES)
|
{
|
var pra = new { gatewayId = i_gwId, folderId = i_backupId };
|
var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/folder/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限);
|
//检测状态码
|
if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 创建网关备份(返回备份主键,返回null代表失败)
|
/// </summary>
|
/// <param name="gwId">网关id</param>
|
/// <param name="i_backName">备份名字</param>
|
/// <returns></returns>
|
private string CreatGatewayBackup(string gwId, string i_backName)
|
{
|
//创建一个备份名字
|
var pra = new { backupClassify = "USER_DEFINED_BACKUP", backupDataType = "ZIGBEE", folderName = i_backName, gatewayId = gwId };
|
var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/folder/add", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限);
|
//检测状态码
|
if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
|
{
|
return null;
|
}
|
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<IdInfoClass>(result.Data.ToString());
|
return info.Id;
|
}
|
|
#endregion
|
|
#region ■ 开始网关数据备份___________________
|
|
/// <summary>
|
/// 开始上传数据
|
/// </summary>
|
/// <param name="gatewayId"></param>
|
/// <param name="backupClassId"></param>
|
private bool StartUpLoadData(string gatewayId, string backupClassId)
|
{
|
//开始备份网关数据
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uStartBackupgatewayData));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
bool threadAction = true;
|
bool success = false;
|
//等待时间
|
int waitime = 60;
|
//计时时间
|
int TimeOut = 0;
|
|
HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
|
{
|
if (topic == gatewayId + "/BackupGwDataFile_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
|
if (statu == 1)
|
{
|
threadAction = false;
|
//网关数据备份失败
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
|
return;
|
}
|
if (statu == 2)
|
{
|
threadAction = false;
|
success = true;
|
//上传数据成功
|
string msg2 = Language.StringByID(R.MyInternationalizationString.uUploadDataSuccess);
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg2);
|
}
|
//将时间刷新,然后等待时间变更为30秒
|
TimeOut = 0;
|
waitime = 300;
|
}
|
else if (topic == gatewayId + "/BackupGwDataFileProgress_Respon")
|
{
|
//刷新等待时间
|
TimeOut = 0;
|
//上传进度百分比
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
|
if (statu != 0)
|
{
|
threadAction = false;
|
//网关数据备份失败
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
|
return;
|
}
|
//设置进度百分比
|
var persent = Convert.ToInt32(jobject["Data"]["BackupPercent"].ToString());
|
ProgressFormBar.Current.SetValue(persent, 100);
|
}
|
});
|
//发送数据
|
var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/gateway/file/create";
|
string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A账号权限);
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6200 } };
|
var data = new Newtonsoft.Json.Linq.JObject {
|
{ "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
|
jObject.Add("Data", data);
|
|
HdlGatewayLogic.Current.SendJobjectData(gatewayId, "BackupGwDataFile", jObject.ToString());
|
|
while (threadAction == true && TimeOut < waitime)
|
{
|
System.Threading.Thread.Sleep(100);
|
TimeOut++;
|
}
|
//清除事件
|
HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
|
|
if (TimeOut >= waitime)
|
{
|
//响应超时,网关数据备份失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndBackupgatewayDataFail);
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
System.Threading.Thread.Sleep(1000);
|
|
return success;
|
}
|
|
#endregion
|
|
#region ■ 从云端获取备份文件列表_____________
|
|
/// <summary>
|
/// 从云端获取网关的备份列表
|
/// </summary>
|
/// <param name="gatewayId">网关di</param>
|
/// <param name="backMode">获取的备份类型</param>
|
/// <param name="mode">失败时是否显示tip消息</param>
|
public List<BackupListNameInfo> GetGatewayBackupListFromDb(string gatewayId, BackUpMode backMode, ShowNetCodeMode mode = ShowNetCodeMode.YES)
|
{
|
var pra = new { mac = gatewayId };
|
var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/folder/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限);
|
//检测状态码
|
if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
|
{
|
return null;
|
}
|
var listTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BackupListNameInfo>>(result.Data.ToString());
|
var strDiv = HdlBackupLogic.Current.GetBackUpModeText(backMode);
|
|
var listData = new List<BackupListNameInfo>();
|
foreach (var info in listTemp)
|
{
|
if (info.BackupClassify != strDiv || info.BackupDataType != "ZIGBEE")
|
{
|
//不是指定的备份
|
continue;
|
}
|
listData.Add(info);
|
}
|
return listData;
|
}
|
|
/// <summary>
|
/// 发送从云端获取备份文件列表的命令给网关
|
/// </summary>
|
/// <param name="gatewayId"></param>
|
/// <param name="backupClassId"></param>
|
/// <returns></returns>
|
private bool SendGetGatewayFileListComandToGateway(string gatewayId, string backupClassId)
|
{
|
//正在获取备份文件列表
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
int result = -1;
|
HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
|
{
|
if (topic == gatewayId + "/GetDataFileList_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
|
if (result != 0)
|
{
|
//获取备份文件列表失败
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail));
|
return;
|
}
|
}
|
});
|
//发送数据
|
var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/backup/file/findAll";
|
string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A账号权限);
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6202 } };
|
var data = new Newtonsoft.Json.Linq.JObject {
|
{ "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
|
jObject.Add("Data", data);
|
|
HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDataFileList", jObject.ToString());
|
|
int timeOut = 0;
|
while (result == -1 && timeOut < 30)
|
{
|
System.Threading.Thread.Sleep(1000);
|
timeOut++;
|
}
|
//移除事件
|
HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
|
|
if (result != 0)
|
{
|
string msg = Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail);
|
if (result == -1)
|
{
|
//响应超时,获取备份文件列表失败
|
msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGetBackupFileListFail);
|
}
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 从云端下载备份文件_________________
|
|
/// <summary>
|
/// 发送从云端下载备份文件的命令到网关
|
/// </summary>
|
/// <param name="gatewayId"></param>
|
/// <param name="backupClassId"></param>
|
/// <returns></returns>
|
private bool SendDownloadGatewayFileComandToGateway(string gatewayId, string backupClassId)
|
{
|
//正在下载备份文件
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
bool threadAction = true;
|
bool success = false;
|
int timeOut = 0;
|
HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
|
{
|
if (topic == gatewayId + "/RestoreDataFileProgress_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
var result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
|
if (result == 1 || result == 3)
|
{
|
//下载备份文件失败
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uDownloadBackupFileFail));
|
threadAction = false;
|
return;
|
}
|
else if (result == 2)
|
{
|
//下载成功
|
success = true;
|
threadAction = false;
|
return;
|
}
|
else if (result == 0)
|
{
|
//刷新等待时间
|
timeOut = 0;
|
//设置进度百分比
|
var persent = Convert.ToInt32(jobject["Data"]["RestoreDataPercent"].ToString());
|
//网关下载完成之后,它自己会卡一会,才会发送2过来
|
ProgressFormBar.Current.SetValue(persent - 1, 100);
|
}
|
}
|
});
|
|
//发送数据
|
var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/gateway/file/downOne";
|
string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A账号权限);
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6203 } };
|
var data = new Newtonsoft.Json.Linq.JObject {
|
{ "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
|
jObject.Add("Data", data);
|
|
HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDataFileList", jObject.ToString());
|
|
while (threadAction == true && timeOut < 30)
|
{
|
System.Threading.Thread.Sleep(1000);
|
timeOut++;
|
}
|
//移除事件
|
HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
|
|
if (timeOut >= 30)
|
{
|
//响应超时,下载备份文件失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndDownloadBackupFileFail);
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
return success;
|
}
|
|
#endregion
|
|
#region ■ 编辑网关备份名称___________________
|
|
/// <summary>
|
/// 编辑网关备份名称
|
/// </summary>
|
/// <param name="i_backId">备份的主键</param>
|
/// <param name="i_newName">备份的新名称</param>
|
/// <param name="mode">失败时是否显示tip消息</param>
|
/// <returns></returns>
|
public bool EditorGatewayBackupName(string i_backId, string i_newName, ShowNetCodeMode mode = ShowNetCodeMode.YES)
|
{
|
var pra = new { gatewayFolderId = i_backId, folderName = i_newName, homeId = Common.Config.Instance.Home.Id };
|
var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/folder/update", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限);
|
//检测状态码
|
if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 网关还原___________________________
|
|
/// <summary>
|
/// 执行网关还原操作
|
/// </summary>
|
/// <param name="gatewayId">网关ID</param>
|
/// <param name="backupId">备份主键</param>
|
public bool RecoverGateway(string gatewayId, string backupId)
|
{
|
//展开进度条
|
ProgressFormBar.Current.Start();
|
//发送从云端获取备份文件列表的命令给网关
|
var result = this.SendGetGatewayFileListComandToGateway(gatewayId, backupId);
|
if (result == false)
|
{
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return false;
|
}
|
|
//发送从云端下载备份文件的命令到网关
|
result = this.SendDownloadGatewayFileComandToGateway(gatewayId, backupId);
|
if (result == false)
|
{
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return false;
|
}
|
|
////恢复协调器nv分区的组网信息
|
//result = this.RestoreGatewayNV(realGateway);
|
//if (result == false)
|
//{
|
// //关闭进度条
|
// ProgressFormBar.Current.Close();
|
// return false;
|
//}
|
|
//打开协调器串口发送功能
|
//result = this.OpenZbMsComSend(realGateway);
|
//if (result == false)
|
//{
|
// //关闭进度条
|
// ProgressFormBar.Current.Close();
|
// return false;
|
//}
|
|
//重启网关系统
|
result = this.GatewayReboot(gatewayId);
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return result;
|
}
|
|
#endregion
|
|
#region ■ 重启网关系统_______________________
|
|
/// <summary>
|
/// 重启网关系统
|
/// </summary>
|
/// <param name="gatewayId"></param>
|
/// <returns></returns>
|
private bool GatewayReboot(string gatewayId)
|
{
|
//正在重启网关系统
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayRerooting));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
int result = -1;
|
HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
|
{
|
if (topic == gatewayId + "/" + "GwReboot_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
|
}
|
});
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 83 } };
|
HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GwReboot", jObject.ToString());
|
|
int timeOut = 0;
|
while (result == -1 && timeOut < 30)
|
{
|
System.Threading.Thread.Sleep(1000);
|
timeOut++;
|
}
|
//移除事件
|
HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
|
|
if (result != 0)
|
{
|
//重启网关系统失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uGatewayRerootFail);
|
if (result == -1)
|
{
|
msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
}
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
|
//网关已经接收到重启命令,接下来去判断网关是否重启完成
|
bool gatewatAction = false;
|
bool threadAction = true;
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
timeOut = 0;
|
while (gatewatAction == false)
|
{
|
//大概网关重启要60秒
|
if (timeOut >= 65 && timeOut % 5 == 0)
|
{
|
//5秒一次,去获取版本
|
var data = HdlGatewayLogic.Current.RefreshGatewayInfo(gatewayId, false, ShowErrorMode.NO);
|
if (data != null)
|
{
|
gatewatAction = true;
|
threadAction = false;
|
break;
|
}
|
}
|
System.Threading.Thread.Sleep(1000);
|
timeOut++;
|
//设置进度值
|
ProgressFormBar.Current.SetValue(timeOut, 180);
|
if (timeOut >= 180)
|
{
|
//180秒还等不到的话,网关应该出问题了
|
threadAction = false;
|
break;
|
}
|
}
|
});
|
while (threadAction == true)
|
{
|
System.Threading.Thread.Sleep(4000);
|
}
|
if (gatewatAction == true)
|
{
|
//设置进度值:100%
|
ProgressFormBar.Current.SetValue(1, 1);
|
System.Threading.Thread.Sleep(1000);
|
//网关数据恢复成功!
|
string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayDataSuccess);
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
|
return true;
|
}
|
else
|
{
|
//响应超时,重启网关系统失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGatewayRerootFail);
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region ■ 保存协调器的nv分区组网信息_________
|
|
/// <summary>
|
/// 保存协调器的nv分区组网信息
|
/// </summary>
|
/// <param name="realGateway"></param>
|
/// <returns></returns>
|
private bool SaveNVFile(ZbGateway realGateway)
|
{
|
//正在保存协调器nv分区信息
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayNVFileSaving));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
int result = -1;
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
if (topic == gatewayID + "/" + "ZbGwOperation/SaveNVFile_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
result = Convert.ToInt32(jobject["Data"]["Flag"].ToString());
|
}
|
};
|
realGateway.Actions += action;
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 500 } };
|
var data = new Newtonsoft.Json.Linq.JObject { { "ImageName", "NVImage.bin" }, { "ImagePath", "/etc/hdlDat/" } };
|
jObject.Add("Data", data);
|
realGateway.Send("ZbGwOperation/SaveNVFile", jObject.ToString());
|
|
int TimeOut = 0;
|
while (result == -1 && TimeOut < 60)
|
{
|
System.Threading.Thread.Sleep(1000);
|
TimeOut++;
|
ProgressFormBar.Current.SetValue(TimeOut, 60);
|
}
|
realGateway.Actions -= action;
|
if (result != 0)
|
{
|
//保存协调器的nv分区组网信息失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uSaveGatewayNVFileFail);
|
if (result == -1)
|
{
|
msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
}
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 打开协调器串口发送功能_____________
|
|
/// <summary>
|
/// 打开协调器串口发送功能
|
/// </summary>
|
/// <param name="realGateway"></param>
|
/// <returns></returns>
|
private bool OpenZbMsComSend(ZbGateway realGateway)
|
{
|
//正在打开协调器串口发送功能
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uZbMsComSendOpening));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
int result = -1;
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
if (topic == gatewayID + "/" + "OpenZbMsComSend_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
|
}
|
};
|
realGateway.Actions += action;
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6119 } };
|
realGateway.Send("OpenZbMsComSend", jObject.ToString());
|
|
int TimeOut = 0;
|
while (result == -1 && TimeOut < 30)
|
{
|
System.Threading.Thread.Sleep(1000);
|
TimeOut++;
|
}
|
realGateway.Actions -= action;
|
if (result != 0)
|
{
|
//打开协调器串口发送功能失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uOpenZbMsComSendFail);
|
if (result == -1)
|
{
|
msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
}
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 恢复协调器nv分区的组网信息_________
|
|
/// <summary>
|
/// 恢复协调器nv分区的组网信息
|
/// </summary>
|
/// <param name="realGateway"></param>
|
/// <returns></returns>
|
private bool RestoreGatewayNV(ZbGateway realGateway)
|
{
|
//正在恢复协调器nv分区
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayNVRestoring));
|
ProgressFormBar.Current.SetValue(0);
|
System.Threading.Thread.Sleep(1000);
|
|
int result = -1;
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
if (topic == gatewayID + "/" + "ZbGwOperation/RestoreNV_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
result = Convert.ToInt32(jobject["Data"]["Flag"].ToString());
|
}
|
};
|
realGateway.Actions += action;
|
|
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 501 } };
|
var data = new Newtonsoft.Json.Linq.JObject { { "ImageName", "NVImage.bin" }, { "ImagePath", "/etc/hdlDat/" } };
|
jObject.Add("Data", data);
|
realGateway.Send("ZbGwOperation/RestoreNV", jObject.ToString());
|
|
int TimeOut = 0;
|
while (result == -1 && TimeOut < 60)
|
{
|
System.Threading.Thread.Sleep(1000);
|
TimeOut++;
|
ProgressFormBar.Current.SetValue(TimeOut, 60);
|
}
|
realGateway.Actions -= action;
|
if (result != 0)
|
{
|
//恢复协调器nv分区失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayNVFail);
|
if (result == -1)
|
{
|
//响应超时,恢复协调器nv分区失败
|
msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndRestoreGatewayNVFail);
|
}
|
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
|
return true;
|
}
|
|
#endregion
|
}
|
}
|