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

📄 103device.cpp~

📁 电力系统Linux设备通讯程序 主要是为了各大电网通讯数据代码
💻 CPP~
📖 第 1 页 / 共 5 页
字号:
			cnode = m_pxml->GetChildNode(node, sztmp, "", "");			if (!m_pxml->GetNodeAttr(cnode, "value", sztmp)) continue;			BYTE igroup = (BYTE)sztmp.toInt();			if (!GetGroupData(a10, igroup, 0, 1))			{				ExplainGroupData(a10);				SendMsgToMain(-1, "申请采样值错误");				return false;			}		}		ExplainGroupData(a10);	}	SendMsgToMain(1, "申请采样值成功");	return true;}bool C103Device::GetSwitch(){	m_SwitchValue.SetSize(0);	for (int i=0; i<m_iCpuNum; i++)	{		it = m_CommParam.at(i);		if (!ResetCU())		{			SendMsgToMain(-1, "申请开关量错误");			return false;		}		m_bSwitch = true;		if (!GI())		{			SendMsgToMain(-1, "申请开关量错误");		}		int iErrors = 0, itimes = 0;		while (!m_bGIFinished)		{			if (!m_bHaveL1UserData)//如果没有一级用户数据,要先申请二级用户数据			{				while (!m_bHaveL1UserData)				{					if (!RequestL2UserData())					{						FlibFCB();						if (iErrors++ > 3)						{							SendMsgToMain(-1, "申请开关量错误");							return false;						}					}					else					{						iErrors = 0;						if (itimes++ > 50)						{							SendMsgToMain(-1, "申请开关量错误");							return false;						}					}				}			}			else 			{				if (RequestL1UserData())				{					iErrors = 0;					itimes = 0;					if (m_ReceData.GetSize() > 0) ProcessData();				}				else 				{					FlibFCB();					if (iErrors++ > 3)					{						SendMsgToMain(-1, "申请开关量错误");						return false;					}				}			}		}	}	st_switchvalue* pSwitchValue = new st_switchvalue[m_SwitchValue.GetSize()];	memset(pSwitchValue, 0x00, sizeof(st_switchvalue));	for (int i=0; i<m_SwitchValue.GetSize(); i++)	{		memcpy(&pSwitchValue[i], &m_SwitchValue[i], sizeof(st_switchvalue));	}	CDataNode* pNode = new CDataNode();	memcpy(&pNode->m_nodeinfo, &m_CmdInfo, sizeof(st_nodeinfo));	pNode->m_nodeinfo.mtype = m_CmdInfo.requestid;	pNode->m_nodeinfo.requestid = m_CmdInfo.mtype;	pNode->m_nodeinfo.m_iResult = 1;	pNode->m_nodeinfo.m_SegmentPid = (long)pSwitchValue;	pNode->m_nodeinfo.m_iSize = sizeof(st_switchvalue)*m_SwitchValue.GetSize();	pNode->m_nodeinfo.m_DataType = DATA_REQUESTSWITCHVALUE;	g_PublicClass.m_NodeManage.AddSendDataNode((void*)pNode);	m_bSwitch = false;	SendMsgToMain(1, "申请开关量成功");	return true;}bool C103Device::GetYaBan(){	m_CmdInfo.m_SegmentPid = 0;	m_CmdInfo.m_iSize = 0;	for (int i=0; i<m_iCpuNum; i++)	{		it = m_CommParam.at(i);		if (!ResetCU())		{			SendMsgToMain(-1, "申请软压板错误");			return false;		}		CString sztmp = "";		sztmp.sprintf("%d", (*it).CpuNo);		QDomNode node, cnode;		node = m_pxml->GetDomNode("body", "RYABANCONFIG", "cpuno", sztmp);		if (node.isNull())		{			SendMsgToMain(-1, "申请软压板错误");			return false;		}		int ilen = m_pxml->GetChildNodeCount(node);		CAsdu10 a10;		for (int j=0; j<ilen; j++)		{			sztmp.sprintf("GROUPNO%d", j+1);			cnode = m_pxml->GetChildNode(node, sztmp, "", "");			if (!m_pxml->GetNodeAttr(cnode, "value", sztmp)) continue;			BYTE igroup = (BYTE)sztmp.toInt();			if (!GetGroupData(a10, igroup, 0, 1))			{				ExplainGroupData(a10);				SendMsgToMain(-1, "申请软压板错误");				return false;			}		}		ExplainGroupData(a10);	}	SendMsgToMain(1, "申请软压板成功");	return true;}bool C103Device::CheckTime(){	it = m_CommParam.at(0);	int itmpsendaddr = (*it).SendAddress;	(*it).SendAddress = 0xff;		QDateTime nowDateTime = QDateTime::currentDateTime();	QDate nowDate = nowDateTime.date();	QTime nowTime = nowDateTime.time();	CAsdu06 a6;	memset(a6.m_Cp56Time2a.byte, 0x00, 7*sizeof(BYTE));	a6.m_Cp56Time2a.Time.Years = nowDate.year()-2000;	a6.m_Cp56Time2a.Time.Months = nowDate.month();	a6.m_Cp56Time2a.Time.DaysOfMonth = nowDate.day();	a6.m_Cp56Time2a.Time.Hours = nowTime.hour();	a6.m_Cp56Time2a.Time.Minutes = nowTime.minute();	a6.m_Cp56Time2a.Time.Milliseconds = (WORD)(nowTime.second()*1000+nowTime.msec());	CByteArray sData;	a6.BulidArray(sData);	if (!SendNoConfirm(sData))	{		(*it).SendAddress = itmpsendaddr;		SendMsgToMain(-1, "申请修改时钟失败");		return false;	}	(*it).SendAddress = itmpsendaddr;	SendMsgToMain(1, "申请修改时钟成功");	return true;}bool C103Device::RequireDistrubt(){	for (int i=0; i<m_iCpuNum; i++)	{		it = m_CommParam.at(i);		if (!ResetCU())		{			SendMsgToMain(-1, "申请扰动波形错误");			return false;		}		int itimes = 0;				if (!SendAsdu24(0, 0x18, 0x01, 0))		{			SendMsgToMain(-1, "申请扰动波形失败");			return false;		}		while (m_bHaveL1UserData) 		{			if (RequestL1UserData())			{				if (m_ReceData.GetSize() == 0)				{					if (itimes++ > 5)					{						SendMsgToMain(-1, "申请扰动波形失败");						return false;					}				}				else itimes = 0;				if (m_ReceData.GetSize() > 0) ProcessData();			}			else FlibFCB();		}	}	if (m_DDTable.GetSize() > 0)	{		SendMsgToMain(1, "申请扰动波形成功,数据正在上送,请等待");	}	else	{		SendMsgToMain(1, "申请扰动波形成功,但没有波形可传送");	}	return true;}bool C103Device::XunJian(){	for (int i=0; i<m_iCpuNum; i++)	{		it = m_CommParam.at(i);		if ((*it).bInit == false)		{			if (!ResetCU()) return false;		}		if (!RequestL2UserData())		{			FlibFCB();			return false;		}		int itimes = 0;		while (m_bHaveL1UserData)		{			if (RequestL1UserData())			{				if (m_ReceData.GetSize() == 0)				{					if (itimes++ > 10) break;				}				else itimes = 0;				if (m_ReceData.GetSize() > 0) ProcessData();			}			else 			{				FlibFCB();				return false;			}		}	}	if (m_DDTable.GetSize() > 0)	{		GetDistrubData();	}	return true;}bool C103Device::GetGroupData(CAsdu10& a10, BYTE iGroup, BYTE iEntry, BYTE iKod){		int itime = 0;//添加从配置文件中读取该组的结束标志,在下面的注释处使用	if (!SendAsdu21(iGroup, iEntry, iKod)) return false;		while (1)	{		if (m_bHaveL1UserData)		{			if (RequestL1UserData())			{				if (m_ReceData.GetSize() > 0)				{					if (m_ReceData[0] == 0x0a)					{						itime = 0;						a10.SaveAsdu(m_ReceData);						if (a10.m_COT == 0x01)//南瑞RCS系列保护送故障时测距值和电流值等信息						{							CFaultExplain FaultExplain;							a10.ExplainAsdu(FaultExplain);							m_FaultExplain.Add(FaultExplain);						}						else//此处不会出现修改定值等的传送原因						{							a10.ExplainAsdu();							if (a10.m_NGD.ngd.Cont == 0) break;//此处应该用上面读取的结束标志来判断						}					}					else 					{						ProcessData();					}				}			}			else return false;		}		else		{			while (1) 			{				if (!RequestL2UserData()) return false;								if (m_bHaveL1UserData) break;				if (itime++ > m_iFixTime) return false;//在iFixTime次都没有一级用户数据时退出				usleep(200);			}		}	}		return true;}void C103Device::ExplainGroupData(CAsdu10& a10){    printf("explain a10 group,a10 dataset count %d\n",a10.m_DataSets.count());    //if(a10.m_DataSets.count()==0)return;	st_paramvalue* pEValue = new st_paramvalue[a10.m_DataSets.count()];	memset(pEValue, 0x00, sizeof(st_paramvalue)*a10.m_DataSets.count());	DataSet* pDataSet = NULL;	CString sztmp = "", szcpuno = "", szgroup = "", szentry = "";	for (int i=0; i<(int)a10.m_DataSets.count(); i++)	{		sztmp = "";		pEValue[i].m_StationNo = g_PublicClass.m_StationNo;//需要修改		pEValue[i].m_MachineNo = m_DevInfo.m_EquipNo;		pEValue[i].m_Sector = 0;//需要修改		pEValue[i].m_FunCode = a10.m_FUN;		pDataSet = a10.m_DataSets.at(i);		szcpuno.sprintf("%d", (*it).CpuNo);		szgroup.sprintf("%d", pDataSet->gin.GROUP);		szentry.sprintf("%d", pDataSet->gin.ENTRY);		QDomNode node, cnode;		node = m_pxml->GetDomNode("body", "pcpuno", szcpuno, "pgroup", szgroup);		if (node.isNull()) continue;		cnode = m_pxml->GetChildNode(node, "ELEMENT", "pentry", szentry);		if (!m_pxml->GetNodeAttr(node, "group", szgroup)) continue;		pEValue[i].m_Group = szgroup.toInt();		if (!m_pxml->GetNodeAttr(node, "cpuno", sztmp)) continue;		pEValue[i].m_CpuNo = sztmp.toInt();		if (!m_pxml->GetNodeAttr(cnode, "entry", szentry)) continue;		pEValue[i].m_Entry = szentry.toInt();		if (m_iPrimary == 1)		{			pEValue[i].m_ValueType = pDataSet->gdd.gdd.DataType;		}		else		{			if (m_pxml->GetNodeAttr(cnode, "type", sztmp)) continue;			pEValue[i].m_ValueType = sztmp.toInt();		}		pEValue[i].m_ValueLen = pDataSet->gdd.gdd.DataSize;		pEValue[i].m_ValueIndex = i+1;		switch (pDataSet->gdd.gdd.DataType)		{			case 1://OS8ASCII字符串			{				memcpy(pEValue[i].m_Value, pDataSet->gid.GetData(), pDataSet->gid.GetSize());				break;			}			case 2://成组8位串			{				CString strtmp = "";				for (int j=0; j<pDataSet->gid.GetSize(); j++)				{					strtmp.sprintf("%X", pDataSet->gid.GetAt(j));					sztmp += strtmp;				}				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			case 3://无符号整数			{				uint itmp = 0;				if (pDataSet->gid.GetSize() <= (int)sizeof(uint))				{					memcpy(&itmp, pDataSet->gid.GetData(), pDataSet->gid.GetSize());				}				sztmp.sprintf("%d", itmp);				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			case 4://整数			{				int itmp = 0;				if (pDataSet->gid.GetSize() <= (int)sizeof(int))				{					memcpy(&itmp, pDataSet->gid.GetData(), pDataSet->gid.GetSize());				}				sztmp.sprintf("%d", itmp);				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			case 7://R32.23短实数			{				float ftmp = 0;				if (pDataSet->gid.GetSize() <= (int)sizeof(float))				{					memcpy(&ftmp, pDataSet->gid.GetData(), pDataSet->gid.GetSize());				}				sztmp.sprintf("%g", ftmp);				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			case 35://国电南自WDK上定值时的特殊类型,和94规约有一点联系			{				BYTE b1 =  pDataSet->gid.GetAt(1)/16;				BYTE b2 =  pDataSet->gid.GetAt(1)%16;				BYTE b3 =  pDataSet->gid.GetAt(0)/16;				BYTE b4 =  pDataSet->gid.GetAt(0)%16;				switch (b1)				{				case 0:					sztmp.sprintf("%d%d%d.0", b2, b3, b4);					break;				case 1:					sztmp.sprintf("%d%d.%d", b2, b3, b4);					break;				case 2:					sztmp.sprintf("%d.%d%d", b2, b3, b4);					break;				case 3:					sztmp.sprintf("0.%d%d%d", b2, b3, b4);					break;				default: break;				}				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			case 36://国电南自WDK上定值时的特殊类型,和94规约有一点联系			{				sztmp.sprintf("%02X%02X", pDataSet->gid.GetAt(1), pDataSet->gid.GetAt(0));				memcpy(pEValue[i].m_Value, sztmp.data(), sztmp.length());				break;			}			default: break;		}	}	CDataNode* pNode = new CDataNode();	memcpy(&pNode->m_nodeinfo, &m_CmdInfo, sizeof(st_nodeinfo));	pNode->m_nodeinfo.mtype = m_CmdInfo.requestid;	pNode->m_nodeinfo.requestid = m_CmdInfo.mtype;	pNode->m_nodeinfo.m_iResult = 1;	pNode->m_nodeinfo.m_SegmentPid = (long)pEValue;	pNode->m_nodeinfo.m_iSize = sizeof(st_paramvalue)*a10.m_DataSets.count();	if (m_CmdInfo.m_DataType == WM_REQUESTPARAMVALUE)//申请定值	{		pNode->m_nodeinfo.m_DataType = DATA_REQUESTPARAMVALUE;	}	else if (m_CmdInfo.m_DataType == WM_REQUESTPVSECTOR)//申请定值区号	{		pNode->m_nodeinfo.m_DataType = DATA_REQUESTSECTOR;	}	else if (m_CmdInfo.m_DataType == WM_REQUESTANLOGVALUE)//申请采样值	{		pNode->m_nodeinfo.m_DataType = DATA_REQUESTANLOGVALUE;	}	else if (m_CmdInfo.m_DataType == WM_REQUESTSHUVALUE)//申请压板状态	{		pNode->m_nodeinfo.m_DataType = DATA_REQUESTSHIFTVALUE;	}	g_PublicClass.m_NodeManage.AddSendDataNode((void*)pNode);}void C103Device::SendMsgToMain(int iResult, CString szMsg /* = "" */){	CDataNode* pNode = new CDataNode();	memcpy(&pNode->m_nodeinfo, &m_CmdInfo, sizeof(st_nodeinfo));	pNode->m_nodeinfo.mtype = m_CmdInfo.requestid;	pNode->m_nodeinfo.requestid = m_CmdInfo.mtype;	pNode->m_nodeinfo.m_iResult = iResult;	pNode->m_nodeinfo.m_DisplayFlag = 1;	if (szMsg != "")	{		char* pMsg = new char[szMsg.length()+1];		memset(pMsg, 0x00, szMsg.length()+1);		memcpy(pMsg, szMsg.data(), szMsg.length());		pNode->m_nodeinfo.m_SegmentPid = (long)pMsg;

⌨️ 快捷键说明

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