1 /** @file 2 * @brief Bluetooth subsystem logging helpers. 3 */ 4 5 /* 6 * Copyright (c) 2017 Nordic Semiconductor ASA 7 * Copyright (c) 2015-2016 Intel Corporation 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 #ifndef __BT_LOG_H 12 #define __BT_LOG_H 13 14 #include <ble_os.h> 15 16 #include <bluetooth/bluetooth.h> 17 #include <bluetooth/uuid.h> 18 #include <bluetooth/hci.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #if !defined(BT_DBG_ENABLED) 25 #define BT_DBG_ENABLED 1 26 #endif 27 28 #if defined(CONFIG_BT_DEBUG_LOG) 29 30 #if !defined(SYS_LOG_DOMAIN) 31 #define SYS_LOG_DOMAIN "bt" 32 #endif 33 #define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG 34 35 #define BT_DBG(fmt, ...) \ 36 if (BT_DBG_ENABLED) { \ 37 SYS_LOG_DBG("(%p) " fmt, k_current_get(), \ 38 ##__VA_ARGS__); \ 39 } 40 41 #define BT_ERR(fmt, ...) SYS_LOG_ERR(fmt, ##__VA_ARGS__) 42 #define BT_WARN(fmt, ...) SYS_LOG_WRN(fmt, ##__VA_ARGS__) 43 #define BT_INFO(fmt, ...) SYS_LOG_INF(fmt, ##__VA_ARGS__) 44 45 /* Enabling debug increases stack size requirement considerably */ 46 #define BT_STACK_DEBUG_EXTRA 300 47 #else 48 #include <ulog/ulog.h> 49 50 #define BT_DBG(fmt, ...) \ 51 if (BT_DBG_ENABLED) { \ 52 LOGD("[DBG]",fmt"\n", ##__VA_ARGS__); \ 53 } 54 #define BT_ERR(fmt, ...) LOGE("[ERR]",fmt"\n", ##__VA_ARGS__) 55 #define BT_WARN(fmt, ...) LOGW("[WARN]",fmt"\n", ##__VA_ARGS__) 56 #define BT_INFO(fmt, ...) LOGI("[INFO]",fmt"\n", ##__VA_ARGS__) 57 58 #define BT_STACK_DEBUG_EXTRA 0 59 60 #endif 61 62 #define BT_ASSERT(cond) if (!(cond)) { \ 63 BT_ERR("assert: '" #cond "' failed"); \ 64 k_oops(); \ 65 } 66 #define BT_ASSERT_MSG(cond, fmt, ...) if (!(cond)) { \ 67 BT_ERR(fmt, ##__VA_ARGS__); \ 68 BT_ERR("assert: '" #cond "' failed"); \ 69 k_oops(); \ 70 } 71 72 #define BT_HEXDUMP_DBG(_data, _length, _str) \ 73 aos_log_hexdump(_str, (char *)_data, _length) 74 75 /* NOTE: These helper functions always encodes into the same buffer storage. 76 * It is the responsibility of the user of this function to copy the information 77 * in this string if needed. 78 * 79 * NOTE: These functions are not thread-safe! 80 */ 81 const char *bt_hex_real(const void *buf, size_t len); 82 const char *bt_addr_str_real(const bt_addr_t *addr); 83 const char *bt_addr_le_str_real(const bt_addr_le_t *addr); 84 const char *bt_uuid_str_real(const struct bt_uuid *uuid); 85 86 /* NOTE: log_strdup does not guarantee a duplication of the string. 87 * It is therefore still the responsibility of the user to handle the 88 * restrictions in the underlying function call. 89 */ 90 #define bt_hex(buf, len) log_strdup(bt_hex_real(buf, len)) 91 #define bt_addr_str(addr) log_strdup(bt_addr_str_real(addr)) 92 #define bt_addr_le_str(addr) log_strdup(bt_addr_le_str_real(addr)) 93 #define bt_uuid_str(uuid) log_strdup(bt_uuid_str_real(uuid)) 94 95 void hextostring(const uint8_t *source, char *dest, int len); 96 u8_t stringtohex(char *str, u8_t *out, u8_t count); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 102 #endif /* __BT_LOG_H */ 103