-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于打印数据的调试问题 #29
Comments
不会添加代码,好尴尬啊 |
嗯嗯 是这个功能 easylogger 里没找到这个函数啊 |
EasyLogger 还不支持这个功能。我把 ulog 的这个功能贴出来,你方便改造一下,好用以后,提个 pr 吗 :) /**
* dump the hex format data to log
*
* @param name name for hex object, it will show on log header
* @param width hex number for every line, such as: 16, 32
* @param buf hex buffer
* @param size buffer size
*/
void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t size)
{
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
rt_size_t i, j;
rt_size_t log_len = 0;
char *log_buf = NULL, dump_string[8];
int fmt_result;
RT_ASSERT(ulog.init_ok);
/* get log buffer */
log_buf = get_log_buf();
/* lock output */
output_lock();
for (i = 0, log_len = 0; i < size; i += width)
{
/* package header */
fmt_result = rt_snprintf(log_buf, ULOG_LINE_BUF_SIZE, "D/HEX %s: %04X-%04X: ", name, i, i + width);
/* calculate log length */
if ((fmt_result > -1) && (fmt_result <= ULOG_LINE_BUF_SIZE))
{
log_len = fmt_result;
}
else
{
log_len = ULOG_LINE_BUF_SIZE;
}
/* dump hex */
for (j = 0; j < width; j++)
{
if (i + j < size)
{
rt_snprintf(dump_string, sizeof(dump_string), "%02X ", buf[i + j]);
}
else
{
rt_strncpy(dump_string, " ", sizeof(dump_string));
}
log_len += ulog_strcpy(log_len, log_buf + log_len, dump_string);
if ((j + 1) % 8 == 0)
{
log_len += ulog_strcpy(log_len, log_buf + log_len, " ");
}
}
log_len += ulog_strcpy(log_len, log_buf + log_len, " ");
/* dump char for hex */
for (j = 0; j < width; j++)
{
if (i + j < size)
{
rt_snprintf(dump_string, sizeof(dump_string), "%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
log_len += ulog_strcpy(log_len, log_buf + log_len, dump_string);
}
}
/* overflow check and reserve some space for newline sign */
if (log_len + rt_strlen(ULOG_NEWLINE_SIGN) > ULOG_LINE_BUF_SIZE)
{
log_len = ULOG_LINE_BUF_SIZE - rt_strlen(ULOG_NEWLINE_SIGN);
}
/* package newline sign */
log_len += ulog_strcpy(log_len, log_buf + log_len, ULOG_NEWLINE_SIGN);
/* do log output */
do_output(LOG_LVL_DBG, NULL, RT_TRUE, log_buf, log_len);
}
/* unlock output */
output_unlock();
} |
可以的 |
ulog 哪个的 开源吗? 看类型定义应给是rtthread的? 我怎么没找到 |
很快会开源出来,可以关注下 RT-Thread 公众号 |
ok |
ulog 已经开源出来了,你可以对比看下哈 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在调试过程中,很多时候会遇到打印一个数组的每个元素。比如串口调试时,可能会打印接收或者发送数组中的每个数据。
我现在的做法是:
`
for(uint16_t i = 0; i < len; i++){
}
elog_raw("\r\n");
但这样会造成打印繁琐问题,而且在关闭打印之后,for循环会空跑一圈,造成时间浪费。 我现在的想法是:
void elog_buff(char *type,char *pbuff,uint8_t len)
{
}
`
不知道大伙感觉这个方法怎么样?
The text was updated successfully, but these errors were encountered: