⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 equipandperforminfo.cs

📁 该项目实现在.net 2003上
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Diagnostics;
using System.Windows.Forms;

using ctd.E1Analyzer.GlobalConstant;
//using ctd.E1Analyzer.DatabaseOper;

namespace ctd.E1Analyzer.EquipAndPerformInfoPacket
{

	
	/// <summary>
	/// EquipAndPerformInfo 的摘要说明。
	///1、 一些设备接口和电路信息的配置放在该结构中
	///2、 测试和控制结果存放在该结构中
	///3、 该结构完整一个帧的译码程序,如果该帧需要应答,
	/// </summary>
	public class EquipAndPerformInfo
	{
		public EquipAndPerformInfo()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
			m_OutServiceInsertParamCount = new OutServiceInsertParamCount();
            m_TestResultCount = new TestResultCount(); 
			m_LastTimeRecMessage = new _LastTimeRecMessage();
			m_CirConfigParam = new CirConfigParam();
			m_CommConfigParam = new CommConfigParam();
			testPattern = 170;
            //
			staName = "局站名";
			lnkName = "电路名";
			//m_Db = new Database();
			//m_Db.OpenDatebase();
		}
				
		private byte [] curFrame;  //当前帧
		byte[] ackFrame = null;    //应答帧
       // public Database m_Db;
 
