2018-07-25 17:31:05 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-07-25 17:31:05 +08:00
|
|
|
*
|
2018-10-12 16:02:20 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-07-25 17:31:05 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-04-14 chenyong first version
|
2023-06-10 11:40:37 +08:00
|
|
|
* 2023-06-09 CX optimize at_vprintfln interface
|
2018-07-25 17:31:05 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <at.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dump hex format data to console device
|
|
|
|
*
|
|
|
|
* @param name name for hex object, it will show on log header
|
|
|
|
* @param buf hex buffer
|
|
|
|
* @param size buffer size
|
|
|
|
*/
|
|
|
|
void at_print_raw_cmd(const char *name, const char *buf, rt_size_t size)
|
|
|
|
{
|
|
|
|
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
|
|
|
|
#define WIDTH_SIZE 32
|
|
|
|
|
|
|
|
rt_size_t i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i += WIDTH_SIZE)
|
|
|
|
{
|
|
|
|
rt_kprintf("[D/AT] %s: %04X-%04X: ", name, i, i + WIDTH_SIZE);
|
|
|
|
for (j = 0; j < WIDTH_SIZE; j++)
|
|
|
|
{
|
|
|
|
if (i + j < size)
|
|
|
|
{
|
2022-10-18 15:51:40 +08:00
|
|
|
rt_kprintf("%02X ", (unsigned char)buf[i + j]);
|
2018-07-25 17:31:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf(" ");
|
|
|
|
}
|
|
|
|
if ((j + 1) % 8 == 0)
|
|
|
|
{
|
|
|
|
rt_kprintf(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rt_kprintf(" ");
|
|
|
|
for (j = 0; j < WIDTH_SIZE; j++)
|
|
|
|
{
|
|
|
|
if (i + j < size)
|
|
|
|
{
|
|
|
|
rt_kprintf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rt_kprintf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 13:12:03 -05:00
|
|
|
rt_weak rt_size_t at_utils_send(rt_device_t dev,
|
2021-07-08 12:02:29 +08:00
|
|
|
rt_off_t pos,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size)
|
|
|
|
{
|
|
|
|
return rt_device_write(dev, pos, buffer, size);
|
|
|
|
}
|
|
|
|
|
2023-09-22 17:34:26 +08:00
|
|
|
rt_size_t at_vprintf(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
|
2018-07-25 17:31:05 +08:00
|
|
|
{
|
2023-09-22 17:34:26 +08:00
|
|
|
rt_size_t len = vsnprintf(send_buf, buf_size, format, args);
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-25 17:31:05 +08:00
|
|
|
|
|
|
|
#ifdef AT_PRINT_RAW_CMD
|
2023-09-22 17:34:26 +08:00
|
|
|
at_print_raw_cmd("sendline", send_buf, len);
|
2018-07-25 17:31:05 +08:00
|
|
|
#endif
|
|
|
|
|
2023-09-22 17:34:26 +08:00
|
|
|
return at_utils_send(device, 0, send_buf, len);
|
2018-07-25 17:31:05 +08:00
|
|
|
}
|
|
|
|
|
2023-09-22 17:34:26 +08:00
|
|
|
rt_size_t at_vprintfln(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
|
2018-07-25 17:31:05 +08:00
|
|
|
{
|
2023-09-22 17:34:26 +08:00
|
|
|
rt_size_t len = vsnprintf(send_buf, buf_size - 2, format, args);
|
|
|
|
if (len == 0)
|
2023-06-10 11:40:37 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-22 17:34:26 +08:00
|
|
|
send_buf[len++] = '\r';
|
|
|
|
send_buf[len++] = '\n';
|
2018-07-25 17:31:05 +08:00
|
|
|
|
2021-07-07 23:49:42 +08:00
|
|
|
#ifdef AT_PRINT_RAW_CMD
|
|
|
|
at_print_raw_cmd("sendline", send_buf, len);
|
|
|
|
#endif
|
|
|
|
|
2021-07-08 12:02:29 +08:00
|
|
|
return at_utils_send(device, 0, send_buf, len);
|
2018-07-25 17:31:05 +08:00
|
|
|
}
|