Skip to content

Commit

Permalink
Merge branch 'feature/add_at_debug_feature' into 'master'
Browse files Browse the repository at this point in the history
feat(debug): Added some debug options to allow different kinds of esp-at debug output

See merge request application/esp-at!1530
  • Loading branch information
xcguang committed Mar 7, 2024
2 parents 20a4922 + 3bce3b3 commit b776ba7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
24 changes: 23 additions & 1 deletion components/at/src/at_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ esp_err_t at_wifi_deinit(void)
}
#endif

#if CONFIG_AT_WIFI_DUMP_STATIS_DEBUG
static void at_wifi_statistics_task(void *params)
{
while (1) {
vTaskDelay(CONFIG_AT_WIFI_DUMP_STATIS_INTV_MS / portTICK_PERIOD_MS);
esp_wifi_statis_dump(0xFFFFFFFF);
}
}
#endif

esp_err_t esp_at_netif_init(void)
{
#ifdef CONFIG_AT_WIFI_COMMAND_SUPPORT
Expand All @@ -73,9 +83,17 @@ static void at_module_init(void)
"Bin version:%s(%s)\r\n", CONFIG_ESP_AT_FW_VERSION, esp_at_get_current_module_name());
#endif

#if CONFIG_AT_DEBUG
char *versions = (char *)malloc(AT_TEMP_BUFFER_SIZE);
ret = esp_at_get_core_version((char *)versions, AT_TEMP_BUFFER_SIZE);
ret += snprintf((char *)versions + ret, AT_TEMP_BUFFER_SIZE - ret, "SDK version:%s\r\n", esp_get_idf_version());
ret += snprintf((char *)versions + ret, AT_TEMP_BUFFER_SIZE - ret, "%s", version);
printf("%.*s\r\n", ret, versions);
free(versions);
#endif

esp_at_module_init(version);
free(version);

ESP_LOGD(TAG, "at module init done");
}

Expand Down Expand Up @@ -282,6 +300,10 @@ void esp_at_init(void)
esp_netif_create_default_wifi_sta();
esp_netif_create_default_wifi_ap();
at_wifi_init();

#ifdef CONFIG_AT_WIFI_DUMP_STATIS_DEBUG
xTaskCreate(at_wifi_statistics_task, "wifi-dbg", 2048, NULL, 1, NULL);
#endif
#endif

// initialize the interface for esp-at and mcu communication
Expand Down
44 changes: 44 additions & 0 deletions main/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,48 @@ config AT_RAINMAKER_COMMAND_SUPPORT
default n
depends on AT_ENABLE
depends on IDF_TARGET_ESP32C3

menuconfig AT_DEBUG
bool "Enable ESP-AT Debug"
default n
help
Enabling this option allows different kinds of ESP-AT debug output, and these debug outputs will be sent to the AT log port.
All ESP-AT debug features increase the size of the final binary.

config AT_TX_DATA_DEBUG
bool "Logging the data sent from AT to MCU (AT ----> MCU)"
depends on AT_DEBUG && (LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE)
default y

config AT_TX_DATA_MAX_LEN
int "The maximum length of the data sent from AT to MCU to be logged"
depends on AT_TX_DATA_DEBUG
default 8192
help
Logging the data with the length of AT_TX_DATA_MAX_LEN.
You can speed up the data transfer by setting a smaller value.

config AT_RX_DATA_DEBUG
bool "Logging the data received by AT from MCU (AT <---- MCU)"
depends on AT_DEBUG && (LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE)
default y

config AT_RX_DATA_MAX_LEN
int "The maximum length of the data received by AT from MCU to be logged"
depends on AT_RX_DATA_DEBUG
default 8192
help
Logging the data with the length of AT_RX_DATA_MAX_LEN.
You can speed up the data transfer by setting a smaller value.

config AT_WIFI_DUMP_STATIS_DEBUG
bool "Periodically dump Wi-Fi statistics"
depends on AT_DEBUG && (LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE)
default n

config AT_WIFI_DUMP_STATIS_INTV_MS
int "The interval of dumping Wi-Fi statistics (ms)"
depends on AT_WIFI_DUMP_STATIS_DEBUG
default 3000

endmenu
15 changes: 14 additions & 1 deletion main/interface/at_interface_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@ static int32_t at_port_read_data(uint8_t *buffer, int32_t len)
if (!s_interface_ops.read_data) {
return -1;
}
return s_interface_ops.read_data(buffer, len);
int32_t ret = s_interface_ops.read_data(buffer, len);

#if CONFIG_AT_RX_DATA_DEBUG
if (ret > 0) {
ESP_LOG_BUFFER_HEXDUMP("intf-rx", buffer, at_min(ret, CONFIG_AT_RX_DATA_MAX_LEN), ESP_LOG_INFO);
}
#endif

return ret;
}

static int32_t at_port_write_data(uint8_t *data, int32_t len)
{
if (!s_interface_ops.write_data) {
return -1;
}

#if CONFIG_AT_TX_DATA_DEBUG
ESP_LOG_BUFFER_HEXDUMP("intf-tx", data, at_min(len, CONFIG_AT_TX_DATA_MAX_LEN), ESP_LOG_INFO);
#endif

return s_interface_ops.write_data(data, len);
}

Expand Down

0 comments on commit b776ba7

Please sign in to comment.