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

📄 publicclass.cpp

📁 为电力系统开发保护设备装置通讯的源代码 采用串口通讯, ret hat 9下 QT开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
CDeviceNode* CNodeManage ::FindDevicebyEquipNo(int EquipNo,int Level,int & index) {    CDeviceNode* pNode=NULL;    index=-1;    DeviceInfoListType::iterator it;    for(int i=0;i<(int)m_DeviceNode.count();i++)    {		pNode=m_DeviceNode.at(i);		if(Level==0)		{			if((int)pNode->m_deviceinfo.m_EquipNo==EquipNo) return pNode;		}		else if(Level==1)	   //查找二级接点		{			for(int j=0;j<(int)pNode->m_ChildDevList.count();j++)			{				it=pNode->m_ChildDevList.at(j);				if((int)(*it).m_EquipNo==EquipNo) 				{					index=j;return pNode;				}			}		}		else		{			if((int)pNode->m_deviceinfo.m_EquipNo==EquipNo) return pNode;			for(int j=0;j<(int)pNode->m_ChildDevList.count();j++)			{				it=pNode->m_ChildDevList.at(j);				if((int)(*it).m_EquipNo==EquipNo) 				{					index=j;return pNode;				}			}		}    }    return NULL;}CDeviceNode* CNodeManage ::FindDevicebyEquipNo(QString RecordIndex,int Level,int & index) {    CDeviceNode* pNode=NULL;    index=-1;    DeviceInfoListType::iterator it;QString s1;    for(int i=0;i<(int)m_DeviceNode.count();i++)    {		pNode=m_DeviceNode.at(i);		if(Level==0)		{			s1.sprintf("%s",pNode->m_deviceinfo.m_RecordIndex);			if(s1==RecordIndex) return pNode;		}		else if(Level==1)	   //查找二级接点		{			for(int j=0;j<(int)pNode->m_ChildDevList.count();j++)			{				it=pNode->m_ChildDevList.at(j);				s1.sprintf("%s",(*it).m_RecordIndex);				if(s1==RecordIndex) 				{					index=j;return pNode;				}			}		}		else		{			s1.sprintf("%s",pNode->m_deviceinfo.m_RecordIndex);			if(s1==RecordIndex) return pNode;			for(int j=0;j<(int)pNode->m_ChildDevList.count();j++)			{				it=pNode->m_ChildDevList.at(j);				s1.sprintf("%s",(*it).m_RecordIndex);				if(s1==RecordIndex) 				{					index=j;return pNode;				}			}		}    }    return NULL;}void CNodeManage ::FindDeviceNo(QString RecordIndex, int & index) {    CDeviceNode* pNode=NULL;    index=-1;    DeviceInfoListType::iterator it;QString s1;    for(int i=0;i<(int)m_DeviceNode.count();i++)    {		pNode=m_DeviceNode.at(i);		if (pNode->m_ChildDevList.count() == 0)		{			s1.sprintf("%s",pNode->m_deviceinfo.m_RecordIndex);			if(s1==RecordIndex) 			{				index=pNode->m_deviceinfo.m_EquipNo;			}			return;		}		for(int j=0;j<(int)pNode->m_ChildDevList.count();j++)		{			it=pNode->m_ChildDevList.at(j);			s1.sprintf("%s",(*it).m_RecordIndex);			if(s1==RecordIndex) 			{				index=(*it).m_EquipNo;return;			}		}    }    return;}void CNodeManage :: DeleteDeviceNode(void* pNode){    m_DeviceNode.remove((CDeviceNode*)pNode);    }CDataNode* CNodeManage :: FindRecvDataNode(long ithreadid /* = -1 */){	if (ithreadid == -1)	{		if (m_RecvNode.count() > 0)			return m_RecvNode.at(0);		return NULL;	}	int iSize = m_RecvNode.count();	if (iSize == 0) return NULL;	CDataNode* pDataNode = NULL;	for (int i=0; i<iSize; i++)	{		pDataNode = m_RecvNode.at(i);		if (pDataNode->m_nodeinfo.m_CurrentThread == ithreadid)		{			return pDataNode;		}	}	return NULL;}void CNodeManage :: DeleteRecvDataNode(CDataNode* pNode){    if(!pNode) return;    char* buff=NULL;    if(pNode->m_nodeinfo.m_SegmentPid>0)    {		buff=(char*)pNode->m_nodeinfo.m_SegmentPid;		if (buff) delete buff;    }    m_RecvNode.remove(pNode);}//***************用于下发命令的函数***************************************bool CNodeManage :: AddSendDataNode(long DestPid,long DestThread,unsigned int DataType,				    int iMachineNo){    st_nodeinfo st;    memset(&st,0x00,sizeof(st_nodeinfo));    if(DestPid==0) return 0;    st.mtype=DestPid;st.requestid=getpid();st.m_CurrentThread=DestThread;st.m_DataType=DataType;    st.m_DataFrom=0;st.m_iResult=0;st.m_DisplayFlag=1;    st.m_Level=0;st.m_TransThread=0;st.m_MachineNo=iMachineNo;    CDataNode* pNode=new CDataNode();    memcpy(&pNode->m_nodeinfo,&st,sizeof(st_nodeinfo));    m_SendNode.append(pNode);    return 1;}bool CNodeManage :: AddSendDataNode(long DestPid,long DestThread,unsigned int DataType,				  void* qbuf,int iSize,				  unsigned int DataFrom,int iResult,int DisplayFlag,				  int Level,long TransThread){    st_nodeinfo st;    memset(&st,0x00,sizeof(st_nodeinfo));    if(DestPid==0) return 0;    st.mtype=DestPid;st.requestid=getpid();st.m_CurrentThread=DestThread;st.m_DataType=DataType;    st.m_DataFrom=DataFrom;st.m_iResult=iResult;st.m_DisplayFlag=DisplayFlag;    st.m_Level=Level;st.m_TransThread=TransThread;    if(qbuf&&iSize>0)    {	char* buff=new char[iSize];	memcpy(buff,qbuf,iSize);	st.m_SegmentPid=(long)buff;	st.m_iSize=iSize;    }    CDataNode* pNode=new CDataNode();    memcpy(&pNode->m_nodeinfo,&st,sizeof(st_nodeinfo));    m_SendNode.append(pNode);    return 1;}bool CNodeManage :: AddSendDataNode(void* ppNode){    m_SendNode.append((CDataNode*)ppNode);    return 1;}bool CNodeManage :: AddDispDataNode(void* ppNode){    m_DispNode.append((CDataNode*)ppNode);    return 1;}CDataNode* CNodeManage :: FindSendDataNode(){    if(m_SendNode.count()>0)	return m_SendNode.at(0);    return NULL;}CDataNode* CNodeManage :: FindDispDataNode(){    if(m_DispNode.count()>0)	return m_DispNode.at(0);    return NULL;}void CNodeManage :: DeleteDispDataNode(CDataNode* pNode){	if (!pNode) return;    char* buff=NULL;    if (pNode->m_nodeinfo.m_SegmentPid>0)    {		buff=(char*)pNode->m_nodeinfo.m_SegmentPid;		delete [] buff;    }    m_DispNode.remove(pNode);}void CNodeManage :: DeleteSendDataNode(CDataNode* pNode){    if(!pNode) return;    uchar* buff=NULL;    if(pNode->m_nodeinfo.m_SegmentPid>0)    {		buff=(uchar*)pNode->m_nodeinfo.m_SegmentPid;		delete [] buff;	}	m_SendNode.remove(pNode);}//add by huyongchunCDataNode* CNodeManage::FindCmdFromRDN(int EquipNo){	int iSize = m_RecvNode.count();	if (iSize == 0) return NULL;	CDataNode* pDataNode = NULL;	for (int i=0; i<iSize; i++)	{		pDataNode = m_RecvNode.at(i);		if (pDataNode->m_nodeinfo.m_CurrentThread != 0)		{			if (pDataNode->m_nodeinfo.m_MachineNo == EquipNo)			{				return pDataNode;			}		}	}    return NULL;}	CDataNode* CNodeManage::FindCmdFromRDN(long threadid, int EquipNo /* = 0 */){	int iSize = m_RecvNode.count();	if (iSize == 0) return NULL;	CDataNode* pDataNode = NULL;	for (int i=0; i<iSize; i++)	{		pDataNode = m_RecvNode.at(i);		if (pDataNode->m_nodeinfo.m_CurrentThread == threadid)		{			if (EquipNo != 0)			{				if (pDataNode->m_nodeinfo.m_MachineNo == EquipNo)				{					return pDataNode;				}			}			else return pDataNode;				}	}    return NULL;}//end addCCommand :: CCommand(){    }CCommand :: ~CCommand(){    }CPublicClass :: CPublicClass(){    m_UniqueId=0;    m_Stop=FALSE;    m_DbSelfCheckInterval=120;	m_MainForm = NULL;	m_bComm = false;    return;}CPublicClass :: ~CPublicClass(){    return;}CXMLReader* CPublicClass::FindXmlFile(QString szFileName){	CXMLReader* pxml = NULL;	for (int i=0; i<(int)m_XmlList.count(); i++)	{		pxml = m_XmlList.at(i);		if (pxml->m_FileName == szFileName)		{			return pxml;		}	}	pxml = new CXMLReader(szFileName);	if (!pxml->OpenDomXMLFile())	{		delete pxml;		pxml = NULL;		return NULL;	}	m_XmlList.append(pxml);	return pxml;}void CPublicClass :: InstallCommand(){    CCommand* pCmd=NULL;    pCmd=new CCommand();pCmd->m_CmmId=WM_MODIFYTIME;    pCmd->m_CmmStr=_T("申请修改时钟");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTPARAMVALUE;    pCmd->m_CmmStr=_T("申请定值");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTPVSECTOR;    pCmd->m_CmmStr=_T("申请定值区号");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_MODIFYPARAMVALUE;    pCmd->m_CmmStr=_T("修改设备定值");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTCHGPVSECTOR;    pCmd->m_CmmStr=_T("切换定值区号");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTANLOGVALUE;    pCmd->m_CmmStr=_T("申请采样值");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_SERIESANLOGBEGIN;    pCmd->m_CmmStr=_T("连续采样记录开始");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_SERIESANLOGEND;    pCmd->m_CmmStr=_T("连续采样记录停止");m_CommandList.append(pCmd);        pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTSWITCHVALUE;    pCmd->m_CmmStr=_T("申请开关量");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_MODIFYSWITCHVALUE;    pCmd->m_CmmStr=_T("申请修改开关量");m_CommandList.append(pCmd);        pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTSHUVALUE;    pCmd->m_CmmStr=_T("申请软压板");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_SHUTTERSTATEON;    pCmd->m_CmmStr=_T("申请投软压板");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_SHUTTERSTATEOFF;    pCmd->m_CmmStr=_T("申请退软压板");m_CommandList.append(pCmd);        pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTDISTURBDATA;    pCmd->m_CmmStr=_T("申请扰动波形");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTFILELIST;    pCmd->m_CmmStr=_T("申请文件列表");m_CommandList.append(pCmd);        pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTREMOTEREC;    pCmd->m_CmmStr=_T("申请遥控录波");m_CommandList.append(pCmd);        pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTCOMMSTATE;    pCmd->m_CmmStr=_T("申请通信状态");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTCOMMRESET;    pCmd->m_CmmStr=_T("申请通信复位");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTHFRESET;    pCmd->m_CmmStr=_T("申请高频复归");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_REQUESTHFEXCHG;    pCmd->m_CmmStr=_T("申请高频交换");m_CommandList.append(pCmd);    pCmd=new CCommand();pCmd->m_CmmId=WM_ACTIONSIGNALRESET;    pCmd->m_CmmStr=_T("动作信号复归");m_CommandList.append(pCmd);}QString CPublicClass :: GetNewRecordIndex(int iHeader){    QDate qd=QDate::currentDate();QTime qt=QTime::currentTime();    QString s1,tmps,currForward;iHeader=0;    tmps=m_UniqueCode+"xxxxx";tmps=tmps.mid(0,5);tmps=tmps.upper();    currForward.sprintf("%s%04d%04d%02d%02d%02d%02d%02d%03d",tmps.data(),m_StationNo,	       qd.year(),qd.month(),qd.day(),	       qt.hour(),qt.minute(),qt.second(),qt.msec());    if(currForward!=m_ForwardStr) m_UniqueId=0;    m_UniqueId++;    s1.sprintf("%s%04d",currForward.data(),(int)m_UniqueId);    m_ForwardStr=currForward;    return s1;       }QString CPublicClass :: GetWorkPath(){    QString s;    s.sprintf("%s",getenv("PWD"));s=s.stripWhiteSpace();        //使用Ps    QString cmd;    cmd.sprintf("ps -ef|grep %s >tempfile","znl4monitor");    system(cmd.data());    QFile f("tempfile");    f.open(IO_ReadOnly);    char buf[1024];    f.readLine(buf,1024);    f.close();//f.remove();    cmd.sprintf("%s",buf);    //查找"./"    int index0=cmd.find("./",0);    if(index0>=0)     { s.sprintf("%s",getenv("PWD"));s=s.stripWhiteSpace(); return s;    }    index0=cmd.find("pts/",0);    if(index0<0) index0=0;    int index1=cmd.find("/",index0+1);    int index2=cmd.findRev("/",cmd.length());    if(index1<0||index2<0||index1==index2) return "/root";    s=cmd.mid(index1,index2-index1);    return s;}int CPublicClass ::GetPIDbyModulName(QString ModulName){    FILE *f;char buf[1024];QString s;    s.sprintf("ps -e|grep '%s'",ModulName.data());    f = popen(s,"r");      s.sprintf("%s",fgets(buf,1024,f));      s=s.stripWhiteSpace();    pclose(f);    int index=s.find(" ",0);    if(index<0) return -1;    s=s.mid(0,index);    return s.toInt();}QString _T(QString s){    if(s.isNull()) return "";    QTextCodec *codec = QTextCodec::codecForName("utf8");    QString loc = codec->toUnicode( s.data() );     return loc;}QString _T(QCString s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    QString loc = codec->toUnicode( s.data() );     return loc;}QString _T(char *s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    QString loc = codec->toUnicode( s);     return loc;}QString _T(const char *s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    QString loc = codec->toUnicode((char*)s);     return loc;}QCString _R(QString s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    int l=-1;    QCString loc = codec->fromUnicode( s,l );     return loc;}QCString _R(QCString s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    int l=-1;    QCString loc = codec->fromUnicode( QString(s.data()),l);     return loc;}QCString _R(char *s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    int l=-1;    QCString loc = codec->fromUnicode( QString(s),l);     return loc;}QCString _R(const char *s){    QTextCodec *codec = QTextCodec::codecForName("utf8");    int l=-1;    QCString loc = codec->fromUnicode( QString(s),l);     return loc;}int  _getKeyId(){    QTime t=QTime::currentTime();    QString s=t.toString("hhmmsszzz");    return s.toInt();}bool _isFileExists(QString Filename){    return QFile::exists (Filename);}void Sleep(int itime){	usleep(itime*1000);}

⌨️ 快捷键说明

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