mt_mt.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <regex.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include "mt_mt.h"
  9. #include "mt_aq.h"
  10. #include "mt_pq.h"
  11. //static MultiTable_t *gMT;
  12. static regex_t regex_comment;
  13. static regex_t regex;
  14. static unsigned int currLine = 0;
  15. void ReleaseSubTableItem(Item_t *pItem)
  16. {
  17. if (pItem != NULL)
  18. {
  19. if (pItem->filepath != NULL)
  20. {
  21. free(pItem->filepath);
  22. pItem->filepath = NULL;
  23. }
  24. if (pItem->pData != NULL)
  25. {
  26. free(pItem->pData);
  27. }
  28. memset(pItem, 0, sizeof(Item_t));
  29. }
  30. }
  31. void ReleaseSubTable(SubTable_t *pSubTable)
  32. {
  33. if (pSubTable != NULL)
  34. {
  35. int i;
  36. for (i=0; i<pSubTable->itemNum; i++)
  37. {
  38. if(pSubTable->itemList[i] != NULL)
  39. {
  40. ReleaseSubTableItem(pSubTable->itemList[i]);
  41. free(pSubTable->itemList[i]);
  42. }
  43. }
  44. memset(pSubTable, 0, sizeof(SubTable_t));
  45. }
  46. }
  47. void ReleaseMultiTable(MultiTable_t *pMT)
  48. {
  49. if (pMT != NULL)
  50. {
  51. int i;
  52. for (i=0; i<pMT->modelNum; i++)
  53. {
  54. if(pMT->modelList[i] != NULL)
  55. {
  56. ReleaseSubTable(pMT->modelList[i]);
  57. free(pMT->modelList[i]);
  58. }
  59. }
  60. memset(pMT, 0, sizeof(SubTable_t));
  61. }
  62. }
  63. int GetValue(char *buf, char *StringID, char *StringValue)
  64. {
  65. char *pch;
  66. int retval = -1;
  67. regmatch_t match[2];
  68. retval = regexec(&regex, buf, 1, match, 0);
  69. if( !retval ){
  70. //puts("Match");
  71. //printf("==>%s", buf);
  72. }
  73. else if( retval == REG_NOMATCH ){
  74. //puts("No match");
  75. //printf("==>%s", buf);
  76. }
  77. else{
  78. //regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  79. //fprintf(stderr, "Error at %s line %d\n", filename, currLine);
  80. }
  81. pch = strtok (buf," =");
  82. if (pch && strcmp(pch,StringID) == 0)
  83. {
  84. //printf ("%s=\n",pch);
  85. pch = strtok (NULL, " =\"");
  86. //printf ("\"%s\"\n",pch);
  87. strcpy(StringValue, pch);
  88. retval = 0;
  89. }
  90. else
  91. {
  92. retval = -1;
  93. }
  94. return retval;
  95. }
  96. int SubTable_AddItem(SubTable_t *pSubTable, char *itemName, char *itemFile)
  97. {
  98. int retval = 0;
  99. int currItemIndex;
  100. if (pSubTable == NULL)
  101. {
  102. return -1;
  103. }
  104. if (itemName == NULL)
  105. {
  106. return -1;
  107. }
  108. if (itemFile == NULL)
  109. {
  110. return -1;
  111. }
  112. currItemIndex = pSubTable->itemNum;
  113. pSubTable->itemList[currItemIndex] = malloc(sizeof(Item_t));
  114. if (pSubTable->itemList[currItemIndex] == NULL)
  115. {
  116. retval = -1;
  117. }
  118. else
  119. {
  120. pSubTable->itemNum++;
  121. memset(pSubTable->itemList[currItemIndex], 0 , sizeof(Item_t));
  122. strcpy(pSubTable->itemList[currItemIndex]->name, itemName);
  123. //check error
  124. pSubTable->itemList[currItemIndex]->filepath = malloc(strlen(itemFile)+1);
  125. if (pSubTable->itemList[currItemIndex]->filepath == NULL)
  126. {
  127. fprintf(stderr, "%s %d malloc error\n", __FUNCTION__, __LINE__);
  128. pSubTable->itemNum--;
  129. retval = -1;
  130. }
  131. else
  132. {
  133. strcpy(pSubTable->itemList[currItemIndex]->filepath, itemFile);
  134. }
  135. }
  136. return retval;
  137. }
  138. int parseItem(Item_t *pItem)
  139. {
  140. int retval = 0;
  141. if (pItem != NULL)
  142. {
  143. if (strcmp(pItem->name, "AQ_OSD_TAB") == 0)
  144. {
  145. retval = parseAQ(pItem);
  146. }
  147. else if (strcmp(pItem->name, "PQ_OSD_TAB") == 0)
  148. {
  149. retval = parsePQ(pItem);
  150. }
  151. else if (strcmp(pItem->name, "COLOR_TMP_TAB") == 0)
  152. {
  153. retval = parsePQ(pItem);
  154. }
  155. else
  156. {
  157. retval = -1;
  158. }
  159. }
  160. return retval;
  161. }
  162. int parseSubTable(SubTable_t *pSubTable)
  163. {
  164. int retval = 0;
  165. int i;
  166. if (pSubTable == NULL)
  167. {
  168. return -1;
  169. }
  170. for (i=0;i<pSubTable->itemNum; i++)
  171. {
  172. retval = parseItem(pSubTable->itemList[i]);
  173. if (retval == -1)
  174. {
  175. fprintf(stderr, "%s %d parse Item %d fail\n", __FUNCTION__, __LINE__, i);
  176. break;
  177. }
  178. }
  179. return retval;
  180. }
  181. MultiTable_t *ParseMultiTableINI(char *filename)
  182. {
  183. FILE *fp = NULL;
  184. MultiTable_t *pMT = NULL;
  185. int retval;
  186. char buf[LINEMAX];
  187. regmatch_t match[2];
  188. int step = 0;
  189. char StringValue[256];
  190. char ItemNameStr[256];
  191. int currModelIndex=0;
  192. if (filename == NULL)
  193. {
  194. fprintf(stderr, "%s filename == NULL\n", __FUNCTION__);
  195. return NULL;
  196. }
  197. printf("Read ini from %s\n", filename);
  198. fp = fopen(filename, "rb");
  199. if (fp == NULL)
  200. {
  201. fprintf(stderr, "%s Can't open file %s\n", __FUNCTION__, filename);
  202. return NULL;
  203. }
  204. /* Compile regular expression */
  205. //retval = regcomp(&regex, "^(TableName|DefaultModel|ModelName|ItemName|ItemFile)+[ \t]*=[ \t]*\"[a-zA-Z0-9._/\\]*\"[ \t]*", 0);
  206. retval = regcomp(&regex, "[a-zA-Z][ \t]*=[ \t]*\"[a-zA-Z0-9._/\\]*\"[ \t]*", 0);
  207. if(retval)
  208. {
  209. fprintf(stderr, "Could not compile regex\n");
  210. fclose(fp);
  211. return NULL;
  212. }
  213. retval = regcomp(&regex_comment, "^[ \t]*#[.]*", 0);
  214. if(retval)
  215. {
  216. regfree(&regex);
  217. fclose(fp);
  218. fprintf(stderr, "Could not compile regex\n");
  219. return NULL;
  220. }
  221. pMT = (MultiTable_t *)malloc(sizeof(MultiTable_t));
  222. if (pMT == NULL)
  223. {
  224. regfree(&regex);
  225. regfree(&regex_comment);
  226. fclose(fp);
  227. fprintf(stderr, "MultiTable_t malloc fail\n");
  228. return NULL;
  229. }
  230. memset(pMT, 0, sizeof(MultiTable_t));
  231. currLine = 0;
  232. while( (fgets (buf , LINEMAX , fp) != NULL))
  233. {
  234. currLine++;
  235. retval = regexec(&regex_comment, buf, 1, match, 0);
  236. if( !retval ){
  237. //puts("Match comment");
  238. //printf("==>%s", buf);
  239. }
  240. else if( retval == REG_NOMATCH ){
  241. //puts("No match");
  242. //printf("==>%s", buf);
  243. //printf("step %d\n", step);
  244. switch (step)
  245. {
  246. case 0:
  247. retval=GetValue(buf, "TableName", StringValue);
  248. if (retval == 0)
  249. {
  250. if (strlen(StringValue) < TABLENAMELEN)
  251. {
  252. strcpy(pMT->name,StringValue);
  253. }
  254. else
  255. {
  256. fprintf(stderr, "Tablename too long, max len is %d\n", TABLENAMELEN);
  257. memcpy(pMT->name,StringValue, TABLENAMELEN);
  258. pMT->name[TABLENAMELEN]='\0';
  259. }
  260. }
  261. else
  262. {
  263. fprintf(stderr, "Multitable file expect string: TableName=\"abcd\"\n");
  264. }
  265. break;
  266. case 1:
  267. retval=GetValue(buf, "DefaultModel", StringValue);
  268. if (retval == 0)
  269. {
  270. if (strlen(StringValue) < MODELNAMELEN)
  271. {
  272. strcpy(pMT->defaultModelName,StringValue);
  273. }
  274. else
  275. {
  276. fprintf(stderr, "DefaultModelName too long, max len is %d\n", MODELNAMELEN);
  277. memcpy(pMT->defaultModelName,StringValue, MODELNAMELEN);
  278. pMT->defaultModelName[MODELNAMELEN]='\0';
  279. }
  280. }
  281. else
  282. {
  283. fprintf(stderr,"Multitable file expect string: DefaultModel=\"abcd\"\n");
  284. }
  285. break;
  286. case 2:
  287. retval=GetValue(buf, "ModelName", StringValue);
  288. if (retval == 0)
  289. {
  290. SubTable_t *pSubTable = NULL;
  291. pMT->modelNum++;
  292. currModelIndex = pMT->modelNum-1;
  293. pSubTable = (SubTable_t*)malloc(sizeof(SubTable_t));
  294. if (pSubTable == NULL)
  295. {
  296. fprintf(stderr, "Unable to allocate SubTable_t memory %s %d\n", __FUNCTION__, __LINE__);
  297. retval = -1;
  298. }
  299. else
  300. {
  301. memset(pSubTable, 0, sizeof(SubTable_t));
  302. pMT->modelList[currModelIndex] = pSubTable;
  303. if (strlen(StringValue) < MODELNAMELEN)
  304. {
  305. strcpy(pSubTable->modelName,StringValue);
  306. }
  307. else
  308. {
  309. fprintf(stderr, "ModelName too long, max len is %d\n", MODELNAMELEN);
  310. memcpy(pSubTable->modelName,StringValue, MODELNAMELEN);
  311. pSubTable->modelName[MODELNAMELEN]='\0';
  312. }
  313. }
  314. }
  315. else
  316. {
  317. fprintf(stderr, "Multitable file expect string: DefaultModel=\"abcd\"\n");
  318. }
  319. break;
  320. case 3:
  321. case 5:
  322. case 7:
  323. retval=GetValue(buf, "ItemName", ItemNameStr);
  324. break;
  325. case 4:
  326. case 6:
  327. case 8:
  328. retval=GetValue(buf, "ItemFile", StringValue);
  329. if (retval == 0)
  330. {
  331. SubTable_AddItem(pMT->modelList[currModelIndex], ItemNameStr, StringValue);
  332. }
  333. break;
  334. }
  335. if (retval == 0)
  336. {
  337. step++;
  338. }
  339. else
  340. {
  341. //Error happen break
  342. fprintf(stderr, "Error at %s line %d\n", filename, currLine);
  343. break;
  344. }
  345. if (step >= 9)
  346. {
  347. break;
  348. }
  349. }
  350. else{
  351. //regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  352. fprintf(stderr, "Error at %s line %d\n", filename, currLine);
  353. fclose(fp);
  354. regfree(&regex);
  355. regfree(&regex_comment);
  356. free(pMT);
  357. pMT = NULL;
  358. return NULL;
  359. }
  360. }
  361. if (step != 9)
  362. {
  363. fprintf(stderr, "Error Multitable ini missing item\n");
  364. free(pMT);
  365. pMT = NULL;
  366. }
  367. fclose(fp);
  368. regfree(&regex);
  369. regfree(&regex_comment);
  370. return pMT;
  371. }
  372. int GenSubTableBuf(SubTable_t *pSubTable)
  373. {
  374. int i;
  375. Item_t *pItem = NULL;
  376. unsigned char *pOutBuf = NULL;
  377. if (pSubTable == NULL)
  378. {
  379. fprintf(stderr, "%s error, pSubTable == NULL\n", __FUNCTION__);
  380. return -1;
  381. }
  382. pOutBuf = malloc(MAXBINSIZE);
  383. if (pOutBuf== NULL)
  384. {
  385. fprintf(stderr, "%s error, pSubTable->pData malloc error!\n", __FUNCTION__);
  386. return -1;
  387. }
  388. pSubTable->pData = pOutBuf;
  389. pSubTable->subTableSize = 0;
  390. //fwrite(pSubTable->modelName, sizeof(char)*MODELNAMELEN, 1, fp);
  391. writeTempBuf(pSubTable->modelName, sizeof(char)*MODELNAMELEN, &pOutBuf);
  392. pSubTable->subTableSize += sizeof(char)*MODELNAMELEN;
  393. //fwrite(&pSubTable->subTableSize, sizeof(unsigned int), 1, fp);
  394. writeTempBuf(&pSubTable->subTableSize, sizeof(unsigned int), &pOutBuf);
  395. pSubTable->subTableSize += sizeof(unsigned int);
  396. //fwrite(&pSubTable->currTableStartOffset, sizeof(unsigned int), 1, fp);
  397. writeTempBuf(&pSubTable->currTableStartOffset, sizeof(unsigned int), &pOutBuf);
  398. pSubTable->subTableSize += sizeof(unsigned int);
  399. //fwrite(&pSubTable->itemNum, sizeof(unsigned int), 1, fp);
  400. writeTempBuf(&pSubTable->itemNum, sizeof(unsigned int), &pOutBuf);
  401. pSubTable->subTableSize += sizeof(unsigned int);
  402. //fwrite(&pSubTable->subTableNo, sizeof(unsigned int), 1, fp);
  403. writeTempBuf(&pSubTable->subTableNo, sizeof(unsigned int), &pOutBuf);
  404. pSubTable->subTableSize += sizeof(unsigned int);
  405. for (i=0; i<pSubTable->itemNum; i++)
  406. {
  407. pItem = pSubTable->itemList[i];
  408. if (i==0)
  409. {
  410. pItem->offset = 16+16+(16+8)*pSubTable->itemNum;
  411. }
  412. else
  413. {
  414. pItem->offset = pSubTable->itemList[i-1]->offset +
  415. pSubTable->itemList[i-1]->size + pSubTable->itemList[i-1]->dummyByteNums;
  416. }
  417. //fwrite(pItem->name, sizeof(char)*ITEMNAMELEN, 1, fp);
  418. writeTempBuf(pItem->name, sizeof(char)*ITEMNAMELEN, &pOutBuf);
  419. pSubTable->subTableSize += sizeof(char)*ITEMNAMELEN;
  420. //fwrite(&pItem->offset, sizeof(unsigned int), 1, fp);
  421. writeTempBuf(&pItem->offset, sizeof(unsigned int), &pOutBuf);
  422. pSubTable->subTableSize += sizeof(unsigned int);
  423. //fwrite(&pItem->size, sizeof(unsigned int), 1, fp);
  424. writeTempBuf(&pItem->size, sizeof(unsigned int), &pOutBuf);
  425. pSubTable->subTableSize += sizeof(unsigned int);
  426. }
  427. for (i=0; i<pSubTable->itemNum; i++)
  428. {
  429. pItem = pSubTable->itemList[i];
  430. //fwrite(pItem->pData, pItem->size, 1, fp);
  431. writeTempBuf(pItem->pData, pItem->size, &pOutBuf);
  432. pSubTable->subTableSize += pItem->size;
  433. //for 4 bytes aligment
  434. if (pItem->dummyByteNums != 0)
  435. {
  436. char dummy = 0;
  437. int j;
  438. for(j=0; j<pItem->dummyByteNums; j++)
  439. {
  440. //fwrite(&dummy, sizeof(char), 1, fp);
  441. writeTempBuf(&dummy,sizeof(char), &pOutBuf);
  442. }
  443. pSubTable->subTableSize += pItem->dummyByteNums;
  444. }
  445. }
  446. pOutBuf = pSubTable->pData + (sizeof (char)*MODELNAMELEN);
  447. writeTempBuf(&pSubTable->subTableSize, sizeof(unsigned int), &pOutBuf);
  448. //pSubTable->checksum = CalCulate_XOR_CheckSum(pSubTable->pData, pSubTable->subTableSize);
  449. return 0;
  450. }
  451. int writeMultiTable(MultiTable_t *pMTab, char *outputFilename)
  452. {
  453. FILE *fp = 0;
  454. unsigned char *pOutBuf = NULL;
  455. int i;
  456. if (pMTab == NULL)
  457. {
  458. fprintf(stderr, "%s Error! pMTab == NULL\n", __FUNCTION__);
  459. return -1;
  460. }
  461. pOutBuf = malloc(MAXMULTITABLEBINSIZE);
  462. if (pOutBuf== NULL)
  463. {
  464. fprintf(stderr, "%s error, pMTab->pData malloc error!\n", __FUNCTION__);
  465. return -1;
  466. }
  467. pMTab->pData = pOutBuf;
  468. pMTab->totalSize = 0;
  469. fp = fopen(outputFilename, "wb");
  470. if (fp == NULL)
  471. {
  472. fprintf(stderr, "Unable to write file %s\n", outputFilename);
  473. return -1;
  474. }
  475. for (i=0; i<pMTab->modelNum; i++)
  476. {
  477. pMTab->modelList[i]->subTableNo = i;
  478. if (i==0)
  479. {
  480. pMTab->subTableOffset[0] = 24 + 8*pMTab->modelNum;
  481. pMTab->modelList[0]->currTableStartOffset = pMTab->subTableOffset[0];
  482. }
  483. else
  484. {
  485. pMTab->subTableOffset[i] = pMTab->subTableOffset[i-1]+pMTab->modelList[i-1]->subTableSize;
  486. pMTab->modelList[i]->currTableStartOffset = pMTab->subTableOffset[i];
  487. }
  488. GenSubTableBuf(pMTab->modelList[i]);
  489. pMTab->modelList[i]->checksum = CalCulate_XOR_CheckSum(pMTab->modelList[i]->pData, pMTab->modelList[i]->subTableSize/sizeof(unsigned int));
  490. if (i==0)
  491. {
  492. pMTab->subTableOffset[0] = 24 + 8*pMTab->modelNum;
  493. }
  494. else
  495. {
  496. pMTab->subTableOffset[i] = pMTab->subTableOffset[i-1]+pMTab->modelList[i-1]->subTableSize;
  497. }
  498. }
  499. //fwrite(pMTab->name, sizeof(char)*TABLENAMELEN, 1, fp);
  500. writeTempBuf(pMTab->name, sizeof(char)*TABLENAMELEN, &pOutBuf);
  501. pMTab->totalSize += sizeof(char)*TABLENAMELEN;
  502. //fwrite(&pMTab->modelNum, sizeof(unsigned int), 1, fp);
  503. writeTempBuf(&pMTab->modelNum, sizeof(unsigned int), &pOutBuf);
  504. pMTab->totalSize += sizeof(unsigned int);
  505. //fwrite(&pMTab->totalSize, sizeof(unsigned int), 1, fp);
  506. writeTempBuf(&pMTab->totalSize, sizeof(unsigned int), &pOutBuf);
  507. pMTab->totalSize += sizeof(unsigned int);
  508. //fwrite(&pMTab->tableChecksum, sizeof(unsigned int), 1, fp);
  509. writeTempBuf(&pMTab->tableChecksum, sizeof(unsigned int), &pOutBuf);
  510. pMTab->totalSize += sizeof(unsigned int);
  511. for (i=0; i<pMTab->modelNum; i++)
  512. {
  513. //fwrite(&pMTab->subTableOffset[i], sizeof(unsigned int), 1, fp);
  514. writeTempBuf(&pMTab->subTableOffset[i], sizeof(unsigned int), &pOutBuf);
  515. pMTab->totalSize += sizeof(unsigned int);
  516. //fwrite(&pMTab->modelList[i]->checksum, sizeof(unsigned int), 1, fp);
  517. writeTempBuf(&pMTab->modelList[i]->checksum, sizeof(unsigned int), &pOutBuf);
  518. pMTab->totalSize += sizeof(unsigned int);
  519. }
  520. for (i=0; i<pMTab->modelNum; i++)
  521. {
  522. writeTempBuf(pMTab->modelList[i]->pData, pMTab->modelList[i]->subTableSize, &pOutBuf);
  523. pMTab->totalSize += pMTab->modelList[i]->subTableSize;
  524. }
  525. pOutBuf = pMTab->pData + 16; // point to Main Table total size
  526. writeTempBuf(&pMTab->totalSize, sizeof(unsigned int), &pOutBuf);
  527. pOutBuf = pMTab->pData + 24; // point to SubTable 0 start offset position
  528. pMTab->tableChecksum = CalCulate_XOR_CheckSum(pOutBuf, pMTab->modelNum*2);
  529. pOutBuf = pMTab->pData + 20; // point to Table check sum
  530. writeTempBuf(&pMTab->tableChecksum, sizeof(unsigned int), &pOutBuf);
  531. fwrite(pMTab->pData, pMTab->totalSize, 1, fp);
  532. fflush(fp);
  533. fclose(fp);
  534. return 0;
  535. }
  536. int writeMultiTableFlag(MultiTable_t *pMTab, char *outputFilename)
  537. {
  538. unsigned char updated = 0;
  539. FILE *fp;
  540. if (pMTab == NULL)
  541. {
  542. fprintf(stderr, "%s Error! pMTab == NULL\n", __FUNCTION__);
  543. return -1;
  544. }
  545. fp = fopen(outputFilename, "wb");
  546. if (fp == NULL)
  547. {
  548. fprintf(stderr, "Unable to write file %s\n", outputFilename);
  549. return -1;
  550. }
  551. fwrite(&updated, sizeof(unsigned char), 1, fp);
  552. fwrite(pMTab->defaultModelName, sizeof(char)*MODELNAMELEN, 1, fp);
  553. fflush(fp);
  554. fclose(fp);
  555. return 0;
  556. }
  557. int writeOutputBuf(void *pData, unsigned int size, unsigned char **pOutBuf, FILE *fp)
  558. {
  559. int retval =0;
  560. #if WRITEITEMTOFILE
  561. if (fp != NULL)
  562. {
  563. fwrite(pData, size, 1, fp);
  564. }
  565. else
  566. {
  567. fprintf(stderr, "%s %d error\n", __FUNCTION__, __LINE__);
  568. retval = -1;
  569. goto out;
  570. }
  571. #endif
  572. if (*pOutBuf != NULL)
  573. {
  574. memcpy(*pOutBuf,pData, size);
  575. *pOutBuf = *pOutBuf + size;
  576. }
  577. else
  578. {
  579. fprintf(stderr, "%s %d error\n", __FUNCTION__, __LINE__);
  580. retval = -1;
  581. }
  582. out:
  583. return retval;
  584. }
  585. int writeTempBuf(void *pData, unsigned int size, unsigned char **pOutBuf)
  586. {
  587. int retval =0;
  588. if (*pOutBuf != NULL)
  589. {
  590. memcpy(*pOutBuf,pData, size);
  591. *pOutBuf = *pOutBuf + size;
  592. }
  593. else
  594. {
  595. fprintf(stderr, "%s %d error\n", __FUNCTION__, __LINE__);
  596. retval = -1;
  597. }
  598. return retval;
  599. }
  600. unsigned int CalCulate_XOR_CheckSum(void *pBuffer, unsigned int size)
  601. {
  602. unsigned int idx = 0, checksum = 0;
  603. for (idx = 0; idx < size; idx++)
  604. {
  605. checksum = checksum ^ ((unsigned int *)pBuffer)[idx];
  606. }
  607. return checksum;
  608. }