| | |
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return -1;
|
| | | }
|
| | | ChannelIdInfo data = null;
|
| | | 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 = Newtonsoft.Json.JsonConvert.DeserializeObject<ChannelIdInfo>(jobject["Data"].ToString());
|
| | | data = Convert.ToInt32(jobject["Data"]["Channel"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
| | | realWay.Send("ZbGw/GetChannel", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (data == null && TimeOut < 30)
|
| | | while (data == -1 && TimeOut < 30)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (data == null)
|
| | | if (data == -1)
|
| | | {
|
| | | //获取协调器信道失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | return -1;
|
| | | }
|
| | |
|
| | | return data.Channel;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关信道信息
|
| | | /// </summary>
|
| | | private class ChannelIdInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 网关信道
|
| | | /// </summary>
|
| | | public int Channel = -1;
|
| | | return data;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return null;
|
| | | }
|
| | | CoordinatorMacInfo data = 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 = Newtonsoft.Json.JsonConvert.DeserializeObject<CoordinatorMacInfo>(jobject["Data"].ToString());
|
| | | data = jobject["Data"]["MacAddr"].ToString();
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | return null;
|
| | | }
|
| | |
|
| | | return data.MacAddr;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关协调器Mac信息
|
| | | /// </summary>
|
| | | private class CoordinatorMacInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 调器Mac
|
| | | /// </summary>
|
| | | public string MacAddr = string.Empty;
|
| | | return data;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
|
| | | return -1;
|
| | | }
|
| | | PanIdInfo data = null;
|
| | | 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);
|
| | | data = Newtonsoft.Json.JsonConvert.DeserializeObject<PanIdInfo>(jobject["Data"].ToString());
|
| | | panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | |
| | | realWay.Send("ZbGw/GetPanId", jObject.ToString());
|
| | |
|
| | | int TimeOut = 0;
|
| | | while (data == null && TimeOut < 30)
|
| | | while (panId == -1 && TimeOut < 30)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | if (data == null)
|
| | | if (panId == -1)
|
| | | {
|
| | | //获取协调器PanID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg);
|
| | | return -1;
|
| | | }
|
| | |
|
| | | return data.PANID;
|
| | | 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>
|
| | | /// 网关PanId信息
|
| | | /// 设置网关自动备份设置
|
| | | /// </summary>
|
| | | private class PanIdInfo
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="statu"></param>
|
| | | /// <returns></returns>
|
| | | public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu)
|
| | | {
|
| | | /// <summary>
|
| | | /// PanId
|
| | | /// </summary>
|
| | | public int PANID = -1;
|
| | | 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
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
|
| | | {
|
| | | //没有找到真实物理网关
|
| | | return false;
|
| | | }
|
| | | string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
|
| | | //创建文件对象
|
| | | var result = await realWay.CreateFileAsync(fileName);
|
| | | if (result == null || result.Result != 0)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //发送数据流
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | var result2 = await realWay.SendFileAsync(byteData);
|
| | | if (result2 == null || result2.Result != 0)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //ZbGateway realWay = null;
|
| | | //if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
|
| | | //{
|
| | | // //没有找到真实物理网关
|
| | | // return false;
|
| | | //}
|
| | | //string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
|
| | | ////创建文件对象
|
| | | //var result = await realWay.CreateFileAsync(fileName);
|
| | | //if (result == null || result.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | ////发送数据流
|
| | | //var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
|
| | | //var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | //var result2 = await realWay.SendFileAsync(byteData);
|
| | | //if (result2 == null || result2.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | return true;
|
| | | }
|
| | |
|