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

📄 eqpool.cpp

📁 电信机房MDF、电源柜监控源码,主要用在通信机房配线设备监控、电源柜监控
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// EQPool.cpp: implementation of the CEQPool class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MDF.h"
#include "EQPool.h"
#include "MDFDlg.h"
#include "ClientSock.h"
#include ".\eqpool.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CMDFApp theApp ;

//##ModelId=44B6F88602B0
CEQPool::CEQPool()
{
	m_nCount = 0 ;					//已加载设备数
	//ResetEQ() ;
	m_pAdoDB = theApp.m_pAdoDB;
}

//##ModelId=44B6F88602BF
CEQPool::~CEQPool()
{
	//int i,j ;
	//CList<sCmd,sCmd> *pCmdList ;
	//CList<sAShield , sAShield> *pShield ;

	//for( i = 0 ; i < EQ_MAX ; i++ )
	//{
	//	if( m_EQArray[i].bIsUse )
	//	{
	//		//CloseHandle( m_EQArray[i].hEvent ) ;

	//		if( m_EQArray[i].pCmdList != NULL )
	//		{
	//			pCmdList = (CList<sCmd,sCmd> *)m_EQArray[i].pCmdList ;
	//			pCmdList->RemoveAll() ;
	//			delete pCmdList ;
	//		}

	//		for( j = 0 ; j < PORT_MAX ; j++ )
	//		{
	//			if( m_EQArray[i].sPort[j].bIsUse )
	//			{
	//				if( m_EQArray[i].sPort[j].pShield != NULL )
	//				{
	//					pShield = (CList<sAShield , sAShield>*)m_EQArray[i].sPort[j].pShield ;
	//					pShield->RemoveAll() ;
	//					delete pShield ;
	//				}
	//			}
	//		}
	//	}
	//}

	//m_EQArray.RemoveAll() ;
}

//##ModelId=44B6F88602AF
int CEQPool::ClearEQ()	//清空设备池
{
	int i,j,len ;
	CString strTip ;
	sCommEQ* pEQ ;

	CList< sCmd , sCmd >	*pCmdList ;	
	CList< sAShield , sAShield >	*pShield ;

	try
	{
		len = GetCount() ;
		

		if( len <= 0 )
			return 0 ;

		for( i = 0 ; i < len ; i++ )
		{

			pEQ = &m_EQArray[i] ;

			pCmdList = (CList<sCmd,sCmd>*)(pEQ->pCmdList) ;

			if( pEQ->nPortNum > 0 )
			{
				for( j = 0 ; j < pEQ->nPortNum ; j++ )
				{
					pShield = (CList< sAShield , sAShield >*)(pEQ->sPort[j].pShield) ;

					if(pShield != NULL )
					{
						if( !pShield->IsEmpty() )
							pShield->RemoveAll() ;
						delete pShield ;
						pShield = NULL ;
					}
				}
			}

			if( pCmdList != NULL )
			{
				if( !pCmdList->IsEmpty() )
					pCmdList->RemoveAll() ;

				delete pCmdList ;
				pCmdList = NULL ;
				strTip.Format("程序:清除命令队列 %s ",pEQ->strName) ;
				theApp.TestWriteLog(strTip) ;
			}

			pEQ->bIsUse = FALSE ;

		}

		ResetEQ() ;
		strTip.Format("系统:清除所有监测设备") ;
		theApp.OutPut(strTip) ;
		//theApp.OutPut(strTip) ;

		m_nCount = 0 ;

		return 0 ;
	}
	catch (_com_error e)
	{
		strTip.Format("异常:清除设备出现异常 %s",(LPCSTR)e.Description()) ;
		theApp.OutPut(strTip) ;
		return -1 ;
	}
}



