Bluetooth: Convert string helpers to use log_strdup
This reduces the multiple buffer requirement to a single buffer. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
251d99132d
commit
cd4cf4e580
3 changed files with 16 additions and 45 deletions
|
@ -1,8 +1,8 @@
|
|||
zephyr_library()
|
||||
|
||||
zephyr_library_sources(dummy.c)
|
||||
zephyr_library_sources(log.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_DEBUG log.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_RPA rpa.c)
|
||||
|
||||
zephyr_library_link_libraries(subsys__bluetooth)
|
||||
|
|
|
@ -19,23 +19,14 @@
|
|||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
#if defined(CONFIG_BT_DEBUG)
|
||||
const char *bt_hex(const void *buf, size_t len)
|
||||
const char *bt_hex_real(const void *buf, size_t len)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
static char hexbufs[4][129];
|
||||
static u8_t curbuf;
|
||||
static char str[129];
|
||||
const u8_t *b = buf;
|
||||
unsigned int mask;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
mask = irq_lock();
|
||||
str = hexbufs[curbuf++];
|
||||
curbuf %= ARRAY_SIZE(hexbufs);
|
||||
irq_unlock(mask);
|
||||
|
||||
len = min(len, (sizeof(hexbufs[0]) - 1) / 2);
|
||||
len = min(len, (sizeof(hex) - 1) / 2);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i * 2] = hex[b[i] >> 4];
|
||||
|
@ -47,38 +38,20 @@ const char *bt_hex(const void *buf, size_t len)
|
|||
return str;
|
||||
}
|
||||
|
||||
const char *bt_addr_str(const bt_addr_t *addr)
|
||||
const char *bt_addr_str_real(const bt_addr_t *addr)
|
||||
{
|
||||
static char bufs[4][BT_ADDR_STR_LEN];
|
||||
unsigned int mask;
|
||||
static u8_t cur;
|
||||
char *str;
|
||||
static char str[BT_ADDR_STR_LEN];
|
||||
|
||||
mask = irq_lock();
|
||||
str = bufs[cur++];
|
||||
cur %= ARRAY_SIZE(bufs);
|
||||
irq_unlock(mask);
|
||||
|
||||
bt_addr_to_str(addr, str, sizeof(bufs[cur]));
|
||||
bt_addr_to_str(addr, str, sizeof(str));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
const char *bt_addr_le_str(const bt_addr_le_t *addr)
|
||||
const char *bt_addr_le_str_real(const bt_addr_le_t *addr)
|
||||
{
|
||||
static char bufs[8][BT_ADDR_LE_STR_LEN];
|
||||
unsigned int mask;
|
||||
static u8_t cur;
|
||||
char *str;
|
||||
static char str[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
mask = irq_lock();
|
||||
str = bufs[cur++];
|
||||
cur %= ARRAY_SIZE(bufs);
|
||||
irq_unlock(mask);
|
||||
|
||||
bt_addr_le_to_str(addr, str, sizeof(bufs[cur]));
|
||||
bt_addr_le_to_str(addr, str, sizeof(str));
|
||||
|
||||
return str;
|
||||
}
|
||||
#endif /* CONFIG_BT_DEBUG */
|
||||
|
||||
|
|
|
@ -92,15 +92,13 @@ static inline __printf_like(1, 2) void _bt_log_dummy(const char *fmt, ...) {};
|
|||
k_oops(); \
|
||||
}
|
||||
|
||||
/* This helper is only available when BT_DEBUG is enabled */
|
||||
const char *bt_hex(const void *buf, size_t len);
|
||||
|
||||
/* These helpers are only safe to be called from internal threads as they're
|
||||
* not multi-threading safe
|
||||
*/
|
||||
const char *bt_addr_str(const bt_addr_t *addr);
|
||||
const char *bt_addr_le_str(const bt_addr_le_t *addr);
|
||||
const char *bt_hex_real(const void *buf, size_t len);
|
||||
const char *bt_addr_str_real(const bt_addr_t *addr);
|
||||
const char *bt_addr_le_str_real(const bt_addr_le_t *addr);
|
||||
|
||||
#define bt_hex(buf, len) log_strdup(bt_hex_real(buf, len))
|
||||
#define bt_addr_str(addr) log_strdup(bt_addr_str_real(addr))
|
||||
#define bt_addr_le_str(addr) log_strdup(bt_addr_le_str_real(addr))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue