Objectdepot.cpp 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465
  1. #include "StdAfx.h"
  2. //#include "Global.h"
  3. #include "RunTimeDepot.h"
  4. #include "CharacterProcess.h"
  5. #include "CheckProcess.h"
  6. #include ".\objectdepot.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. HANDLE g_hProc = NULL;
  11. HANDLE g_hCtrl = NULL;
  12. /************************************************************************/
  13. /*
  14. 全局函数:获取长度;
  15. */
  16. /************************************************************************/
  17. int GetLength(const int &nIdx)
  18. {
  19. if ( nIdx == 1)
  20. return 2;
  21. int nSum = 2;
  22. for(int i = 1; i < nIdx; i++)
  23. nSum += 3;
  24. return nSum;
  25. }
  26. CObjectdepot::CObjectdepot(void)
  27. {
  28. //GenerationDepotModel();
  29. //GenerationRunModel();
  30. }
  31. CObjectdepot::~CObjectdepot(void)
  32. {
  33. if ( g_hProc )
  34. {
  35. CloseHandle(g_hProc);
  36. g_hProc = NULL;
  37. }
  38. }
  39. void CObjectdepot::InitThread()
  40. {
  41. g_hCtrl = CreateEvent(NULL, TRUE ,TRUE ,NULL);
  42. if ( g_hCtrl == NULL )
  43. return ;
  44. g_hProc = CreateThread(NULL,0,DataDealThreadProcess,this,0,NULL);
  45. if ( g_hProc == NULL )
  46. return;
  47. }
  48. // 所有变量的取值线程;
  49. DWORD CObjectdepot::DataDealThreadProcess(PVOID pParam)
  50. {
  51. do
  52. {
  53. // 以下是假过程,思路原型;
  54. // 1.遍历所有设备;
  55. // int iCount = g_ArrayDevice.Size();
  56. // for (int i = 0; i < iCount ; i++)
  57. // {
  58. // STDevice device = g_ArrayDevice[i];
  59. // // 2.遍历该设备所有变量;
  60. // int VarSize = device.VarSize();
  61. // for ( int n = 0; n < VarSize; n++)
  62. // {
  63. // STVariant variant = device.Variant[i];
  64. // // 3.获取设备信息,与g_vtRecv对比;
  65. // vector <STRecvMessage>::iterator it_recvmessage;
  66. // for ( it_recvmessage = g_vtRecv.begin(); it_recvmessage != g_vtRecv.end(); it_recvmessage++)
  67. // {
  68. // STRecvMessage recvmessage = *it_recvmessage;
  69. // if(device.iPort == recvmessage.iPort && device.iAddr == recvmessage.iAddr)
  70. // {
  71. // // 4.获取变量的Mark特征码;
  72. // if( strcmp(variant.szMark, recvmessag.szMark) == 0)
  73. // {
  74. // // 5.获取最终变量值;
  75. // GetVariantValue(variant, recvmessage.byRecv);
  76. // // GetVarinatValue函数原型:
  77. // // void GetVariantValue(STVariant &var, const BYTE *&pRecv);
  78. // }
  79. // }
  80. // }
  81. // }
  82. // }
  83. } while (WaitForSingleObject(g_hCtrl, 10) != WAIT_OBJECT_0);
  84. return 0;
  85. }
  86. void CObjectdepot::GenerationDepotModel()
  87. {
  88. CMarkup xml;
  89. if ( !xml.Load(szDepotPath) )
  90. {
  91. xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
  92. // 添加根元素;
  93. xml.AddElem("depotobject");
  94. xml.AddAttrib("object_count",0);
  95. xml.AddChildElem("static_code");
  96. xml.AddChildAttrib("ele_count",0);
  97. xml.IntoElem();
  98. xml.AddChildElem("connection_standard");
  99. xml.IntoElem();
  100. xml.AddChildElem("standard","RS232");
  101. xml.AddChildElem("standard","RS485");
  102. xml.AddChildElem("standard","RJ45");
  103. xml.OutOfElem();
  104. xml.AddChildElem("protocol_type");
  105. xml.IntoElem();
  106. xml.AddChildElem("type","RS232电总");
  107. xml.AddChildElem("type","RS485电总");
  108. xml.AddChildElem("type","ModbusRtu");
  109. xml.AddChildElem("type","ModbusAsicc");
  110. xml.AddChildElem("type","SNMP");
  111. xml.OutOfElem();
  112. xml.OutOfElem();
  113. xml.Save(szDepotPath);
  114. }
  115. }
  116. void CObjectdepot::GenerationRunModel()
  117. {
  118. CMarkup xml;
  119. if ( !xml.Load(szRunTimeDepotPath) )
  120. {
  121. xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
  122. // 添加根元素;
  123. xml.AddElem("Current_Object_Run");
  124. xml.Save(szRunTimeDepotPath);
  125. }
  126. }
  127. #if SETDEPOT_PATH
  128. void CObjectdepot::SetDevicesDepotPath(char *szPath)
  129. {
  130. memset(szDepotPath,0,MAX_PATH);
  131. memcpy(szDepotPath,szPath,strlen(szPath));
  132. }
  133. void CObjectdepot::SetRuntimeDevicesDepotPath(char *szPath)
  134. {
  135. memset(szRunTimeDepotPath,0,MAX_PATH);
  136. memcpy(szRunTimeDepotPath,szPath,strlen(szPath));
  137. }
  138. void CObjectdepot::SetDevicesDepotPath(CString strPath)
  139. {
  140. memset(szDepotPath,0,MAX_PATH);
  141. strcpy(szDepotPath,strPath);
  142. }
  143. void CObjectdepot::SetRuntimeDevicesDepotPath(CString strPath)
  144. {
  145. memset(szRunTimeDepotPath,0,MAX_PATH);
  146. strcpy(szRunTimeDepotPath,strPath);
  147. }
  148. #endif
  149. #if DEVICES_DEPOT
  150. /************************************************************************/
  151. /*
  152. 函数:根据函数参数,从设备库获取参数创建运行时设备库元素;
  153. 参数:
  154. iComPort: 串口;
  155. iAddr: 地址;
  156. szName: 设备名称;
  157. 测试结果:OK;
  158. */
  159. /************************************************************************/
  160. STRunObject* CObjectdepot::CreateRunObject(const int &iComPort, const int &iAddr,const char *szName)
  161. {
  162. STDepotObject *depotobject = LookupElement(szName);
  163. if ( depotobject == NULL)
  164. return NULL;
  165. STRunObject *runobject = new STRunObject ; // 容器指针;
  166. runobject->iPort = iComPort;
  167. //memcpy(runobject->st_rundevice.szUName,szName,strlen(szName));
  168. strcpy(runobject->st_rundevice.szUName,szName);
  169. runobject->st_rundevice.iAddr = iAddr;
  170. //memcpy(runobject->st_rundevice.szSID,depotobject->szSID, strlen(depotobject->szSID));
  171. strcpy(runobject->st_rundevice.szSID,depotobject->szSID);
  172. //memcpy(&(runobject->st_runphy), &(depotobject->st_depotphy), sizeof(depotobject->st_depotphy));
  173. runobject->st_runphy.iDBit = depotobject->st_depotphy.iDBit;
  174. runobject->st_runphy.iIntl = depotobject->st_depotphy.iIntl;
  175. runobject->st_runphy.iPaty = depotobject->st_depotphy.iPaty;
  176. runobject->st_runphy.iRate = depotobject->st_depotphy.iRate;
  177. runobject->st_runphy.iRsTm = depotobject->st_depotphy.iRsTm;
  178. runobject->st_runphy.iSBit = depotobject->st_depotphy.iSBit;
  179. strcpy(runobject->st_runphy.szComType,depotobject->st_depotphy.szComType);
  180. strcpy(runobject->st_runphy.szLineType,depotobject->st_depotphy.szLineType);
  181. strcpy(runobject->st_runphy.szPinDef,depotobject->st_depotphy.szPinDef);
  182. strcpy(runobject->st_rundevice.szCheck,"None");
  183. if ( depotobject->vt_commandformat.size() == 0)
  184. {
  185. return NULL;
  186. }
  187. // 不做命令的选择,全部命令都用上,只在变量里做取舍;
  188. // 命令的组合,需要在外部做一个类进行处理归类;
  189. vector <STCommandTable>::iterator it_commandtable;
  190. for ( it_commandtable = depotobject->vt_commandtable.begin(); it_commandtable != depotobject->vt_commandtable.end(); it_commandtable++)
  191. {
  192. STRunCommand RunCommand = {0};
  193. STCommandTable commandtable = *it_commandtable;
  194. // ?如何实现长度动态计算szSend;
  195. // 如果无法实现,则在创建设备库时,事先计算好长度,再填入便行,不必拘于此处的计算;
  196. int nIndex = 0;
  197. BYTE *szSend = new BYTE[depotobject->ByteCount*3 ];
  198. ZeroMemory(szSend,depotobject->ByteCount*3 );
  199. memset(szSend, 32, depotobject->ByteCount*3-1 );// 空格填充;
  200. vector <STCommandFormat>::iterator it_commandformat;
  201. for ( it_commandformat = depotobject->vt_commandformat.begin(); it_commandformat != depotobject->vt_commandformat.end(); it_commandformat++)
  202. {
  203. STCommandFormat commandformat = *it_commandformat;
  204. if ( strcmp(commandformat.szName,"addr") == 0 )
  205. {
  206. CString strHex = "";
  207. if ( strcmp(commandformat.szLen,"2") == 0)
  208. {
  209. char szHex[3] = {0};
  210. szHex[0] = CCharacterProcess::Byte_to_ASCII((iAddr >> 4) & 0x0F);
  211. szHex[1] = CCharacterProcess::Byte_to_ASCII( iAddr & 0x0F);
  212. strHex.Format("%02X",szHex[0]);
  213. memcpy(szSend+nIndex,strHex, 2);
  214. strHex.Format("%02X",szHex[1]);
  215. memcpy(szSend+nIndex + 3,strHex,2);
  216. }
  217. else if ( strcmp(commandformat.szLen,"1") == 0)
  218. {
  219. if ( strcmp(commandformat.szData,"?") == 0)
  220. {
  221. strHex.Format("%02X",iAddr);
  222. memcpy(szSend+nIndex,strHex, 2);
  223. }
  224. if ( commandformat.szData[0] == '+' )
  225. {
  226. strHex.Format("%02X", iAddr + atoi(commandformat.szData+1));
  227. memcpy(szSend+nIndex,strHex, 2);
  228. }
  229. if ( commandformat.szData[0] == '#') // 出现'#',表示复杂运算;
  230. {
  231. CString strData;
  232. strData.Format("%s",commandformat.szData);
  233. int nIdex1 =-1,nIdex2 =-1,nIdex3=-1;
  234. nIdex1 = strData.FindOneOf("(");
  235. nIdex2 = strData.FindOneOf(")");
  236. nIdex3 = strData.FindOneOf("^");
  237. int naddr = 0;
  238. if ( strData.GetAt(2) == '-' )
  239. {
  240. CString str;
  241. str = strData.Left(nIdex2);
  242. str = str.Mid(3,nIdex2);
  243. naddr = iAddr - atoi(str.GetBuffer());
  244. str.ReleaseBuffer();
  245. if ( nIdex3 != -1)
  246. {
  247. str = "";
  248. str = strData.Mid(nIdex3+1);
  249. naddr ^= atoi(str.GetBuffer());
  250. str.ReleaseBuffer();
  251. }
  252. }else if ( strData.GetAt(2) == '+' )
  253. {
  254. }else if ( strData.GetAt(2) == '*' )
  255. {
  256. }else if ( strData.GetAt(2) == '/' )
  257. {
  258. }
  259. strHex.Format("%02X", naddr);
  260. memcpy(szSend+nIndex,strHex, 2);
  261. }
  262. }
  263. nIndex += atoi(commandformat.szLen)*3;
  264. continue;
  265. }
  266. // 各协议计算真实检验码,这里应该由一个类处理,接口固定下来;
  267. // 接口原型之一,获取检验码:I_GetCheck(char *&pData, const char *&pCode);
  268. if ( strcmp(commandformat.szName, "check") == 0)
  269. {
  270. strcpy(runobject->st_rundevice.szCheck,commandformat.szData);
  271. if ( strcmp(commandformat.szData,"EMERSON") == 0)
  272. {
  273. CCheckProcess::GetXmlCheck_Emerson((char*)szSend, commandformat.szData,nIndex);
  274. }
  275. if (strcmp(commandformat.szData,"RTUCRC") == 0 )
  276. {
  277. CCheckProcess::GetXmlCheck_Rtu((char*)szSend, commandformat.szData, nIndex);
  278. }
  279. if ( strcmp(commandformat.szData,"fad") == 0 )
  280. {
  281. CCheckProcess::GetXmlCheck_fad((char*)szSend, commandformat.szData, nIndex);
  282. }
  283. if ( strcmp(commandformat.szData,"newave") == 0 )
  284. {
  285. CCheckProcess::GetXmlCheck_newave((char*)szSend, commandformat.szData, nIndex);
  286. }
  287. if ( strcmp(commandformat.szData,"stulz6000") == 0 )
  288. {
  289. CCheckProcess::GetXmlCheck_stulz6000((char*)szSend, commandformat.szData, nIndex);
  290. }
  291. if ( strcmp(commandformat.szData,"cm+") == 0 )
  292. {
  293. CCheckProcess::GetXmlCheck_CM((char*)szSend, commandformat.szData, nIndex);
  294. }
  295. int ilen = strlen(commandformat.szData);
  296. memcpy(szSend+nIndex, commandformat.szData, ilen);
  297. nIndex += ilen+1;
  298. continue;;
  299. }
  300. int iCode = atoi(commandformat.szType);
  301. switch(iCode)
  302. {
  303. case 1:
  304. {
  305. int ilen = atoi(commandformat.szLen);
  306. if ( ilen == 1)
  307. memcpy(szSend+nIndex, commandformat.szData, atoi(commandformat.szLen)*2);
  308. if ( ilen != 1)
  309. {
  310. ilen = GetLength(ilen);
  311. memcpy(szSend+nIndex, commandformat.szData, ilen);
  312. }
  313. }
  314. break;
  315. case 2: // 如何跳过format里有的,但是command中没有元素字节?(undo); 以下处理可以跳过;
  316. {
  317. vector <STCommandStyle>::iterator it_commandstyle;
  318. for ( it_commandstyle = commandtable.vt_commandstyle.begin(); it_commandstyle != commandtable.vt_commandstyle.end(); it_commandstyle++)
  319. {
  320. STCommandStyle commandstyle;
  321. commandstyle = *it_commandstyle;
  322. if ( strcmp(commandstyle.szName,commandformat.szName) == 0)
  323. {
  324. CString str;
  325. str.Format("%s",commandstyle.szData);
  326. if ( str.Find("addr") != -1 )
  327. {
  328. str.Format("%02X", iAddr+47);
  329. memcpy(szSend+nIndex,str, 2);
  330. nIndex += 3;
  331. }
  332. else
  333. {
  334. int ilen = strlen(commandstyle.szData);
  335. memcpy(szSend+nIndex, commandstyle.szData, ilen);
  336. nIndex += ilen +1;
  337. }
  338. break;
  339. }
  340. }
  341. }
  342. break;
  343. case 3: // 如何跳过format里有的,但是command中没有元素字节?(undo); 以下处理可以跳过(iCode=2);
  344. {
  345. vector <STCommandStyle>::iterator it_commandstyle;
  346. for ( it_commandstyle = commandtable.vt_commandstyle.begin(); it_commandstyle != commandtable.vt_commandstyle.end(); it_commandstyle++)
  347. {
  348. STCommandStyle commandstyle;
  349. commandstyle = *it_commandstyle;
  350. if ( strcmp(commandstyle.szName,commandformat.szName) == 0)
  351. {
  352. int ilen = strlen(commandstyle.szData);
  353. memcpy(szSend+nIndex, commandstyle.szData, ilen);
  354. break;
  355. }
  356. }
  357. }
  358. break;
  359. default:
  360. break;
  361. }
  362. if ( strcmp(commandformat.szLen,"?") != 0)
  363. {
  364. int nlen = atoi(commandformat.szLen);
  365. nIndex += nlen*3;
  366. }
  367. }
  368. RunCommand.bRecv = commandtable.bRecv;
  369. sprintf(RunCommand.szTip,"%s",commandtable.szTip);
  370. //memcpy(RunCommand.szSCMD, szSend, depotobject.ByteCount*3 -1); // 这里导致了生成的命令串长度过长,包含多余的空格;
  371. // 去除尾部多余的空格;
  372. for( int i = nIndex-1; i > 0; i--)
  373. {
  374. if ( szSend[i] == 32 )
  375. {
  376. nIndex-- ;
  377. continue;
  378. }
  379. else
  380. {
  381. break;
  382. }
  383. }
  384. memcpy(RunCommand.szSCMD, szSend, nIndex);
  385. #if 0
  386. RunCommand.szMark[0] = iComPort + 48;
  387. RunCommand.szMark[1] = iAddr + 48;
  388. memcpy(RunCommand.szMark + 2, commandtable.szMark, strlen(commandtable.szMark));
  389. #else
  390. memcpy(RunCommand.szMark , commandtable.szMark, strlen(commandtable.szMark));
  391. #endif
  392. runobject->st_rundevice.iPort = iComPort;
  393. runobject->st_rundevice.iAddr = iAddr;
  394. // vs2008 Release下pus_back时出错;
  395. // 这是由于runobject处理过ZeroMemory,对容器的大小处理了,大小=0;
  396. // 导致push_back时越界了;
  397. runobject->st_rundevice.vt_rundevice.push_back(RunCommand);
  398. if ( szSend )
  399. {
  400. delete []szSend;
  401. szSend = NULL;
  402. }
  403. }
  404. if ( depotobject )
  405. {
  406. delete depotobject;
  407. depotobject = NULL;
  408. }
  409. return runobject;
  410. }
  411. /************************************************************************/
  412. /*
  413. 函数:判断元素是否存在;
  414. 参数:
  415. szElementName: 元素名称;
  416. EleType: 元素所属类型;
  417. 测试结果:OK;
  418. */
  419. /************************************************************************/
  420. BOOL CObjectdepot::IsElementExist(const char *szElementName, const int &EleType)
  421. {
  422. // 1.加载设备库xml文件;
  423. CMarkup xml;
  424. if ( !xml.Load(szDepotPath) )
  425. {
  426. LOG4C((LOG_NOTICE,"设备库不存在~"));
  427. return FALSE;
  428. }
  429. BOOL bRet = -1;
  430. xml.FindElem(); // ORDER element is root
  431. xml.IntoElem(); // inside ORDER
  432. // 2.遍历设备库xml文件;
  433. while( xml.FindElem("object_depot") )
  434. {
  435. CString strElement = xml.GetAttrib("name");
  436. int nRet = strElement.Compare(szElementName);
  437. if ( nRet == 0 )
  438. {
  439. LOG4C((LOG_NOTICE,"元素已存在"));
  440. return TRUE;
  441. }
  442. }
  443. xml.OutOfElem();
  444. return FALSE;
  445. }
  446. /************************************************************************/
  447. /*
  448. 函数:向设备库插入元素;
  449. 参数:
  450. STOElement: 设备库元素;
  451. EleType: 元素所属类型;
  452. 测试结果:未测试;
  453. */
  454. /************************************************************************/
  455. void CObjectdepot::InsertElement(const STDepotObject &STOElement, const int &EleType )
  456. {
  457. if ( IsElementExist(STOElement.szName) )
  458. {
  459. LOG4C((LOG_NOTICE,"设备已存在"));
  460. return;
  461. }
  462. CMarkup xml;
  463. if ( !xml.Load(szDepotPath) )
  464. {
  465. LOG4C((LOG_NOTICE,"设备库不存在~"));
  466. return;
  467. }
  468. xml.FindElem(); // ORDER element is root
  469. xml.IntoElem(); // inside ORDER
  470. xml.FindElem("object_depot") ;
  471. // 1.添加depot元素;
  472. xml.AddElem("object_depot");
  473. xml.AddAttrib("name", STOElement.szName); // 设备名称;
  474. xml.AddAttrib("static_id", STOElement.szSID); // 设备静态ID;
  475. // 2.添加depot子元素 ****物理特性;
  476. xml.AddChildElem("physical");
  477. xml.AddChildAttrib("rate",STOElement.st_depotphy.iRate); // 1.波特率;
  478. xml.AddChildAttrib("dataBit", STOElement.st_depotphy.iDBit); // 2.数据位;
  479. xml.AddChildAttrib("stopBit", STOElement.st_depotphy.iSBit); // 3.停止位;
  480. xml.AddChildAttrib("parity", STOElement.st_depotphy.iPaty); // 4.校验位;
  481. xml.AddChildAttrib("iResTime", STOElement.st_depotphy.iRsTm); // 4.校验位;
  482. xml.AddChildAttrib("interval", STOElement.st_depotphy.iIntl); // 5.超时值;
  483. xml.AddChildAttrib("LineType", STOElement.st_depotphy.szLineType); // 6.针脚类型;
  484. xml.AddChildAttrib("comType", STOElement.st_depotphy.szComType); // 7.串口类型;
  485. xml.AddChildAttrib("pinDefi", STOElement.st_depotphy.szPinDef); // 8.针脚定义;
  486. // 3.添加depot子元素 ****文档说明 ;
  487. xml.AddChildElem("document");
  488. xml.AddChildAttrib("Factory", STOElement.st_depotdoc.szFactory);
  489. xml.AddChildAttrib("deviceType", STOElement.st_depotdoc.szdeviceType);
  490. xml.AddChildAttrib("class", STOElement.st_depotdoc.szdeviceClass);
  491. xml.AddChildAttrib("deviceName", STOElement.st_depotdoc.szdeviceName);
  492. xml.AddChildAttrib("unitType", STOElement.st_depotdoc.szUnitType);
  493. xml.AddChildAttrib("protocol", STOElement.st_depotdoc.szProtocol);
  494. // 4.添加 depot子元素 命令格式;
  495. xml.AddChildElem("command_format");
  496. xml.IntoElem();
  497. // 获取命令格式大小;
  498. vector <STCommandFormat>::const_iterator it_commandformat;
  499. for ( it_commandformat = STOElement.vt_commandformat.begin(); it_commandformat != STOElement.vt_commandformat.end(); it_commandformat++)
  500. {
  501. STCommandFormat tag = *it_commandformat;
  502. xml.AddChildElem("format");
  503. xml.AddChildAttrib("name", tag.szName);
  504. xml.AddChildAttrib("len", tag.szLen);
  505. xml.AddChildAttrib("data", tag.szData);
  506. xml.AddChildAttrib("type", tag.szType);
  507. }
  508. xml.OutOfElem();
  509. // 5.添加 depot子元素 命令元;
  510. xml.AddChildElem("command");
  511. xml.IntoElem();
  512. // vector <EleCmd>::iterator it_elcd; 会造成:error C2679: 二进制“=” : 没有找到接受“<未知>”类型的右操作数的运算符(或没有可接受的转换)
  513. // 出现错误的原因:是因为dp是const引用的,所以在it_elcd = dp.vt_msg.begin();时出错;
  514. // 因为dp是const引用,所在dp里的所有变量都不能改变;
  515. vector <STCommandTable>::const_iterator cit_commandtable;
  516. for ( cit_commandtable = STOElement.vt_commandtable.begin(); cit_commandtable != STOElement.vt_commandtable.end(); cit_commandtable++)
  517. {
  518. STCommandTable commandtable = *cit_commandtable;
  519. xml.AddChildElem("cmd");
  520. xml.AddChildAttrib("Mark",commandtable.szMark);
  521. xml.AddChildAttrib("Recv",commandtable.bRecv);
  522. xml.AddChildAttrib("it_tip", commandtable.szTip);
  523. vector <STCommandStyle>::const_iterator cit_commandstyle;
  524. for ( cit_commandstyle = commandtable.vt_commandstyle.begin(); cit_commandstyle != commandtable.vt_commandstyle.end(); cit_commandstyle++)
  525. {
  526. STCommandStyle commandstyle = *cit_commandstyle;
  527. xml.IntoElem();
  528. xml.AddChildElem("element");
  529. xml.AddChildAttrib("name", commandstyle.szName);
  530. xml.AddChildAttrib("data", commandstyle.szData);
  531. xml.OutOfElem();
  532. }
  533. }
  534. xml.OutOfElem();
  535. xml.OutOfElem();
  536. xml.Save(szDepotPath);
  537. }
  538. /************************************************************************/
  539. /*
  540. 函数:从设备库移除元素;
  541. 参数:
  542. szElementName: 设备名称;
  543. EleType: 元素所属类型;
  544. 测试结果:OK;
  545. */
  546. /************************************************************************/
  547. void CObjectdepot::RemoveElement(const char *szElementName, const int &EleType /* = 0 */)
  548. {
  549. CMarkup xml;
  550. if ( !xml.Load(szDepotPath) )
  551. {
  552. LOG4C((LOG_NOTICE,"设备库不存在~"));
  553. return;
  554. }
  555. xml.FindElem(); // ORDER element is root
  556. xml.IntoElem(); // inside ORDER
  557. while(xml.FindElem("object_depot"))
  558. {
  559. CString strName = xml.GetAttrib("name");
  560. if ( strName.Compare(szElementName) == 0)
  561. {
  562. xml.RemoveElem();
  563. break;
  564. }
  565. }
  566. xml.OutOfElem();
  567. xml.Save(szDepotPath);
  568. }
  569. /************************************************************************/
  570. /*
  571. 函数:修改设备库元素;
  572. 参数:
  573. STOElement: 设备库元素;
  574. EleType: 元素所属类型;
  575. 测试结果:未测试;
  576. */
  577. /************************************************************************/
  578. void CObjectdepot::ModifyElement(const STDepotObject &STOElement, const int &EleType /* = 0 */)
  579. {
  580. CMarkup xml;
  581. if ( !xml.Load(szDepotPath) )
  582. {
  583. LOG4C((LOG_NOTICE,"设备库不存在~"));
  584. return;
  585. }
  586. if ( !IsElementExist(STOElement.szName) )
  587. {
  588. InsertElement(STOElement);
  589. return;
  590. }
  591. RemoveElement(STOElement.szName);
  592. InsertElement(STOElement);
  593. }
  594. /************************************************************************/
  595. /*
  596. 函数:查找设备库元素;
  597. 参数:
  598. szElementName: 设备名称;
  599. EleType: 元素所属类型;
  600. 测试结果:OK
  601. */
  602. /************************************************************************/
  603. STDepotObject* CObjectdepot::LookupElement(const char *szElementName, const int &EleType /* = 0 */)
  604. {
  605. CMarkup xml;
  606. if ( !xml.Load(szDepotPath) )
  607. {
  608. LOG4C((LOG_NOTICE,"设备库不存在~"));
  609. return NULL;
  610. }
  611. STDepotObject *depotobject = new STDepotObject;//容器指针;
  612. BOOL bRet = FALSE;
  613. xml.FindElem(); // ORDER element is root
  614. xml.IntoElem(); // inside ORDER
  615. BOOL bGet = FALSE;
  616. while( xml.FindElem("object_depot") )
  617. {
  618. CString strName = xml.GetAttrib("name");
  619. if ( strName.Compare(szElementName) != 0 )
  620. continue;
  621. bGet = TRUE; // 如果找到,设置为TRUE,并在最后break;
  622. //ZeroMemory(depotobject,sizeof(STDepotObject));
  623. sprintf(depotobject->szName ,"%s", xml.GetAttrib("name" )); // 设备名称;
  624. sprintf(depotobject->szSID ,"%s", xml.GetAttrib("static_id" )); // 设备名称;
  625. xml.IntoElem();
  626. xml.FindElem("physical");
  627. depotobject->st_depotphy.iRate = atoi(xml.GetAttrib("rate"));
  628. depotobject->st_depotphy.iDBit = atoi(xml.GetAttrib("dataBit"));
  629. depotobject->st_depotphy.iSBit = atoi(xml.GetAttrib("stopBit"));
  630. depotobject->st_depotphy.iPaty = atoi(xml.GetAttrib("parity"));
  631. depotobject->st_depotphy.iRsTm = atoi(xml.GetAttrib("iResTime"));
  632. depotobject->st_depotphy.iIntl = atoi(xml.GetAttrib("interval"));
  633. sprintf(depotobject->st_depotphy.szLineType, "%s", xml.GetAttrib("LineType"));
  634. sprintf(depotobject->st_depotphy.szComType, "%s", xml.GetAttrib("comType"));
  635. sprintf(depotobject->st_depotphy.szPinDef, "%s", xml.GetAttrib("pinDefi"));
  636. xml.OutOfElem();
  637. xml.IntoElem();
  638. xml.FindElem("document");
  639. sprintf( depotobject->st_depotdoc.szFactory, xml.GetAttrib("Factory"));
  640. sprintf( depotobject->st_depotdoc.szdeviceType, xml.GetAttrib("deviceType"));
  641. sprintf( depotobject->st_depotdoc.szdeviceClass, xml.GetAttrib("class"));
  642. sprintf( depotobject->st_depotdoc.szdeviceName, xml.GetAttrib("deviceName"));
  643. sprintf( depotobject->st_depotdoc.szUnitType, xml.GetAttrib("unitType"));
  644. sprintf( depotobject->st_depotdoc.szProtocol, xml.GetAttrib("protocol"));
  645. xml.OutOfElem();
  646. // 3.继续CreateCommand;
  647. xml.IntoElem();
  648. xml.FindElem("command_format");
  649. depotobject->ByteCount = atoi( xml.GetAttrib("ByteCount"));
  650. while(xml.FindChildElem("format"))
  651. {
  652. STCommandFormat commandformat = {0};
  653. //ZeroMemory(&commandformat,sizeof(STCommandFormat));
  654. sprintf(commandformat.szName, "%s", xml.GetChildAttrib("name"));
  655. sprintf(commandformat.szLen, "%s", xml.GetChildAttrib("len"));
  656. sprintf(commandformat.szType, "%s", xml.GetChildAttrib("type"));
  657. sprintf(commandformat.szData, "%s", xml.GetChildAttrib("data"));
  658. // RUN_ADDOBJECT函数 缺少记录实际字符长度的变量;
  659. CString tmpStr = xml.GetChildAttrib("data");
  660. commandformat.nDatalen = tmpStr.GetLength();
  661. depotobject->vt_commandformat.push_back(commandformat);
  662. }
  663. xml.FindElem("command");
  664. while(xml.FindChildElem("cmd"))
  665. {
  666. STCommandTable commandtable ;//容器指针;
  667. //ZeroMemory(&commandtable,sizeof(STCommandTable));
  668. sprintf(commandtable.szMark,"%s",xml.GetChildAttrib("Mark"));
  669. commandtable.bRecv = atoi(xml.GetChildAttrib("Recv"));
  670. sprintf(commandtable.szTip,"%s",xml.GetChildAttrib("it_tip"));
  671. xml.IntoElem();
  672. while(xml.FindChildElem("element"))
  673. {
  674. STCommandStyle commandstyle = {0};
  675. //ZeroMemory(&commandstyle,sizeof(STCommandStyle));
  676. // sprintf不安全;
  677. //sprintf(tagCM.szName,"%s",m_depot.GetChildAttrib("name"));
  678. //sprintf(tagCM.szData,"%s",m_depot.GetChildAttrib("data"));
  679. // 这里会出错<untakeit>
  680. memcpy(commandstyle.szName, xml.GetChildAttrib("name"), strlen(xml.GetChildAttrib("name")));
  681. memcpy(commandstyle.szData, xml.GetChildAttrib("data"), strlen(xml.GetChildAttrib("data")));
  682. // RUN_ADDOBJECT函数 缺少记录实际字符长度的变量;
  683. CString tmpStr = xml.GetChildAttrib("data");
  684. commandstyle.nDatalen = tmpStr.GetLength();
  685. commandtable.vt_commandstyle.push_back(commandstyle);
  686. }
  687. depotobject->vt_commandtable.push_back(commandtable);
  688. xml.OutOfElem();
  689. }
  690. xml.OutOfElem();
  691. break;
  692. }
  693. xml.OutOfElem();
  694. if ( !bGet )
  695. {
  696. if ( depotobject )
  697. {
  698. delete depotobject;
  699. depotobject = NULL;
  700. }
  701. return NULL;
  702. }
  703. return depotobject;
  704. }
  705. #endif
  706. #if RUNTIME_DEPOT
  707. /************************************************************************/
  708. /*
  709. 函数:运行时设备库元素是否存在;
  710. 参数:
  711. iPort: 串口;
  712. iAddr: 地址;
  713. 返回值:
  714. = -1: 串口无;
  715. = 0: 串口有,地址无;
  716. = 1: 存在;
  717. 测试结果:OK
  718. */
  719. /************************************************************************/
  720. int CObjectdepot::IsSubElementExist(const int &iPort, const int &iAddr)
  721. {
  722. CMarkup xml;
  723. if ( !xml.Load(szRunTimeDepotPath) )
  724. {
  725. LOG4C((LOG_NOTICE,"运行时设备库不存在~"));
  726. return FALSE;
  727. }
  728. int nRet = -1;
  729. xml.FindElem(); // ORDER element is root
  730. xml.IntoElem(); // inside ORDER
  731. // 遍历所有元素;
  732. while( xml.FindElem("run_object") )
  733. {
  734. CString strPort = xml.GetAttrib("port");
  735. int _port = atoi(strPort.GetBuffer());
  736. strPort.ReleaseBuffer();
  737. if ( _port != iPort )
  738. continue;
  739. nRet = 0;
  740. while( xml.FindChildElem("commands") )
  741. {
  742. char szAddr[10] = {0};
  743. itoa(iAddr, szAddr, 10);
  744. if( strcmp(xml.GetChildAttrib("addr"), szAddr) == 0)
  745. {
  746. nRet = 1;
  747. break;
  748. }
  749. }
  750. break;
  751. }
  752. xml.OutOfElem();
  753. return nRet;
  754. }
  755. /************************************************************************/
  756. /*
  757. 函数:向运行时设备库插入元素;
  758. 参数:
  759. iPort: 串口号;
  760. iAddr: 地址;
  761. szName: 设备名称;
  762. 测试结果:OK;
  763. */
  764. /************************************************************************/
  765. BOOL CObjectdepot::InsertSubElement(const int &iPort, const int &iAddr, char *szName)
  766. {
  767. int iRet = IsSubElementExist(iPort,iAddr);
  768. if( iRet == 1)
  769. {
  770. LOG4C((LOG_NOTICE,"运行时设备库:COM%d:%d 已存在",iPort,iAddr));
  771. return FALSE;
  772. }
  773. if ( !IsElementExist(szName))
  774. {
  775. LOG4C((LOG_NOTICE,"设备库:没有该设备档案"));
  776. return FALSE;
  777. }
  778. CMarkup xml;
  779. if ( !xml.Load(szRunTimeDepotPath) )
  780. return FALSE;
  781. STRunObject* tRunObject = CreateRunObject(iPort, iAddr, szName);
  782. if ( tRunObject == NULL )
  783. {
  784. return FALSE;
  785. }
  786. if ( iRet == -1 )
  787. {
  788. //xml.ResetPos();
  789. xml.FindElem(); // ORDER element is root
  790. xml.IntoElem(); // inside ORDER
  791. // 1.添加depot元素;
  792. xml.AddElem("run_object");
  793. xml.AddAttrib("port", tRunObject->iPort);
  794. xml.AddAttrib("ele_count", 1);
  795. // 2.添加depot子元素 物理特性;
  796. xml.AddChildElem("physical");
  797. xml.AddChildAttrib("rate", tRunObject->st_runphy.iRate); // 1.波特率;
  798. xml.AddChildAttrib("dataBit", tRunObject->st_runphy.iDBit); // 2.数据位;
  799. xml.AddChildAttrib("stopBit", tRunObject->st_runphy.iSBit); // 3.停止位;
  800. xml.AddChildAttrib("parity", tRunObject->st_runphy.iPaty); // 4.校验位;
  801. xml.AddChildAttrib("iResTime", tRunObject->st_runphy.iRsTm); // 4.校验位;
  802. xml.AddChildAttrib("interval", tRunObject->st_runphy.iIntl); // 5.超时值;
  803. xml.AddChildAttrib("LineType", tRunObject->st_runphy.szLineType); // 6.针脚类型;
  804. xml.AddChildAttrib("comType", tRunObject->st_runphy.szComType); // 7.串口类型;
  805. xml.AddChildAttrib("pinDefi", tRunObject->st_runphy.szPinDef); // 8.针脚定义;
  806. // 3.添加 depot子元素 命令格式;
  807. xml.AddChildElem("commands");
  808. xml.AddChildAttrib("addr",tRunObject->st_rundevice.iAddr);
  809. xml.AddChildAttrib("name",tRunObject->st_rundevice.szUName);
  810. xml.AddChildAttrib("check",tRunObject->st_rundevice.szCheck);
  811. xml.IntoElem();
  812. // 获取命令格式大小;
  813. vector <STRunCommand>::const_iterator cit_runcommand;
  814. for ( cit_runcommand = tRunObject->st_rundevice.vt_rundevice.begin(); cit_runcommand != tRunObject->st_rundevice.vt_rundevice.end(); cit_runcommand++)
  815. {
  816. STRunCommand runcommand = *cit_runcommand;
  817. xml.AddChildElem("command");
  818. // 在此之前,需要先计算出各命令的检验值;(undo)
  819. xml.AddChildAttrib("send_read", runcommand.szSCMD);
  820. xml.AddChildAttrib("Recv", runcommand.bRecv);
  821. xml.AddChildAttrib("Mark", runcommand.szMark);
  822. xml.AddChildAttrib("label", runcommand.szTip);
  823. }
  824. xml.OutOfElem();
  825. xml.OutOfElem();
  826. }
  827. else if ( iRet == 0)
  828. {
  829. //xml.ResetPos();
  830. xml.FindElem(); // ORDER element is root
  831. xml.IntoElem(); // inside ORDER8
  832. // 1.遍历所有元素,找到插入的串口号;
  833. while( xml.FindElem("run_object") )
  834. {
  835. CString strPort = xml.GetAttrib("port");
  836. int _port = atoi(strPort.GetBuffer());
  837. strPort.ReleaseBuffer();
  838. if ( _port != iPort )
  839. continue;
  840. CString strCount = xml.GetAttrib("ele_count");
  841. int _count = atoi(strCount.GetBuffer());
  842. strCount.ReleaseBuffer();
  843. xml.SetAttrib("ele_count",++_count);
  844. BOOL bAorI = FALSE;
  845. int Max = 0,i = 0;
  846. // 2.循环得出元素地址的最佳插入位置;
  847. while( xml.FindChildElem("commands") )
  848. {
  849. CString strAddr = xml.GetChildAttrib("addr");
  850. int _addr = atoi(strAddr.GetBuffer());
  851. strAddr.ReleaseBuffer();
  852. if ( _addr < iAddr )
  853. if ( _addr > Max )
  854. Max = _addr;
  855. if ( _addr > iAddr && i == 0 )
  856. bAorI = TRUE;
  857. i++;
  858. }
  859. // 3.根据2,开始插入元素;
  860. xml.ResetChildPos();//重新设置子元素索引位置,设置在头部;
  861. if( !bAorI )
  862. {
  863. while( xml.FindChildElem("commands") )
  864. {
  865. CString strAddr = xml.GetChildAttrib("addr");
  866. int _addr = atoi(strAddr.GetBuffer());
  867. strAddr.ReleaseBuffer();
  868. if ( _addr == Max )
  869. break;
  870. }
  871. // 使用AddChildElem是向尾部插入;
  872. xml.AddChildElem("commands");
  873. }
  874. else
  875. {
  876. xml.FindChildElem("physical");
  877. // 使用InsertChildElem 是向头部插入;
  878. //xml.InsertChildElem("commands");
  879. // 使用AddChildElem是向尾部插入;
  880. xml.AddChildElem("commands");
  881. }
  882. xml.AddChildAttrib("addr",tRunObject->st_rundevice.iAddr);
  883. xml.AddChildAttrib("name",tRunObject->st_rundevice.szUName);
  884. xml.AddChildAttrib("check",tRunObject->st_rundevice.szCheck);
  885. xml.IntoElem();
  886. // 获取命令格式大小;
  887. vector <STRunCommand>::const_iterator cit_runcommand;
  888. for ( cit_runcommand = tRunObject->st_rundevice.vt_rundevice.begin(); cit_runcommand != tRunObject->st_rundevice.vt_rundevice.end(); cit_runcommand++)
  889. {
  890. STRunCommand runcommand = *cit_runcommand;
  891. xml.AddChildElem("command");
  892. // 在此之前,需要先计算出各命令的检验值;(undo)
  893. xml.AddChildAttrib("send_read", runcommand.szSCMD);
  894. xml.AddChildAttrib("Recv", runcommand.bRecv);
  895. xml.AddChildAttrib("Mark", runcommand.szMark);
  896. xml.AddChildAttrib("label", runcommand.szTip);
  897. }
  898. xml.OutOfElem();
  899. break;
  900. }
  901. xml.OutOfElem();
  902. }
  903. if ( tRunObject )
  904. {
  905. //ZeroMemory(tRunObject,sizeof(STRunObject));
  906. delete tRunObject;
  907. tRunObject = NULL;
  908. }
  909. xml.Save(szRunTimeDepotPath);
  910. return TRUE;
  911. }
  912. /************************************************************************/
  913. /*
  914. 函数:从运行时设备库中移除元素;
  915. 参数:
  916. iPort: 串口号;
  917. iAddr: 地址,当 =-1 时,表示移除串口(串口下所有设备);
  918. 测试结果:OK;
  919. */
  920. /************************************************************************/
  921. void CObjectdepot::RemoveSubElement(const int &iPort, const int &iAddr)
  922. {
  923. if ( iAddr != -1)
  924. {
  925. if ( 1 != IsSubElementExist(iPort,iAddr) )
  926. {
  927. LOG4C((LOG_NOTICE,"不存在该元素"));
  928. return;
  929. }
  930. }
  931. CMarkup xml;
  932. if ( !xml.Load(szRunTimeDepotPath) )
  933. {
  934. LOG4C((LOG_NOTICE,"设备库不存在~"));
  935. return;
  936. }
  937. xml.FindElem(); // ORDER element is root
  938. xml.IntoElem(); // inside ORDER
  939. while(xml.FindElem("run_object"))
  940. {
  941. CString strPort = xml.GetAttrib("port") ;
  942. int _port = atoi(strPort.GetBuffer());
  943. strPort.ReleaseBuffer();
  944. if ( _port != iPort)
  945. continue;
  946. CString strCount = xml.GetAttrib("ele_count");
  947. int _count = atoi(strCount.GetBuffer());
  948. strCount.ReleaseBuffer();
  949. if ( _count == 1 || iAddr == -1 )
  950. {
  951. xml.RemoveElem();
  952. xml.Save(szRunTimeDepotPath);
  953. break;
  954. }
  955. xml.SetAttrib("ele_count",--_count);
  956. xml.IntoElem();
  957. while(xml.FindElem("commands"))
  958. {
  959. CString strAddr = xml.GetAttrib("addr") ;
  960. int _addr = atoi(strAddr.GetBuffer());
  961. strAddr.ReleaseBuffer();
  962. if ( _addr != iAddr )
  963. continue;
  964. xml.RemoveElem();
  965. xml.Save(szRunTimeDepotPath);
  966. break;
  967. }
  968. xml.OutOfElem();
  969. break;
  970. }
  971. xml.OutOfElem();
  972. xml.Save(szRunTimeDepotPath);
  973. LOG4C((LOG_NOTICE,"删除COM%d:%d 成功",iPort,iAddr));
  974. }
  975. /************************************************************************/
  976. /*
  977. 函数:修改运行时设备库中的元素;
  978. 参数:
  979. iPort: 串口号;
  980. iAddr: 地址;
  981. tRunObject: 运行时设备库元素;
  982. 测试结果:未;
  983. */
  984. /************************************************************************/
  985. void CObjectdepot::ModifySubElement(const int &iPort, const int &iAddr, STRunObject &tRunObject)
  986. {
  987. RemoveSubElement(iPort,iAddr);
  988. InsertSubElement(iPort,iAddr,tRunObject.st_rundevice.szUName);
  989. }
  990. /************************************************************************/
  991. /*
  992. 函数:修改运行时设备库中的物理属性;
  993. 参数:
  994. iPort: 串口号;
  995. ...
  996. 测试结果:OK;
  997. */
  998. /************************************************************************/
  999. void CObjectdepot::ModifySubPhysical( const int &iPort, const int &iRate, const int &iDataBit, const int &iStopBit, const int &iParity, const int &iRespTime, const int &iInterval )
  1000. {
  1001. CMarkup xml;
  1002. if ( !xml.Load(szRunTimeDepotPath) )
  1003. {
  1004. LOG4C((LOG_NOTICE,"运行时设备库不存在"));
  1005. return;
  1006. }
  1007. xml.FindElem();
  1008. xml.IntoElem();
  1009. while( xml.FindElem("run_object") )
  1010. {
  1011. int _port = atoi(xml.GetAttrib("port"));
  1012. if ( _port != iPort)
  1013. continue;
  1014. xml.FindChildElem("physical");
  1015. if( iRate != -1)
  1016. xml.SetChildAttrib("rate",iRate);
  1017. if ( iDataBit != -1)
  1018. xml.SetChildAttrib("dataBit",iDataBit);
  1019. if( iStopBit != -1 )
  1020. xml.SetChildAttrib("stopBit",iStopBit);
  1021. if( iParity != -1 )
  1022. xml.SetChildAttrib("parity",iParity);
  1023. if( iRespTime != -1 )
  1024. xml.SetChildAttrib("iResTime",iRespTime);
  1025. if( iInterval != -1)
  1026. xml.SetChildAttrib("interval",iInterval);
  1027. //xml.SetChildAttrib("",);
  1028. }
  1029. xml.OutOfElem();
  1030. xml.Save(szRunTimeDepotPath);
  1031. }
  1032. /************************************************************************/
  1033. /*
  1034. 函数:查找运行时设备库中的元素;
  1035. 参数:
  1036. iPort: 串口号;
  1037. iAddr: 地址;
  1038. 测试结果:未;
  1039. */
  1040. /************************************************************************/
  1041. STRunDevice* CObjectdepot::LookupSubElement(const int &iPort, const int &iAddr)
  1042. {
  1043. CMarkup xml;
  1044. if ( !xml.Load(szRunTimeDepotPath) )
  1045. {
  1046. LOG4C((LOG_NOTICE,"运行时设备库不存在~"));
  1047. return FALSE;
  1048. }
  1049. int nRet = -1;
  1050. xml.FindElem(); // ORDER element is root
  1051. xml.IntoElem(); // inside ORDER
  1052. STRunDevice *tRunDevice = new STRunDevice; // 容器指针;
  1053. //ZeroMemory(tRunDevice,sizeof(STRunDevice));
  1054. // 遍历所有元素;
  1055. while( xml.FindElem("run_object") )
  1056. {
  1057. CString strPort = xml.GetAttrib("port");
  1058. int _port = atoi(strPort.GetBuffer());
  1059. strPort.ReleaseBuffer();
  1060. if ( _port != iPort )
  1061. continue;
  1062. nRet = 0;
  1063. while( xml.FindChildElem("commands") )
  1064. {
  1065. char szAddr[10] = {0};
  1066. itoa(iAddr, szAddr, 10);
  1067. if( strcmp(xml.GetChildAttrib("addr"), szAddr) == 0)
  1068. {
  1069. // 查找到设备,进行赋值;
  1070. tRunDevice->iPort = iPort;
  1071. tRunDevice->iAddr = iAddr;
  1072. strcpy(tRunDevice->szUName,xml.GetChildAttrib("name"));
  1073. //tRunDevice->szSID //暂时未考虑处理;
  1074. xml.IntoElem();
  1075. STRunCommand tRunCommand = {0};
  1076. while( xml.FindChildElem("command") )
  1077. {
  1078. //ZeroMemory(&tRunCommand,sizeof(STRunCommand));
  1079. //tRunCommand.szMark = xml.GetAttrib("send_read");//tRunDevice->vt_rundevice
  1080. strcpy(tRunCommand.szSCMD, xml.GetChildAttrib("send_read"));
  1081. strcpy(tRunCommand.szTip, xml.GetChildAttrib("Mark"));
  1082. strcpy(tRunCommand.szMark, xml.GetChildAttrib("label"));
  1083. tRunDevice->vt_rundevice.push_back(tRunCommand);
  1084. }
  1085. xml.OutOfElem();
  1086. break;
  1087. }
  1088. }
  1089. xml.OutOfElem();
  1090. return tRunDevice;
  1091. }
  1092. return NULL;
  1093. }
  1094. /************************************************************************/
  1095. /*
  1096. 函数:获取运行时设备库指定串口的物理特性;
  1097. 参数:
  1098. iPort: 串口号;
  1099. 测试结果:OK;
  1100. */
  1101. /************************************************************************/
  1102. STRunPhysical CObjectdepot::LookupSubPhysical(const int &iPort)
  1103. {
  1104. CMarkup xml;
  1105. if ( !xml.Load(szRunTimeDepotPath) )
  1106. {
  1107. LOG4C((LOG_NOTICE,"LookupSubPhysical::运行时设备库不存在~"));
  1108. }
  1109. xml.FindElem(); // ORDER element is root
  1110. xml.IntoElem(); // inside ORDER
  1111. STRunPhysical tRunPhysical = {0};
  1112. // 遍历所有元素;
  1113. while( xml.FindElem("run_object") )
  1114. {
  1115. CString strPort = xml.GetAttrib("port");
  1116. int _port = atoi(strPort.GetBuffer());
  1117. strPort.ReleaseBuffer();
  1118. if ( _port != iPort )
  1119. continue;
  1120. if( xml.FindChildElem("physical") )
  1121. {
  1122. tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
  1123. tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
  1124. tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
  1125. tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
  1126. tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
  1127. tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
  1128. strcpy(tRunPhysical.szLineType, xml.GetChildAttrib("LineType"));
  1129. strcpy(tRunPhysical.szComType , xml.GetChildAttrib("comType"));
  1130. strcpy(tRunPhysical.szPinDef , xml.GetChildAttrib("pinDefi"));
  1131. }
  1132. break;
  1133. }
  1134. xml.OutOfElem();
  1135. return tRunPhysical;
  1136. }
  1137. #endif
  1138. /************************************************************************/
  1139. /*
  1140. 函数:获取运行时设备库指定串口的元素命令集;
  1141. 参数:
  1142. iPort: 串口号;
  1143. iAddr: 地址,当 =-1时,表示获取串口所有设备命令集;
  1144. tRunComInfo: 命令集;
  1145. 测试结果:OK;
  1146. */
  1147. /************************************************************************/
  1148. void CObjectdepot::GetSendCommand(const int &iPort, const int &iAddr, STRunComInfo &tRunComInfo)
  1149. {
  1150. CMarkup xml;
  1151. if ( !xml.Load(szRunTimeDepotPath) )
  1152. {
  1153. LOG4C((LOG_NOTICE,"运行时设备库不存在"));
  1154. return;
  1155. }
  1156. BOOL bRet = FALSE;
  1157. xml.FindElem(); // ORDER element is root
  1158. xml.IntoElem(); // inside ORDER
  1159. // 遍历运行时设备库;
  1160. while( xml.FindElem("run_object") )
  1161. {
  1162. // 找到串口,设备属性;
  1163. if( iPort != atoi(xml.GetAttrib("port")) )
  1164. continue;
  1165. tRunComInfo.iPort = iPort;
  1166. xml.FindChildElem("physical");
  1167. tRunComInfo.tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
  1168. tRunComInfo.tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
  1169. tRunComInfo.tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
  1170. tRunComInfo.tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
  1171. tRunComInfo.tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
  1172. tRunComInfo.tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
  1173. BOOL bRunOne = FALSE;// 是否只运行一个设备;而不是串口下的所有设备;
  1174. // 遍历串口所有设备;
  1175. while( xml.FindChildElem("commands") )
  1176. {
  1177. STSendCommand tSendCommInfo = {0};
  1178. tSendCommInfo.iAddr = atoi(xml.GetChildAttrib("addr"));
  1179. if ( iAddr != -1 )
  1180. {
  1181. if ( tSendCommInfo.iAddr == iAddr )
  1182. bRunOne = TRUE;
  1183. else
  1184. continue;
  1185. }
  1186. strcpy(tSendCommInfo.szCheck, xml.GetChildAttrib("check"));
  1187. xml.IntoElem();
  1188. while( xml.FindChildElem("command") )
  1189. {
  1190. CString strCmd = xml.GetChildAttrib("send_read");
  1191. tSendCommInfo.bRecv = atoi(xml.GetChildAttrib("Recv"));
  1192. strcpy(tSendCommInfo.szMark, xml.GetChildAttrib("Mark"));
  1193. int iLen = strCmd.GetLength();
  1194. int iRLen = 0;
  1195. char szBCmd[500] = {0};
  1196. char szECmd[500] = {0};
  1197. memcpy(szBCmd, strCmd.GetBuffer(),iLen);
  1198. // 将表示16进制ASCII的字符转化成16进制;
  1199. for ( int i = 0, j = 0; i < iLen; i = i+3, j++ )
  1200. {
  1201. szECmd[j] = CCharacterProcess::ASCII_to_Byte(szBCmd[i])*16 + CCharacterProcess::ASCII_to_Byte(szBCmd[i+1]);
  1202. iRLen = j;
  1203. }
  1204. tSendCommInfo.dwSID++;
  1205. tSendCommInfo.iSLen = iRLen+1;
  1206. memcpy(tSendCommInfo.bySend,szECmd,iRLen+1);
  1207. tRunComInfo.vtSendCommand.push_back(tSendCommInfo);
  1208. }
  1209. xml.OutOfElem();
  1210. if ( bRunOne )
  1211. break;
  1212. }
  1213. }
  1214. xml.OutOfElem();
  1215. }
  1216. /************************************************************************/
  1217. /*
  1218. 函数:获取运行时设备库所有串口的所有设备的命令集;
  1219. 参数:
  1220. vtRunComInfo: 命令集;
  1221. 测试结果:OK;
  1222. */
  1223. /************************************************************************/
  1224. void CObjectdepot::GetAllSendCommand(vector<STRunComInfo> &vtRunComInfo)
  1225. {
  1226. CMarkup xml;
  1227. if ( !xml.Load(szRunTimeDepotPath) )
  1228. {
  1229. LOG4C((LOG_NOTICE,"运行时设备库不存在"));
  1230. return;
  1231. }
  1232. BOOL bRet = FALSE;
  1233. xml.FindElem(); // ORDER element is root
  1234. xml.IntoElem(); // inside ORDER
  1235. STRunComInfo tRunComInfo = {0};
  1236. // 遍历运行时设备库;
  1237. while( xml.FindElem("run_object") )
  1238. {
  1239. // 找到串口,设备属性;
  1240. tRunComInfo.iPort = atoi(xml.GetAttrib("port"));
  1241. xml.FindChildElem("physical");
  1242. tRunComInfo.tRunPhysical.iRate = atoi(xml.GetChildAttrib("rate"));
  1243. tRunComInfo.tRunPhysical.iDBit = atoi(xml.GetChildAttrib("dataBit"));
  1244. tRunComInfo.tRunPhysical.iSBit = atoi(xml.GetChildAttrib("stopBit"));
  1245. tRunComInfo.tRunPhysical.iPaty = atoi(xml.GetChildAttrib("parity"));
  1246. tRunComInfo.tRunPhysical.iRsTm = atoi(xml.GetChildAttrib("iResTime"));
  1247. tRunComInfo.tRunPhysical.iIntl = atoi(xml.GetChildAttrib("interval"));
  1248. STSendCommand tSendCommInfo;
  1249. // 遍历串口所有设备;
  1250. while( xml.FindChildElem("commands") )
  1251. {
  1252. //ZeroMemory(&tSendCommInfo,sizeof(STSendCommand));
  1253. //tSendCommInfo.iAddr = atoi(xml.GetChildAttrib("addr"));
  1254. int iAddr = atoi(xml.GetChildAttrib("addr"));
  1255. strcpy(tSendCommInfo.szCheck, xml.GetChildAttrib("check"));
  1256. xml.IntoElem();
  1257. while( xml.FindChildElem("command") )
  1258. {
  1259. tSendCommInfo.iPort = tRunComInfo.iPort; // 1.串口;
  1260. tSendCommInfo.iAddr = iAddr; // 2.地址;
  1261. CString strCmd = xml.GetChildAttrib("send_read");
  1262. tSendCommInfo.bRecv = atoi(xml.GetChildAttrib("Recv")); // 5.是否保存返回;
  1263. strcpy(tSendCommInfo.szMark, xml.GetChildAttrib("Mark")); // 6.命令特征码;
  1264. int iLen = strCmd.GetLength(),iRLen = 0;
  1265. char szBCmd[500] = {0},szECmd[500] = {0};
  1266. memcpy(szBCmd, strCmd.GetBuffer(),iLen);
  1267. // 将表示16进制ASCII的字符转化成16进制;
  1268. for ( int i = 0, j = 0; i < iLen; i = i+3, j++ )
  1269. {
  1270. szECmd[j] = CCharacterProcess::ASCII_to_Byte(szBCmd[i])*16 + CCharacterProcess::ASCII_to_Byte(szBCmd[i+1]);
  1271. iRLen = j;
  1272. }
  1273. tSendCommInfo.dwSID++; // 3.ID号;
  1274. tSendCommInfo.iSLen = iRLen+1; // 4.命令长度;
  1275. memcpy(tSendCommInfo.bySend,szECmd,iRLen+1);
  1276. tRunComInfo.vtSendCommand.push_back(tSendCommInfo);
  1277. }
  1278. xml.OutOfElem();
  1279. }
  1280. vtRunComInfo.push_back(tRunComInfo);
  1281. //ZeroMemory(&tRunComInfo,sizeof(STRunComInfo));
  1282. }
  1283. xml.OutOfElem();
  1284. }
  1285. #if EDITOR_INSERT
  1286. /************************************************************************/
  1287. /*
  1288. 函数:;
  1289. 参数:
  1290. 测试结果:未测试;
  1291. */
  1292. /************************************************************************/
  1293. void CObjectdepot::InsertElementNode(const char *szDeviceName,const char *szID, const STDepotPhysical &tDepotPhysical, const STDeviceDocument &tDeviceDocument)
  1294. {
  1295. if ( IsElementExist(szDeviceName) )
  1296. {
  1297. LOG4C((LOG_NOTICE,"设备已存在"));
  1298. return;
  1299. }
  1300. CMarkup xml;
  1301. if ( !xml.Load(szDepotPath) )
  1302. {
  1303. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1304. return;
  1305. }
  1306. xml.FindElem(); // ORDER element is root
  1307. xml.IntoElem(); // inside ORDER
  1308. xml.FindElem("object_depot") ;
  1309. // 1.添加depot元素;
  1310. xml.AddElem("object_depot");
  1311. xml.AddAttrib("name", szDeviceName); // 设备名称;
  1312. xml.AddAttrib("static_id", szID); // 设备静态ID;
  1313. // 2.添加depot子元素 ****物理特性;
  1314. xml.AddChildElem("physical");
  1315. xml.AddChildAttrib("rate",tDepotPhysical.iRate); // 1.波特率;
  1316. xml.AddChildAttrib("dataBit", tDepotPhysical.iDBit); // 2.数据位;
  1317. xml.AddChildAttrib("stopBit", tDepotPhysical.iSBit); // 3.停止位;
  1318. xml.AddChildAttrib("parity", tDepotPhysical.iPaty); // 4.校验位;
  1319. xml.AddChildAttrib("iResTime", tDepotPhysical.iRsTm); // 4.校验位;
  1320. xml.AddChildAttrib("interval", tDepotPhysical.iIntl); // 5.超时值;
  1321. xml.AddChildAttrib("LineType", tDepotPhysical.szLineType); // 6.针脚类型;
  1322. xml.AddChildAttrib("comType", tDepotPhysical.szComType); // 7.串口类型;
  1323. xml.AddChildAttrib("pinDefi", tDepotPhysical.szPinDef); // 8.针脚定义;
  1324. // 3.添加depot子元素 ****文档说明 ;
  1325. xml.AddChildElem("document");
  1326. xml.AddChildAttrib("Factory", tDeviceDocument.szFactory);
  1327. xml.AddChildAttrib("deviceType", tDeviceDocument.szdeviceType);
  1328. xml.AddChildAttrib("class", tDeviceDocument.szdeviceClass);
  1329. xml.AddChildAttrib("deviceName", tDeviceDocument.szdeviceName);
  1330. xml.AddChildAttrib("unitType", tDeviceDocument.szUnitType);
  1331. xml.AddChildAttrib("protocol", tDeviceDocument.szProtocol);
  1332. // 4.添加 depot子元素 命令格式;
  1333. xml.AddChildElem("command_format");
  1334. // 5.添加 depot子元素 命令元;
  1335. xml.AddChildElem("command");
  1336. #if 0
  1337. xml.IntoElem();
  1338. // 获取命令格式大小;
  1339. vector <STCommandFormat>::const_iterator it_commandformat;
  1340. for ( it_commandformat = STOElement.vt_commandformat.begin(); it_commandformat != STOElement.vt_commandformat.end(); it_commandformat++)
  1341. {
  1342. STCommandFormat tag = *it_commandformat;
  1343. xml.AddChildElem("format");
  1344. xml.AddChildAttrib("name", tag.szName);
  1345. xml.AddChildAttrib("len", tag.szLen);
  1346. xml.AddChildAttrib("data", tag.szData);
  1347. xml.AddChildAttrib("type", tag.szType);
  1348. }
  1349. xml.OutOfElem();
  1350. // 5.添加 depot子元素 命令元;
  1351. xml.AddChildElem("command");
  1352. xml.IntoElem();
  1353. // vector <EleCmd>::iterator it_elcd; 会造成:error C2679: 二进制“=” : 没有找到接受“<未知>”类型的右操作数的运算符(或没有可接受的转换)
  1354. // 出现错误的原因:是因为dp是const引用的,所以在it_elcd = dp.vt_msg.begin();时出错;
  1355. // 因为dp是const引用,所在dp里的所有变量都不能改变;
  1356. vector <STCommandTable>::const_iterator cit_commandtable;
  1357. for ( cit_commandtable = STOElement.vt_commandtable.begin(); cit_commandtable != STOElement.vt_commandtable.end(); cit_commandtable++)
  1358. {
  1359. STCommandTable commandtable = *cit_commandtable;
  1360. xml.AddChildElem("cmd");
  1361. xml.AddChildAttrib("Recv",commandtable.bRecv);
  1362. xml.AddChildAttrib("it_tip", commandtable.szTip);
  1363. vector <STCommandStyle>::const_iterator cit_commandstyle;
  1364. for ( cit_commandstyle = commandtable.vt_commandstyle.begin(); cit_commandstyle != commandtable.vt_commandstyle.end(); cit_commandstyle++)
  1365. {
  1366. STCommandStyle commandstyle = *cit_commandstyle;
  1367. xml.IntoElem();
  1368. xml.AddChildElem("element");
  1369. xml.AddChildAttrib("name", commandstyle.szName);
  1370. xml.AddChildAttrib("data", commandstyle.szData);
  1371. xml.OutOfElem();
  1372. }
  1373. }
  1374. xml.OutOfElem();
  1375. #endif
  1376. xml.OutOfElem();
  1377. xml.Save(szDepotPath);
  1378. }
  1379. /************************************************************************/
  1380. /*
  1381. 函数:;
  1382. 参数:
  1383. 测试结果:未测试;
  1384. */
  1385. /************************************************************************/
  1386. void CObjectdepot::InsertElementPhsycial(const char *szDeviceName,const STDepotPhysical &tDepotPhysical)
  1387. {
  1388. if ( IsElementExist(szDeviceName) )
  1389. {
  1390. LOG4C((LOG_NOTICE,"设备已存在"));
  1391. return;
  1392. }
  1393. CMarkup xml;
  1394. if ( !xml.Load(szDepotPath) )
  1395. {
  1396. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1397. return;
  1398. }
  1399. xml.FindElem(); // ORDER element is root
  1400. xml.IntoElem(); // inside ORDER
  1401. while( xml.FindElem("object_depot"))
  1402. {
  1403. if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
  1404. {
  1405. // 在添加之前,判断物理属性是否存在;
  1406. if ( !xml.FindChildElem("physical") )
  1407. {
  1408. return;
  1409. }
  1410. // 2.添加depot子元素 ****物理特性;
  1411. xml.AddChildElem("physical");
  1412. xml.AddChildAttrib("rate",tDepotPhysical.iRate); // 1.波特率;
  1413. xml.AddChildAttrib("dataBit", tDepotPhysical.iDBit); // 2.数据位;
  1414. xml.AddChildAttrib("stopBit", tDepotPhysical.iSBit); // 3.停止位;
  1415. xml.AddChildAttrib("parity", tDepotPhysical.iPaty); // 4.校验位;
  1416. xml.AddChildAttrib("iResTime", tDepotPhysical.iRsTm); // 4.校验位;
  1417. xml.AddChildAttrib("interval", tDepotPhysical.iIntl); // 5.超时值;
  1418. xml.AddChildAttrib("LineType", tDepotPhysical.szLineType); // 6.针脚类型;
  1419. xml.AddChildAttrib("comType", tDepotPhysical.szComType); // 7.串口类型;
  1420. xml.AddChildAttrib("pinDefi", tDepotPhysical.szPinDef); // 8.针脚定义;
  1421. break;
  1422. }
  1423. }
  1424. xml.OutOfElem();
  1425. xml.Save(szDepotPath);
  1426. }
  1427. /************************************************************************/
  1428. /*
  1429. 函数:;
  1430. 参数:
  1431. 测试结果:未测试;
  1432. */
  1433. /************************************************************************/
  1434. void CObjectdepot::InsertElementDocument(const char *szDeviceName,const STDeviceDocument &tDeviceDocument)
  1435. {
  1436. if ( IsElementExist(szDeviceName) )
  1437. {
  1438. LOG4C((LOG_NOTICE,"设备已存在"));
  1439. return;
  1440. }
  1441. CMarkup xml;
  1442. if ( !xml.Load(szDepotPath) )
  1443. {
  1444. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1445. return;
  1446. }
  1447. xml.FindElem(); // ORDER element is root
  1448. xml.IntoElem(); // inside ORDER
  1449. while( xml.FindElem("object_depot"))
  1450. {
  1451. if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
  1452. {
  1453. // 在添加之前,判断文档属性是否存在;
  1454. if ( !xml.FindChildElem("document") )
  1455. {
  1456. return;
  1457. }
  1458. xml.AddChildElem("document");
  1459. xml.AddChildAttrib("Factory", tDeviceDocument.szFactory);
  1460. xml.AddChildAttrib("deviceType", tDeviceDocument.szdeviceType);
  1461. xml.AddChildAttrib("class", tDeviceDocument.szdeviceClass);
  1462. xml.AddChildAttrib("deviceName", tDeviceDocument.szdeviceName);
  1463. xml.AddChildAttrib("unitType", tDeviceDocument.szUnitType);
  1464. xml.AddChildAttrib("protocol", tDeviceDocument.szProtocol);
  1465. break;
  1466. }
  1467. }
  1468. xml.OutOfElem();
  1469. xml.Save(szDepotPath);
  1470. }
  1471. /************************************************************************/
  1472. /*
  1473. 函数:;
  1474. 参数:
  1475. 测试结果:未测试;
  1476. */
  1477. /************************************************************************/
  1478. void CObjectdepot::InsertElementCmdStyle(
  1479. const char *szDeviceName,
  1480. const char *szKey,
  1481. const char *szLen,
  1482. const char *szContx,
  1483. const char *szType,
  1484. const int &nCount /* = -1 */)
  1485. {
  1486. if ( !IsElementExist(szDeviceName) )
  1487. {
  1488. LOG4C((LOG_NOTICE,"设备已存在"));
  1489. return;
  1490. }
  1491. CMarkup xml;
  1492. if ( !xml.Load(szDepotPath) )
  1493. {
  1494. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1495. return;
  1496. }
  1497. xml.FindElem(); // ORDER element is root
  1498. xml.IntoElem(); // inside ORDER
  1499. while( xml.FindElem("object_depot"))
  1500. {
  1501. if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
  1502. {
  1503. if ( xml.FindChildElem("command_format") )
  1504. {
  1505. if( nCount != -1)
  1506. xml.SetChildAttrib("ByteCount",nCount);
  1507. xml.IntoElem();
  1508. xml.AddChildElem("format");
  1509. xml.AddChildAttrib("name",szKey);
  1510. xml.AddChildAttrib("len",szLen);
  1511. xml.AddChildAttrib("data",szContx);
  1512. xml.AddChildAttrib("type",szType);
  1513. xml.OutOfElem();
  1514. }
  1515. break;
  1516. }
  1517. }
  1518. xml.OutOfElem();
  1519. xml.Save(szDepotPath);
  1520. }
  1521. /************************************************************************/
  1522. /*
  1523. 函数:;
  1524. 参数:
  1525. 测试结果:未测试;
  1526. */
  1527. /************************************************************************/
  1528. void CObjectdepot::InsertElementCommandImpl(const char *szDeviceName,const char *szMark,const char* szStore, const char* szTip)
  1529. {
  1530. if ( !IsElementExist(szDeviceName) )
  1531. {
  1532. LOG4C((LOG_NOTICE,"设备不存在"));
  1533. return;
  1534. }
  1535. CMarkup xml;
  1536. if ( !xml.Load(szDepotPath) )
  1537. {
  1538. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1539. return;
  1540. }
  1541. xml.FindElem(); // ORDER element is root
  1542. xml.IntoElem(); // inside ORDER
  1543. while( xml.FindElem("object_depot"))
  1544. {
  1545. if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
  1546. {
  1547. if ( xml.FindChildElem("command") )
  1548. {
  1549. // 判断Mark是否存在,存在退出;
  1550. xml.IntoElem();
  1551. while( xml.FindChildElem("cmd") )
  1552. {
  1553. if ( strcmp(szMark,xml.GetChildAttrib("Mark")) == 0 )
  1554. {
  1555. xml.OutOfElem();
  1556. return;
  1557. }
  1558. }
  1559. xml.OutOfElem();
  1560. // 添加;
  1561. xml.IntoElem();
  1562. xml.AddChildElem("cmd");
  1563. xml.AddChildAttrib("Recv",szStore);
  1564. xml.AddChildAttrib("Mark",szMark);
  1565. xml.AddChildAttrib("it_tip",szTip);
  1566. xml.OutOfElem();
  1567. }
  1568. break;
  1569. }
  1570. }
  1571. xml.OutOfElem();
  1572. xml.Save(szDepotPath);
  1573. }
  1574. /************************************************************************/
  1575. /*
  1576. 函数:;
  1577. 参数:
  1578. 测试结果:未测试;
  1579. */
  1580. /************************************************************************/
  1581. void CObjectdepot::InsertElementCommandImplItem(const char *szDeviceName,const char *szMark, const char *szKey,const char *szContx)
  1582. {
  1583. if ( !IsElementExist(szDeviceName) )
  1584. {
  1585. LOG4C((LOG_NOTICE,"设备不存在"));
  1586. return;
  1587. }
  1588. CMarkup xml;
  1589. if ( !xml.Load(szDepotPath) )
  1590. {
  1591. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1592. return;
  1593. }
  1594. xml.FindElem(); // ORDER element is root
  1595. xml.IntoElem(); // inside ORDER
  1596. while( xml.FindElem("object_depot"))
  1597. {
  1598. if ( strcmp(szDeviceName, xml.GetAttrib("name")) == 0 )
  1599. {
  1600. if( xml.FindChildElem("command") )
  1601. {
  1602. xml.IntoElem();
  1603. while( xml.FindChildElem("cmd") )
  1604. {
  1605. if ( strcmp(szMark,xml.GetChildAttrib("Mark")) == 0 )
  1606. {
  1607. // 判断key是否存在;
  1608. xml.IntoElem();
  1609. while( xml.FindChildElem("element") )
  1610. {
  1611. if ( strcmp(szKey,xml.GetChildAttrib("name")) == 0 )
  1612. {
  1613. xml.OutOfElem();
  1614. xml.OutOfElem();
  1615. xml.OutOfElem();
  1616. return;
  1617. }
  1618. }
  1619. xml.AddChildElem("element");
  1620. xml.AddChildAttrib("name",szKey);
  1621. xml.AddChildAttrib("data",szContx);
  1622. xml.OutOfElem();
  1623. break;
  1624. }
  1625. }
  1626. }
  1627. break;
  1628. }
  1629. }
  1630. xml.OutOfElem();
  1631. xml.Save(szDepotPath);
  1632. }
  1633. #endif
  1634. #if EDITOR_MODIFY
  1635. /************************************************************************/
  1636. /*
  1637. 函数:;
  1638. 参数:
  1639. 测试结果:未测试;
  1640. */
  1641. /************************************************************************/
  1642. void CObjectdepot::ModifyElementNode(
  1643. const char *szOldDeviceName,
  1644. const char *szNewDeviceName,
  1645. const char *szNewID,
  1646. const STDepotPhysical &tDepotPhysical,
  1647. const STDeviceDocument &tDeviceDocument)
  1648. {
  1649. if ( !IsElementExist(szOldDeviceName) )
  1650. {
  1651. LOG4C((LOG_NOTICE,"设备不存在"));
  1652. return;
  1653. }
  1654. CMarkup xml;
  1655. if ( !xml.Load(szDepotPath) )
  1656. {
  1657. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1658. return;
  1659. }
  1660. xml.FindElem(); // ORDER element is root
  1661. xml.IntoElem(); // inside ORDER
  1662. while( xml.FindElem("object_depot"))
  1663. {
  1664. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1665. {
  1666. xml.SetAttrib("name",szNewDeviceName);
  1667. xml.SetAttrib("static_id",szNewID);
  1668. if ( xml.FindChildElem("physical") )
  1669. {
  1670. xml.SetChildAttrib("rate",tDepotPhysical.iRate);
  1671. xml.SetChildAttrib("dataBit",tDepotPhysical.iDBit);
  1672. xml.SetChildAttrib("stopBit",tDepotPhysical.iSBit);
  1673. xml.SetChildAttrib("parity",tDepotPhysical.iPaty);
  1674. xml.SetChildAttrib("iResTime",tDepotPhysical.iRsTm);
  1675. xml.SetChildAttrib("interval",tDepotPhysical.iIntl);
  1676. xml.SetChildAttrib("LineType",tDepotPhysical.szLineType);
  1677. xml.SetChildAttrib("comType",tDepotPhysical.szComType);
  1678. xml.SetChildAttrib("pinDefi",tDepotPhysical.szPinDef);
  1679. }
  1680. if ( xml.FindChildElem("document") )
  1681. {
  1682. xml.SetChildAttrib("Factory",tDeviceDocument.szFactory);
  1683. xml.SetChildAttrib("deviceType",tDeviceDocument.szdeviceType);
  1684. xml.SetChildAttrib("class",tDeviceDocument.szdeviceClass);
  1685. xml.SetChildAttrib("deviceName",tDeviceDocument.szdeviceName);
  1686. xml.SetChildAttrib("unitType",tDeviceDocument.szUnitType);
  1687. xml.SetChildAttrib("protocol",tDeviceDocument.szProtocol);
  1688. }
  1689. break;
  1690. }
  1691. }
  1692. xml.OutOfElem();
  1693. xml.Save(szDepotPath);
  1694. }
  1695. /************************************************************************/
  1696. /*
  1697. 函数:;
  1698. 参数:
  1699. 测试结果:未测试;
  1700. */
  1701. /************************************************************************/
  1702. void CObjectdepot::ModifyElementPhsycial(const char *szOldDeviceName,const char* szNewDeviceName,const STDepotPhysical &tDepotPhysical)
  1703. {
  1704. if ( !IsElementExist(szOldDeviceName) )
  1705. {
  1706. LOG4C((LOG_NOTICE,"设备不存在"));
  1707. return;
  1708. }
  1709. CMarkup xml;
  1710. if ( !xml.Load(szDepotPath) )
  1711. {
  1712. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1713. return;
  1714. }
  1715. xml.FindElem(); // ORDER element is root
  1716. xml.IntoElem(); // inside ORDER
  1717. while( xml.FindElem("object_depot"))
  1718. {
  1719. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1720. {
  1721. break;
  1722. }
  1723. }
  1724. xml.OutOfElem();
  1725. xml.Save(szDepotPath);
  1726. }
  1727. /************************************************************************/
  1728. /*
  1729. 函数:;
  1730. 参数:
  1731. 测试结果:未测试;
  1732. */
  1733. /************************************************************************/
  1734. void CObjectdepot::ModifyElementDocument(const char *szOldDeviceName,const char* szNewDeviceName,const STDeviceDocument &tDeviceDocument)
  1735. {
  1736. if ( !IsElementExist(szOldDeviceName) )
  1737. {
  1738. LOG4C((LOG_NOTICE,"设备不存在"));
  1739. return;
  1740. }
  1741. CMarkup xml;
  1742. if ( !xml.Load(szDepotPath) )
  1743. {
  1744. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1745. return;
  1746. }
  1747. xml.FindElem(); // ORDER element is root
  1748. xml.IntoElem(); // inside ORDER
  1749. while( xml.FindElem("object_depot"))
  1750. {
  1751. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1752. {
  1753. break;
  1754. }
  1755. }
  1756. xml.OutOfElem();
  1757. xml.Save(szDepotPath);
  1758. }
  1759. /************************************************************************/
  1760. /*
  1761. 函数:修改子元素指令格式;
  1762. 参数:
  1763. szDeviceName:设备名称,这个不会变;
  1764. szKey:关键名;同样不能变;
  1765. */
  1766. /************************************************************************/
  1767. void CObjectdepot::ModifyElementCommandStyle(
  1768. const char *szOldDeviceName,
  1769. const char *szOldKey,
  1770. const char *szNewKey,
  1771. const char *szLen,
  1772. const char *szContx,
  1773. const char *szType,
  1774. const int &nCount)
  1775. {
  1776. if ( !IsElementExist(szOldDeviceName) )
  1777. {
  1778. LOG4C((LOG_NOTICE,"设备不存在"));
  1779. return;
  1780. }
  1781. CMarkup xml;
  1782. if ( !xml.Load(szDepotPath) )
  1783. {
  1784. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1785. return;
  1786. }
  1787. xml.FindElem(); // ORDER element is root
  1788. xml.IntoElem(); // inside ORDER
  1789. while( xml.FindElem("object_depot"))
  1790. {
  1791. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1792. {
  1793. if ( xml.FindChildElem("command_format") )
  1794. {
  1795. if ( nCount != -1)
  1796. xml.SetChildAttrib("ByteCount",nCount);
  1797. BOOL bRet = FALSE;
  1798. xml.IntoElem();
  1799. while( xml.FindChildElem("format") )
  1800. {
  1801. if ( strcmp(szOldKey, xml.GetChildAttrib("name")) == 0 )
  1802. {
  1803. xml.SetChildAttrib("name",szNewKey);
  1804. xml.SetChildAttrib("len",szLen);
  1805. xml.SetChildAttrib("data",szContx);
  1806. xml.SetChildAttrib("type",szType);
  1807. bRet = TRUE;
  1808. break;
  1809. }
  1810. }
  1811. xml.OutOfElem();
  1812. if ( bRet )
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. xml.OutOfElem();
  1818. xml.Save(szDepotPath);
  1819. }
  1820. /************************************************************************/
  1821. /*
  1822. 函数:;
  1823. 参数:
  1824. 测试结果:未测试;
  1825. */
  1826. /************************************************************************/
  1827. void CObjectdepot::ModifyElementCmdImpl(
  1828. const char *szOldDeviceName,
  1829. const char *szOldMark,
  1830. const char *szNewMark,
  1831. const char szStore,
  1832. const char* szTip,
  1833. const char *szOldKey,
  1834. const char *szNewKey,
  1835. const char *szContx)
  1836. {
  1837. if ( !IsElementExist(szOldDeviceName) )
  1838. {
  1839. LOG4C((LOG_NOTICE,"设备不存在"));
  1840. return;
  1841. }
  1842. CMarkup xml;
  1843. if ( !xml.Load(szDepotPath) )
  1844. {
  1845. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1846. return;
  1847. }
  1848. xml.FindElem(); // ORDER element is root
  1849. xml.IntoElem(); // inside ORDER
  1850. while( xml.FindElem("object_depot"))
  1851. {
  1852. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1853. {
  1854. if ( xml.FindChildElem("command") )
  1855. {
  1856. BOOL bRet = FALSE;
  1857. xml.IntoElem();
  1858. while( xml.FindChildElem("cmd") )
  1859. {
  1860. if ( strcmp(szOldMark, xml.GetChildAttrib("Mark")) == 0 )
  1861. {
  1862. xml.SetChildAttrib("Mark",szNewMark);
  1863. xml.SetChildAttrib("Recv",szStore);
  1864. xml.SetChildAttrib("it_tip",szTip);
  1865. xml.IntoElem();
  1866. while( xml.FindChildElem("element") )
  1867. {
  1868. if ( strcmp(szOldKey, xml.GetChildAttrib("name")) == 0 )
  1869. {
  1870. xml.SetChildAttrib("name",szNewKey);
  1871. xml.SetChildAttrib("data",szContx);
  1872. break;
  1873. }
  1874. }
  1875. xml.OutOfElem();
  1876. bRet = TRUE;
  1877. break;
  1878. }
  1879. }
  1880. xml.OutOfElem();
  1881. if ( bRet )
  1882. break;
  1883. }
  1884. }
  1885. }
  1886. xml.OutOfElem();
  1887. xml.Save(szDepotPath);
  1888. }
  1889. /************************************************************************/
  1890. /*
  1891. 函数:;
  1892. 参数:
  1893. 测试结果:未测试;
  1894. */
  1895. /************************************************************************/
  1896. void CObjectdepot::ModifyElementCommand(
  1897. const char *szOldDeviceName,
  1898. const char *szOldMark,
  1899. const char *szNewMark,
  1900. const char szStore,
  1901. const char* szTip)
  1902. {
  1903. if ( !IsElementExist(szOldDeviceName) )
  1904. {
  1905. LOG4C((LOG_NOTICE,"设备不存在"));
  1906. return;
  1907. }
  1908. CMarkup xml;
  1909. if ( !xml.Load(szDepotPath) )
  1910. {
  1911. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1912. return;
  1913. }
  1914. xml.FindElem(); // ORDER element is root
  1915. xml.IntoElem(); // inside ORDER
  1916. while( xml.FindElem("object_depot"))
  1917. {
  1918. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1919. {
  1920. if ( xml.FindChildElem("command") )
  1921. {
  1922. BOOL bRet = FALSE;
  1923. xml.IntoElem();
  1924. while( xml.FindChildElem("cmd") )
  1925. {
  1926. if ( strcmp(szOldMark, xml.GetChildAttrib("Mark")) == 0 )
  1927. {
  1928. xml.SetChildAttrib("Mark",szNewMark);
  1929. xml.SetChildAttrib("Recv",szStore);
  1930. xml.SetChildAttrib("it_tip",szTip);
  1931. bRet = TRUE;
  1932. break;
  1933. }
  1934. }
  1935. xml.OutOfElem();
  1936. if ( bRet )
  1937. break;
  1938. }
  1939. }
  1940. }
  1941. xml.OutOfElem();
  1942. xml.Save(szDepotPath);
  1943. }
  1944. /************************************************************************/
  1945. /*
  1946. 函数:;
  1947. 参数:
  1948. 测试结果:未测试;
  1949. */
  1950. /************************************************************************/
  1951. void CObjectdepot::ModifyElementCommandImplItem(
  1952. const char *szOldDeviceName,
  1953. const char *szOldKey,
  1954. const char *szNewKey,
  1955. const char *szContx)
  1956. {
  1957. if ( !IsElementExist(szOldDeviceName) )
  1958. {
  1959. LOG4C((LOG_NOTICE,"设备已存在"));
  1960. return;
  1961. }
  1962. CMarkup xml;
  1963. if ( !xml.Load(szDepotPath) )
  1964. {
  1965. LOG4C((LOG_NOTICE,"设备库不存在~"));
  1966. return;
  1967. }
  1968. xml.FindElem(); // ORDER element is root
  1969. xml.IntoElem(); // inside ORDER
  1970. while( xml.FindElem("object_depot"))
  1971. {
  1972. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  1973. {
  1974. break;
  1975. }
  1976. }
  1977. xml.OutOfElem();
  1978. xml.Save(szDepotPath);
  1979. }
  1980. #endif
  1981. #if EDITOR_DELETE
  1982. /************************************************************************/
  1983. /*
  1984. 函数:;
  1985. 参数:
  1986. 测试结果:未测试;
  1987. */
  1988. /************************************************************************/
  1989. void CObjectdepot::DeleteElementCommandStyle(const char *szOldDeviceName, const char *szOldKey)
  1990. {
  1991. if ( !IsElementExist(szOldDeviceName) )
  1992. {
  1993. LOG4C((LOG_NOTICE,"设备不存在"));
  1994. return;
  1995. }
  1996. CMarkup xml;
  1997. if ( !xml.Load(szDepotPath) )
  1998. {
  1999. LOG4C((LOG_NOTICE,"设备库不存在~"));
  2000. return;
  2001. }
  2002. xml.FindElem(); // ORDER element is root
  2003. xml.IntoElem(); // inside ORDER
  2004. while( xml.FindElem("object_depot"))
  2005. {
  2006. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  2007. {
  2008. if ( xml.FindChildElem("command_format") )
  2009. {
  2010. xml.IntoElem();
  2011. while( xml.FindChildElem("format") )
  2012. {
  2013. if ( strcmp(szOldKey,xml.GetChildAttrib("name")) == 0 )
  2014. {
  2015. xml.RemoveChildElem();
  2016. xml.OutOfElem();
  2017. xml.Save(szDepotPath);
  2018. return;
  2019. }
  2020. }
  2021. xml.OutOfElem();
  2022. }
  2023. break;
  2024. }
  2025. }
  2026. }
  2027. /************************************************************************/
  2028. /*
  2029. 函数:;
  2030. 参数:
  2031. 测试结果:未测试;
  2032. */
  2033. /************************************************************************/
  2034. void CObjectdepot::DeleteElementCmdImpl(const char *szOldDeviceName, const char *szOldMark)
  2035. {
  2036. if ( !IsElementExist(szOldDeviceName) )
  2037. {
  2038. LOG4C((LOG_NOTICE,"设备不存在"));
  2039. return;
  2040. }
  2041. CMarkup xml;
  2042. if ( !xml.Load(szDepotPath) )
  2043. {
  2044. LOG4C((LOG_NOTICE,"设备库不存在~"));
  2045. return;
  2046. }
  2047. xml.FindElem(); // ORDER element is root
  2048. xml.IntoElem(); // inside ORDER
  2049. while( xml.FindElem("object_depot"))
  2050. {
  2051. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  2052. {
  2053. if ( xml.FindChildElem("command") )
  2054. {
  2055. xml.IntoElem();
  2056. while( xml.FindChildElem("cmd") )
  2057. {
  2058. if ( strcmp(szOldMark,xml.GetChildAttrib("Mark")) == 0 )
  2059. {
  2060. xml.RemoveChildElem();
  2061. xml.OutOfElem();
  2062. xml.Save(szDepotPath);
  2063. return;
  2064. }
  2065. }
  2066. xml.OutOfElem();
  2067. }
  2068. break;
  2069. }
  2070. }
  2071. }
  2072. /************************************************************************/
  2073. /*
  2074. 函数:;
  2075. 参数:
  2076. 测试结果:未测试;
  2077. */
  2078. /************************************************************************/
  2079. void CObjectdepot::DeleteElementCommandImplItem(const char *szOldDeviceName, const char *szOldMark, const char *szOldKey)
  2080. {
  2081. if ( !IsElementExist(szOldDeviceName) )
  2082. {
  2083. LOG4C((LOG_NOTICE,"设备不存在"));
  2084. return;
  2085. }
  2086. CMarkup xml;
  2087. if ( !xml.Load(szDepotPath) )
  2088. {
  2089. LOG4C((LOG_NOTICE,"设备库不存在~"));
  2090. return;
  2091. }
  2092. xml.FindElem(); // ORDER element is root
  2093. xml.IntoElem(); // inside ORDER
  2094. while( xml.FindElem("object_depot"))
  2095. {
  2096. if ( strcmp(szOldDeviceName, xml.GetAttrib("name")) == 0 )
  2097. {
  2098. if ( xml.FindChildElem("command") )
  2099. {
  2100. xml.IntoElem();
  2101. while( xml.FindChildElem("cmd") )
  2102. {
  2103. if ( strcmp(szOldMark,xml.GetChildAttrib("Mark")) == 0 )
  2104. {
  2105. xml.IntoElem();
  2106. while( xml.FindChildElem("element") )
  2107. {
  2108. if ( strcmp(szOldKey,xml.GetChildAttrib("name")) == 0 )
  2109. {
  2110. xml.RemoveChildElem();
  2111. xml.OutOfElem();
  2112. xml.Save(szDepotPath);
  2113. return;
  2114. }
  2115. }
  2116. xml.OutOfElem();
  2117. }
  2118. }
  2119. xml.OutOfElem();
  2120. }
  2121. break;
  2122. }
  2123. }
  2124. }
  2125. #endif