mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 19:54:32 +02:00
feat(openthread): integrate console command with ot command
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -20,8 +20,10 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "linenoise/linenoise.h"
|
#include "linenoise/linenoise.h"
|
||||||
|
#include "esp_console.h"
|
||||||
#define OT_CLI_MAX_LINE_LENGTH 256
|
#define OT_CLI_MAX_LINE_LENGTH 256
|
||||||
|
#define ESP_CONSOLE_PREFIX "esp "
|
||||||
|
#define ESP_CONSOLE_PREFIX_LENGTH 4
|
||||||
|
|
||||||
static TaskHandle_t s_cli_task;
|
static TaskHandle_t s_cli_task;
|
||||||
|
|
||||||
@@ -63,7 +65,13 @@ esp_err_t esp_openthread_cli_input(const char *line)
|
|||||||
|
|
||||||
static void ot_cli_loop(void *context)
|
static void ot_cli_loop(void *context)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
const char *prompt = "> ";
|
const char *prompt = "> ";
|
||||||
|
esp_console_config_t console_config = ESP_CONSOLE_CONFIG_DEFAULT();
|
||||||
|
console_config.max_cmdline_length = OT_CLI_MAX_LINE_LENGTH;
|
||||||
|
|
||||||
|
console_config.hint_color = -1;
|
||||||
|
ret = esp_console_init(&console_config);
|
||||||
|
|
||||||
linenoiseSetMultiLine(true);
|
linenoiseSetMultiLine(true);
|
||||||
linenoiseHistorySetMaxLen(100);
|
linenoiseHistorySetMaxLen(100);
|
||||||
@@ -78,9 +86,23 @@ static void ot_cli_loop(void *context)
|
|||||||
char *line = linenoise(prompt);
|
char *line = linenoise(prompt);
|
||||||
if (line && strnlen(line, OT_CLI_MAX_LINE_LENGTH)) {
|
if (line && strnlen(line, OT_CLI_MAX_LINE_LENGTH)) {
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
esp_openthread_cli_input(line);
|
if (memcmp(line, ESP_CONSOLE_PREFIX, ESP_CONSOLE_PREFIX_LENGTH) == 0) {
|
||||||
|
esp_err_t err = esp_console_run(line + ESP_CONSOLE_PREFIX_LENGTH, &ret);
|
||||||
|
if (err == ESP_ERR_NOT_FOUND) {
|
||||||
|
printf("Unrecognized command\n");
|
||||||
|
} else if (err == ESP_ERR_INVALID_ARG) {
|
||||||
|
// command was empty
|
||||||
|
printf("Command is empty\n");
|
||||||
|
} 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));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
esp_openthread_cli_input(line);
|
||||||
|
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
||||||
|
}
|
||||||
linenoiseHistoryAdd(line);
|
linenoiseHistoryAdd(line);
|
||||||
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
|
||||||
}
|
}
|
||||||
linenoiseFree(line);
|
linenoiseFree(line);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user