		public byte [] CurFrame
		{
			set
			{
			   curFrame = value;
			   ackFrame = null;   //每次
			}
			get
			{
				return curFrame;
			}
		}
		/// <summary>
		/// 该结构记录了控制平台收到的上次告警条目和15分钟性能条目
		/// 目的是当控制平台收到上述消息时,判断是否是测试模块重复发送的条目
		/// </summary>
		public struct _LastTimeRecMessage
		{
			public struct _AlmMessage
			{
				public int AlmType;
				public DateTime HappenTime;
			}
            public _AlmMessage AlmMessage;
			public struct _FifminPfmMessage
			{
				public DateTime HappenTime;
			}
			public _FifminPfmMessage FifminPfmMessage;
		}
		public _LastTimeRecMessage m_LastTimeRecMessage;
		/// <summary>
		/// 对当前收到的帧进行译码,如果该消息需要应答,则构造并返回应答帧
		/// </summary>
		/// <returns>
		/// 如果返回值为null,表示不需要应答,如果,返回值不为null,则为应答帧
		/// </returns>
		public byte[] DecodeCurFrame()
		{
			
			bool IsRepeat = false;    //是否是重发消息
			bool IsFormatRight = true;//消息格式正确
			DateTime dateTime = DateTime.Now;

			switch(curFrame[1])
			{
				case MsgCommandId.EQUIP_RESET_ACK:
					//
					int len = curFrame.Length;
                    ackFrame = new byte[len];
					Array.Copy(curFrame,0,ackFrame,0,len);
					curFrame[1] = 0x31;
                    //
					if(curFrame[2] == 0)
						MessageBox.Show("设备上电复位");
					else if(curFrame[2] == 1)
                        MessageBox.Show("设备按钮复位");
					else if(curFrame[2] == 2)
                        MessageBox.Show("控制软件软复位");
					break;
				case MsgCommandId.START_TEST_ACK:
                    //
					this.StartTestTime = DateTime.Now;
					this.m_CirConfigParam.TestMode =(byte) (curFrame[2] & 0x0f);//测试模式
                    //
					if(this.m_CirConfigParam.TestMode == 0)
					{
						int refuseCause = (curFrame[2]>>4) & 0x0f;
						if(refuseCause == 0)
						{
							MessageBox.Show("设备拒绝测试--未知原因");
						}
						else if(refuseCause == 1)
						{
							MessageBox.Show("设备拒绝测试--接口类型未配置");
						}
						else if(refuseCause == 2)
						{
							MessageBox.Show("设备拒绝测试--电路速率未配置");
						}
						else if(refuseCause == 3)
						{
							MessageBox.Show("设备拒绝测试--本机没有有效时间");
						}

					}
					break;
				case MsgCommandId.STOP_TEST_ACK:
					 this.EndTestTime = new DateTime(
						((int)curFrame[3]<<8) | curFrame[2],
						curFrame[4],
						curFrame[5],
						curFrame[6],
						curFrame[7],
						curFrame[8]
						);
					break;
				case MsgCommandId.ROUTE_TEST_ACK:
					//Debug.WriteLine("《---路由测试应答消息");

					break;
				case MsgCommandId.TIME_CHECK_ACK:
					//Debug.WriteLine("《---时间校正应答消息");
					break;
				case MsgCommandId.INFO_SET_ACK:
					//Debug.WriteLine("《---接口和电路信息设置确认消息");
                    this.m_CirConfigParam.InterfaceType = curFrame[2];
                    this.m_CirConfigParam.SyncAndClockMode = curFrame[3];
					this.m_CirConfigParam.FrameOrRateCatg =  curFrame[4];
                    this.m_CirConfigParam.TimeSlot = (uint)((uint)curFrame[8]<<24) | ((uint)curFrame[7]<<16) | (uint)((uint)curFrame[6]<< 8) | (uint)curFrame[5];

					break;
				case MsgCommandId.OUT_SERVICE_TEST_CTRL_ACK:
                    //Debug.WriteLine("《---中断业务测试控制应答消息");
                    ;
					break;
				case MsgCommandId.REAL_PFM_QUERY_ACK:
					//Debug.WriteLine("《---实时性能信息查询响应消息");
                    m_TestResultCount.Es  = (uint)curFrame[4]<<16  | (uint)curFrame[3]<< 8 | (uint)curFrame[2];
					m_TestResultCount.Ses = (uint)curFrame[7]<<16  | (uint)curFrame[6]<< 8 | (uint)curFrame[5];
					m_TestResultCount.Us  = (uint)curFrame[10]<<16 | (uint)curFrame[9]<< 8 | (uint)curFrame[8];
					m_TestResultCount.Ec  = (uint)curFrame[16]<<32 | (uint)curFrame[15]<< 24 | (uint)curFrame[14]
						                  | (uint)curFrame[13]<<16 | (uint)curFrame[12]<< 8  | (uint)curFrame[11];
					m_TestResultCount.Tc  = (uint)curFrame[22]<<32 | (uint)curFrame[21]<< 24 | (uint)curFrame[20]
						                  | (uint)curFrame[19]<<16 | (uint)curFrame[18]<< 8  | (uint)curFrame[17];

					break;
				case MsgCommandId.FIF_MIN_PFM:
					//Debug.WriteLine("《---15分钟性能上报消息");
					uint es = 0;
					uint ses = 0;
					uint us = 0;
					uint ec = 0;
					uint tc = 0;
										
					try
					{
						es  = (uint)(((uint)curFrame[3]<<8) | curFrame[2]);
						ses = (uint)(((uint)curFrame[5]<<8) | curFrame[4]);
						us  = (uint)(((uint)curFrame[7]<<8) | curFrame[6]);
						ec  = (uint)(((uint)curFrame[11]<<8) |((uint)curFrame[10]<<8) 
							| ((uint)curFrame[9] << 8) | curFrame[8]);
						tc  = (uint)(((uint)curFrame[15]<< 8) |((uint)curFrame[14]<<8) 
							| ((uint)curFrame[13]<< 8) | curFrame[12]);
					}
					catch(Exception e)
					{
                       IsFormatRight = false;
					   //Debug.WriteLine(e.Message);
				       MessageBox.Show(e.Message);


					}
					try
					{
						dateTime = new DateTime(
							(int)((int)curFrame[17]<<8 | curFrame[16]),
							(int)curFrame[18],
							(int)curFrame[19],
							(int)curFrame[20],
							(int)curFrame[21],
							(int)curFrame[22]
							);
					}
					catch
					{
                        IsFormatRight = false;
                        //Debug.WriteLine("15分钟上报信息,日期时间格式错误");
						MessageBox.Show("15分钟上报信息,日期时间格式错误");
					}
					if(IsFormatRight && dateTime == this.m_LastTimeRecMessage.FifminPfmMessage.HappenTime)
					{
						IsRepeat = true;
					}
					//入库
					if(IsFormatRight && !IsRepeat)
					{
						this.m_LastTimeRecMessage.FifminPfmMessage.HappenTime = dateTime;
                        //
						//入库.............................
						string strSql = String.Format("INSERT INTO tab_pfm(StaName,LnkName,es,ses,us,ec,tc,happenTime) VALUES('{0}','{1}',{2},{3},{4},{5},{6},'{7}')",staName,lnkName,es,ses,us,ec,tc,dateTime.ToString("yyyy-MM-dd hh:mm:ss"));
						//m_Db.ExcuteCommand(strSql);
					}
					//生成应答帧
					ackFrame = new byte[2];
					ackFrame[0] = 0;
					ackFrame[1] = 0x39;
					break;
				case MsgCommandId.ALM:
					Debug.WriteLine("《---电路告警上报消息");
					
					int almType = 0;
					//
					try
					{
						almType = (int)curFrame[2];
					}
					catch(Exception e)
					{
						IsFormatRight = false;
						Debug.WriteLine(e.Message);
					}
					try
					{
						dateTime = new DateTime(
							(int)((int)curFrame[4]<<8 | curFrame[3]),
							(int)curFrame[5],
							(int)curFrame[6],
							(int)curFrame[7],
							(int)curFrame[8],
							(int)curFrame[9]

							);
					}
					catch(Exception e)
					{
						Debug.WriteLine(e.Message);
						Debug.WriteLine("告警上报日期格式错误");
						IsFormatRight = false;
					}

					if(IsFormatRight && almType  == this.m_LastTimeRecMessage.AlmMessage.AlmType &&
						dateTime ==  this.m_LastTimeRecMessage.AlmMessage.HappenTime)
					{
						IsRepeat = true;
					}
					//计算并入库
					if(IsFormatRight  && !IsRepeat)
					{
						//计算
						if(almType == 0 
							&& m_LastTimeRecMessage.AlmMessage.AlmType != 0)//告警结束
						{
							TimeSpan timeSpan = dateTime 
								- m_LastTimeRecMessage.AlmMessage.HappenTime;
							int almTime = (int)timeSpan.TotalSeconds;
							
							this.m_TestResultCount.AlmTime[m_LastTimeRecMessage.AlmMessage.AlmType - 1] += (uint)almTime;

						}
						if(almType !=0 && m_LastTimeRecMessage.AlmMessage.AlmType != 0 && almType != m_LastTimeRecMessage.AlmMessage.AlmType)//告警变化
						{
							TimeSpan timeSpan = dateTime 
								- m_LastTimeRecMessage.AlmMessage.HappenTime;
							int almTime = (int)timeSpan.TotalSeconds;
							//
							this.m_TestResultCount.AlmTime[m_LastTimeRecMessage.AlmMessage.AlmType - 1] += (uint)almTime;

						}
                        //入库........................................
						string strSql = String.Format("INSERT INTO tab_alm(StaName,LnkName,almType,startTime,endTime) VALUES('{0}','{1}',{2},'{3}','{4}')",
							staName,
							lnkName,
							this.m_LastTimeRecMessage.AlmMessage.AlmType,
							this.m_LastTimeRecMessage.AlmMessage.HappenTime.ToString("yyyy-MM-dd hh:mm:ss"),
							dateTime.ToString("yyyy-MM-dd hh:mm:ss"));
						//m_Db.ExcuteCommand(strSql);
						//
						this.m_TestResultCount.NowAlmType = (uint)almType;
						this.m_TestResultCount.NowAlmBeginTime = dateTime;
						//置换
						this.m_LastTimeRecMessage.AlmMessage.AlmType = almType;
						this.m_LastTimeRecMessage.AlmMessage.HappenTime = dateTime;
				    }

					//生成应答帧
					ackFrame = new byte[2];
					ackFrame[0] = 0;
					ackFrame[1] = 0x40;
					break;
				case MsgCommandId.CIR_BACK_DELAY_TEST_ACK:
					//Debug.WriteLine("《---环路延时测试响应消息");
					this.m_CirConfigParam.CirBackDelayTime = (uint)curFrame[5]<<24 | (uint)curFrame[4]<<16  | (uint)curFrame[3]<< 8 | (uint)curFrame[2];
					break;
				case MsgCommandId.LAMP_QUERY_ACK:
					//Debug.WriteLine("《---指示灯查询响应消息");
					this.m_CirConfigParam.Lamp = (uint)curFrame[3]<< 8 | (uint)curFrame[2];
					break;
				default:
					break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -