176 lines
3.2 KiB
C
176 lines
3.2 KiB
C
#include "log.h"
|
|
#include "uthash/libut.h"
|
|
#include "esp_common.h"
|
|
#include "apps/sntp.h"
|
|
#include "apps/time.h"
|
|
#include "apps/sntp_time.h"
|
|
#include "cfg.h"
|
|
#include "user_config.h"
|
|
#include "uart.h"
|
|
|
|
static const char hex_asc[] = "0123456789abcdef";
|
|
|
|
char* SysBin2HexStr(char *p, const unsigned char *cp, int count)
|
|
{
|
|
while (count) {
|
|
unsigned char c = *cp++;
|
|
/* put lowercase hex digits */
|
|
*p++ = 0x20 | hex_asc[c >> 4];
|
|
*p++ = 0x20 | hex_asc[c & 0xf];
|
|
count--;
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
void IHW_LOG_BUF(LOG_LEVEL level, const char* pPrefix, unsigned char* pBuf, int iSize)
|
|
{
|
|
int k, j, i = 1;
|
|
char ascString[20];
|
|
char strChar[4];
|
|
|
|
if(pPrefix)
|
|
{
|
|
os_printf("%s_%04X: ", pPrefix, i - 1);
|
|
}
|
|
|
|
memset(ascString, 0 , 20);
|
|
|
|
for(; i <= iSize; i++)
|
|
{
|
|
os_printf("%02X ", pBuf[i - 1]);
|
|
|
|
if(isprint(pBuf[i - 1]))
|
|
{
|
|
memset(strChar, 0, 4);
|
|
sprintf(strChar, "%c", pBuf[i - 1]);
|
|
strcat(ascString, strChar);
|
|
}
|
|
else
|
|
{
|
|
strcat(ascString, ".");
|
|
}
|
|
|
|
if(i % 8 == 0 && i % 16 != 0)
|
|
{
|
|
os_printf(" ");
|
|
strcat(ascString, " ");
|
|
}
|
|
else if(i % 16 == 0)
|
|
{
|
|
os_printf(" %s\n", ascString);
|
|
if(pPrefix && i < iSize)
|
|
{
|
|
os_printf("%s_%04X: ", pPrefix, i - 1);
|
|
}
|
|
|
|
memset(ascString, 0, 20);
|
|
}
|
|
}
|
|
|
|
j = (i - 1) % 16;
|
|
k = j;
|
|
if(j != 0)
|
|
{
|
|
for(; j < 16; j++)
|
|
{
|
|
os_printf(" ");
|
|
|
|
if(j % 8 == 0 && k != 8)
|
|
{
|
|
os_printf(" ");
|
|
strcat(ascString, " ");
|
|
}
|
|
}
|
|
|
|
os_printf(" %s", ascString);
|
|
}
|
|
|
|
os_printf("\n");
|
|
}
|
|
|
|
/**
|
|
* @brief Log 调试等级转字符串
|
|
* @param level 调试等级
|
|
* @return 调试等级对应的字符串
|
|
*/
|
|
const char* LogLevelToStr(LOG_LEVEL level)
|
|
{
|
|
switch(level)
|
|
{
|
|
case LOG_Test:
|
|
return "T";
|
|
|
|
case LOG_Info:
|
|
return "I";
|
|
|
|
case LOG_Call:
|
|
return "C";
|
|
|
|
case LOG_Debug:
|
|
return "D";
|
|
|
|
case LOG_Warn:
|
|
return "W";
|
|
|
|
case LOG_Error:
|
|
return "E";
|
|
|
|
case LOG_Fatal:
|
|
return "F";
|
|
|
|
case LOG_Step:
|
|
return "S";
|
|
|
|
case LOG_Devp:
|
|
return "V";
|
|
|
|
case LOG_Unknown:
|
|
return "U";
|
|
|
|
case LOG_All:
|
|
return "A";
|
|
|
|
default:
|
|
return "?";
|
|
}
|
|
|
|
return "U";
|
|
}
|
|
|
|
/**
|
|
* @brief 输出调试信息
|
|
* @param cFlag 调试信息开关
|
|
* @param pMsg 调试信息内容
|
|
*/
|
|
void IHW_LOG(LOG_LEVEL level, const char* pMsg, ...)
|
|
{
|
|
UT_string* pLogContent = NULL;
|
|
va_list arg_ptr;
|
|
volatile unsigned int tick = xTaskGetTickCount();
|
|
|
|
utstring_new(pLogContent);
|
|
va_start(arg_ptr, pMsg);
|
|
utstring_printf_va(pLogContent, pMsg, arg_ptr);
|
|
va_end(arg_ptr);
|
|
|
|
os_printf("[%08u.%03u] [%s] %s", tick / 100, (tick % 100) * 10, LogLevelToStr(level), utstring_body(pLogContent));
|
|
|
|
utstring_free(pLogContent);
|
|
}
|
|
|
|
void IHW_LOG_RAW(LOG_LEVEL level, const char* pMsg, ...)
|
|
{
|
|
UT_string* pLogContent = NULL;
|
|
va_list arg_ptr;
|
|
|
|
utstring_new(pLogContent);
|
|
va_start(arg_ptr, pMsg);
|
|
utstring_printf_va(pLogContent, pMsg, arg_ptr);
|
|
va_end(arg_ptr);
|
|
|
|
os_printf("%s", utstring_body(pLogContent));
|
|
|
|
utstring_free(pLogContent);
|
|
}
|