#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%d) %s: " format LOG_RESET_COLOR "\n"
/// macro to output logs in startup code, before heap allocator and syscalls have been initialized. log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``
-#define ESP_EARLY_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_EARLY_LOGE( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_ERROR, E, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_WARN`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
-#define ESP_EARLY_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_EARLY_LOGW( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_WARN, W, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_INFO`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
-#define ESP_EARLY_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_EARLY_LOGI( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_INFO, I, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_DEBUG`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
-#define ESP_EARLY_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_EARLY_LOGD( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_DEBUG, D, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_VERBOSE`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
-#define ESP_EARLY_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_EARLY_LOGV( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_VERBOSE, V, ##__VA_ARGS__)
+
+#define ESP_LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) do { \
+ if (LOG_LOCAL_LEVEL >= log_level) { \
+ ets_printf(LOG_FORMAT(log_tag_letter, format), esp_log_timestamp(), tag, ##__VA_ARGS__); \
+ }} while(0)
#ifndef BOOTLOADER_BUILD
-#define ESP_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
-#define ESP_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
-#define ESP_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
-#define ESP_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
-#define ESP_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
+#define ESP_LOGE( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
+#define ESP_LOGW( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
+#define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
+#define ESP_LOGD( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
+#define ESP_LOGV( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, tag, format, ##__VA_ARGS__)
#else
/**
* macro to output logs at ESP_LOG_ERROR level.
- *
+ *
* @param tag tag of the log, which can be used to change the log level by ``esp_log_level_set`` at runtime.
*
* @see ``printf``
*
* @see ``printf``
*/
-#define ESP_LOG_LEVEL(level, tag, format, ...) do {\
- if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
- else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
- else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
- else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
- else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }}while(0)
+#define ESP_LOG_LEVEL(level, tag, format, ...) do { \
+ if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
+ else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
+ else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
+ else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
+ else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
+ } while(0)
/** runtime macro to output logs at a specified level. Also check the level with ``LOG_LOCAL_LEVEL``.
- *
+ *
* @see ``printf``, ``ESP_LOG_LEVEL``
*/
-#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do {\
- if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); } while(0);
+#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do { \
+ if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
+ } while(0)
#ifdef __cplusplus
}
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
- esp_get_free_heap_size(), err, data->proto, data->tos)
+ esp_get_free_heap_size(), err, data->proto, data->tos);
} else {
ESP_LOGW(MESH_TAG,
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
- esp_get_free_heap_size(), err, data->proto, data->tos)
+ esp_get_free_heap_size(), err, data->proto, data->tos);
}
}
ESP_LOGI(MESH_TAG, "layer:%d, rtableSize:%d, %s%s", mesh_layer,
esp_mesh_get_routing_table_size(),
is_mesh_connected ? "CONNECT" : "DISCONNECT",
- esp_mesh_is_root() ? "<ROOT>" : "[NODE]")
+ esp_mesh_is_root() ? "<ROOT>" : "[NODE]");
vTaskDelay(10 * 1000 / portTICK_RATE_MS);
continue;
}
CONFIG_MESH_ROUTE_TABLE_SIZE * 6, &route_table_size);
if (send_count && !(send_count % 100)) {
ESP_LOGI(MESH_TAG, "size:%d/%d,send_count:%d", route_table_size,
- esp_mesh_get_routing_table_size(), send_count)
+ esp_mesh_get_routing_table_size(), send_count);
}
send_count++;
tx_buf[25] = (send_count >> 24) & 0xff;
"[ROOT-2-UNICAST:%d][L:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
send_count, mesh_layer, MAC2STR(mesh_parent_addr.addr),
MAC2STR(route_table[i].addr), esp_get_free_heap_size(),
- err, data.proto, data.tos)
+ err, data.proto, data.tos);
} else if (!(send_count % 100)) {
ESP_LOGW(MESH_TAG,
"[ROOT-2-UNICAST:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr),
MAC2STR(route_table[i].addr), esp_get_free_heap_size(),
- err, data.proto, data.tos)
+ err, data.proto, data.tos);
}
}
if (route_table_size < 10) {
data.size = RX_SIZE;
err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
if (err != ESP_OK || !data.size) {
- ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size)
+ ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size);
continue;
}
/* extract send count */
recv_count, send_count, mesh_layer,
MAC2STR(mesh_parent_addr.addr), MAC2STR(from.addr),
data.size, esp_get_free_heap_size(), flag, err, data.proto,
- data.tos)
+ data.tos);
}
}
vTaskDelete(NULL);
#endif
static uint8_t last_layer = 0;
static int disconnect_count = 0;
- ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id)
+ ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id);
switch (event.id) {
case MESH_EVENT_STARTED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>")
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>");
break;
case MESH_EVENT_STOPPED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>")
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>");
break;
case MESH_EVENT_CHILD_CONNECTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, "MACSTR"",
event.info.child_connected.aid,
- MAC2STR(event.info.child_connected.mac))
+ MAC2STR(event.info.child_connected.mac));
break;
case MESH_EVENT_CHILD_DISCONNECTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHILD_DISCONNECTED>aid:%d, "MACSTR"",
event.info.child_disconnected.aid,
- MAC2STR(event.info.child_disconnected.mac))
+ MAC2STR(event.info.child_disconnected.mac));
break;
case MESH_EVENT_ROUTING_TABLE_ADD:
ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_ADD>add %d, new:%d",
event.info.routing_table.rt_size_change,
- event.info.routing_table.rt_size_new)
+ event.info.routing_table.rt_size_new);
break;
case MESH_EVENT_ROUTING_TABLE_REMOVE:
ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_REMOVE>remove %d, new:%d",
event.info.routing_table.rt_size_change,
- event.info.routing_table.rt_size_new)
+ event.info.routing_table.rt_size_new);
break;
case MESH_EVENT_NO_PARNET_FOUND:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_NO_PARNET_FOUND>scan times:%d",
- event.info.no_parent.scan_times)
+ event.info.no_parent.scan_times);
/* TODO handler for the failure */
break;
"<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, discnx:%d",
last_layer, mesh_layer, MAC2STR(mesh_parent_addr.addr),
esp_mesh_is_root() ? "<ROOT>" :
- (mesh_layer == 2) ? "<layer2>" : "", disconnect_count)
+ (mesh_layer == 2) ? "<layer2>" : "", disconnect_count);
disconnect_count = 0;
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
esp_mesh_set_group_id((mesh_addr_t * ) MESH_GROUP_ID, 1))
ESP_ERROR_CHECK(esp_mesh_get_group_list(&group, 1))
ESP_LOGI(MESH_TAG, "num:%d, group "MACSTR"\n",
- esp_mesh_get_group_num(), MAC2STR(group.addr))
+ esp_mesh_get_group_num(), MAC2STR(group.addr));
}
#endif
esp_mesh_comm_p2p_start();
case MESH_EVENT_PARENT_DISCONNECTED:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_PARENT_DISCONNECTED>reason:%d, count:%d",
- event.info.disconnected.reason, disconnect_count)
+ event.info.disconnected.reason, disconnect_count);
if (event.info.disconnected.reason == 201) {
disconnect_count++;
}
ESP_LOGI(MESH_TAG, "<MESH_EVENT_LAYER_CHANGE>layer:%d-->%d%s",
last_layer, mesh_layer,
esp_mesh_is_root() ? "<ROOT>" :
- (mesh_layer == 2) ? "<layer2>" : "")
+ (mesh_layer == 2) ? "<layer2>" : "");
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
break;
case MESH_EVENT_ROOT_ADDRESS:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_ADDRESS>rc_addr:"MACSTR"",
- MAC2STR(event.info.root_addr.addr))
+ MAC2STR(event.info.root_addr.addr));
break;
case MESH_EVENT_ROOT_GOT_IP:
"<MESH_EVENT_ROOT_GOT_IP>sta ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
IP2STR(&event.info.got_ip.ip_info.ip),
IP2STR(&event.info.got_ip.ip_info.netmask),
- IP2STR(&event.info.got_ip.ip_info.gw))
+ IP2STR(&event.info.got_ip.ip_info.gw));
break;
case MESH_EVENT_ROOT_LOST_IP:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_LOST_IP>")
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_LOST_IP>");
break;
case MESH_EVENT_VOTE_STARTED:
"<MESH_EVENT_VOTE_STARTED>attempts:%d, reason:%d, rc_addr:"MACSTR"",
event.info.vote_started.attempts,
event.info.vote_started.reason,
- MAC2STR(event.info.vote_started.rc_addr.addr))
+ MAC2STR(event.info.vote_started.rc_addr.addr));
break;
case MESH_EVENT_VOTE_STOPPED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_DONE>")
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_DONE>");
break;
case MESH_EVENT_ROOT_SWITCH_REQ:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_ROOT_SWITCH_REQ>reason:%d, rc_addr:"MACSTR"",
event.info.switch_req.reason,
- MAC2STR( event.info.switch_req.rc_addr.addr))
+ MAC2STR( event.info.switch_req.rc_addr.addr));
break;
case MESH_EVENT_ROOT_SWITCH_ACK:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>")
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>");
break;
case MESH_EVENT_TODS_STATE:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d",
- event.info.toDS_state)
+ event.info.toDS_state);
;
break;
default:
- ESP_LOGI(MESH_TAG, "unknown")
+ ESP_LOGI(MESH_TAG, "unknown");
break;
}
}
ESP_ERROR_CHECK(esp_mesh_set_switch_parent_paras(&switch_paras));
/* mesh start */
ESP_ERROR_CHECK(esp_mesh_start());
- ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d\n", esp_get_free_heap_size())
+ ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d\n", esp_get_free_heap_size());
}