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

📄 ysdataprocess.cpp

📁 电力故障信息采集,主要是针对南自的保护装置,这个程序用在Linux操作系统下
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	CDataBase db;int ret=0;QString SqlStr="";long result=0;bool bNew=0;	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	SqlStr.sprintf("Select A.Code,A.DESCRIPTION From %s A where RecordIndex='%s';",TableName.data(),RecordIndex.data());	ret=db.SqlSelect(hdbc,SqlStr,result);	if(ret<0){db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);return 0;}	int rowcount=db.GetRecordCount(result);	QString s1="";	for(int i=0;i<rowcount;i++)	{		s1=db.GetFieldValue(result,i,0);   st.m_MachineNo=s1.toInt();		s1=db.GetFieldValue(result,i,1);   memcpy(st.m_MachineName,s1.data(),80);	}	db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);	return true;}//填充通讯参数bool BCDataProcess::FillCommunicationParam(long &hdbc,QString RecordIndex,QString CommType,st_deviceinfo &st){	//for debug	CDataBase db;int ret=0;QString SqlStr="";long result=0;bool bNew=0;	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	SqlStr.sprintf("Select ENGDSC,DEFVALUE From DEV_COMMPARAM where DRRECORDINDEX='%s' and COMMTYPE='%s';",				   RecordIndex.data(),CommType.data());	ret=db.SqlSelect(hdbc,SqlStr,result);	if(ret<0){db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);return 0;}	int rowcount=db.GetRecordCount(result);	QString Name="",Value="";	for(int i=0;i<rowcount;i++)	{		Name=db.GetFieldValue(result,i,0);   Name=Name.toUpper();		Value=db.GetFieldValue(result,i,1);   Value=Value.toUpper();		if(CommType=="RS")   //串口		{			if(Name=="ADDRESS") 	 st.m_MachineAddr=Value.toInt();			if(Name=="PORT")		 st.m_Port=Value.toInt();			if(Name=="SPEED")		 st.m_Speed=Value.toInt();			if(Name=="PARITY")		 st.m_Parity=Value.toInt();			if(Name=="DATABITS")	 st.m_DataBit=Value.toInt();			if(Name=="STOPBITS")	 st.m_StopBit=Value.toInt();		}		else if(CommType=="TCPSERVER")		{			if(Name=="ADDRESS") 	 st.m_MachineAddr=Value.toInt();			if(Name=="SOCKETPORT") 	 st.m_SocketPort=Value.toInt();			if(Name=="IPADDRESS") 	 memcpy(st.m_IPAddress,Value.data(),20);		}		else if(CommType=="TCPCLIENT")		{			if(Name=="ADDRESS") 	 st.m_MachineAddr=Value.toInt();			if(Name=="SOCKETPORT") 	 st.m_SocketPort=Value.toInt();			if(Name=="IPADDRESS") 	 memcpy(st.m_IPAddress,Value.data(),20);		}	}	db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);	return true;}////////////////////////////当有突发数据时通知操作模块//////////////////////////////bool BCDataProcess::NoticOperModule(long &hdbc,st_nodeinfo &info){	int pid=GetModulePid(hdbc,"99");				//得到操作模块的进程号	if(pid==-1) return false;   					//操作模块没有运行	CDataNode* sendNode=new CDataNode();	memcpy(&sendNode->m_nodeinfo,&info,sizeof(st_nodeinfo));	sendNode->m_nodeinfo.mtype=pid;     			//操作模块的进程号	sendNode->m_nodeinfo.m_iResult=1;				//结果	sendNode->m_nodeinfo.transtopid=0;				//不需要转发	g_PublicClass.m_NodeManage.AddSendDataNode(sendNode);	return true;}////////////////////////////当有信息时通知操作模块////////////////////////////////TableName=信息存放表名,RecordIndex=[flag=0]记录号;[flag=1]命令编号bool BCDataProcess::NoticOperModule(long &hdbc,QString TableName,QString RecordIndex,int DataType,int flag){	int pid=GetModulePid(hdbc,"99");				//得到操作模块的进程号	if(pid==-1) return false;   					//操作模块没有运行	CDataNode* sendNode=new CDataNode();	sendNode->m_nodeinfo.mtype=pid;     			//操作模块的进程号	sendNode->m_nodeinfo.requestid=g_PublicClass.m_SelfPid;	sendNode->m_nodeinfo.m_iResult=1;				//结果	sendNode->m_nodeinfo.transtopid=0;				//不需要转发	sendNode->m_nodeinfo.m_DataType=DataType;			//数据类型	memcpy(sendNode->m_nodeinfo.m_TableName,TableName.data(),TableName.length());	if(flag==0)	{		memcpy(sendNode->m_nodeinfo.m_RecordFlag,RecordIndex.data(),RecordIndex.length());	}	else	{		memcpy(sendNode->m_nodeinfo.m_UniqueCmd,RecordIndex.data(),RecordIndex.length());	}	g_PublicClass.m_NodeManage.AddSendDataNode(sendNode);	return true;}/////////////////////////////通知设备号为MainNo的模块///////////////////////////////////一般用于主模块将信息插入SendState表后,通知上行模块"数据库SendState中有新的数据需要发送"//接收到此信息的上行模块,将从SendState中得到需要发送的记录信息void BCDataProcess::NoticSendModule(long &hdbc,int MainNo,int sender)//Liang		2006-11-01{	int pid,threadid;	bool b=GetModulePidByMachineNo(hdbc,MainNo,pid,threadid);	if(!b) return;	CDataNode* sendNode=new CDataNode();	sendNode->m_nodeinfo.mtype=pid;	sendNode->m_nodeinfo.m_iResult=1;	sendNode->m_nodeinfo.transtopid=0;	sendNode->m_nodeinfo.requestid=g_PublicClass.m_SelfPid;	sendNode->m_nodeinfo.m_CurrentThread=0;//Liang 2006-03-16	sendNode->m_nodeinfo.m_TransThread=threadid;//Liang 2006-03-16	sendNode->m_nodeinfo.m_RecvMachineNo=MainNo;	sendNode->m_nodeinfo.m_MachineNo=sender;//Liang		2006-11-01	strcpy(sendNode->m_nodeinfo.m_TableName,"SENDSTATE");//Liang		2006-11-01	sendNode->m_nodeinfo.m_DataType=DATA_FORCESEND;	g_PublicClass.m_NodeManage.AddSendDataNode(sendNode);	return;}//////////////////////////是否上送指定编号的上行设备////////////////////////bool BCDataProcess::MakeToSendState(long &hdbc,st_nodeinfo &info){	//找出所有正在运行的上行设备	CDataBase db;int ret=0;long result=0;bool bNew=0;QString SqlStr="";	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	SqlStr.sprintf("Select CODE from  XDEVICEINFO where PHFLAG>'10' and PHFLAG<'20' ;");	//Liang	2006/7/28	ret=db.SqlSelect(hdbc,SqlStr,result);	if(ret<0)	{		db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);return 0;	}	int rowcount=db.GetRecordCount(result);	for(int i=0;i<rowcount;i++)	{		int MainNo=db.GetFieldValue(result,i,0).toInt();		if(!FilterMessage(hdbc,MainNo,info)) continue;		if(info.m_DataType==DATA_EVENT)	//直接将记录号插入SendSate表中		{			InsertRecordToSendState(hdbc,QString(info.m_TableName),QString(info.m_RecordFlag),1,MainNo,0);		}		else if (info.m_DataType==DATA_FAULT)		{			InsertRecordToSendState(hdbc,QString(info.m_TableName),QString(info.m_RecordFlag),0,MainNo,0);		}		else		{			InsertRecordToSendState(hdbc,QString(info.m_TableName),QString(info.m_RecordFlag),1,MainNo,0);		}		//通知MainNo有新的数据需要发送		NoticSendModule(hdbc,MainNo,info.m_MachineNo);	}	db.ClearResult(result);if(bNew) db.DisConnectDataBase(hdbc);	return true;}//////////////////////////是否上送指定编号的上行设备//////////////////////////此函数为过滤原则,暂时没有完成bool BCDataProcess::FilterMessage(long &hdbc,int MachineNo,st_nodeinfo &info){	if(MachineNo<=0||info.m_MachineNo<=0) return 0;	int h=0;h=hdbc;	return true;}/////////////////////////////////////插入一条记录到发送状态表/////////////////////////bool BCDataProcess::InsertRecordToSendState(long &hdbc,QString TableName,QString fRecordIndex,int iPubLevel,int MainNo,int Status){	//printf("insertrecordtosendstate %d\n", MainNo);	CDataBase db;int ret=0;QString SqlStr="";bool bNew=0;	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	QString RecordIndex  =g_PublicClass.GetNewRecordIndex("");	QString CDateTime = getTimeStr();	SqlStr.sprintf("Insert Into SendState(RECORDINDEX,TABLENAME,RECORDINDEXNO,PUBLEVEL,MAINSTATIONNO,STATUS , SENDDATE , CURRENTDATE) \				   Values('%s','%s','%s',%d,%d,%d, %s , %s);",				   RecordIndex.data(),TableName.data(),fRecordIndex.data(),iPubLevel,MainNo,Status , CDateTime.data() , CDateTime.data());	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,2,"事件插入发送状态表时出错!");	}	if(bNew) db.DisConnectDataBase(hdbc);	return !(ret<0);}/////////////////////////////////////插入一条记录到当前定值表/////////////////////////bool BCDataProcess::InsertParam(long &hdbc,QString UniqueCmd,QString ParamType,st_paramvalue &st){ParamType=ParamType;	CDataBase db;bool bNew=0;int ret=0;QString SqlStr="";QString serr="";	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	QString CurrentDate=getTimeStr();	QString RecordIndex  =g_PublicClass.GetNewRecordIndex(QString("%1").arg(st.m_MachineNo));	SqlStr.sprintf("delete from CURR_GROUP_VAL where STATIONNO=%d and DEVICENO=%d and CPUNO=%d and EGROUP=%d;",				   st.m_StationNo,st.m_MachineNo,st.m_CpuNo,st.m_Group);	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,2,"删除定值时出错!");	}	SqlStr.sprintf("Insert Into CURR_GROUP_VAL( \												CMDINDEX ,RECORDINDEX,\												STATIONNO ,DEVICENO,CPUNO,\												EGROUP,ENTRY,EVALUE,PATHNAME,NAME,ValueType) \				   Values('%s','%s',%d,%d,%d,%d,%d,'%s','%s','%s',%d);",				   UniqueCmd.data(),RecordIndex.data(),				   st.m_StationNo,st.m_MachineNo,st.m_CpuNo,				   st.m_Group,st.m_Entry,QString(st.m_Value).data(),				   GetCimPathName(hdbc,st.m_StationNo,st.m_MachineNo).data(),				   GetCimName(hdbc,st.m_StationNo,st.m_MachineNo).data(),st.m_ValueType);	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,2,"写定值时出错!");	}	if(bNew) db.DisConnectDataBase(hdbc);	return !(ret<0);}/////////////////////////////////插入批次定值记录到定值表///////////////////////////////////bool BCDataProcess::InsertParam(long &hdbc,QString UniqueCmd,QString ParamType,void* pParam,int size){ParamType=ParamType;	if(!pParam||size==0) return false;	int count=size/sizeof(st_paramvalue);	if(count<=0) return false;	st_paramvalue pst[count];memset(&pst,0x00,sizeof(st_paramvalue)*count);	memcpy(&pst,pParam,size);	CDataBase db;bool bNew=0;int ret=0;QString SqlStr="";QString serr="";	bool bc=isConnectDatabase(hdbc,bNew);if(!bc) return 0;	QString CurrentDate=getTimeStr();	//每50条写入一次	int cs=(count-1)/50+1;	QString tmpStr="";bool bOk=true;	for (int group_value=-1,i=0;i<count;++i)	{		if (pst[i].m_Group != group_value)		{			SqlStr.sprintf("delete from CURR_GROUP_VAL where STATIONNO=%d and DEVICENO=%d and CPUNO=%d and EGROUP=%d;",						   pst[i].m_StationNo,pst[i].m_MachineNo,pst[i].m_CpuNo,pst[i].m_Group);			ret=db.SqlExec(hdbc,SqlStr);			if(ret<0)			{				WriteSysLog(hdbc,2,"删除定值时出错!");			}			group_value=pst[i].m_Group;		}	}	for(int i=0;i<cs;i++)	{		SqlStr="";int toBound=(i+1)*50;if(toBound>count) toBound=count;		for(int j=i*50;j<toBound;j++)		{			QString RecordIndex  =g_PublicClass.GetNewRecordIndex(QString("%1").arg(pst[j].m_MachineNo));			tmpStr.sprintf("Insert Into CURR_GROUP_VAL( \														CMDINDEX ,RECORDINDEX,\														STATIONNO ,DEVICENO,CPUNO,\														EGROUP,ENTRY,EVALUE,PathName,Name,\"VALUETYPE\") \						   Values('%s','%s',%d,%d,%d,%d,%d,'%s','%s','%s',%d);",						   UniqueCmd.data(),RecordIndex.data(),						   pst[j].m_StationNo,pst[j].m_MachineNo,pst[j].m_CpuNo,						   pst[j].m_Group,pst[j].m_Entry,QString(pst[j].m_Value).data(),						   GetCimPathName(hdbc,pst[j].m_StationNo,pst[j].m_MachineNo).data(),						   GetCimName(hdbc,pst[j].m_StationNo,pst[j].m_MachineNo).data(),pst[j].m_ValueType);			SqlStr+=tmpStr;		}		ret=db.SqlExec(hdbc,SqlStr);		if(ret<0)		{			bOk=false;WriteSysLog(hdbc,2,"写定值时出错!");		}	}	if(bNew) db.DisConnectDataBase(hdbc);	return bOk;}/////////////////////////////////////插入一条记录到自检信息/////////////////////////bool BCDataProcess::InsertSelfChk(long &hdbc,st_event &st,QString &RecordIndex){	CDataBase db;bool bNew=0;int ret=0;QString SqlStr="";QString serr="";	bool bc = isConnectDatabase(hdbc,bNew);	if (!bc)	{		//数据库连接失败,将结构存入文件		PushEventToFile((void*)&st, DATA_EVENT, sizeof(st_event));		return 0;	}	QString CurrentDate = getTimeStr();	RecordIndex = g_PublicClass.GetNewRecordIndex(QString("%1").arg(st.m_MachineNo));	SqlStr.sprintf("Insert Into ALERT_RPT( \										   RECORDINDEX,\										   STATIONNO,DEVICENO,CPUNO,\										   FLAG,ACTTIME,FUN,INF,DPI,PathName,Name) \				   Values('%s', %d,%d,%d, %d,'%s',%d,%d,%d,'%s','%s');",				   RecordIndex.data(),				   st.m_StationNo,st.m_MachineNo,st.m_CpuNo,				   st.m_MsgType,st.m_ActionTime,0,0,0,				   GetCimPathName(hdbc,st.m_StationNo,st.m_MachineNo).data(),				   GetCimName(hdbc,st.m_StationNo,st.m_MachineNo).data());	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,0,"写自检报告时出错!");	}	if(bNew) db.DisConnectDataBase(hdbc);	return !(ret<0);}/////////////////////////////////////插入一条记录到自检信息表表身///////////////////////////当PRecordIndex=""时,采用故障序号查找表头bool BCDataProcess::InsertSelfChkAct(long &hdbc,void* pAct,int size,QString PRecordIndex){	//处理结构	if(!pAct||size==0) return false;	int count=size/sizeof(st_eventact);if(count<=0) return false;	st_eventact pst[count];memset(&pst,0x00,sizeof(st_eventact)*count);memcpy(&pst,pAct,size);	CDataBase db;bool bNew=0;int ret=0;QString SqlStr="";QString tmpStr="";QString serr="";	bool bc=isConnectDatabase(hdbc,bNew);	if(!bc)	{		//数据库连接失败,将结构存入文件		PushEventToFile((void*)&pst,DATA_EVENTACT,sizeof(st_eventact)*count);return 0;	}	if(PRecordIndex==""||PRecordIndex.isEmpty())	{		PRecordIndex=GetRecordIndexByEventNum(hdbc,"ALERT_RPT",pst[0].m_MachineNo,pst[0].m_FaultNum);	}	for(int i=0;i<count;i++)	{		tmpStr.sprintf("Update ALERT_RPT Set Fun=%d,Inf=%d,Dpi=%d,PFUNCODE=%d,PINFCODE=%d,EGROUP=%d,ENTRY=%d \					   where RecordIndex='%s';",					   pst[i].m_FunCode,pst[i].m_InfCode,pst[i].m_Dpi,pst[i].m_PFunCode,pst[i].m_PInfCode,pst[i].m_Group,pst[i].m_Entry,PRecordIndex.data());		SqlStr+=tmpStr;	}	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,2,"写自检报告动作元件时出错!");	}	if(bNew) db.DisConnectDataBase(hdbc);	return !(ret<0);}/////////////////////////////////////插入一条记录到故障信息表/////////////////////////bool BCDataProcess::InsertFaultReport(long &hdbc,st_fault &st,QString &RecordIndex){	CDataBase db;bool bNew=0;int ret=0;QString SqlStr="";QString serr="";	bool bc=isConnectDatabase(hdbc,bNew);	if(!bc)	{		//数据库连接失败,将结构存入文件		PushEventToFile((void*)&st,DATA_FAULT,sizeof(st_fault));return 0;	}	QString CurrentDate=getTimeStr();	RecordIndex=g_PublicClass.GetNewRecordIndex(QString("%1").arg(st.m_MachineNo));	SqlStr.sprintf("Insert Into EVENT_RPT(\										  RECORDINDEX,\										  STATIONNO,DEVICENO,CPUNO,\										  ACTTIME,RETTIME,\										  FUN,INF,DPI,NOF,FAN,PathName,Name) \				   Values('%s', %d,%d,%d ,'%s',%d, %d,%d,%d,%d,%d,'%s','%s');",				   RecordIndex.data(),				   st.m_StationNo,st.m_MachineNo,st.m_CpuNo,				   st.m_ActionTime,0,				   0,0,0,0,0,				   GetCimPathName(hdbc,st.m_StationNo,st.m_MachineNo).data(),				   GetCimName(hdbc,st.m_StationNo,st.m_MachineNo).data());	//cout<<"***************************************\n";	//cout <<SqlStr.data()<<endl;	//cout<<"***************************************\n";	ret=db.SqlExec(hdbc,SqlStr);	if(ret<0)	{		WriteSysLog(hdbc,0,"写故障报告时出错!");	}	else	{		if(!QString(st.m_WaveFile).isEmpty())		{			InsertFaultWave(hdbc,st,RecordIndex);			InsertFaultWaveFiles(hdbc,RecordIndex,st.m_MachineNo,QString(st.m_WaveFile),"hdr");			InsertFaultWaveFiles(hdbc,RecordIndex,st.m_MachineNo,QString(st.m_WaveFile),"cfg");			InsertFaultWaveFiles(hdbc,RecordIndex,st.m_MachineNo,QString(st.m_WaveFile),"dat");		}	}	if(bNew) db.DisConnectDataBase(hdbc);	return !(ret<0);}/////////////////////////////////////插入若干条记录到故障信息表表身/////////////////////////bool BCDataProcess::InsertFaultAct(long &hdbc,void* pAct,int size,QString PRecordIndex){

⌨️ 快捷键说明

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