Select one of the symbols to view example projects that use it.
 
Outline
#include "sdkconfig.h"
#include <sys/cdefs.h>
#include "esp_console.h"
#include "console_private.h"
#include "esp_log.h"
#include "linenoise/linenoise.h"
TAG
esp_console_setup_prompt(const char *, esp_console_repl_com_t *)
esp_console_setup_history(const char *, uint32_t, esp_console_repl_com_t *)
esp_console_common_init(size_t, esp_console_repl_com_t *)
esp_console_start_repl(esp_console_repl_t *)
esp_console_repl_task(void *)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
argtable3
linenoise
private_include
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/console/esp_console_common.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include "sdkconfig.h" #include <sys/cdefs.h> // __containerof #include "esp_console.h" #include "console_private.h" #include "esp_log.h" #include "linenoise/linenoise.h"6 includes static const char *TAG = "console.common"; esp_err_t esp_console_setup_prompt(const char *prompt, esp_console_repl_com_t *repl_com) { /* set command line prompt */ const char *prompt_temp = "esp>"; if (prompt) { prompt_temp = prompt; }{...} snprintf(repl_com->prompt, CONSOLE_PROMPT_MAX_LEN - 1, LOG_COLOR_I "%s " LOG_RESET_COLOR, prompt_temp); /* Figure out if the terminal supports escape sequences */ int probe_status = linenoiseProbe(); if (probe_status) { /* zero indicates success */ linenoiseSetDumbMode(1); #if CONFIG_LOG_COLORS /* Since the terminal doesn't support escape sequences, * don't use color codes in the s_prompt. *//* ... */ snprintf(repl_com->prompt, CONSOLE_PROMPT_MAX_LEN - 1, "%s ", prompt_temp);/* ... */ #endif //CONFIG_LOG_COLORS }{...} return ESP_OK; }{ ... } esp_err_t esp_console_setup_history(const char *history_path, uint32_t max_history_len, esp_console_repl_com_t *repl_com) { esp_err_t ret = ESP_OK; repl_com->history_save_path = history_path; if (history_path) { /* Load command history from filesystem */ linenoiseHistoryLoad(history_path); }{...} /* Set command history size */ if (linenoiseHistorySetMaxLen(max_history_len) != 1) { ESP_LOGE(TAG, "set max history length to %"PRIu32" failed", max_history_len); ret = ESP_FAIL; goto _exit; }{...} return ESP_OK; _exit: return ret; }{ ... } esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_repl_com_t *repl_com) { esp_err_t ret = ESP_OK; /* Initialize the console */ esp_console_config_t console_config = ESP_CONSOLE_CONFIG_DEFAULT(); repl_com->max_cmdline_length = console_config.max_cmdline_length; /* Replace the default command line length if passed as a parameter */ if (max_cmdline_length != 0) { console_config.max_cmdline_length = max_cmdline_length; repl_com->max_cmdline_length = max_cmdline_length; }{...} #if CONFIG_LOG_COLORS console_config.hint_color = atoi(LOG_COLOR_CYAN); #else console_config.hint_color = -1; #endif ret = esp_console_init(&console_config); if (ret != ESP_OK) { goto _exit; }{...} ret = esp_console_register_help_command(); if (ret != ESP_OK) { goto _exit; }{...} /* Configure linenoise line completion library */ /* Enable multiline editing. If not set, long commands will scroll within single line */ linenoiseSetMultiLine(1); /* Tell linenoise where to get command completions and hints */ linenoiseSetCompletionCallback(&esp_console_get_completion); linenoiseSetHintsCallback((linenoiseHintsCallback *)&esp_console_get_hint); return ESP_OK; _exit: return ret; }{ ... } esp_err_t esp_console_start_repl(esp_console_repl_t *repl) { esp_err_t ret = ESP_OK; esp_console_repl_com_t *repl_com = __containerof(repl, esp_console_repl_com_t, repl_core); // check if already initialized if (repl_com->state != CONSOLE_REPL_STATE_INIT) { ret = ESP_ERR_INVALID_STATE; goto _exit; }{...} repl_com->state = CONSOLE_REPL_STATE_START; xTaskNotifyGive(repl_com->task_hdl); return ESP_OK; _exit: return ret; }{ ... } void esp_console_repl_task(void *args) { esp_console_repl_universal_t *repl_conf = (esp_console_repl_universal_t *) args; esp_console_repl_com_t *repl_com = &repl_conf->repl_com; const int uart_channel = repl_conf->uart_channel; /* Waiting for task notify. This happens when `esp_console_start_repl()` * function is called. *//* ... */ ulTaskNotifyTake(pdTRUE, portMAX_DELAY); /* Change standard input and output of the task if the requested UART is * NOT the default one. This block will replace stdin, stdout and stderr. *//* ... */ if (uart_channel != CONFIG_ESP_CONSOLE_UART_NUM) { char path[CONSOLE_PATH_MAX_LEN] = { 0 }; snprintf(path, CONSOLE_PATH_MAX_LEN, "/dev/uart/%d", uart_channel); stdin = fopen(path, "r"); stdout = fopen(path, "w"); stderr = stdout; }{...} /* Disable buffering on stdin of the current task. * If the console is ran on a different UART than the default one, * buffering shall only be disabled for the current one. *//* ... */ setvbuf(stdin, NULL, _IONBF, 0); /* This message shall be printed here and not earlier as the stdout * has just been set above. *//* ... */ printf("\r\n" "Type 'help' to get the list of commands.\r\n" "Use UP/DOWN arrows to navigate through command history.\r\n" "Press TAB when typing command name to auto-complete.\r\n"); if (linenoiseIsDumbMode()) { printf("\r\n" "Your terminal application does not support escape sequences.\n\n" "Line editing and history features are disabled.\n\n" "On Windows, try using Putty instead.\r\n"); }{...} linenoiseSetMaxLineLen(repl_com->max_cmdline_length); while (repl_com->state == CONSOLE_REPL_STATE_START) { char *line = linenoise(repl_com->prompt); if (line == NULL) { ESP_LOGD(TAG, "empty line"); /* Ignore empty lines */ continue; }{...} /* Add the command to the history */ linenoiseHistoryAdd(line); /* Save command history to filesystem */ if (repl_com->history_save_path) { linenoiseHistorySave(repl_com->history_save_path); }{...} /* Try to run the command */ int ret; esp_err_t err = esp_console_run(line, &ret); if (err == ESP_ERR_NOT_FOUND) { printf("Unrecognized command\n"); }{...} else if (err == ESP_ERR_INVALID_ARG) { // command was empty }{...} else if (err == ESP_OK && ret != ESP_OK) { printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(ret)); }{...} else if (err != ESP_OK) { printf("Internal error: %s\n", esp_err_to_name(err)); }{...} /* linenoise allocates line buffer on the heap, so need to free it */ linenoiseFree(line); }{...} ESP_LOGD(TAG, "The End"); vTaskDelete(NULL); }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.