12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465 |
- #include "StdAfx.h"
- //#include "Global.h"
- #include "RunTimeDepot.h"
- #include "CharacterProcess.h"
- #include "CheckProcess.h"
- #include ".\objectdepot.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- HANDLE g_hProc = NULL;
- HANDLE g_hCtrl = NULL;
- /************************************************************************/
- /*
- 全局函数:获取长度;
- */
- /************************************************************************/
- int GetLength(const int &nIdx)
- {
- if ( nIdx == 1)
- return 2;
-
- int nSum = 2;
- for(int i = 1; i < nIdx; i++)
- nSum += 3;
-
- return nSum;
- }
- CObjectdepot::CObjectdepot(void)
- {
- //GenerationDepotModel();
- //GenerationRunModel();
- }
- CObjectdepot::~CObjectdepot(void)
- {
- if ( g_hProc )
- {
- CloseHandle(g_hProc);
- g_hProc = NULL;
- }
- }
- void CObjectdepot::InitThread()
- {
- g_hCtrl = CreateEvent(NULL, TRUE ,TRUE ,NULL);
- if ( g_hCtrl == NULL )
- return ;
- g_hProc = CreateThread(NULL,0,DataDealThreadProcess,this,0,NULL);
- if ( g_hProc == NULL )
- return;
- }
- // 所有变量的取值线程;
- DWORD CObjectdepot::DataDealThreadProcess(PVOID pParam)
- {
- do
- {
- // 以下是假过程,思路原型;
- // 1.遍历所有设备;
- // int iCount = g_ArrayDevice.Size();
- // for (int i = 0; i < iCount ; i++)
- // {
- // STDevice device = g_ArrayDevice[i];
- // // 2.遍历该设备所有变量;
- // int VarSize = device.VarSize();
- // for ( int n = 0; n < VarSize; n++)
- // {
- // STVariant variant = device.Variant[i];
- // // 3.获取设备信息,与g_vtRecv对比;
- // vector <STRecvMessage>::iterator it_recvmessage;
- // for ( it_recvmessage = g_vtRecv.begin(); it_recvmessage != g_vtRecv.end(); it_recvmessage++)
- // {
- // STRecvMessage recvmessage = *it_recvmessage;
- // if(device.iPort == recvmessage.iPort && device.iAddr == recvmessage.iAddr)
- // {
- // // 4.获取变量的Mark特征码;
- // if( strcmp(variant.szMark, recvmessag.szMark) == 0)
- // {
- // // 5.获取最终变量值;
- // GetVariantValue(variant, recvmessage.byRecv);
- // // GetVarinatValue函数原型:
- // // void GetVariantValue(STVariant &var, const BYTE *&pRecv);
- // }
- // }
- // }
- // }
- // }
- } while (WaitForSingleObject(g_hCtrl, 10) != WAIT_OBJECT_0);
- return 0;
- }
- void CObjectdepot::GenerationDepotModel()
- {
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
- // 添加根元素;
- xml.AddElem("depotobject");
- xml.AddAttrib("object_count",0);
- xml.AddChildElem("static_code");
- xml.AddChildAttrib("ele_count",0);
- xml.IntoElem();
- xml.AddChildElem("connection_standard");
- xml.IntoElem();
- xml.AddChildElem("standard","RS232");
- xml.AddChildElem("standard","RS485");
- xml.AddChildElem("standard","RJ45");
- xml.OutOfElem();
- xml.AddChildElem("protocol_type");
- xml.IntoElem();
- xml.AddChildElem("type","RS232电总");
- xml.AddChildElem("type","RS485电总");
- xml.AddChildElem("type","ModbusRtu");
- xml.AddChildElem("type","ModbusAsicc");
- xml.AddChildElem("type","SNMP");
- xml.OutOfElem();
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- }
- void CObjectdepot::GenerationRunModel()
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
- // 添加根元素;
- xml.AddElem("Current_Object_Run");
- xml.Save(szRunTimeDepotPath);
- }
- }
- #if SETDEPOT_PATH
- void CObjectdepot::SetDevicesDepotPath(char *szPath)
- {
- memset(szDepotPath,0,MAX_PATH);
- memcpy(szDepotPath,szPath,strlen(szPath));
- }
- void CObjectdepot::SetRuntimeDevicesDepotPath(char *szPath)
- {
- memset(szRunTimeDepotPath,0,MAX_PATH);
- memcpy(szRunTimeDepotPath,szPath,strlen(szPath));
- }
- void CObjectdepot::SetDevicesDepotPath(CString strPath)
- {
- memset(szDepotPath,0,MAX_PATH);
- strcpy(szDepotPath,strPath);
- }
- void CObjectdepot::SetRuntimeDevicesDepotPath(CString strPath)
- {
- memset(szRunTimeDepotPath,0,MAX_PATH);
- strcpy(szRunTimeDepotPath,strPath);
- }
- #endif
- #if DEVICES_DEPOT
- /************************************************************************/
- /*
- 函数:根据函数参数,从设备库获取参数创建运行时设备库元素;
- 参数:
- iComPort: 串口;
- iAddr: 地址;
- szName: 设备名称;
- 测试结果:OK;
- */
- /************************************************************************/
- STRunObject* CObjectdepot::CreateRunObject(const int &iComPort, const int &iAddr,const char *szName)
- {
- STDepotObject *depotobject = LookupElement(szName);
- if ( depotobject == NULL)
- return NULL;
- STRunObject *runobject = new STRunObject ; // 容器指针;
- runobject->iPort = iComPort;
- //memcpy(runobject->st_rundevice.szUName,szName,strlen(szName));
- strcpy(runobject->st_rundevice.szUName,szName);
- runobject->st_rundevice.iAddr = iAddr;
- //memcpy(runobject->st_rundevice.szSID,depotobject->szSID, strlen(depotobject->szSID));
- strcpy(runobject->st_rundevice.szSID,depotobject->szSID);
- //memcpy(&(runobject->st_runphy), &(depotobject->st_depotphy), sizeof(depotobject->st_depotphy));
-
- runobject->st_runphy.iDBit = depotobject->st_depotphy.iDBit;
- runobject->st_runphy.iIntl = depotobject->st_depotphy.iIntl;
- runobject->st_runphy.iPaty = depotobject->st_depotphy.iPaty;
- runobject->st_runphy.iRate = depotobject->st_depotphy.iRate;
- runobject->st_runphy.iRsTm = depotobject->st_depotphy.iRsTm;
- runobject->st_runphy.iSBit = depotobject->st_depotphy.iSBit;
- strcpy(runobject->st_runphy.szComType,depotobject->st_depotphy.szComType);
- strcpy(runobject->st_runphy.szLineType,depotobject->st_depotphy.szLineType);
- strcpy(runobject->st_runphy.szPinDef,depotobject->st_depotphy.szPinDef);
- strcpy(runobject->st_rundevice.szCheck,"None");
- if ( depotobject->vt_commandformat.size() == 0)
- {
- return NULL;
- }
- // 不做命令的选择,全部命令都用上,只在变量里做取舍;
- // 命令的组合,需要在外部做一个类进行处理归类;
- vector <STCommandTable>::iterator it_commandtable;
- for ( it_commandtable = depotobject->vt_commandtable.begin(); it_commandtable != depotobject->vt_commandtable.end(); it_commandtable++)
- {
- STRunCommand RunCommand = {0};
- STCommandTable commandtable = *it_commandtable;
- // ?如何实现长度动态计算szSend;
- // 如果无法实现,则在创建设备库时,事先计算好长度,再填入便行,不必拘于此处的计算;
- int nIndex = 0;
- BYTE *szSend = new BYTE[depotobject->ByteCount*3 ];
- ZeroMemory(szSend,depotobject->ByteCount*3 );
- memset(szSend, 32, depotobject->ByteCount*3-1 );// 空格填充;
- vector <STCommandFormat>::iterator it_commandformat;
- for ( it_commandformat = depotobject->vt_commandformat.begin(); it_commandformat != depotobject->vt_commandformat.end(); it_commandformat++)
- {
- STCommandFormat commandformat = *it_commandformat;
- if ( strcmp(commandformat.szName,"addr") == 0 )
- {
- CString strHex = "";
- if ( strcmp(commandformat.szLen,"2") == 0)
- {
- char szHex[3] = {0};
- szHex[0] = CCharacterProcess::Byte_to_ASCII((iAddr >> 4) & 0x0F);
- szHex[1] = CCharacterProcess::Byte_to_ASCII( iAddr & 0x0F);
- strHex.Format("%02X",szHex[0]);
- memcpy(szSend+nIndex,strHex, 2);
- strHex.Format("%02X",szHex[1]);
- memcpy(szSend+nIndex + 3,strHex,2);
- }
- else if ( strcmp(commandformat.szLen,"1") == 0)
- {
- if ( strcmp(commandformat.szData,"?") == 0)
- {
- strHex.Format("%02X",iAddr);
- memcpy(szSend+nIndex,strHex, 2);
- }
- if ( commandformat.szData[0] == '+' )
- {
- strHex.Format("%02X", iAddr + atoi(commandformat.szData+1));
- memcpy(szSend+nIndex,strHex, 2);
- }
- if ( commandformat.szData[0] == '#') // 出现'#',表示复杂运算;
- {
- CString strData;
- strData.Format("%s",commandformat.szData);
- int nIdex1 =-1,nIdex2 =-1,nIdex3=-1;
- nIdex1 = strData.FindOneOf("(");
- nIdex2 = strData.FindOneOf(")");
- nIdex3 = strData.FindOneOf("^");
- int naddr = 0;
- if ( strData.GetAt(2) == '-' )
- {
- CString str;
- str = strData.Left(nIdex2);
- str = str.Mid(3,nIdex2);
- naddr = iAddr - atoi(str.GetBuffer());
- str.ReleaseBuffer();
- if ( nIdex3 != -1)
- {
- str = "";
- str = strData.Mid(nIdex3+1);
- naddr ^= atoi(str.GetBuffer());
- str.ReleaseBuffer();
- }
- }else if ( strData.GetAt(2) == '+' )
- {
- }else if ( strData.GetAt(2) == '*' )
- {
- }else if ( strData.GetAt(2) == '/' )
- {
- }
- strHex.Format("%02X", naddr);
- memcpy(szSend+nIndex,strHex, 2);
- }
- }
- nIndex += atoi(commandformat.szLen)*3;
- continue;
- }
- // 各协议计算真实检验码,这里应该由一个类处理,接口固定下来;
- // 接口原型之一,获取检验码:I_GetCheck(char *&pData, const char *&pCode);
- if ( strcmp(commandformat.szName, "check") == 0)
- {
- strcpy(runobject->st_rundevice.szCheck,commandformat.szData);
- if ( strcmp(commandformat.szData,"EMERSON") == 0)
- {
- CCheckProcess::GetXmlCheck_Emerson((char*)szSend, commandformat.szData,nIndex);
- }
-
- if (strcmp(commandformat.szData,"RTUCRC") == 0 )
- {
- CCheckProcess::GetXmlCheck_Rtu((char*)szSend, commandformat.szData, nIndex);
- }
-
- if ( strcmp(commandformat.szData,"fad") == 0 )
- {
- CCheckProcess::GetXmlCheck_fad((char*)szSend, commandformat.szData, nIndex);
- }
- if ( strcmp(commandformat.szData,"newave") == 0 )
- {
- CCheckProcess::GetXmlCheck_newave((char*)szSend, commandformat.szData, nIndex);
- }
- if ( strcmp(commandformat.szData,"stulz6000") == 0 )
- {
- CCheckProcess::GetXmlCheck_stulz6000((char*)szSend, commandformat.szData, nIndex);
- }
- if ( strcmp(commandformat.szData,"cm+") == 0 )
- {
- CCheckProcess::GetXmlCheck_CM((char*)szSend, commandformat.szData, nIndex);
- }
- int ilen = strlen(commandformat.szData);
- memcpy(szSend+nIndex, commandformat.szData, ilen);
- nIndex += ilen+1;
- continue;;
- }
- int iCode = atoi(commandformat.szType);
- switch(iCode)
- {
- case 1:
- {
- int ilen = atoi(commandformat.szLen);
- if ( ilen == 1)
- memcpy(szSend+nIndex, commandformat.szData, atoi(commandformat.szLen)*2);
- if ( ilen != 1)
- {
- ilen = GetLength(ilen);
- memcpy(szSend+nIndex, commandformat.szData, ilen);
- }
-
- }
- break;
- case 2: // 如何跳过format里有的,但是command中没有元素字节?(undo); 以下处理可以跳过;
- {
- vector <STCommandStyle>::iterator it_commandstyle;
- for ( it_commandstyle = commandtable.vt_commandstyle.begin(); it_commandstyle != commandtable.vt_commandstyle.end(); it_commandstyle++)
- {
- STCommandStyle commandstyle;
- commandstyle = *it_commandstyle;
- if ( strcmp(commandstyle.szName,commandformat.szName) == 0)
- {
- CString str;
- str.Format("%s",commandstyle.szData);
- if ( str.Find("addr") != -1 )
- {
- str.Format("%02X", iAddr+47);
- memcpy(szSend+nIndex,str, 2);
- nIndex += 3;
- }
- else
- {
- int ilen = strlen(commandstyle.szData);
- memcpy(szSend+nIndex, commandstyle.szData, ilen);
- nIndex += ilen +1;
- }
- break;
- }
- }
- }
- break;
- case 3: // 如何跳过format里有的,但是command中没有元素字节?(undo); 以下处理可以跳过(iCode=2);
- {
- vector <STCommandStyle>::iterator it_commandstyle;
- for ( it_commandstyle = commandtable.vt_commandstyle.begin(); it_commandstyle != commandtable.vt_commandstyle.end(); it_commandstyle++)
- {
- STCommandStyle commandstyle;
- commandstyle = *it_commandstyle;
- if ( strcmp(commandstyle.szName,commandformat.szName) == 0)
- {
- int ilen = strlen(commandstyle.szData);
- memcpy(szSend+nIndex, commandstyle.szData, ilen);
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- if ( strcmp(commandformat.szLen,"?") != 0)
- {
- int nlen = atoi(commandformat.szLen);
- nIndex += nlen*3;
- }
- }
- RunCommand.bRecv = commandtable.bRecv;
- sprintf(RunCommand.szTip,"%s",commandtable.szTip);
- //memcpy(RunCommand.szSCMD, szSend, depotobject.ByteCount*3 -1); // 这里导致了生成的命令串长度过长,包含多余的空格;
- // 去除尾部多余的空格;
- for( int i = nIndex-1; i > 0; i--)
- {
- if ( szSend[i] == 32 )
- {
- nIndex-- ;
- continue;
- }
- else
- {
- break;
- }
- }
- memcpy(RunCommand.szSCMD, szSend, nIndex);
- #if 0
- RunCommand.szMark[0] = iComPort + 48;
- RunCommand.szMark[1] = iAddr + 48;
- memcpy(RunCommand.szMark + 2, commandtable.szMark, strlen(commandtable.szMark));
- #else
- memcpy(RunCommand.szMark , commandtable.szMark, strlen(commandtable.szMark));
- #endif
- runobject->st_rundevice.iPort = iComPort;
- runobject->st_rundevice.iAddr = iAddr;
- // vs2008 Release下pus_back时出错;
- // 这是由于runobject处理过ZeroMemory,对容器的大小处理了,大小=0;
- // 导致push_back时越界了;
- runobject->st_rundevice.vt_rundevice.push_back(RunCommand);
- if ( szSend )
- {
- delete []szSend;
- szSend = NULL;
- }
- }
- if ( depotobject )
- {
- delete depotobject;
- depotobject = NULL;
- }
- return runobject;
- }
- /************************************************************************/
- /*
- 函数:判断元素是否存在;
- 参数:
- szElementName: 元素名称;
- EleType: 元素所属类型;
- 测试结果:OK;
- */
- /************************************************************************/
- BOOL CObjectdepot::IsElementExist(const char *szElementName, const int &EleType)
- {
- // 1.加载设备库xml文件;
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return FALSE;
- }
- BOOL bRet = -1;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- // 2.遍历设备库xml文件;
- while( xml.FindElem("object_depot") )
- {
- CString strElement = xml.GetAttrib("name");
- int nRet = strElement.Compare(szElementName);
- if ( nRet == 0 )
- {
- LOG4C((LOG_NOTICE,"元素已存在"));
- return TRUE;
- }
- }
- xml.OutOfElem();
- return FALSE;
- }
- /************************************************************************/
- /*
- 函数:向设备库插入元素;
- 参数:
- STOElement: 设备库元素;
- EleType: 元素所属类型;
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElement(const STDepotObject &STOElement, const int &EleType )
- {
- if ( IsElementExist(STOElement.szName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- xml.FindElem("object_depot") ;
- // 1.添加depot元素;
- xml.AddElem("object_depot");
- xml.AddAttrib("name", STOElement.szName); // 设备名称;
- xml.AddAttrib("static_id", STOElement.szSID); // 设备静态ID;
- // 2.添加depot子元素 ****物理特性;
- xml.AddChildElem("physical");
- xml.AddChildAttrib("rate",STOElement.st_depotphy.iRate); // 1.波特率;
- xml.AddChildAttrib("dataBit", STOElement.st_depotphy.iDBit); // 2.数据位;
- xml.AddChildAttrib("stopBit", STOElement.st_depotphy.iSBit); // 3.停止位;
- xml.AddChildAttrib("parity", STOElement.st_depotphy.iPaty); // 4.校验位;
- xml.AddChildAttrib("iResTime", STOElement.st_depotphy.iRsTm); // 4.校验位;
- xml.AddChildAttrib("interval", STOElement.st_depotphy.iIntl); // 5.超时值;
- xml.AddChildAttrib("LineType", STOElement.st_depotphy.szLineType); // 6.针脚类型;
- xml.AddChildAttrib("comType", STOElement.st_depotphy.szComType); // 7.串口类型;
- xml.AddChildAttrib("pinDefi", STOElement.st_depotphy.szPinDef); // 8.针脚定义;
- // 3.添加depot子元素 ****文档说明 ;
- xml.AddChildElem("document");
- xml.AddChildAttrib("Factory", STOElement.st_depotdoc.szFactory);
- xml.AddChildAttrib("deviceType", STOElement.st_depotdoc.szdeviceType);
- xml.AddChildAttrib("class", STOElement.st_depotdoc.szdeviceClass);
- xml.AddChildAttrib("deviceName", STOElement.st_depotdoc.szdeviceName);
- xml.AddChildAttrib("unitType", STOElement.st_depotdoc.szUnitType);
- xml.AddChildAttrib("protocol", STOElement.st_depotdoc.szProtocol);
- // 4.添加 depot子元素 命令格式;
- xml.AddChildElem("command_format");
- xml.IntoElem();
- // 获取命令格式大小;
- vector <STCommandFormat>::const_iterator it_commandformat;
- for ( it_commandformat = STOElement.vt_commandformat.begin(); it_commandformat != STOElement.vt_commandformat.end(); it_commandformat++)
- {
- STCommandFormat tag = *it_commandformat;
- xml.AddChildElem("format");
- xml.AddChildAttrib("name", tag.szName);
- xml.AddChildAttrib("len", tag.szLen);
- xml.AddChildAttrib("data", tag.szData);
- xml.AddChildAttrib("type", tag.szType);
- }
- xml.OutOfElem();
- // 5.添加 depot子元素 命令元;
- xml.AddChildElem("command");
- xml.IntoElem();
- // vector <EleCmd>::iterator it_elcd; 会造成:error C2679: 二进制“=” : 没有找到接受“<未知>”类型的右操作数的运算符(或没有可接受的转换)
- // 出现错误的原因:是因为dp是const引用的,所以在it_elcd = dp.vt_msg.begin();时出错;
- // 因为dp是const引用,所在dp里的所有变量都不能改变;
- vector <STCommandTable>::const_iterator cit_commandtable;
- for ( cit_commandtable = STOElement.vt_commandtable.begin(); cit_commandtable != STOElement.vt_commandtable.end(); cit_commandtable++)
- {
- STCommandTable commandtable = *cit_commandtable;
- xml.AddChildElem("cmd");
- xml.AddChildAttrib("Mark",commandtable.szMark);
- xml.AddChildAttrib("Recv",commandtable.bRecv);
- xml.AddChildAttrib("it_tip", commandtable.szTip);
- vector <STCommandStyle>::const_iterator cit_commandstyle;
- for ( cit_commandstyle = commandtable.vt_commandstyle.begin(); cit_commandstyle != commandtable.vt_commandstyle.end(); cit_commandstyle++)
- {
- STCommandStyle commandstyle = *cit_commandstyle;
- xml.IntoElem();
- xml.AddChildElem("element");
- xml.AddChildAttrib("name", commandstyle.szName);
- xml.AddChildAttrib("data", commandstyle.szData);
- xml.OutOfElem();
- }
- }
- xml.OutOfElem();
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:从设备库移除元素;
- 参数:
- szElementName: 设备名称;
- EleType: 元素所属类型;
- 测试结果:OK;
- */
- /************************************************************************/
- void CObjectdepot::RemoveElement(const char *szElementName, const int &EleType /* = 0 */)
- {
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while(xml.FindElem("object_depot"))
- {
- CString strName = xml.GetAttrib("name");
- if ( strName.Compare(szElementName) == 0)
- {
- xml.RemoveElem();
- break;
-
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:修改设备库元素;
- 参数:
- STOElement: 设备库元素;
- EleType: 元素所属类型;
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElement(const STDepotObject &STOElement, const int &EleType /* = 0 */)
- {
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- if ( !IsElementExist(STOElement.szName) )
- {
- InsertElement(STOElement);
- return;
- }
- RemoveElement(STOElement.szName);
- InsertElement(STOElement);
- }
- /************************************************************************/
- /*
- 函数:查找设备库元素;
- 参数:
- szElementName: 设备名称;
- EleType: 元素所属类型;
- 测试结果:OK
- */
- /************************************************************************/
- STDepotObject* CObjectdepot::LookupElement(const char *szElementName, const int &EleType /* = 0 */)
- {
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return NULL;
- }
- STDepotObject *depotobject = new STDepotObject;//容器指针;
- BOOL bRet = FALSE;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- BOOL bGet = FALSE;
- while( xml.FindElem("object_depot") )
- {
- CString strName = xml.GetAttrib("name");
- if ( strName.Compare(szElementName) != 0 )
- continue;
- bGet = TRUE; // 如果找到,设置为TRUE,并在最后break;
- //ZeroMemory(depotobject,sizeof(STDepotObject));
- sprintf(depotobject->szName ,"%s", xml.GetAttrib("name" )); // 设备名称;
- sprintf(depotobject->szSID ,"%s", xml.GetAttrib("static_id" )); // 设备名称;
- xml.IntoElem();
- xml.FindElem("physical");
- depotobject->st_depotphy.iRate = atoi(xml.GetAttrib("rate"));
- depotobject->st_depotphy.iDBit = atoi(xml.GetAttrib("dataBit"));
- depotobject->st_depotphy.iSBit = atoi(xml.GetAttrib("stopBit"));
- depotobject->st_depotphy.iPaty = atoi(xml.GetAttrib("parity"));
- depotobject->st_depotphy.iRsTm = atoi(xml.GetAttrib("iResTime"));
- depotobject->st_depotphy.iIntl = atoi(xml.GetAttrib("interval"));
- sprintf(depotobject->st_depotphy.szLineType, "%s", xml.GetAttrib("LineType"));
- sprintf(depotobject->st_depotphy.szComType, "%s", xml.GetAttrib("comType"));
- sprintf(depotobject->st_depotphy.szPinDef, "%s", xml.GetAttrib("pinDefi"));
- xml.OutOfElem();
- xml.IntoElem();
- xml.FindElem("document");
- sprintf( depotobject->st_depotdoc.szFactory, xml.GetAttrib("Factory"));
- sprintf( depotobject->st_depotdoc.szdeviceType, xml.GetAttrib("deviceType"));
- sprintf( depotobject->st_depotdoc.szdeviceClass, xml.GetAttrib("class"));
- sprintf( depotobject->st_depotdoc.szdeviceName, xml.GetAttrib("deviceName"));
- sprintf( depotobject->st_depotdoc.szUnitType, xml.GetAttrib("unitType"));
- sprintf( depotobject->st_depotdoc.szProtocol, xml.GetAttrib("protocol"));
- xml.OutOfElem();
- // 3.继续CreateCommand;
- xml.IntoElem();
- xml.FindElem("command_format");
- depotobject->ByteCount = atoi( xml.GetAttrib("ByteCount"));
- while(xml.FindChildElem("format"))
- {
- STCommandFormat commandformat = {0};
- //ZeroMemory(&commandformat,sizeof(STCommandFormat));
- sprintf(commandformat.szName, "%s", xml.GetChildAttrib("name"));
- sprintf(commandformat.szLen, "%s", xml.GetChildAttrib("len"));
- sprintf(commandformat.szType, "%s", xml.GetChildAttrib("type"));
- sprintf(commandformat.szData, "%s", xml.GetChildAttrib("data"));
- // RUN_ADDOBJECT函数 缺少记录实际字符长度的变量;
- CString tmpStr = xml.GetChildAttrib("data");
- commandformat.nDatalen = tmpStr.GetLength();
- depotobject->vt_commandformat.push_back(commandformat);
- }
- xml.FindElem("command");
- while(xml.FindChildElem("cmd"))
- {
- STCommandTable commandtable ;//容器指针;
- //ZeroMemory(&commandtable,sizeof(STCommandTable));
-
- sprintf(commandtable.szMark,"%s",xml.GetChildAttrib("Mark"));
- commandtable.bRecv = atoi(xml.GetChildAttrib("Recv"));
- sprintf(commandtable.szTip,"%s",xml.GetChildAttrib("it_tip"));
- xml.IntoElem();
- while(xml.FindChildElem("element"))
- {
- STCommandStyle commandstyle = {0};
- //ZeroMemory(&commandstyle,sizeof(STCommandStyle));
- // sprintf不安全;
- //sprintf(tagCM.szName,"%s",m_depot.GetChildAttrib("name"));
- //sprintf(tagCM.szData,"%s",m_depot.GetChildAttrib("data"));
- // 这里会出错<untakeit>
- memcpy(commandstyle.szName, xml.GetChildAttrib("name"), strlen(xml.GetChildAttrib("name")));
- memcpy(commandstyle.szData, xml.GetChildAttrib("data"), strlen(xml.GetChildAttrib("data")));
- // RUN_ADDOBJECT函数 缺少记录实际字符长度的变量;
- CString tmpStr = xml.GetChildAttrib("data");
- commandstyle.nDatalen = tmpStr.GetLength();
- commandtable.vt_commandstyle.push_back(commandstyle);
- }
- depotobject->vt_commandtable.push_back(commandtable);
- xml.OutOfElem();
- }
- xml.OutOfElem();
- break;
- }
- xml.OutOfElem();
- if ( !bGet )
- {
- if ( depotobject )
- {
- delete depotobject;
- depotobject = NULL;
- }
- return NULL;
- }
- return depotobject;
- }
- #endif
- #if RUNTIME_DEPOT
- /************************************************************************/
- /*
- 函数:运行时设备库元素是否存在;
- 参数:
- iPort: 串口;
- iAddr: 地址;
- 返回值:
- = -1: 串口无;
- = 0: 串口有,地址无;
- = 1: 存在;
- 测试结果:OK
- */
- /************************************************************************/
- int CObjectdepot::IsSubElementExist(const int &iPort, const int &iAddr)
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"运行时设备库不存在~"));
- return FALSE;
- }
- int nRet = -1;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- // 遍历所有元素;
- while( xml.FindElem("run_object") )
- {
- CString strPort = xml.GetAttrib("port");
- int _port = atoi(strPort.GetBuffer());
- strPort.ReleaseBuffer();
- if ( _port != iPort )
- continue;
- nRet = 0;
- while( xml.FindChildElem("commands") )
- {
- char szAddr[10] = {0};
- itoa(iAddr, szAddr, 10);
- if( strcmp(xml.GetChildAttrib("addr"), szAddr) == 0)
- {
- nRet = 1;
- break;
- }
- }
- break;
- }
- xml.OutOfElem();
- return nRet;
- }
- /************************************************************************/
- /*
- 函数:向运行时设备库插入元素;
- 参数:
- iPort: 串口号;
- iAddr: 地址;
- szName: 设备名称;
- 测试结果:OK;
- */
- /************************************************************************/
- BOOL CObjectdepot::InsertSubElement(const int &iPort, const int &iAddr, char *szName)
- {
- int iRet = IsSubElementExist(iPort,iAddr);
- if( iRet == 1)
- {
- LOG4C((LOG_NOTICE,"运行时设备库:COM%d:%d 已存在",iPort,iAddr));
- return FALSE;
- }
- if ( !IsElementExist(szName))
- {
- LOG4C((LOG_NOTICE,"设备库:没有该设备档案"));
- return FALSE;
- }
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- return FALSE;
- STRunObject* tRunObject = CreateRunObject(iPort, iAddr, szName);
- if ( tRunObject == NULL )
- {
- return FALSE;
- }
- if ( iRet == -1 )
- {
- //xml.ResetPos();
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- // 1.添加depot元素;
- xml.AddElem("run_object");
- xml.AddAttrib("port", tRunObject->iPort);
- xml.AddAttrib("ele_count", 1);
- // 2.添加depot子元素 物理特性;
- xml.AddChildElem("physical");
- xml.AddChildAttrib("rate", tRunObject->st_runphy.iRate); // 1.波特率;
- xml.AddChildAttrib("dataBit", tRunObject->st_runphy.iDBit); // 2.数据位;
- xml.AddChildAttrib("stopBit", tRunObject->st_runphy.iSBit); // 3.停止位;
- xml.AddChildAttrib("parity", tRunObject->st_runphy.iPaty); // 4.校验位;
- xml.AddChildAttrib("iResTime", tRunObject->st_runphy.iRsTm); // 4.校验位;
- xml.AddChildAttrib("interval", tRunObject->st_runphy.iIntl); // 5.超时值;
- xml.AddChildAttrib("LineType", tRunObject->st_runphy.szLineType); // 6.针脚类型;
- xml.AddChildAttrib("comType", tRunObject->st_runphy.szComType); // 7.串口类型;
- xml.AddChildAttrib("pinDefi", tRunObject->st_runphy.szPinDef); // 8.针脚定义;
- // 3.添加 depot子元素 命令格式;
- xml.AddChildElem("commands");
- xml.AddChildAttrib("addr",tRunObject->st_rundevice.iAddr);
- xml.AddChildAttrib("name",tRunObject->st_rundevice.szUName);
- xml.AddChildAttrib("check",tRunObject->st_rundevice.szCheck);
- xml.IntoElem();
- // 获取命令格式大小;
- vector <STRunCommand>::const_iterator cit_runcommand;
- for ( cit_runcommand = tRunObject->st_rundevice.vt_rundevice.begin(); cit_runcommand != tRunObject->st_rundevice.vt_rundevice.end(); cit_runcommand++)
- {
- STRunCommand runcommand = *cit_runcommand;
- xml.AddChildElem("command");
- // 在此之前,需要先计算出各命令的检验值;(undo)
- xml.AddChildAttrib("send_read", runcommand.szSCMD);
- xml.AddChildAttrib("Recv", runcommand.bRecv);
- xml.AddChildAttrib("Mark", runcommand.szMark);
- xml.AddChildAttrib("label", runcommand.szTip);
- }
- xml.OutOfElem();
- xml.OutOfElem();
- }
- else if ( iRet == 0)
- {
- //xml.ResetPos();
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER8
- // 1.遍历所有元素,找到插入的串口号;
- while( xml.FindElem("run_object") )
- {
- CString strPort = xml.GetAttrib("port");
- int _port = atoi(strPort.GetBuffer());
- strPort.ReleaseBuffer();
- if ( _port != iPort )
- continue;
- CString strCount = xml.GetAttrib("ele_count");
- int _count = atoi(strCount.GetBuffer());
- strCount.ReleaseBuffer();
- xml.SetAttrib("ele_count",++_count);
- BOOL bAorI = FALSE;
- int Max = 0,i = 0;
- // 2.循环得出元素地址的最佳插入位置;
- while( xml.FindChildElem("commands") )
- {
- CString strAddr = xml.GetChildAttrib("addr");
- int _addr = atoi(strAddr.GetBuffer());
- strAddr.ReleaseBuffer();
- if ( _addr < iAddr )
- if ( _addr > Max )
- Max = _addr;
- if ( _addr > iAddr && i == 0 )
- bAorI = TRUE;
- i++;
- }
- // 3.根据2,开始插入元素;
- xml.ResetChildPos();//重新设置子元素索引位置,设置在头部;
-
- if( !bAorI )
- {
- while( xml.FindChildElem("commands") )
- {
- CString strAddr = xml.GetChildAttrib("addr");
- int _addr = atoi(strAddr.GetBuffer());
- strAddr.ReleaseBuffer();
- if ( _addr == Max )
- break;
- }
- // 使用AddChildElem是向尾部插入;
- xml.AddChildElem("commands");
- }
- else
- {
- xml.FindChildElem("physical");
- // 使用InsertChildElem 是向头部插入;
- //xml.InsertChildElem("commands");
- // 使用AddChildElem是向尾部插入;
- xml.AddChildElem("commands");
- }
-
- xml.AddChildAttrib("addr",tRunObject->st_rundevice.iAddr);
- xml.AddChildAttrib("name",tRunObject->st_rundevice.szUName);
- xml.AddChildAttrib("check",tRunObject->st_rundevice.szCheck);
- xml.IntoElem();
- // 获取命令格式大小;
- vector <STRunCommand>::const_iterator cit_runcommand;
- for ( cit_runcommand = tRunObject->st_rundevice.vt_rundevice.begin(); cit_runcommand != tRunObject->st_rundevice.vt_rundevice.end(); cit_runcommand++)
- {
- STRunCommand runcommand = *cit_runcommand;
- xml.AddChildElem("command");
- // 在此之前,需要先计算出各命令的检验值;(undo)
- xml.AddChildAttrib("send_read", runcommand.szSCMD);
- xml.AddChildAttrib("Recv", runcommand.bRecv);
- xml.AddChildAttrib("Mark", runcommand.szMark);
- xml.AddChildAttrib("label", runcommand.szTip);
- }
- xml.OutOfElem();
-
- break;
- }
- xml.OutOfElem();
- }
- if ( tRunObject )
- {
- //ZeroMemory(tRunObject,sizeof(STRunObject));
- delete tRunObject;
- tRunObject = NULL;
- }
- xml.Save(szRunTimeDepotPath);
- return TRUE;
- }
- /************************************************************************/
- /*
- 函数:从运行时设备库中移除元素;
- 参数:
- iPort: 串口号;
- iAddr: 地址,当 =-1 时,表示移除串口(串口下所有设备);
- 测试结果:OK;
- */
- /************************************************************************/
- void CObjectdepot::RemoveSubElement(const int &iPort, const int &iAddr)
- {
- if ( iAddr != -1)
- {
- if ( 1 != IsSubElementExist(iPort,iAddr) )
- {
- LOG4C((LOG_NOTICE,"不存在该元素"));
- return;
- }
- }
-
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while(xml.FindElem("run_object"))
- {
- CString strPort = xml.GetAttrib("port") ;
- int _port = atoi(strPort.GetBuffer());
- strPort.ReleaseBuffer();
- if ( _port != iPort)
- continue;
- CString strCount = xml.GetAttrib("ele_count");
- int _count = atoi(strCount.GetBuffer());
- strCount.ReleaseBuffer();
- if ( _count == 1 || iAddr == -1 )
- {
- xml.RemoveElem();
- xml.Save(szRunTimeDepotPath);
- break;
- }
- xml.SetAttrib("ele_count",--_count);
- xml.IntoElem();
- while(xml.FindElem("commands"))
- {
- CString strAddr = xml.GetAttrib("addr") ;
- int _addr = atoi(strAddr.GetBuffer());
- strAddr.ReleaseBuffer();
- if ( _addr != iAddr )
- continue;
-
- xml.RemoveElem();
- xml.Save(szRunTimeDepotPath);
- break;
- }
- xml.OutOfElem();
- break;
- }
- xml.OutOfElem();
- xml.Save(szRunTimeDepotPath);
- LOG4C((LOG_NOTICE,"删除COM%d:%d 成功",iPort,iAddr));
- }
- /************************************************************************/
- /*
- 函数:修改运行时设备库中的元素;
- 参数:
- iPort: 串口号;
- iAddr: 地址;
- tRunObject: 运行时设备库元素;
- 测试结果:未;
- */
- /************************************************************************/
- void CObjectdepot::ModifySubElement(const int &iPort, const int &iAddr, STRunObject &tRunObject)
- {
- RemoveSubElement(iPort,iAddr);
- InsertSubElement(iPort,iAddr,tRunObject.st_rundevice.szUName);
- }
- /************************************************************************/
- /*
- 函数:修改运行时设备库中的物理属性;
- 参数:
- iPort: 串口号;
- ...
- 测试结果:OK;
- */
- /************************************************************************/
- void CObjectdepot::ModifySubPhysical( const int &iPort, const int &iRate, const int &iDataBit, const int &iStopBit, const int &iParity, const int &iRespTime, const int &iInterval )
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"运行时设备库不存在"));
- return;
- }
- xml.FindElem();
- xml.IntoElem();
- while( xml.FindElem("run_object") )
- {
- int _port = atoi(xml.GetAttrib("port"));
- if ( _port != iPort)
- continue;
- xml.FindChildElem("physical");
- if( iRate != -1)
- xml.SetChildAttrib("rate",iRate);
- if ( iDataBit != -1)
- xml.SetChildAttrib("dataBit",iDataBit);
- if( iStopBit != -1 )
- xml.SetChildAttrib("stopBit",iStopBit);
- if( iParity != -1 )
- xml.SetChildAttrib("parity",iParity);
- if( iRespTime != -1 )
- xml.SetChildAttrib("iResTime",iRespTime);
- if( iInterval != -1)
- xml.SetChildAttrib("interval",iInterval);
- //xml.SetChildAttrib("",);
- }
- xml.OutOfElem();
- xml.Save(szRunTimeDepotPath);
- }
- /************************************************************************/
- /*
- 函数:查找运行时设备库中的元素;
- 参数:
- iPort: 串口号;
- iAddr: 地址;
- 测试结果:未;
- */
- /************************************************************************/
- STRunDevice* CObjectdepot::LookupSubElement(const int &iPort, const int &iAddr)
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"运行时设备库不存在~"));
- return FALSE;
- }
- int nRet = -1;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- STRunDevice *tRunDevice = new STRunDevice; // 容器指针;
- //ZeroMemory(tRunDevice,sizeof(STRunDevice));
- // 遍历所有元素;
- while( xml.FindElem("run_object") )
- {
- CString strPort = xml.GetAttrib("port");
- int _port = atoi(strPort.GetBuffer());
- strPort.ReleaseBuffer();
- if ( _port != iPort )
- continue;
- nRet = 0;
- while( xml.FindChildElem("commands") )
- {
- char szAddr[10] = {0};
- itoa(iAddr, szAddr, 10);
- if( strcmp(xml.GetChildAttrib("addr"), szAddr) == 0)
- {
- // 查找到设备,进行赋值;
- tRunDevice->iPort = iPort;
- tRunDevice->iAddr = iAddr;
- strcpy(tRunDevice->szUName,xml.GetChildAttrib("name"));
- //tRunDevice->szSID //暂时未考虑处理;
- xml.IntoElem();
- STRunCommand tRunCommand = {0};
- while( xml.FindChildElem("command") )
- {
- //ZeroMemory(&tRunCommand,sizeof(STRunCommand));
- //tRunCommand.szMark = xml.GetAttrib("send_read");//tRunDevice->vt_rundevice
- strcpy(tRunCommand.szSCMD, xml.GetChildAttrib("send_read"));
- strcpy(tRunCommand.szTip, xml.GetChildAttrib("Mark"));
- strcpy(tRunCommand.szMark, xml.GetChildAttrib("label"));
- tRunDevice->vt_rundevice.push_back(tRunCommand);
- }
- xml.OutOfElem();
- break;
- }
- }
- xml.OutOfElem();
- return tRunDevice;
- }
-
- return NULL;
- }
- /************************************************************************/
- /*
- 函数:获取运行时设备库指定串口的物理特性;
- 参数:
- iPort: 串口号;
- 测试结果:OK;
- */
- /************************************************************************/
- STRunPhysical CObjectdepot::LookupSubPhysical(const int &iPort)
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"LookupSubPhysical::运行时设备库不存在~"));
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- STRunPhysical tRunPhysical = {0};
- // 遍历所有元素;
- while( xml.FindElem("run_object") )
- {
- CString strPort = xml.GetAttrib("port");
- int _port = atoi(strPort.GetBuffer());
- strPort.ReleaseBuffer();
- if ( _port != iPort )
- continue;
- if( xml.FindChildElem("physical") )
- {
- tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
- tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
- tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
- tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
- tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
- tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
- strcpy(tRunPhysical.szLineType, xml.GetChildAttrib("LineType"));
- strcpy(tRunPhysical.szComType , xml.GetChildAttrib("comType"));
- strcpy(tRunPhysical.szPinDef , xml.GetChildAttrib("pinDefi"));
- }
- break;
- }
- xml.OutOfElem();
- return tRunPhysical;
- }
- #endif
- /************************************************************************/
- /*
- 函数:获取运行时设备库指定串口的元素命令集;
- 参数:
- iPort: 串口号;
- iAddr: 地址,当 =-1时,表示获取串口所有设备命令集;
- tRunComInfo: 命令集;
- 测试结果:OK;
- */
- /************************************************************************/
- void CObjectdepot::GetSendCommand(const int &iPort, const int &iAddr, STRunComInfo &tRunComInfo)
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"运行时设备库不存在"));
- return;
- }
- BOOL bRet = FALSE;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- // 遍历运行时设备库;
- while( xml.FindElem("run_object") )
- {
- // 找到串口,设备属性;
- if( iPort != atoi(xml.GetAttrib("port")) )
- continue;
- tRunComInfo.iPort = iPort;
- xml.FindChildElem("physical");
- tRunComInfo.tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
- tRunComInfo.tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
- tRunComInfo.tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
- tRunComInfo.tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
- tRunComInfo.tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
- tRunComInfo.tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
- BOOL bRunOne = FALSE;// 是否只运行一个设备;而不是串口下的所有设备;
-
- // 遍历串口所有设备;
- while( xml.FindChildElem("commands") )
- {
- STSendCommand tSendCommInfo = {0};
- tSendCommInfo.iAddr = atoi(xml.GetChildAttrib("addr"));
- if ( iAddr != -1 )
- {
- if ( tSendCommInfo.iAddr == iAddr )
- bRunOne = TRUE;
- else
- continue;
- }
- strcpy(tSendCommInfo.szCheck, xml.GetChildAttrib("check"));
- xml.IntoElem();
- while( xml.FindChildElem("command") )
- {
- CString strCmd = xml.GetChildAttrib("send_read");
- tSendCommInfo.bRecv = atoi(xml.GetChildAttrib("Recv"));
- strcpy(tSendCommInfo.szMark, xml.GetChildAttrib("Mark"));
- int iLen = strCmd.GetLength();
- int iRLen = 0;
- char szBCmd[500] = {0};
- char szECmd[500] = {0};
- memcpy(szBCmd, strCmd.GetBuffer(),iLen);
- // 将表示16进制ASCII的字符转化成16进制;
- for ( int i = 0, j = 0; i < iLen; i = i+3, j++ )
- {
- szECmd[j] = CCharacterProcess::ASCII_to_Byte(szBCmd[i])*16 + CCharacterProcess::ASCII_to_Byte(szBCmd[i+1]);
- iRLen = j;
- }
- tSendCommInfo.dwSID++;
- tSendCommInfo.iSLen = iRLen+1;
- memcpy(tSendCommInfo.bySend,szECmd,iRLen+1);
- tRunComInfo.vtSendCommand.push_back(tSendCommInfo);
- }
- xml.OutOfElem();
- if ( bRunOne )
- break;
- }
- }
- xml.OutOfElem();
- }
- /************************************************************************/
- /*
- 函数:获取运行时设备库所有串口的所有设备的命令集;
- 参数:
- vtRunComInfo: 命令集;
- 测试结果:OK;
- */
- /************************************************************************/
- void CObjectdepot::GetAllSendCommand(vector<STRunComInfo> &vtRunComInfo)
- {
- CMarkup xml;
- if ( !xml.Load(szRunTimeDepotPath) )
- {
- LOG4C((LOG_NOTICE,"运行时设备库不存在"));
- return;
- }
- BOOL bRet = FALSE;
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- STRunComInfo tRunComInfo = {0};
- // 遍历运行时设备库;
- while( xml.FindElem("run_object") )
- {
- // 找到串口,设备属性;
- tRunComInfo.iPort = atoi(xml.GetAttrib("port"));
- xml.FindChildElem("physical");
- tRunComInfo.tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
- tRunComInfo.tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
- tRunComInfo.tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
- tRunComInfo.tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
- tRunComInfo.tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
- tRunComInfo.tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
- STSendCommand tSendCommInfo;
- // 遍历串口所有设备;
- while( xml.FindChildElem("commands") )
- {
- //ZeroMemory(&tSendCommInfo,sizeof(STSendCommand));
- //tSendCommInfo.iAddr = atoi(xml.GetChildAttrib("addr"));
- int iAddr = atoi(xml.GetChildAttrib("addr"));
- strcpy(tSendCommInfo.szCheck, xml.GetChildAttrib("check"));
- xml.IntoElem();
- while( xml.FindChildElem("command") )
- {
- tSendCommInfo.iPort = tRunComInfo.iPort; // 1.串口;
- tSendCommInfo.iAddr = iAddr; // 2.地址;
- CString strCmd = xml.GetChildAttrib("send_read");
- tSendCommInfo.bRecv = atoi(xml.GetChildAttrib("Recv")); // 5.是否保存返回;
- strcpy(tSendCommInfo.szMark, xml.GetChildAttrib("Mark")); // 6.命令特征码;
- int iLen = strCmd.GetLength(),iRLen = 0;
- char szBCmd[500] = {0},szECmd[500] = {0};
- memcpy(szBCmd, strCmd.GetBuffer(),iLen);
- // 将表示16进制ASCII的字符转化成16进制;
- for ( int i = 0, j = 0; i < iLen; i = i+3, j++ )
- {
- szECmd[j] = CCharacterProcess::ASCII_to_Byte(szBCmd[i])*16 + CCharacterProcess::ASCII_to_Byte(szBCmd[i+1]);
- iRLen = j;
- }
- tSendCommInfo.dwSID++; // 3.ID号;
- tSendCommInfo.iSLen = iRLen+1; // 4.命令长度;
- memcpy(tSendCommInfo.bySend,szECmd,iRLen+1);
- tRunComInfo.vtSendCommand.push_back(tSendCommInfo);
- }
- xml.OutOfElem();
- }
- vtRunComInfo.push_back(tRunComInfo);
- //ZeroMemory(&tRunComInfo,sizeof(STRunComInfo));
- }
- xml.OutOfElem();
- }
- #if EDITOR_INSERT
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementNode(const char *szDeviceName,const char *szID, const STDepotPhysical &tDepotPhysical, const STDeviceDocument &tDeviceDocument)
- {
- if ( IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- xml.FindElem("object_depot") ;
- // 1.添加depot元素;
- xml.AddElem("object_depot");
- xml.AddAttrib("name", szDeviceName); // 设备名称;
- xml.AddAttrib("static_id", szID); // 设备静态ID;
- // 2.添加depot子元素 ****物理特性;
- xml.AddChildElem("physical");
- xml.AddChildAttrib("rate",tDepotPhysical.iRate); // 1.波特率;
- xml.AddChildAttrib("dataBit", tDepotPhysical.iDBit); // 2.数据位;
- xml.AddChildAttrib("stopBit", tDepotPhysical.iSBit); // 3.停止位;
- xml.AddChildAttrib("parity", tDepotPhysical.iPaty); // 4.校验位;
- xml.AddChildAttrib("iResTime", tDepotPhysical.iRsTm); // 4.校验位;
- xml.AddChildAttrib("interval", tDepotPhysical.iIntl); // 5.超时值;
- xml.AddChildAttrib("LineType", tDepotPhysical.szLineType); // 6.针脚类型;
- xml.AddChildAttrib("comType", tDepotPhysical.szComType); // 7.串口类型;
- xml.AddChildAttrib("pinDefi", tDepotPhysical.szPinDef); // 8.针脚定义;
- // 3.添加depot子元素 ****文档说明 ;
- xml.AddChildElem("document");
- xml.AddChildAttrib("Factory", tDeviceDocument.szFactory);
- xml.AddChildAttrib("deviceType", tDeviceDocument.szdeviceType);
- xml.AddChildAttrib("class", tDeviceDocument.szdeviceClass);
- xml.AddChildAttrib("deviceName", tDeviceDocument.szdeviceName);
- xml.AddChildAttrib("unitType", tDeviceDocument.szUnitType);
- xml.AddChildAttrib("protocol", tDeviceDocument.szProtocol);
- // 4.添加 depot子元素 命令格式;
- xml.AddChildElem("command_format");
- // 5.添加 depot子元素 命令元;
- xml.AddChildElem("command");
- #if 0
- xml.IntoElem();
- // 获取命令格式大小;
- vector <STCommandFormat>::const_iterator it_commandformat;
- for ( it_commandformat = STOElement.vt_commandformat.begin(); it_commandformat != STOElement.vt_commandformat.end(); it_commandformat++)
- {
- STCommandFormat tag = *it_commandformat;
- xml.AddChildElem("format");
- xml.AddChildAttrib("name", tag.szName);
- xml.AddChildAttrib("len", tag.szLen);
- xml.AddChildAttrib("data", tag.szData);
- xml.AddChildAttrib("type", tag.szType);
- }
- xml.OutOfElem();
- // 5.添加 depot子元素 命令元;
- xml.AddChildElem("command");
- xml.IntoElem();
- // vector <EleCmd>::iterator it_elcd; 会造成:error C2679: 二进制“=” : 没有找到接受“<未知>”类型的右操作数的运算符(或没有可接受的转换)
- // 出现错误的原因:是因为dp是const引用的,所以在it_elcd = dp.vt_msg.begin();时出错;
- // 因为dp是const引用,所在dp里的所有变量都不能改变;
- vector <STCommandTable>::const_iterator cit_commandtable;
- for ( cit_commandtable = STOElement.vt_commandtable.begin(); cit_commandtable != STOElement.vt_commandtable.end(); cit_commandtable++)
- {
- STCommandTable commandtable = *cit_commandtable;
- xml.AddChildElem("cmd");
- xml.AddChildAttrib("Recv",commandtable.bRecv);
- xml.AddChildAttrib("it_tip", commandtable.szTip);
- vector <STCommandStyle>::const_iterator cit_commandstyle;
- for ( cit_commandstyle = commandtable.vt_commandstyle.begin(); cit_commandstyle != commandtable.vt_commandstyle.end(); cit_commandstyle++)
- {
- STCommandStyle commandstyle = *cit_commandstyle;
- xml.IntoElem();
- xml.AddChildElem("element");
- xml.AddChildAttrib("name", commandstyle.szName);
- xml.AddChildAttrib("data", commandstyle.szData);
- xml.OutOfElem();
- }
- }
- xml.OutOfElem();
- #endif
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementPhsycial(const char *szDeviceName,const STDepotPhysical &tDepotPhysical)
- {
- if ( IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
- {
- // 在添加之前,判断物理属性是否存在;
- if ( !xml.FindChildElem("physical") )
- {
- return;
- }
- // 2.添加depot子元素 ****物理特性;
- xml.AddChildElem("physical");
- xml.AddChildAttrib("rate",tDepotPhysical.iRate); // 1.波特率;
- xml.AddChildAttrib("dataBit", tDepotPhysical.iDBit); // 2.数据位;
- xml.AddChildAttrib("stopBit", tDepotPhysical.iSBit); // 3.停止位;
- xml.AddChildAttrib("parity", tDepotPhysical.iPaty); // 4.校验位;
- xml.AddChildAttrib("iResTime", tDepotPhysical.iRsTm); // 4.校验位;
- xml.AddChildAttrib("interval", tDepotPhysical.iIntl); // 5.超时值;
- xml.AddChildAttrib("LineType", tDepotPhysical.szLineType); // 6.针脚类型;
- xml.AddChildAttrib("comType", tDepotPhysical.szComType); // 7.串口类型;
- xml.AddChildAttrib("pinDefi", tDepotPhysical.szPinDef); // 8.针脚定义;
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementDocument(const char *szDeviceName,const STDeviceDocument &tDeviceDocument)
- {
- if ( IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
- {
- // 在添加之前,判断文档属性是否存在;
- if ( !xml.FindChildElem("document") )
- {
- return;
- }
- xml.AddChildElem("document");
- xml.AddChildAttrib("Factory", tDeviceDocument.szFactory);
- xml.AddChildAttrib("deviceType", tDeviceDocument.szdeviceType);
- xml.AddChildAttrib("class", tDeviceDocument.szdeviceClass);
- xml.AddChildAttrib("deviceName", tDeviceDocument.szdeviceName);
- xml.AddChildAttrib("unitType", tDeviceDocument.szUnitType);
- xml.AddChildAttrib("protocol", tDeviceDocument.szProtocol);
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementCmdStyle(
- const char *szDeviceName,
- const char *szKey,
- const char *szLen,
- const char *szContx,
- const char *szType,
- const int &nCount /* = -1 */)
- {
- if ( !IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command_format") )
- {
- if( nCount != -1)
- xml.SetChildAttrib("ByteCount",nCount);
- xml.IntoElem();
- xml.AddChildElem("format");
- xml.AddChildAttrib("name",szKey);
- xml.AddChildAttrib("len",szLen);
- xml.AddChildAttrib("data",szContx);
- xml.AddChildAttrib("type",szType);
- xml.OutOfElem();
- }
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementCommandImpl(const char *szDeviceName,const char *szMark,const char* szStore, const char* szTip)
- {
- if ( !IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command") )
- {
- // 判断Mark是否存在,存在退出;
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szMark,xml.GetChildAttrib("Mark")) == 0 )
- {
- xml.OutOfElem();
- return;
- }
- }
- xml.OutOfElem();
-
- // 添加;
- xml.IntoElem();
- xml.AddChildElem("cmd");
- xml.AddChildAttrib("Recv",szStore);
- xml.AddChildAttrib("Mark",szMark);
- xml.AddChildAttrib("it_tip",szTip);
- xml.OutOfElem();
- }
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::InsertElementCommandImplItem(const char *szDeviceName,const char *szMark, const char *szKey,const char *szContx)
- {
- if ( !IsElementExist(szDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if( xml.FindChildElem("command") )
- {
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szMark,xml.GetChildAttrib("Mark")) == 0 )
- {
- // 判断key是否存在;
- xml.IntoElem();
- while( xml.FindChildElem("element") )
- {
- if ( strcmp(szKey,xml.GetChildAttrib("name")) == 0 )
- {
- xml.OutOfElem();
- xml.OutOfElem();
- xml.OutOfElem();
- return;
- }
- }
-
- xml.AddChildElem("element");
- xml.AddChildAttrib("name",szKey);
- xml.AddChildAttrib("data",szContx);
- xml.OutOfElem();
- break;
- }
- }
- }
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- #endif
- #if EDITOR_MODIFY
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementNode(
- const char *szOldDeviceName,
- const char *szNewDeviceName,
- const char *szNewID,
- const STDepotPhysical &tDepotPhysical,
- const STDeviceDocument &tDeviceDocument)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- xml.SetAttrib("name",szNewDeviceName);
- xml.SetAttrib("static_id",szNewID);
- if ( xml.FindChildElem("physical") )
- {
- xml.SetChildAttrib("rate",tDepotPhysical.iRate);
- xml.SetChildAttrib("dataBit",tDepotPhysical.iDBit);
- xml.SetChildAttrib("stopBit",tDepotPhysical.iSBit);
- xml.SetChildAttrib("parity",tDepotPhysical.iPaty);
- xml.SetChildAttrib("iResTime",tDepotPhysical.iRsTm);
- xml.SetChildAttrib("interval",tDepotPhysical.iIntl);
- xml.SetChildAttrib("LineType",tDepotPhysical.szLineType);
- xml.SetChildAttrib("comType",tDepotPhysical.szComType);
- xml.SetChildAttrib("pinDefi",tDepotPhysical.szPinDef);
- }
- if ( xml.FindChildElem("document") )
- {
- xml.SetChildAttrib("Factory",tDeviceDocument.szFactory);
- xml.SetChildAttrib("deviceType",tDeviceDocument.szdeviceType);
- xml.SetChildAttrib("class",tDeviceDocument.szdeviceClass);
- xml.SetChildAttrib("deviceName",tDeviceDocument.szdeviceName);
- xml.SetChildAttrib("unitType",tDeviceDocument.szUnitType);
- xml.SetChildAttrib("protocol",tDeviceDocument.szProtocol);
- }
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementPhsycial(const char *szOldDeviceName,const char* szNewDeviceName,const STDepotPhysical &tDepotPhysical)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementDocument(const char *szOldDeviceName,const char* szNewDeviceName,const STDeviceDocument &tDeviceDocument)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:修改子元素指令格式;
- 参数:
- szDeviceName:设备名称,这个不会变;
- szKey:关键名;同样不能变;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementCommandStyle(
- const char *szOldDeviceName,
- const char *szOldKey,
- const char *szNewKey,
- const char *szLen,
- const char *szContx,
- const char *szType,
- const int &nCount)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command_format") )
- {
- if ( nCount != -1)
- xml.SetChildAttrib("ByteCount",nCount);
-
- BOOL bRet = FALSE;
- xml.IntoElem();
- while( xml.FindChildElem("format") )
- {
- if ( strcmp(szOldKey, xml.GetChildAttrib("name")) == 0 )
- {
- xml.SetChildAttrib("name",szNewKey);
- xml.SetChildAttrib("len",szLen);
- xml.SetChildAttrib("data",szContx);
- xml.SetChildAttrib("type",szType);
- bRet = TRUE;
- break;
- }
- }
- xml.OutOfElem();
- if ( bRet )
- break;
- }
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementCmdImpl(
- const char *szOldDeviceName,
- const char *szOldMark,
- const char *szNewMark,
- const char szStore,
- const char* szTip,
- const char *szOldKey,
- const char *szNewKey,
- const char *szContx)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command") )
- {
- BOOL bRet = FALSE;
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szOldMark, xml.GetChildAttrib("Mark")) == 0 )
- {
- xml.SetChildAttrib("Mark",szNewMark);
- xml.SetChildAttrib("Recv",szStore);
- xml.SetChildAttrib("it_tip",szTip);
- xml.IntoElem();
- while( xml.FindChildElem("element") )
- {
- if ( strcmp(szOldKey, xml.GetChildAttrib("name")) == 0 )
- {
- xml.SetChildAttrib("name",szNewKey);
- xml.SetChildAttrib("data",szContx);
- break;
- }
- }
- xml.OutOfElem();
- bRet = TRUE;
- break;
- }
- }
- xml.OutOfElem();
- if ( bRet )
- break;
- }
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementCommand(
- const char *szOldDeviceName,
- const char *szOldMark,
- const char *szNewMark,
- const char szStore,
- const char* szTip)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command") )
- {
- BOOL bRet = FALSE;
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szOldMark, xml.GetChildAttrib("Mark")) == 0 )
- {
- xml.SetChildAttrib("Mark",szNewMark);
- xml.SetChildAttrib("Recv",szStore);
- xml.SetChildAttrib("it_tip",szTip);
- bRet = TRUE;
- break;
- }
- }
- xml.OutOfElem();
- if ( bRet )
- break;
- }
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::ModifyElementCommandImplItem(
- const char *szOldDeviceName,
- const char *szOldKey,
- const char *szNewKey,
- const char *szContx)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备已存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- break;
- }
- }
- xml.OutOfElem();
- xml.Save(szDepotPath);
- }
- #endif
- #if EDITOR_DELETE
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::DeleteElementCommandStyle(const char *szOldDeviceName, const char *szOldKey)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command_format") )
- {
- xml.IntoElem();
- while( xml.FindChildElem("format") )
- {
- if ( strcmp(szOldKey,xml.GetChildAttrib("name")) == 0 )
- {
- xml.RemoveChildElem();
- xml.OutOfElem();
- xml.Save(szDepotPath);
- return;
- }
- }
- xml.OutOfElem();
- }
- break;
- }
- }
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::DeleteElementCmdImpl(const char *szOldDeviceName, const char *szOldMark)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command") )
- {
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szOldMark,xml.GetChildAttrib("Mark")) == 0 )
- {
- xml.RemoveChildElem();
- xml.OutOfElem();
- xml.Save(szDepotPath);
- return;
- }
- }
- xml.OutOfElem();
- }
- break;
- }
- }
- }
- /************************************************************************/
- /*
- 函数:;
- 参数:
- 测试结果:未测试;
- */
- /************************************************************************/
- void CObjectdepot::DeleteElementCommandImplItem(const char *szOldDeviceName, const char *szOldMark, const char *szOldKey)
- {
- if ( !IsElementExist(szOldDeviceName) )
- {
- LOG4C((LOG_NOTICE,"设备不存在"));
- return;
- }
- CMarkup xml;
- if ( !xml.Load(szDepotPath) )
- {
- LOG4C((LOG_NOTICE,"设备库不存在~"));
- return;
- }
- xml.FindElem(); // ORDER element is root
- xml.IntoElem(); // inside ORDER
- while( xml.FindElem("object_depot"))
- {
- if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
- {
- if ( xml.FindChildElem("command") )
- {
- xml.IntoElem();
- while( xml.FindChildElem("cmd") )
- {
- if ( strcmp(szOldMark,xml.GetChildAttrib("Mark")) == 0 )
- {
- xml.IntoElem();
- while( xml.FindChildElem("element") )
- {
- if ( strcmp(szOldKey,xml.GetChildAttrib("name")) == 0 )
- {
- xml.RemoveChildElem();
- xml.OutOfElem();
- xml.Save(szDepotPath);
- return;
- }
- }
- xml.OutOfElem();
- }
- }
- xml.OutOfElem();
- }
- break;
- }
- }
- }
- #endif
|