mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
feat(ble_mesh): add ext log initialization functions
(cherry picked from commit 7b7b9de28d)
Co-authored-by: luoxu <luoxu@espressif.com>
This commit is contained in:
@@ -211,11 +211,6 @@ void bt_mesh_ext_mem_swap(void *buf, size_t length)
|
||||
sys_mem_swap(buf, length);
|
||||
}
|
||||
|
||||
uint32_t bt_mesh_ext_log_timestamp(void)
|
||||
{
|
||||
return esp_log_timestamp();
|
||||
}
|
||||
|
||||
/* Net buf */
|
||||
void bt_mesh_ext_buf_simple_init(struct net_buf_simple *buf, size_t reserve_head)
|
||||
{
|
||||
@@ -4006,8 +4001,6 @@ void bt_mesh_ext_mbt_server_cb_evt_to_btc(uint8_t event, void *model, void *ctx)
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint64_t config_ble_mesh_stack_trace_level : 3;
|
||||
|
||||
uint64_t config_ble_mesh_use_ble_50: 1;
|
||||
uint64_t config_ble_mesh_use_duplicate_scan : 1;
|
||||
uint64_t config_ble_mesh_pb_adv : 1;
|
||||
@@ -4172,8 +4165,6 @@ typedef struct {
|
||||
} bt_mesh_ext_config_t;
|
||||
|
||||
static const bt_mesh_ext_config_t bt_mesh_ext_cfg = {
|
||||
.config_ble_mesh_stack_trace_level = BLE_MESH_LOG_LEVEL,
|
||||
|
||||
.config_ble_mesh_use_ble_50 = IS_ENABLED(CONFIG_BLE_MESH_USE_BLE_50),
|
||||
.config_ble_mesh_use_duplicate_scan = IS_ENABLED(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN),
|
||||
.config_ble_mesh_pb_adv = IS_ENABLED(CONFIG_BLE_MESH_PB_ADV),
|
||||
@@ -4963,6 +4954,106 @@ static const bt_mesh_ext_funcs_t bt_mesh_ext_func = {
|
||||
/* CONFIG_BLE_MESH_MBT_SRV */
|
||||
};
|
||||
|
||||
#define BLE_MESH_LIB_TRACE_TAG "BLE_MESH(lib)"
|
||||
#define BLE_MESH_LOG_FORMAT_START(level) LOG_COLOR_ ## level #level " (%" PRIu32 ") %s: "
|
||||
#define BLE_MESH_LOG_FORMAT_END LOG_RESET_COLOR "\n"
|
||||
|
||||
void bt_mesh_lib_log_error(const char *format, ...)
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_NO_LOG ||\
|
||||
/* Disable log output when compressed logging
|
||||
* is enabled but ERR logs are not preserved */\
|
||||
(CONFIG_BLE_MESH_STACK_ERR_LOG_COMPRESSION &&\
|
||||
!CONFIG_BLE_MESH_STACK_ERR_LOG_PRESERVE))
|
||||
return;
|
||||
#else
|
||||
if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) &&
|
||||
BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, ERROR)) {
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
esp_log_write(ESP_LOG_ERROR, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_START(E), esp_log_timestamp(), BLE_MESH_LIB_TRACE_TAG);
|
||||
esp_log_writev(ESP_LOG_ERROR, BLE_MESH_LIB_TRACE_TAG, format, args);
|
||||
esp_log_write(ESP_LOG_ERROR, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_END);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_lib_log_warn(const char *format, ...)
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_NO_LOG ||\
|
||||
/* Disable log output when compressed logging
|
||||
* is enabled but WARN logs are not preserved */\
|
||||
(CONFIG_BLE_MESH_STACK_WARN_LOG_COMPRESSION &&\
|
||||
!CONFIG_BLE_MESH_STACK_WARN_LOG_PRESERVE))
|
||||
return;
|
||||
#else
|
||||
if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) &&
|
||||
BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, WARN)) {
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
esp_log_write(ESP_LOG_WARN, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_START(W), esp_log_timestamp(), BLE_MESH_LIB_TRACE_TAG);
|
||||
esp_log_writev(ESP_LOG_WARN, BLE_MESH_LIB_TRACE_TAG, format, args);
|
||||
esp_log_write(ESP_LOG_WARN, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_END);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_lib_log_info(const char *format, ...)
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_NO_LOG ||\
|
||||
/* Disable log output when compressed logging
|
||||
* is enabled but INFO logs are not preserved */\
|
||||
(CONFIG_BLE_MESH_STACK_INFO_LOG_COMPRESSION &&\
|
||||
!CONFIG_BLE_MESH_STACK_INFO_LOG_PRESERVE))
|
||||
return;
|
||||
#else
|
||||
if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) &&
|
||||
BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, INFO)) {
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
esp_log_write(ESP_LOG_INFO, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_START(I), esp_log_timestamp(), BLE_MESH_LIB_TRACE_TAG);
|
||||
esp_log_writev(ESP_LOG_INFO, BLE_MESH_LIB_TRACE_TAG, format, args);
|
||||
esp_log_write(ESP_LOG_INFO, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_END);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_lib_log_debug(const char *format, ...)
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_NO_LOG ||\
|
||||
/* Disable log output when compressed logging
|
||||
* is enabled but DEBUG logs are not preserved */\
|
||||
(CONFIG_BLE_MESH_STACK_DEBUG_LOG_COMPRESSION &&\
|
||||
!CONFIG_BLE_MESH_STACK_DEBUG_LOG_PRESERVE))
|
||||
return;
|
||||
#else
|
||||
if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) &&
|
||||
BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, DEBUG)) {
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
esp_log_write(ESP_LOG_DEBUG, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_START(D), esp_log_timestamp(), BLE_MESH_LIB_TRACE_TAG);
|
||||
esp_log_writev(ESP_LOG_DEBUG, BLE_MESH_LIB_TRACE_TAG, format, args);
|
||||
esp_log_write(ESP_LOG_DEBUG, BLE_MESH_LIB_TRACE_TAG, BLE_MESH_LOG_FORMAT_END);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Keep symbols alive.
|
||||
* @note Dummy function to stop the linker from
|
||||
* optimizing away unused code.The dummy
|
||||
* function is discarded after linking,
|
||||
* so it adds zero bytes to the final binary.
|
||||
*/
|
||||
void bt_mesh_lib_ext_func_dummy_call(void)
|
||||
{
|
||||
(void *)bt_hex(NULL, 0);
|
||||
}
|
||||
|
||||
int bt_mesh_v11_ext_init(void)
|
||||
{
|
||||
return bt_mesh_v11_init(&bt_mesh_ext_cfg, sizeof(bt_mesh_ext_cfg),
|
||||
|
||||
Reference in New Issue
Block a user