|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -#include "esp_openthread_cli.h" |
8 | 7 |
|
9 | 8 | #include <stdio.h> |
10 | 9 | #include <string.h> |
11 | | - |
| 10 | +#include "sdkconfig.h" |
12 | 11 | #include "openthread/cli.h" |
13 | 12 |
|
14 | 13 | #include "esp_check.h" |
15 | 14 | #include "esp_err.h" |
16 | 15 | #include "esp_log.h" |
17 | 16 | #include "esp_openthread.h" |
18 | 17 | #include "esp_openthread_common_macro.h" |
| 18 | +#include "esp_openthread_cli.h" |
19 | 19 | #include "esp_openthread_task_queue.h" |
20 | 20 | #include "freertos/FreeRTOS.h" |
21 | 21 | #include "freertos/task.h" |
@@ -63,6 +63,40 @@ esp_err_t esp_openthread_cli_input(const char *line) |
63 | 63 | return esp_openthread_task_queue_post(line_handle_task, line_copy); |
64 | 64 | } |
65 | 65 |
|
| 66 | +static int ot_cli_console_callback(int argc, char **argv) |
| 67 | +{ |
| 68 | + char cli_cmd[OT_CLI_MAX_LINE_LENGTH] = {0}; |
| 69 | + strncpy(cli_cmd, argv[1], sizeof(cli_cmd) - strlen(cli_cmd) - 1); |
| 70 | + for (int i = 2; i < argc; i++) { |
| 71 | + strncat(cli_cmd, " ", sizeof(cli_cmd) - strlen(cli_cmd) - 1); |
| 72 | + strncat(cli_cmd, argv[i], sizeof(cli_cmd) - strlen(cli_cmd) - 1); |
| 73 | + } |
| 74 | + s_cli_task = xTaskGetCurrentTaskHandle(); |
| 75 | + if (esp_openthread_cli_input(cli_cmd) == ESP_OK) { |
| 76 | + xTaskNotifyWait(0, 0, NULL, portMAX_DELAY); |
| 77 | + } else { |
| 78 | + printf("Openthread task is busy, failed to run command: %s\n", cli_cmd); |
| 79 | + } |
| 80 | + s_cli_task = NULL; |
| 81 | + return 0; |
| 82 | +} |
| 83 | + |
| 84 | +esp_err_t esp_openthread_cli_console_command_register(void) |
| 85 | +{ |
| 86 | + esp_console_cmd_t cmd = { |
| 87 | + .command = CONFIG_OPENTHREAD_CONSOLE_COMMAND_PREFIX, |
| 88 | + .help = "Execute `"CONFIG_OPENTHREAD_CONSOLE_COMMAND_PREFIX" ...` to run openthread cli", |
| 89 | + .hint = NULL, |
| 90 | + .func = ot_cli_console_callback, |
| 91 | + }; |
| 92 | + return esp_console_cmd_register(&cmd); |
| 93 | +} |
| 94 | + |
| 95 | +esp_err_t esp_openthread_cli_console_command_unregister(void) |
| 96 | +{ |
| 97 | + return esp_console_cmd_deregister(CONFIG_OPENTHREAD_CONSOLE_COMMAND_PREFIX); |
| 98 | +} |
| 99 | + |
66 | 100 | static void ot_cli_loop(void *context) |
67 | 101 | { |
68 | 102 | int ret = 0; |
|
0 commit comments