Logger.c 20 KB

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