📄 nrlan103.cpp
字号:
{ index = ++(iter->second); } else { index = 1; indexMap.insert (make_pair (cstr, index)); }#ifndef USE_LIBXML2 m_pxml->GetNodeAttr (cnode, "up-group", szupgroup); szupgroup.sprintf ("%d", szupgroup.toInt () + index - 1); m_pxml->GetNodeAttr (cnode, "export", szexport);#else attrNode=xprc.selectSingleNode(cnode,"@up-group"); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::GroupHandler(CAsdu10& a10)]can not loacate "<<exprBuff<<"/@up-group"<<endl; } szupgroup.sprintf("%d",atoi(attrNode.value().c_str())+index-1);#endif if (szexport == "true") {#ifndef USE_LIBXML2 gnode = m_pxml->InsertChildNode (gtnode, "GROUP"); m_pxml->InsertNodeAttr (gnode, "cpuno", "1"); m_pxml->InsertNodeAttr (gnode, "character", cstr); m_pxml->InsertNodeAttr (gnode, "desc", szdesc); m_pxml->InsertNodeAttr (gnode, "index", str.sprintf ("%d", index)); m_pxml->InsertNodeAttr (gnode, "group", szupgroup);#else Element gtElem=gnode.addChildElement("GROUP"); gtElem.setAttributeValue("cpuno","1"); gtElem.setAttributeValue("character",cstr.data()); gtElem.setAttributeValue("desc",szdesc.data()); str.sprintf("%d",index); gtElem.setAttributeValue("index",str.data()); gtElem.setAttributeValue("group",szupgroup.data());#endif }#ifndef USE_LIBXML2 ///@todo replacement QDomNode bodyNode/* = gtnode.parentNode ()*/; gnode = m_pxml->InsertChildNode (bodyNode, cstr); m_pxml->InsertNodeAttr (gnode, "pgroup", str.sprintf ("%d", a10.m_DataSets.at (i)->gin. GROUP));#else Element gElem=(Element)xprc.selectSingleNode(rootElem,"//body"); gElem=gElem.addChildElement(cstr.data()); str.sprintf("%d",a10.m_DataSets.at(i)->gin.GROUP); gElem.setAttributeValue("pgroup",str.data());#endif if (szexport == "true") {#ifndef USE_LIBXML2 m_pxml->InsertNodeAttr (gnode, "group", szupgroup); m_pxml->InsertNodeAttr (gnode, "index", str.sprintf ("%d", index)); m_pxml->InsertNodeAttr (gnode, "pcpuno", "1");#else gElem.setAttributeValue("group",szupgroup.data()); str.sprintf("%d",index); gElem.setAttributeValue("index",str.data()); gElem.setAttributeValue("pcpuno","1");#endif }#ifndef USE_LIBXML2 m_pxml->InsertNodeAttr (gnode, "cpuno", "1");#else gElem.setAttributeValue("cpuno","1");#endif nodeMap. insert (make_pair (a10.m_DataSets.at (i)->gin.GROUP, gnode)); gQueue.push_back (a10.m_DataSets.at (i)->gin.GROUP); } } if (a10.m_NGD.ngd.Cont == 0) { CmdParam cmd; cmd.type = 21; cmd.cot = 42; cmd.addr = m_DevInfo.m_MachineAddr; cmd.fun = 254; cmd.inf = 241; cmd.num = 1; m_CmdParam.append (cmd); cmdit = m_CmdParam.at (0); DataSet *pds = new DataSet; pds->gin.GROUP = gQueue[0]; pds->gin.ENTRY = 0; pds->kod = 10; m_CmdDataSets.append (pds); currentState = COLLECT_E; gQueue.pop_front (); SendAsdu21 (); } } else { if (currentState == COLLECT_E) { for (int i = 0; i < a10.m_DataSets.count (); i++) { eQueue.push_back (a10.m_DataSets.at (i)->gin); } if (a10.m_NGD.ngd.Cont == 0) { if (gQueue.empty ()) { lastg = eQueue.back ().GROUP; laste = eQueue.back ().ENTRY; currentState = DETAIL; CmdParam cmd; cmd.type = 21; cmd.cot = 42; cmd.addr = m_DevInfo.m_MachineAddr; cmd.fun = 254; cmd.inf = 243; cmd.num = 1; m_CmdParam.append (cmd); cmdit = m_CmdParam.at (0); DataSet *pds = new DataSet; pds->gin.GROUP = eQueue[0].GROUP; pds->gin.ENTRY = eQueue[0].ENTRY; pds->kod = 0; m_CmdDataSets.append (pds); SendAsdu21 (); return; } CmdParam cmd; cmd.type = 21; cmd.cot = 42; cmd.addr = m_DevInfo.m_MachineAddr; cmd.fun = 254; cmd.inf = 241; cmd.num = 1; m_CmdParam.append (cmd); cmdit = m_CmdParam.at (0); DataSet *pds = new DataSet; pds->gin.GROUP = gQueue[0]; pds->gin.ENTRY = 0; pds->kod = 1; m_CmdDataSets.append (pds); gQueue.pop_front (); SendAsdu21 (); } } } return;}/*! \fn CNRLan103::ProcessAlert(int icpuno, DataSet* pDataSet) */void CNRLan103::ProcessAlert(int icpuno, DataSet* pDataSet){ /// @todo implement me QString szgroup = "", szentry = "", szcpuno = "", sztmp = ""; szgroup.sprintf ("%d", pDataSet->gin.GROUP); szentry.sprintf ("%d", pDataSet->gin.ENTRY); szcpuno.sprintf ("%d", icpuno);#ifndef USE_LIBXML2 QDomNode node, cnode; node = m_pxml->GetDomNodex (QString("body"), "ALERT", "pgroup", szgroup.data(), "pcpuno",szcpuno.data(),NULL,NULL); if (node.isNull ()) { return; } cnode = m_pxml->GetChildNode (node, "ELEMENT", "pentry", szentry.data(),NULL,NULL); if (cnode.isNull ()) { return; }#else Element rootElem=m_pConfDoc->getRootElement(); XPathProcessor xprc(*m_pConfDoc); char exprBuff[100]; sprintf(exprBuff,"//body/ALERT[@pgroup='%s'][@pcpuno='%s']/ELEMENT[@pentry='%s']",szgroup.data(),szcpuno.data(),szentry.data()); Element entryElem=xprc.selectSingleNode(rootElem,exprBuff); if(entryElem.isNull()) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]can not locate "<<exprBuff<<endl; return; }#endif QDate date = QDate::currentDate (); BYTE dpi = 0; WORD wmsec = 0; if (pDataSet->gdd.gdd.DataType == 0x12) { dpi = pDataSet->gid[0]; memcpy (&wmsec, &pDataSet->gid[1], 2); sztmp.sprintf ("%04d%02d%02d%02d%02d%02d%03d", date.year (), date.month (), date.day (), pDataSet->gid[4], pDataSet->gid[3], wmsec / 1000, wmsec % 1000); } st_event EVENT; st_eventact EVENTACT; st_event *pRpt_Event = &EVENT; memset (pRpt_Event, 0x00, sizeof (st_event)); st_eventact *pEventAct = &EVENTACT; memset (pEventAct, 0x00, sizeof (st_eventact)); pRpt_Event->m_StationNo = g_PublicClass.m_StationNo; pRpt_Event->m_MachineNo = m_DevInfo.m_MachineNo; pRpt_Event->m_Entry = 0; pRpt_Event->m_FaultNum = ++m_iFaultNo; strcpy (pRpt_Event->m_MachineName, m_DevInfo.m_MachineName); memcpy (pRpt_Event->m_ActionTime, sztmp.data (), sztmp.length ());#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (node, "cpuno", szcpuno)) return;#else Node attrNode=xprc.selectSingleNode(entryElem,"../@cpuno"); if(attrNode.isNull()) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]can not locate ../@cpuno"<<endl; return; }#endif pRpt_Event->m_CpuNo = szcpuno.toInt (); pEventAct->m_CpuNo = szcpuno.toInt ();#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (cnode, "desc", sztmp)) return;#else try { sztmp=entryElem.getAttributeValue("desc").c_str(); } catch(DOMException& e) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]"<<e.what()<<endl; return; }#endif if (dpi == 1) sztmp += m_szDpi1; else sztmp += m_szDpi2; pEventAct->m_MachineNo = m_DevInfo.m_MachineNo; pEventAct->m_FaultNum = m_iFaultNo; memcpy (pEventAct->m_ActElement, sztmp.data (), sztmp.length ()); pEventAct->m_ActTime = 0; pEventAct->m_Dpi = dpi;#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (cnode, "fun", sztmp)) return;#else try { entryElem.getAttributeValue("fun"); } catch(DOMException& e) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]"<<e.what()<<endl; return; }#endif pEventAct->m_FunCode = sztmp.toInt ();#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (cnode, "inf", sztmp)) return;#else try { entryElem.getAttributeValue("inf"); } catch(DOMException& e) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]"<<e.what()<<endl; return; }#endif pEventAct->m_InfCode = sztmp.toInt ();#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (node, "group", sztmp)) return;#else try { entryElem.getAttributeValue("group"); } catch(DOMException& e) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]"<<e.what()<<endl; return; }#endif pEventAct->m_Group = sztmp.toInt ();#ifndef USE_LIBXML2 if (!m_pxml->GetNodeAttr (cnode, "entry", sztmp)) return;#else try { entryElem.getAttributeValue("entry"); } catch(DOMException& e) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]"<<e.what()<<endl; return; }#endif pEventAct->m_Entry = sztmp.toInt (); sztmp.sprintf ("%s", m_DevInfo.m_MachineName); g_PublicClass.m_Ini.SetKeyIntValue (sztmp, "FAULTNO", m_iFaultNo); QString recordIndex; if(!m_dp.InsertSelfChk(this->m_hdbc,EVENT,recordIndex)) { ///may be printed some message cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]!m_dp.InsertSelfChk"<<endl; return; } if(!m_dp.InsertSelfChkAct(this->m_hdbc,pEventAct,sizeof(st_eventact),recordIndex)) { cout<<*this<<"[ERROR][CNRLan103::ProcessAlert]!!m_dp.InsertSelfChkAct"<<endl; return; } this->NotifyMsg(DATA_EVENT,recordIndex,"RPT_SELFCHK",1);}/*! \fn CNRLan103::ProcessAsdu11(CAsdu& a) */void CNRLan103::ProcessAsdu11(CAsdu& a){ /// @todo implement me if (!collecting) return; assert (a.m_ASDUData.GetSize () > 0); BYTE buff[a.m_ASDUData.GetSize ()]; memcpy (buff, a.m_ASDUData.GetData (), a.m_ASDUData.GetSize ()); //in actual value,correct asdu11;damned RCS! if (a.m_INF == 244) { BYTE tmp = buff[1]; buff[1] = buff[2]; buff[2] = buff[3]; buff[3] = tmp; } BYTE g = buff[1]; BYTE e = buff[2]; BYTE *pos = buff + 4; ///communicator.printData (buff, a.m_ASDUData.GetSize (), "ASDU11 DUMP", 0);#ifdef USE_LIBXML2 XPathProcessor xprc(*m_pConfDoc);#endif if (*pos != 1) {#ifndef USE_LIBXML2 map < BYTE, QDomNode >::iterator iter = nodeMap.find (g);#else map < BYTE, Element >::iterator iter = nodeMap.find (g);#endif if (iter == nodeMap.end ()) { printf ("unexpected group %u from device\n", g); collecting = false; return; } //not seperate waveandlog&waveswitch yet#ifndef USE_LIBXML2 currentEntry = m_pxml->InsertChildNode (iter->second, "ELEMENT");#else currentEntry=iter->second.addChildElement("ELEMENT");#endif QString szpentry, szentry; szpentry.sprintf ("%u", e);#ifndef USE_LIBXML2 QString groupName=iter->second.GetName (); szentry.sprintf ("%u", m_pxml->GetChildNodeCount (iter->second) - 1); m_pxml->InsertNodeAttr (currentEntry, "pentry", szpentry);#else QString groupName=iter->second.name().c_str(); szentry.sprintf("%u",currentEntry.childrenCount()); currentEntry.setAttributeValue("pentry",szpentry.data());#endif //switch value if (groupName == "FAULT" || groupName == "SWITCH" || groupName == "ALERT") { currentState = SWITCH;#ifndef USE_LIBXML2 m_pxml->InsertNodeAttr (currentEntry, "entry", szentry); m_pxml->InsertNodeAttr (currentEntry, "entry", szentry); m_pxml->InsertNodeAttr (currentEntry, "inf", szentry); m_pxml->InsertNodeAttr (currentEntry, "pfun", "184"); m_pxml->InsertNodeAttr (currentEntry, "pinf", szentry);#else currentEntry.setAttributeValue("entry", szentry.data()); currentEntry.setAttributeValue("entry", szentry.data()); currentEntry.setAttributeValue("inf", szentry.data()); currentEntry.setAttributeValue("pfun", "184"); currentEntry.setAttributeValue("pinf", szentry.data());#endif } //param & analog else if (groupName == "PARAM" || groupName == "ANALOG" || groupName == "SECTOR" || groupName == "RYABAN") { currentState = PARAM;#ifndef USE_LIBXML2 m_pxml->InsertNodeAttr (currentEntry, "entry", szentry);#else currentEntry.setAttributeValue("entry", szentry.data());#endif } //wave else if (groupName == "WAVEANALOG" || groupName == "WAVESWITCH") { currentState = WAVE; } } QString str; str.sprintf ("<ELEMENT pgroup=\"%u\" pentry=\"%u\"", g, e); int next = 0; for (int i = 0; i < buff[3]; i++) { next += processSingle (&pos[next], str); if (next > a.m_ASDUData.GetSize () - 1) { break; } } //continue query if (eQueue.size () > 0 && *pos == 1) eQueue.pop_front (); cout<<*this<<"[INFO][CNRL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -