📄 nrlan103.cpp
字号:
#endif lastRecvWaveTime=time(NULL); QString msg; CAsdu31 a31 (a); a31.ExplainAsdu (); a.m_ASDUData.Append (a31.m_ASDUData); if (a31.m_TOO == 37 || a31.m_TOO == 35) //当前模拟通道传输完毕,开始申请下一个模拟通道的数据 { msg.sprintf ("a31.m_Acc:%d\tm_Ddt.acc:%d\n", a31.m_ACC, m_Ddt.acc); communicator.printData (NULL, 0, msg.data (), 1); SendAsdu25 (a31.m_Addr, a31.m_FUN, a31.m_FAN, 0x42, a31.m_TOV, a31.m_ACC /*a31.m_ACC+1 */ ); } else if (a31.m_TOO == 40 || a31.m_TOO == 38) //数字通道传输完毕,开始申请第一个模拟通道的数据 { SendAsdu25 (a31.m_Addr, a31.m_FUN, a31.m_FAN, 0x44, a31.m_TOV, a31.m_ACC /*+1 */ ); } else if (a31.m_TOO == 32) { SendAsdu25 (a31.m_Addr, a31.m_FUN, a31.m_FAN, 0x40, a31.m_TOV, a31.m_ACC /*+1 */ ); ProcessWave (); m_CmdParam.clear (); m_CmdDataSets.clear (); m_bWaving = false; return; } else if (a31.m_TOO == 33 || a31.m_TOO == 34) { SendAsdu25 (a31.m_Addr, a31.m_FUN, a31.m_FAN, 0x41, a31.m_TOV, a31.m_ACC); m_CmdParam.clear (); m_CmdDataSets.clear (); if (m_bCmding) { m_bCmding = false; } }}/*! \fn CNRLan103::AdjustClock() */void CNRLan103::AdjustClock(){ /// @todo implement me QDateTime nowDateTime = QDateTime::currentDateTime (); QDate nowDate = nowDateTime.date (); QTime nowTime = nowDateTime.time (); NRLAN103::ASDUbuff a; a.size = 13; a.buff[3] = 0xff; CP56Time2a *m_Cp56Time2a = (CP56Time2a *) a.buff + 6; memset (m_Cp56Time2a->byte, 0x00, 7 * sizeof (BYTE)); m_Cp56Time2a->Time.Years = nowDate.year () - 2000; m_Cp56Time2a->Time.Months = nowDate.month (); m_Cp56Time2a->Time.DaysOfMonth = nowDate.day (); m_Cp56Time2a->Time.Hours = nowTime.hour (); m_Cp56Time2a->Time.Minutes = nowTime.minute (); m_Cp56Time2a->Time.Milliseconds = (WORD) (nowTime.second () * 1000 + nowTime.msec ()); communicator.udpsend (a, 6003);}/*! \fn CNRLan103::CheckDisturb() */void CNRLan103::CheckDisturb(){ /// @todo implement me // printf("CNRLan103::CheckDisturb()\n"); if (collecting||m_bWaving||m_bCmding) { return; } QString szcpuno = "", szfun = "", szaddr = "", szcpuaddr = "", szdevaddr = "", msg = "";#ifndef USE_LIBXML2 QDomNode node, cnode;#endif; if (m_DDTable.GetSize () > 0) { m_Ddt = m_DDTable.GetAt (0); printf("m_DDTable.GetSize()=%d\n",m_DDTable.GetSize()); m_DDTable.RemoveAt (0); printf("m_DDTable.GetSize()=%d\n",m_DDTable.GetSize()); szcpuaddr.sprintf ("%d", m_Ddt.addr); szdevaddr.sprintf ("%d", m_DevInfo.m_MachineAddr); msg.sprintf ("--@@NRLan103 ddt.addr=%d @@--\n", m_Ddt.addr); ///communicator.printData (NULL, 0, msg.data (), 1);#ifndef USE_LIBXML2 node = m_pxml->GetDomNodex (QString("body"), "CPUCONFIG", "index","1",NULL,NULL/*, "devaddr",szdevaddr*/); if (node.isNull ()) return; m_pxml->GetNodeAttr (node, "fun", szfun);#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); Node attrNode=xprc.selectSingleNode(rootElem,"//CPUCONFIG[@index='1']/@fun"); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::CheckDisturb()]can not locate ////CPUCONFIG[@index='1']/@fun"<<endl; return; } szfun=attrNode.value().c_str();#endif m_bWaving = true; SendAsdu24 (m_Ddt.addr, szfun.toInt() , m_Ddt.FAN, 1, 1, 0); lastRecvWaveTime=time(NULL); } else { if (m_iWaveFlag == 0) return; if (m_iNeedDdtTime++ < 10) return; //for debug // return; // if(!m_CmdParam.isEmpty()&&m_CmdParam.at(0)-)return; //m_bCmding = true; m_iNeedDdtTime = 0; m_CmdParam.clear (); m_CmdDataSets.clear ();#ifdef NRLAN_DEBUG printf("checkDisturb\n");#endif for (int i = 0; i < m_iCpuNum; i++) { szcpuno.sprintf ("%d", i + 1);#ifndef USE_LIBXML2 node = m_pxml->GetDomNodex (QString("body"), "CPUCONFIG", "index", szcpuno.data(),NULL,NULL); if (node.isNull ()) { m_CmdParam.clear (); m_CmdDataSets.clear (); return; } m_pxml->GetNodeAttr (node, "fun", szfun); m_pxml->GetNodeAttr (node, "addr", szaddr);#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); char exprBuff[100]; bzero(exprBuff,100); sprintf(exprBuff,"//CPUCONFIG[@index='%d']",i+1); Node node=xprc.selectSingleNode(rootElem,exprBuff); if(node.isNull()) { cout<<*this<<"[ERROR][CNRLan103::CheckDisturb()]can not locate "<<exprBuff<<endl; return; } Node attrNode=xprc.selectSingleNode(node,"@fun"); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::CheckDisturb()]can not locate "<<exprBuff<<"/@fun"<<endl; return; } szfun=attrNode.value().c_str();#endif CmdParam cmd; cmd.type = 24; cmd.cot = 31; // cmd.addr = szaddr.toInt (); cmd.addr = m_DevInfo.m_MachineAddr; cmd.fun = szfun.toInt (); cmd.inf = 0; cmd.too = 24; cmd.tov = 1; cmd.acc = 0; cmd.fanno = 0; m_CmdParam.append (cmd); QString msg; msg.sprintf ("device at address %d push a query for asdu23\n", m_DevInfo.m_MachineAddr); communicator.printData (NULL, 0, msg.data (), 1); } cmdit = m_CmdParam.at (0);#ifdef NRLAN_DEBUG printf("will send Asdu24\n");#endif SendAsdu24 ((*cmdit).addr, (*cmdit).fun, (*cmdit).fanno, (*cmdit).too,(*cmdit).tov, (*cmdit).acc);#ifdef NRLAN_DEBUG printf("send Asdu24 complete\n");#endif }}/*! \fn CNRLan103::GetAnalog() */void CNRLan103::GetAnalog(){ /// @todo implement me m_bCmding = true; QString szcpuno = "", szgroup = "", sztmp = "", szaddr = "", szdevaddr = ""; szdevaddr.sprintf ("%d", m_DevInfo.m_MachineAddr);#ifndef USE_LIBXML2 QDomNode node, cnode;#endif for (int i = 0; i < m_iCpuNum; i++) { szcpuno.sprintf ("%d", i + 1);#ifndef USE_LIBXML2 node =m_pxml->GetDomNodex (QString("body"), "CPUCONFIG", "index", szcpuno.data(),NULL,NULL/*, "devaddr",szdevaddr*/); if (node.isNull ()) { m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } m_pxml->GetNodeAttr (node, "addr", szaddr); cnode = m_pxml->GetChildNode (node, "GROUP", "charc", "ANALOG",NULL,NULL); m_pxml->GetNodeAttr (cnode, "value", szgroup);#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); char exprBuff[100]; bzero(exprBuff,100); sprintf(exprBuff,"//CPUCONFIG[@index='%s']/GROUP[@charc='ANALOG']/@value",szcpuno.data()); Node attrNode=xprc.selectSingleNode(rootElem,exprBuff); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::GetAnalog()]can not locate "<<exprBuff<<endl; m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } szgroup=attrNode.value().c_str();#endif CmdParam cmd; cmd.type = 21; cmd.cot = 40; cmd.addr = szaddr.toInt (); cmd.fun = 254; cmd.inf = 241; cmd.num = 1; m_CmdParam.append (cmd); DataSet *pds = new DataSet; pds->gin.GROUP = szgroup.toInt (); pds->gin.ENTRY = 0; pds->kod = 1; m_CmdDataSets.append (pds); } cmdit = m_CmdParam.at (0); SendAsdu21 ();}/*! \fn CNRLan103::GetDingZhi() */void CNRLan103::GetDingZhi(){ /// @todo implement me m_CmdParam.clear (); m_CmdDataSets.clear (); QString msg; m_bCmding = true; QString szcpuno = "", szgroup = "", szentry = "", sztmp = "", szaddr = "";#ifndef USE_LIBXML2 QDomNode node, cnode;#endif for (int i = 0; i < m_iCpuNum; i++) { szcpuno.sprintf ("%d", i + 1);#ifndef USE_LIBXML2 node = m_pxml->GetDomNode(static_cast<QString>("body"),static_cast<QString>("config")); // node = node.parentNode(); // printf("node name\t%s\n",node.nodeName().lower().data()); node = m_pxml->GetChildNode (node, "CPUCONFIG", "index", szcpuno.data(),NULL,NULL); if (node.isNull ()) { ///printf("CNRLan103::GetDingzhi():\n\tcan not locate CPUCONFIG in xml file\n"); m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } m_pxml->GetNodeAttr (node, "addr", szaddr);/* cnode = m_pxml->GetChildNode (node, "GROUP", "charc", "SECTOR"); m_pxml->GetNodeAttr (cnode, "value", szgroup); m_pxml->GetNodeAttr (cnode, "entry", szentry);*/#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); char exprBuff[100]; bzero(exprBuff,100); sprintf(exprBuff,"//CPUCONFIG[@index='%s']/@addr",szcpuno.data()); Node attrNode=xprc.selectSingleNode(rootElem,exprBuff); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::GetDingzhi()]can not locate "<<exprBuff<<endl; m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } szgroup=attrNode.value().c_str();#endif CmdParam cmd; cmd.type = 21; cmd.cot = 40; cmd.addr = szaddr.toInt (); cmd.fun = 254; cmd.inf = 241; cmd.num = 1; // m_CmdParam.append (cmd); DataSet *pds = new DataSet; // pds->gin.GROUP = szgroup.toInt (); // pds->gin.ENTRY = szentry.toInt (); // pds->kod = 1; // m_CmdDataSets.append (pds);#ifndef USE_LIBXML2 cnode=node.GetChildNode(0); do { //cnode = m_pxml->GetChildNode (node, "GROUP", "charc", "PARAM",NULL,NULL); if(cnode.GetName()!="GROUP") { ///@todo replacement // cnode=cnode.nextSibling(); continue; } m_pxml->GetNodeAttr (cnode, "charc", szgroup); if(szgroup!="PARAM") { ///@todo replacement // cnode=cnode.nextSibling(); continue; } m_pxml->GetNodeAttr (cnode, "value", szgroup); m_CmdParam.append (cmd); pds = new DataSet; pds->gin.GROUP = szgroup.toInt (); pds->gin.ENTRY = 0; pds->kod = 1; m_CmdDataSets.append (pds); ///@todo replacement // cnode=cnode.nextSibling(); } while(!cnode.isNull()); printf("gen a param \n");#else bzero(exprBuff,100); sprintf(exprBuff,"//CPUCONFIG[@index='%s']/GROUP[@charc='PARAM']/@value",szcpuno.data()); NodeSet paramGroupSet=xprc.selectNodes(rootElem,exprBuff); for(int i=0;i<paramGroupSet.count();i++) { m_CmdParam.append (cmd); pds = new DataSet; pds->gin.GROUP = atoi(paramGroupSet.getAt(i).value().c_str()); pds->gin.ENTRY = 0; pds->kod = 1; m_CmdDataSets.append (pds); }#endif } cmdit = m_CmdParam.at (0); SendAsdu21 ();}/*! \fn CNRLan103::GetSector() */void CNRLan103::GetSector(){ /// @todo implement me m_bCmding = true; QString szcpuno = "", szgroup = "", sztmp = "", szaddr = "", szdevaddr = "", szentry = ""; szdevaddr.sprintf ("%d", m_DevInfo.m_MachineAddr);#ifndef USE_LIBXML2 QDomNode node, cnode;#endif for (int i = 0; i < m_iCpuNum; i++) { szcpuno.sprintf ("%d", i + 1);#ifndef USE_LIBXML2 node = m_pxml->GetDomNodex (QString("body"), "CPUCONFIG", "index", szcpuno.data(),NULL,NULL/*, "devaddr",szdevaddr*/); if (node.isNull ()) { m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } m_pxml->GetNodeAttr (node, "addr", szaddr); cnode = m_pxml->GetChildNode (node, "GROUP", "charc", "SECTOR",NULL,NULL); m_pxml->GetNodeAttr (cnode, "value", szgroup); m_pxml->GetNodeAttr (cnode, "entry", szentry);#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); char exprBuff[100]; bzero(exprBuff,100); sprintf(exprBuff,"//CPUCONFIG[@index='%s']/GROUP[@charc='SECTOR']/@value",szcpuno.data()); Node attrNode=xprc.selectSingleNode(rootElem,exprBuff); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::GetSector()]can not locate "<<exprBuff<<endl; m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } szaddr=szcpuno; szgroup=attrNode.value().c_str(); sprintf(exprBuff,"//CPUCONFIG[@index='%s']/GROUP[@charc='SECTOR']/@entry",szcpuno.data()); attrNode=xprc.selectSingleNode(rootElem,exprBuff); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::GetSector()]can not locate "<<exprBuff<<endl; m_CmdParam.clear (); m_CmdDataSets.clear (); m_bCmding=false; return; } szentry=attrNode.value().c_str();#endif CmdParam cmd; cmd.type = 21; cmd.cot = 40; cmd.addr = szaddr.toInt (); cmd.fun = 254; cmd.inf = 241; cmd.num = 1; m_CmdParam.append (cmd); DataSet *pds = new DataSet; pds->gin.GROUP = szgroup.toInt (); pds->gin.ENTRY = szentry.toInt (); pds->kod = 1; m_CmdDataSets.append (pds); } cmdit = m_CmdParam.at (0); SendAsdu21 ();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -