Logger.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /**
  2. * MIT License
  3. *
  4. * Copyright (c) 2018 Infineon Technologies AG
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE
  23. *
  24. * \file
  25. *
  26. * \brief This file contains a light weight logger implementation.
  27. *
  28. * \addtogroup grLogger
  29. * @{
  30. *
  31. */
  32. #include <stdio.h>
  33. #include "optiga/common/Logger.h"
  34. #include "optiga/pal/pal_os_timer.h"
  35. /// @cond hidden
  36. /*****************************************************************************
  37. * Defines
  38. *****************************************************************************/
  39. //If ENABLE_UARTLOG is defined, assign UartWriteData as log writer
  40. #ifdef ENABLE_UARTLOG
  41. #include "Uart.h"
  42. pFWriteData pfWriter = (pFWriteData)UartWriteData;
  43. #else
  44. //The function does nothing
  45. static int32_t WriteData(uint32_t PdwHandle, const uint8_t* PprgbBuf, uint32_t PdwDataLen)
  46. {
  47. //lint --e{715} suppress "The parameters are not used as this is filler function"
  48. return 1;
  49. }
  50. pFWriteData pfWriter = (pFWriteData)WriteData;
  51. #endif
  52. /*****************************************************************************
  53. * Common Functions
  54. *****************************************************************************/
  55. /**
  56. * Convert Byte to Hex String
  57. *
  58. */
  59. void ConvUint8ToHexString (uint8_t* PprgbHexByteArray, uint8_t* PprgbHexString, \
  60. uint32_t dwNoOfBytes, uint8_t PbIsSpaceReq)
  61. {
  62. //lint --e{818} suppress "PprgbHexString is modified in function"
  63. uint32_t dwLoop = 0;
  64. uint8_t bNibble = 0, bHexByte = 0;
  65. do
  66. {
  67. if((NULL == PprgbHexByteArray) || (NULL == PprgbHexString))
  68. {
  69. return;
  70. }
  71. for (dwLoop = 0; dwLoop < dwNoOfBytes; dwLoop++)
  72. {
  73. bHexByte = PprgbHexByteArray[dwLoop];
  74. /*Convert Byte to HexString */
  75. bNibble = (bHexByte & 0xF0)>>4;
  76. if (bNibble > 0x09)
  77. PprgbHexString [0] = bNibble + 0x37;
  78. else
  79. PprgbHexString [0] = bNibble + 0x30;
  80. bNibble = bHexByte & 0x0F;
  81. if (bNibble > 0x09)
  82. PprgbHexString [1] = bNibble + 0x37;
  83. else
  84. PprgbHexString [1] = bNibble + 0x30;
  85. if(PbIsSpaceReq)
  86. {
  87. PprgbHexString [2] = ' ';
  88. PprgbHexString += 3;
  89. }
  90. else
  91. {
  92. PprgbHexString += 2;
  93. }
  94. }
  95. *PprgbHexString = 0x00;
  96. } while(0);
  97. }
  98. /**
  99. * Convert Uint32 to Hex String
  100. *
  101. */
  102. void ConvUint32ToHexString (uint32_t dwVal, uint8_t* PprgbHexString)
  103. {
  104. uint8_t rgbByteArray [5];
  105. do
  106. {
  107. if(NULL == PprgbHexString)
  108. {
  109. return;
  110. }
  111. rgbByteArray [0] = (uint8_t)(dwVal >> 24);
  112. rgbByteArray [1] = (uint8_t)((dwVal & 0x00FF0000) >> 16);
  113. rgbByteArray [2] = (uint8_t)((dwVal & 0x0000FF00) >> 8);
  114. rgbByteArray [3] = (uint8_t)((dwVal & 0x000000FF));
  115. ConvUint8ToHexString(rgbByteArray, PprgbHexString, 4, 0);
  116. } while(0);
  117. }
  118. /**
  119. * Convert Uint32 to Decimal String
  120. *
  121. */
  122. void ConvUint32ToDecString (uint32_t dwVal, uint8_t* PprgbDecStr, \
  123. uint8_t bExpStrLen, uint8_t bFillChar)
  124. {
  125. uint8_t rgbTempStr [12] = {0};
  126. uint8_t bCount;
  127. do
  128. {
  129. if(NULL ==PprgbDecStr)
  130. {
  131. return;
  132. }
  133. bCount = 0;
  134. for (;;)
  135. {
  136. rgbTempStr [bCount] = (dwVal % 10) + 0x30;
  137. dwVal = dwVal / 10;
  138. bCount++;
  139. if(0x00 == dwVal)
  140. {
  141. break;
  142. }
  143. }
  144. while(bExpStrLen > bCount)
  145. {
  146. *PprgbDecStr = bFillChar;
  147. PprgbDecStr++;
  148. bExpStrLen--;
  149. }
  150. bCount--;
  151. for(;;)
  152. {
  153. *PprgbDecStr = rgbTempStr[bCount];
  154. PprgbDecStr++;
  155. if(0x00 == bCount)
  156. {
  157. break;
  158. }
  159. bCount--;
  160. }
  161. *PprgbDecStr = 0x00;
  162. } while(0);
  163. }
  164. /*****************************************************************************
  165. * Static functions
  166. *****************************************************************************/
  167. #ifdef ENABLE_LOG
  168. /**
  169. * Return current system time in milliseconds as a string
  170. *
  171. */
  172. static void GetSystemDateTime(char_t *pszSystemTime)
  173. {
  174. uint32_t dwTimeInMilliSecs = 0;
  175. if(pszSystemTime == NULL)
  176. {
  177. return;
  178. }
  179. dwTimeInMilliSecs = pal_os_timer_get_time_in_milliseconds();
  180. ConvUint32ToDecString (dwTimeInMilliSecs, (uint8_t *)pszSystemTime, 10, '0');
  181. }
  182. /**
  183. * Perform packet analysis. This is specific to IFX I2C protocol
  184. *
  185. */
  186. static void DumpPacketAnalysis(uint8_t* prgbBuf, uint16_t wLen, bool_t fDirection)
  187. {
  188. uint16_t wOffset = 0, wFrameLength, wTemp;
  189. uint8_t bFctr, bPctr, bTemp, bAckNumber;
  190. char_t pszTemp[256];
  191. bool_t bControlFrame = TRUE;
  192. //for packet analysis there must be minimum 5 bytes
  193. if(wLen < 5)
  194. {
  195. return;
  196. }
  197. if(prgbBuf == NULL)
  198. {
  199. return;
  200. }
  201. //0 for send
  202. if(fDirection == TX_DIRECTION)
  203. {
  204. wOffset = 1;
  205. CONSOLE_LOGSTRINGLINE("->->->->-> Packet Analysis ->->->->->");
  206. }
  207. else
  208. {
  209. CONSOLE_LOGSTRINGLINE("<-<-<-<-<- Packet Analysis <-<-<-<-<-");
  210. }
  211. do
  212. {
  213. //frame type
  214. bFctr = *(prgbBuf+wOffset);
  215. bAckNumber = bFctr & 0x03;
  216. if(bFctr & 0x80)
  217. {
  218. CONSOLE_LOGSTRINGLINE("Frame type: Control frame");
  219. }
  220. else
  221. {
  222. bControlFrame = FALSE;
  223. CONSOLE_LOGSTRINGLINE("Frame type: Data frame");
  224. }
  225. //seq counter 0110 0000 = 0x60
  226. bTemp = ((bFctr & 0x60) >> 5);
  227. switch(bTemp)
  228. {
  229. case 0x00:
  230. CONSOLE_LOGSTRING("Seq Counter: Ack for ");
  231. ConvUint32ToDecString((uint32_t)bAckNumber,(uint8_t*)pszTemp, 0, '0');
  232. CONSOLE_LOGSTRINGLINE(pszTemp);
  233. break;
  234. case 0x01:
  235. CONSOLE_LOGSTRING("Seq Counter: Nak for ");
  236. ConvUint32ToDecString((uint32_t)bAckNumber,(uint8_t*)pszTemp, 0, '0');
  237. CONSOLE_LOGSTRINGLINE(pszTemp);
  238. break;
  239. case 0x02:
  240. CONSOLE_LOGSTRINGLINE("Seq Counter: Re-synch");
  241. break;
  242. default:
  243. CONSOLE_LOGSTRINGLINE("************************** Seq Counter: RFU ***********************");
  244. }
  245. //frame number 0000 1100 = 0x60
  246. bTemp = ((bFctr & 0x0C) >> 2);
  247. CONSOLE_LOGSTRING("Frame number: ");
  248. ConvUint32ToDecString((uint32_t)bTemp,(uint8_t*)pszTemp, 0, '0');
  249. CONSOLE_LOGSTRINGLINE(pszTemp);
  250. //ack number
  251. CONSOLE_LOGSTRING("Ack number: ");
  252. ConvUint32ToDecString((uint32_t)bAckNumber,(uint8_t*)pszTemp, 0, '0');
  253. CONSOLE_LOGSTRINGLINE(pszTemp);
  254. //Frame length:
  255. wOffset++;
  256. wFrameLength = ((uint16_t)*(prgbBuf + wOffset) << 8) | (uint16_t)*(prgbBuf + wOffset + 1);
  257. CONSOLE_LOGSTRING("Frame length: ");
  258. ConvUint32ToDecString((uint32_t)wFrameLength,(uint8_t*)pszTemp, 0, '0');
  259. CONSOLE_LOGSTRINGLINE(pszTemp);
  260. wOffset += 2;
  261. //N/w and transport info not present for control frame
  262. if(bControlFrame)
  263. {
  264. break;
  265. }
  266. //channel info
  267. bPctr = *(prgbBuf+wOffset);
  268. bTemp = bPctr >> 4;
  269. CONSOLE_LOGSTRING("Channel info: ");
  270. ConvUint32ToDecString((uint32_t)bTemp,(uint8_t*)pszTemp, 0, '0');
  271. CONSOLE_LOGSTRINGLINE(pszTemp);
  272. bTemp = bPctr & 0x07;
  273. switch(bTemp)
  274. {
  275. case 0x00:
  276. CONSOLE_LOGSTRINGLINE("Chaining info: Single packet");
  277. break;
  278. case 0x01:
  279. CONSOLE_LOGSTRINGLINE("Chaining info: First packet");
  280. break;
  281. case 0x02:
  282. CONSOLE_LOGSTRINGLINE("Chaining info: Intermediate packet");
  283. break;
  284. case 0x04:
  285. CONSOLE_LOGSTRINGLINE("Chaining info: Last packet");
  286. break;
  287. case 0x07:
  288. CONSOLE_LOGSTRINGLINE("********************* Chaining info: Chaining error ********************* ");
  289. break;
  290. default:
  291. CONSOLE_LOGSTRINGLINE("********************* Chaining info: RFU***********************");
  292. }
  293. wOffset += 1;
  294. //exclude till offset and checksum
  295. wTemp = wOffset+2;
  296. if(wLen > wTemp)
  297. {
  298. wTemp = wLen - wTemp;
  299. }
  300. else
  301. {
  302. // no data bytes
  303. break;
  304. }
  305. if(fDirection == TX_DIRECTION)
  306. {
  307. CONSOLE_LOGSTRING("Command data : ");
  308. }
  309. else
  310. {
  311. CONSOLE_LOGSTRING("Response data : ");
  312. }
  313. Util_DumpHex((prgbBuf+wOffset), wTemp);
  314. CONSOLE_LOGSTRINGLINE(" ");
  315. }while(0);
  316. //0 for send
  317. if(fDirection == TX_DIRECTION)
  318. {
  319. CONSOLE_LOGSTRINGLINE("->->->->-> Packet Analysis ->->->->->");
  320. }
  321. else
  322. {
  323. CONSOLE_LOGSTRINGLINE("<-<-<-<-<- Packet Analysis <-<-<-<-<-");
  324. }
  325. }
  326. #endif
  327. /*****************************************************************************
  328. * Exposed Logging APIs
  329. *****************************************************************************/
  330. /**
  331. * Logs a New Line
  332. */
  333. void Util_NewLine(uint32_t PdwUartPort)
  334. {
  335. uint8_t rgbcrlf [2] = {0x0D, 0x0A};
  336. //lint --e{534} The return value is not used*/
  337. pfWriter(PdwUartPort, rgbcrlf, 2);
  338. }
  339. /**
  340. * Logs a string with new line
  341. */
  342. void Util_LogStringLine(uint32_t PdwUartPort, const char_t *pszString)
  343. {
  344. if(pszString == NULL)
  345. {
  346. return;
  347. }
  348. //lint --e{534} The return value is not used*/
  349. pfWriter(PdwUartPort, (uint8_t *)pszString, strlen(pszString));
  350. Util_NewLine(PdwUartPort);
  351. }
  352. /**
  353. * Logs a string
  354. */
  355. void Util_LogString(uint32_t PdwUartPort, const char_t *PpszString)
  356. {
  357. if(PpszString == NULL)
  358. {
  359. return;
  360. }
  361. //lint --e{534} The return value is not used*/
  362. pfWriter(PdwUartPort, (uint8_t *)PpszString, strlen(PpszString));
  363. }
  364. #ifdef ENABLE_LOG
  365. /**
  366. * Logs a byte array
  367. */
  368. void Util_LogArray(uint8_t* prgbBuf, uint16_t wLen, bool_t fDirection, bool_t fDumpPacketAnalysis)
  369. {
  370. char_t szTemp[50];
  371. if(prgbBuf == NULL)
  372. {
  373. return;
  374. }
  375. memset(szTemp,0, 50);
  376. GetSystemDateTime(szTemp);
  377. //lint --e{534} The return value is not used*/
  378. pfWriter(CONSOLE_PORT, (uint8_t*)szTemp, strlen(szTemp));
  379. //lint --e{534} The return value is not used*/
  380. pfWriter(CONSOLE_PORT, (uint8_t*)" ", 1);
  381. if(fDirection == TX_DIRECTION)
  382. {
  383. //lint --e{534} The return value is not used*/
  384. pfWriter(CONSOLE_PORT, (uint8_t*)">> ", 4);
  385. }
  386. else
  387. {
  388. //lint --e{534} The return value is not used*/
  389. pfWriter(CONSOLE_PORT, (uint8_t*)"<< ", 4);
  390. }
  391. Util_DumpHex(prgbBuf, wLen);
  392. Util_NewLine(CONSOLE_PORT);
  393. if(fDumpPacketAnalysis)
  394. {
  395. DumpPacketAnalysis(prgbBuf, wLen, fDirection);
  396. }
  397. return;
  398. }
  399. #endif
  400. /**
  401. * Logs a four byte value
  402. */
  403. void Util_LogInt(uint32_t PdwUartPort, const char_t *pszMsg, uint32_t dwValue)
  404. {
  405. uint8_t rgbString [12] = {0};
  406. if(pszMsg == NULL)
  407. {
  408. return;
  409. }
  410. Util_LogString(PdwUartPort, pszMsg);
  411. Util_LogString(PdwUartPort, " 0x");
  412. ConvUint32ToHexString((uint32_t)dwValue, rgbString);
  413. Util_LogString(PdwUartPort, (char_t*)rgbString);
  414. Util_LogString(PdwUartPort, "(");
  415. ConvUint32ToDecString((uint32_t)dwValue, rgbString, 0, '0');
  416. Util_LogString(PdwUartPort, (char_t*)rgbString);
  417. Util_LogStringLine(PdwUartPort, ")");
  418. }
  419. /**
  420. * Logs an array in hex format
  421. */
  422. void Util_DumpHex(uint8_t* prgbBuf, uint16_t wLen)
  423. {
  424. uint16_t wIndex;
  425. uint8_t rgbHexString[5];
  426. if(prgbBuf == NULL)
  427. {
  428. return;
  429. }
  430. for(wIndex = 0; wIndex < wLen; wIndex++)
  431. {
  432. ConvUint8ToHexString ((uint8_t*)(prgbBuf+wIndex), rgbHexString, 1, 1);
  433. //lint --e{534} The return value is not used*/
  434. pfWriter(CONSOLE_PORT, rgbHexString, 3);
  435. }
  436. }
  437. /*****************************************************************************
  438. * Level based logging Exposed APIs
  439. *****************************************************************************/
  440. /// @endcond
  441. #ifdef ENABLE_LOG
  442. //This is second log writer
  443. pFWriteData2 pfWriter2 = NULL;
  444. //This is the arguement to be passed to pfWriter.It refers to the handle to writer context/structure.
  445. void* pHandle = NULL;
  446. //Stores the level of Logging
  447. static uint32_t dwLevelEnabler = (uint32_t)((1<<eInfo)|(1<<eWarning)|(1<<eError));
  448. //Store the layer type of Logging
  449. static uint32_t dwLayerEnabler = 0;
  450. /**
  451. * \brief This structure contains Logging information
  452. */
  453. typedef struct sLogMessage {
  454. ///Message to be logged
  455. char_t* pzStringMessage;
  456. ///Message Type
  457. eLogLayer eLogMsgLayer;
  458. ///Message Level
  459. eLogLevel eLogMsgLevel;
  460. }sLogMessage;
  461. /**
  462. * Sets the state of the Logging Level.
  463. *
  464. * \param[in] eLevel Logging Level
  465. * \param[in] eValue Set value
  466. */
  467. void Util_SetLogLevelState(eLogLevel PeLevel,eSetState PeValue)
  468. {
  469. //Validate Level
  470. if((eInfo <= PeLevel)&&(eError >= PeLevel))
  471. {
  472. switch(PeValue)
  473. {
  474. case eEnable:
  475. {
  476. dwLevelEnabler |= (uint32_t)(1<<PeLevel);
  477. break;
  478. }
  479. case eDisable:
  480. {
  481. dwLevelEnabler &= (uint32_t)(~(1<<PeLevel));
  482. break;
  483. }
  484. case eInvalid:
  485. default:
  486. break;
  487. }
  488. }
  489. }
  490. /**
  491. * Returns the current state of Logging level.
  492. *
  493. * \param[in] eLevel Logging Level
  494. *
  495. * \retval #eSetState
  496. */
  497. eSetState Util_GetLogLevelState(eLogLevel PeLevel)
  498. {
  499. //Validate Level
  500. if((eInfo <= PeLevel)&&(eError >= PeLevel))
  501. return (((dwLevelEnabler)&(1<<PeLevel))?eEnable:eDisable);
  502. else
  503. return eInvalid;
  504. }
  505. /**
  506. * Sets the state of the Logging Layer.
  507. *
  508. * \param[in] eLayer Logging Layer
  509. * \param[in] eValue Set value
  510. */
  511. void Util_SetLogLayerState(eLogLayer PeLayer,eSetState PeValue)
  512. {
  513. //Validate Layer
  514. if((eHS <= PeLayer)&&(eTL >= PeLayer))
  515. {
  516. switch(PeValue)
  517. {
  518. case eEnable:
  519. {
  520. dwLayerEnabler |= (uint32_t)(1<<PeLayer);
  521. break;
  522. }
  523. case eDisable:
  524. {
  525. dwLayerEnabler &= (uint32_t)(~(1<<PeLayer));
  526. break;
  527. }
  528. case eInvalid:
  529. default:
  530. break;
  531. }
  532. }
  533. }
  534. /**
  535. * Returns the current state of the Logging Layer.
  536. *
  537. * \param[in] eLayer Logging Level
  538. *
  539. * \retval #eSetState
  540. */
  541. eSetState Util_GetLogLayerState(eLogLayer PeLayer)
  542. {
  543. //Validate Layer
  544. if((eHS <= PeLayer)&&(eTL >= PeLayer))
  545. return (((dwLayerEnabler)&(1<<PeLayer))?eEnable:eDisable);
  546. else
  547. return eInvalid;
  548. }
  549. /**
  550. * Sets the Log Writer and handle.
  551. *
  552. * \param[in] pWriter function pointer to pFWriteData2
  553. * \param[in] pHdl Handle to writer context/structure
  554. *
  555. */
  556. void Util_SetLogWriter(pFWriteData2 pWriter,void* pHdl)
  557. {
  558. pfWriter2 = pWriter;
  559. pHandle = pHdl;
  560. }
  561. /**
  562. * \brief Logs a message.
  563. */
  564. static void Util_WriteMessage(sLogMessage* psLogMessage)
  565. {
  566. char_t charBuffer[103];
  567. char timeString[9]; // space for "HH:MM:SS\0"
  568. char_t* szMsgLevel[eError] = {LOGGER_LEVEL_INFO,
  569. LOGGER_LEVEL_WARNING,
  570. LOGGER_LEVEL_ERROR};
  571. char_t* szMsgType[eTL] = {LOGGER_TYPE_HANDSHAKE,
  572. LOGGER_TYPE_RECORDLAYER,
  573. LOGGER_TYPE_TRANSPORTLAYER};
  574. GetSystemDateTime(timeString);
  575. #ifndef WIN32
  576. sprintf(charBuffer,LOG_FORMAT,timeString,szMsgLevel[psLogMessage->eLogMsgLevel -1 ],
  577. szMsgType[psLogMessage->eLogMsgLayer -1 ],psLogMessage->pzStringMessage,"\n");
  578. #else
  579. sprintf_s(charBuffer,103,LOG_FORMAT,timeString,szMsgLevel[psLogMessage->eLogMsgLevel -1 ],
  580. szMsgType[psLogMessage->eLogMsgLayer -1 ],psLogMessage->pzStringMessage,"\n");
  581. #endif
  582. pfWriter2(pHandle,(uint8_t*)charBuffer,strlen(charBuffer));
  583. }
  584. /**
  585. * Logs a message with type and level information and content of the buffer.
  586. * Currently the message cannot be greater than 80 bytes.This will be upgraded in future
  587. *
  588. * \param[in] pzMsg Message to be logged
  589. * \param[in] eLayer Logging Layer
  590. * \param[in] eLevel Logging Level
  591. * \param[in] PrgbBuffer Pointer to the buffer to be logged
  592. * \param[in] wLen Length message to be logged
  593. *
  594. */
  595. void Util_LogMsgArray(char* pzMsg, uint8_t* PrgbBuffer, uint16_t wLen, eLogLayer eLayer, eLogLevel eLevel)
  596. {
  597. sLogMessage sLogMes;
  598. uint16_t wCount = wLen;
  599. uint8_t bBytes = 25;
  600. uint8_t * prgbbuf = PrgbBuffer;
  601. eSetState eCurrentState = Util_GetLogLevelState(eLevel);
  602. uint8_t rgbHexString[100];
  603. do
  604. {
  605. if((NULL==pHandle)||(NULL ==pfWriter2) || (eEnable != eCurrentState) || (PrgbBuffer == NULL))
  606. {
  607. break;
  608. }
  609. sLogMes.eLogMsgLevel = eLevel;
  610. sLogMes.eLogMsgLayer = eLayer;
  611. sLogMes.pzStringMessage = pzMsg;
  612. Util_WriteMessage(&sLogMes);
  613. while(wCount > 0)
  614. {
  615. if(wCount < 25)
  616. {
  617. bBytes = (uint8_t)wCount;
  618. }
  619. ConvUint8ToHexString ((uint8_t*)(prgbbuf), rgbHexString, bBytes, 1);
  620. pfWriter2(pHandle, rgbHexString, (bBytes*3));
  621. prgbbuf+= bBytes;
  622. wCount-=bBytes;
  623. }
  624. pfWriter2(pHandle, (uint8_t *)"\n", 1);
  625. }while (0);
  626. }
  627. /**
  628. * Logs a message with type and level information.
  629. * Currently the message cannot be greater than 80 bytes.This will be upgraded in future
  630. *
  631. * \param[in] pzMsg Message to be logged
  632. * \param[in] eLayer Logging Layer
  633. * \param[in] eLevel Logging Level
  634. *
  635. */
  636. void Util_LogMessage(char* pzMsg, eLogLayer eLayer, eLogLevel eLevel)
  637. {
  638. sLogMessage sLogMes;
  639. eSetState eCurrentState = Util_GetLogLevelState(eLevel);
  640. do
  641. {
  642. if((NULL==pHandle)||(NULL ==pfWriter2) || (eEnable != eCurrentState))
  643. {
  644. break;
  645. }
  646. sLogMes.eLogMsgLevel = eLevel;
  647. sLogMes.eLogMsgLayer = eLayer;
  648. sLogMes.pzStringMessage = pzMsg;
  649. Util_WriteMessage(&sLogMes);
  650. }while (0);
  651. }
  652. /**
  653. * Logs a 4 byte debug value with type and level information.
  654. *
  655. * Currently the message cannot be greater than 80 bytes.This will be upgraded in future
  656. * \param[in] dwDBValue 4 byte value to be logged
  657. * \param[in] eLayer Logging Layer
  658. * \param[in] eLevel Logging Level
  659. *
  660. */
  661. void Util_LogDebugVal(uint32_t dwDBValue, eLogLayer eLayer, eLogLevel eLevel)
  662. {
  663. uint8_t rgbString [12];
  664. if((NULL!=pHandle)&&(NULL !=pfWriter2))
  665. {
  666. ConvUint32ToHexString(dwDBValue, rgbString);
  667. Util_LogMessage((char_t*)rgbString,eLayer,eLevel);
  668. }
  669. }
  670. #endif //#ENABLE_LOG
  671. /**
  672. * @}
  673. */