/***************************************************
		初始设备部分待检查
		
****************************************************/
//##ModelId=44B6F88602A3
int CEQPool::InitEQ()
{
	int nSort = 0 ;
	int nNo = 0 ;
	int nResult = 0 ;
	int i,j,k,nCount,nState ;

	CString strError ;

	sCommEQ* pEQ ; 

	CString strTip ;		//系统提示信息
	CString strStep ;		//系统运行阶段信息
	CString strSQL ;		//SQL语句
	CString strName,strKeyName ;
	CString strTable1,strTable2,strTable3 ;

	_variant_t var;
	_RecordsetPtr pRsPtr1, pRsPtr2, pRsPtr3 ;

	CList<sCmd , sCmd>	*pCmdList ;	
	CList<sAShield , sAShield>	*pShield ;

	try
	{
		strTip.Empty() ;

		strTip = "系统:初始化 监测设备..." ;

		theApp.OutPut(strTip) ;
		

		pRsPtr1.CreateInstance(__uuidof(Recordset));
		pRsPtr2.CreateInstance(__uuidof(Recordset));
		pRsPtr3.CreateInstance(__uuidof(Recordset));

		//******读取监测模块表******
		strStep = "异常:初始化" ;

		strTable1 = "CMTSVModule" ; //监测模块表

		strSQL.Format("SELECT * FROM %s",strTable1) ;

		strTip = strStep + "读监测模块表:CMTSVModule 出错:" ;

		if( m_pAdoDB->ReadDB(strSQL, pRsPtr1,strTip) != 0 )//读监测模块表
		{
			return -1 ;//完全未能初始化
		}

		if( pRsPtr1->adoEOF ) //监测设备
		{
			strTip = strStep + "表 CMTSVModule 不存在监测模块数据,请先录入" ;
			theApp.OutPut(strTip) ;
			return -1 ;
		}

//**************读取所有监测模块设备***************

		for( i = 0 , nCount = 0 ; !pRsPtr1->adoEOF ; nCount++)
		{
			nState = 0 ;

			pCmdList = new CList<sCmd,sCmd> ;//@@@

			//获取监测模块名

			strTip = strStep + " 读表 CMTSVModule 的 监测模块名 SVMName 出错:" ;

			if( m_pAdoDB->GetRdData( "SVMName",pRsPtr1,var,strTip ) != 0 )
			{
				nResult++ ;
				nState = 1 ;
				m_EQArray[i].strName = "未知" ;
			}
			else
				m_pAdoDB->GetStrVar(var, m_EQArray[i].strName, strTip) ;

			strName = m_EQArray[i].strName ;
			strName.TrimLeft() ;
			strName.TrimRight() ;
			strStep.Format("异常:初始化 设备 %s" , strName ) ;

			//获取监测模块ID号
			strTip.Format("%s 读表 CMTSVModule 的 监测模块ID号 SVMID 出错:",strStep) ;
			
			if( m_pAdoDB->GetRdData( "SVMID", pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;
				nState = 1 ;
				m_EQArray[i].nID = -1 ;
			}
			else
				m_pAdoDB->GetIntVar(var,m_EQArray[i].nID,strTip) ;

			//获取监测模块类型ID
			strTip.Format("%s 读表 CMTSVModule 的 监测模类型ID SVMTID 出错:",strStep) ;

			if( m_pAdoDB->GetRdData( "SVMTID", pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].nTID = -1 ;
			}
			else
				m_pAdoDB->GetIntVar(var, m_EQArray[i].nTID, strTip) ;

//*************读取监测模块类型表************
			strTable2 = "CMTSVModuleType" ;//监测模块类型表
			strSQL.Format("SELECT * FROM %s WHERE %s=%d",strTable2,"SVMTID",m_EQArray[i].nTID) ;
			strTip.Format("%s 读表 CMTSVModuleType 出错:",strStep) ;

			if( m_pAdoDB->ReadDB(strSQL, pRsPtr2, strTip) != 0 )//读监测类型表
			{
				nResult++ ;
				nState = 2 ;
			}

			if( !pRsPtr2->adoEOF )
			{
				strTip.Format("%s 读表 CMTSVModuleType 的 监测模块编码 SVMTNum 出错:",strStep) ;

				if( m_pAdoDB->GetRdData("SVMTNum",pRsPtr2,var,strTip) != 0 )
				{
					nResult++ ;
					nState = 2 ;
					m_EQArray[i].strType.Empty() ;
				}
				else
					m_pAdoDB->GetStrVar(var,m_EQArray[i].strType,strTip) ;
			}
			else//~异常~数据库无此类型
			{
				strTip.Format("%s 读表 CMTSVModuleType 类型 :SVMTID 不存在 ",strStep) ; 
				theApp.OutPut(strTip) ;
				nResult++ ;
				nState = 2 ;
			}

			pRsPtr2->Close() ; 
			//******关闭数据表******

			//获取监测模块通讯ADR地址
			strTip.Format("%s 读表 CMTSVModule 的 监测模块地址编码 SVMAddrCode 出错:",strStep) ;

			if( m_pAdoDB->GetRdData("SVMAddrCode",pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].strIDAddr.Empty() ;
			}
			else
				m_pAdoDB->GetStrVar(var,m_EQArray[i].strIDAddr,strTip) ;

			//获取监测模块通讯来源地址
			strTip.Format("%s 读表 CMTSVModule 的 监测模块的来源地址 SVMADDRSource 出错:",strStep) ;

			if( m_pAdoDB->GetRdData("SVMADDRSource",pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;	
				nState = 2 ;
				m_EQArray[i].strCommAddr = "" ;
			}
			else
				m_pAdoDB->GetStrVar(var,m_EQArray[i].strCommAddr,strTip) ;

			//获取监测模块通讯模式
			strTip.Format("%s 读表 CMTSVModule 的 监测模块的通讯方式 SVMComModel 出错:",strStep) ;

			if( m_pAdoDB->GetRdData("SVMComModel",pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].nModel = -1 ;
			}
			else
				m_pAdoDB->GetIntVar(var,m_EQArray[i].nModel,strTip) ; // 0 -- UDP ; 1 -- 串口 ; 2 -- TCP

			//获取监测模块的端口数
			strTip.Format("%s 读表 CMTSVModule 的 监测模块的端口数 SVMPortNum 出错:",strStep) ;

			if( m_pAdoDB->GetRdData("SVMPortNum",pRsPtr1,var,strTip) != 0 )
			{
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].nPortNum = 0 ;
			}
			else
				m_pAdoDB->GetIntVar(var,m_EQArray[i].nPortNum,strTip) ;

			if( m_EQArray[i].nPortNum == 0 )
			{
				strTip.Format("%s 读表 CMTSVModule 的 端口数为0 设备无法正常运行",strStep) ; 
				theApp.OutPut(strTip) ;
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].nPortNum = 0 ;
			}

//****************初始化端口**********************
			strTable2 = "CMTSVModulePort" ;//读监测模块端口表
			strSQL.Format("SELECT * FROM %s WHERE SVMID = %d ",strTable2,m_EQArray[i].nID) ;

			strTip.Format("%s 读表 CMTSVModulePort 出错:",strStep) ;

			if( m_pAdoDB->ReadDB(strSQL, pRsPtr2,strTip) != 0 )//读数据库监测模块端口表
			{
				nResult++ ;
				nState = 2 ;
				m_EQArray[i].nPortNum = 0 ;
			}

			for( j = 0 ; j < m_EQArray[i].nPortNum ; j++ ) //根据配置的端口数目读端口数据。
			{
				m_EQArray[i].sPort[j].nANum = 0 ;		//端口告警次数请零
				m_EQArray[i].sPort[j].bIsUse = TRUE ;	//端口使用标志

				if( !pRsPtr2->adoEOF )
				{
					//读取端口序号

					strTip = strStep + " 读表 CMTSVModulePort 的 监测模块端口序号 SVMPSort 出错" ;
					if( m_pAdoDB->GetRdData("SVMPSort",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 2 ;
						m_EQArray[i].sPort[j].strPortSort.Empty() ;
					}
					else
						m_pAdoDB->GetStrVar(var,m_EQArray[i].sPort[j].strPortSort ,strTip) ;

					//读取被监测点序号
					strTip = strStep + " 读表 CMTSVModulePort 的 被监测点序号 SVSpotSort 出错" ;
					
					if( m_pAdoDB->GetRdData("SVSpotSort",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].strSpotSort.Empty() ;												
					}
					else
						m_pAdoDB->GetStrVar(var, m_EQArray[i].sPort[j].strSpotSort ,strTip) ;

					//读取被监测设备序号
					strTip = strStep + " 读表 CMTSVModulePort 的 被监测设备ID号 SVDID 出错" ;

					if( m_pAdoDB->GetRdData("SVDID",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].nSVDID = -1 ;
					}
					else
						m_pAdoDB->GetIntVar(var,m_EQArray[i].sPort[j].nSVDID,strTip) ;

					//读取监测模块端口类型 0 状态量 1 模拟量
					strTip = strStep + " 读表 CMTSVModulePort 的 监测模块端口类型 SVMPType 出错" ;
					if( m_pAdoDB->GetRdData("SVMPType",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 2 ;
						m_EQArray[i].sPort[j].nType = -1 ;
					}
					else
						m_pAdoDB->GetIntVar(var,m_EQArray[i].sPort[j].nType,strTip) ;
					
					//读取一级告警范围
					strTip = strStep + " 读表 CMTSVModulePort 的 一级告警范围 SVMPAlarmL1 出错" ;
					if( m_pAdoDB->GetRdData("SVMPAlarmL1",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].strAlarmL1 = "" ;												
					}
					else
						m_pAdoDB->GetStrVar(var, m_EQArray[i].sPort[j].strAlarmL1,strTip) ;

					//读取二级告警范围
					strTip = strStep + " 读表 CMTSVModulePort 的 二级告警范围 SVMPAlarmL2 出错" ;

					if( m_pAdoDB->GetRdData("SVMPAlarmL2",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].strAlarmL2 = "" ;												
					}
					else
						m_pAdoDB->GetStrVar(var, m_EQArray[i].sPort[j].strAlarmL2,strTip) ;

					//读取三级告警范围
					strTip = strStep + " 读表 CMTSVModulePort 的 三级告警范围 SVMPAlarmL3 出错" ;

					if( m_pAdoDB->GetRdData("SVMPAlarmL3",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].strAlarmL3 = "" ;												
					}
					else
						m_pAdoDB->GetStrVar(var, m_EQArray[i].sPort[j].strAlarmL3,strTip) ;

					//读取告警屏蔽数
					strTip = strStep + " 读表 CMTSVModulePort 的 告警屏蔽数 MaskingNum 出错" ;
					if( m_pAdoDB->GetRdData("MaskingNum",pRsPtr2,var,strTip) != 0 )
					{
						nResult++ ;
						nState = 1 ;
						m_EQArray[i].sPort[j].nAShieldNum = 0 ;												
					}
					else
						m_pAdoDB->GetIntVar(var, m_EQArray[i].sPort[j].nAShieldNum,strTip) ;

//*****************读告警屏蔽表*********************

⌨️ 快捷键说明

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