diff --git a/examples/openthread/ot_br/CMakeLists.txt b/examples/openthread/ot_br/CMakeLists.txt index b9b1ee9995..277bba7681 100644 --- a/examples/openthread/ot_br/CMakeLists.txt +++ b/examples/openthread/ot_br/CMakeLists.txt @@ -7,4 +7,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(otbr_esp) +project(esp_ot_br) diff --git a/examples/openthread/ot_br/Makefile b/examples/openthread/ot_br/Makefile index 4cbaed78c2..90be4f93ce 100644 --- a/examples/openthread/ot_br/Makefile +++ b/examples/openthread/ot_br/Makefile @@ -3,7 +3,7 @@ # project subdirectory. # -PROJECT_NAME := otbr_esp +PROJECT_NAME := esp_ot_br EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/common_components/protocol_examples_common diff --git a/examples/openthread/ot_cli/Makefile b/examples/openthread/ot_cli/Makefile index 5cfeb53892..6853ae8065 100644 --- a/examples/openthread/ot_cli/Makefile +++ b/examples/openthread/ot_cli/Makefile @@ -3,6 +3,6 @@ # project subdirectory. # -PROJECT_NAME := ot_esp_cli +PROJECT_NAME := esp_ot_cli include $(IDF_PATH)/make/project.mk diff --git a/examples/openthread/ot_cli/main/CMakeLists.txt b/examples/openthread/ot_cli/main/CMakeLists.txt index e6843110b8..c1d5ea7b00 100644 --- a/examples/openthread/ot_cli/main/CMakeLists.txt +++ b/examples/openthread/ot_cli/main/CMakeLists.txt @@ -1,2 +1,8 @@ -idf_component_register(SRCS "esp_ot_udp_socket.c" "esp_ot_tcp_socket.c" "esp_ot_cli_extension.c" "esp_ot_cli.c" +set(srcs "esp_ot_cli.c") + +if(CONFIG_OPENTHREAD_CLI_ESP_EXTENSION) + list(APPEND srcs "esp_ot_cli_extension.c" "esp_ot_tcp_socket.c" "esp_ot_udp_socket.c") +endif() + +idf_component_register(SRCS "${srcs}" INCLUDE_DIRS ".") diff --git a/examples/openthread/ot_cli/main/Kconfig.projbuild b/examples/openthread/ot_cli/main/Kconfig.projbuild index 2d29cf7431..eeafa91032 100644 --- a/examples/openthread/ot_cli/main/Kconfig.projbuild +++ b/examples/openthread/ot_cli/main/Kconfig.projbuild @@ -1,30 +1,22 @@ -menu "Openthread" +menu "OpenThread CLI Example" - menuconfig OPENTHREAD_CUSTOM_COMMAND - bool "Enable custom command in ot-cli" - default n + config OPENTHREAD_CLI_ESP_EXTENSION + bool "Enable Espressif's extended features" + default y + help + Enable Espressif's extended features include TCP socket, UDP socket. - config OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE - bool "Enable openthread tcp socket" - depends on OPENTHREAD_CUSTOM_COMMAND - default n - - config OPENTHEAD_EXAMPLE_TCP_SERVER_PORT + config OPENTHREAD_CLI_TCP_SERVER_PORT int "the port of TCP server" default 12345 - depends on OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE + depends on OPENTHREAD_CLI_ESP_EXTENSION help Set the connect port of socket - config OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE - bool "Enable openthread udp socket" - depends on OPENTHREAD_CUSTOM_COMMAND - default n - - config OPENTHEAD_EXAMPLE_UDP_SERVER_PORT + config OPENTHREAD_CLI_UDP_SERVER_PORT int "the port of UDP server" default 54321 - depends on OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE + depends on OPENTHREAD_CLI_ESP_EXTENSION help Set the connect port of socket diff --git a/examples/openthread/ot_cli/main/esp_ot_cli.c b/examples/openthread/ot_cli/main/esp_ot_cli.c index 7eefe0ed20..6cdabe5612 100644 --- a/examples/openthread/ot_cli/main/esp_ot_cli.c +++ b/examples/openthread/ot_cli/main/esp_ot_cli.c @@ -35,14 +35,15 @@ #include "openthread/instance.h" #include "openthread/tasklet.h" -#if CONFIG_OPENTHREAD_CUSTOM_COMMAND +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION #include "esp_ot_cli_extension.h" -#endif // CONFIG_OPENTHREAD_CUSTOM_COMMAND +#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION #define TAG "ot_esp_cli" -extern void otAppCliInit(otInstance *instance); +extern void otAppCliInit(otInstance *aInstance); +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t *config) { esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD(); @@ -52,6 +53,7 @@ static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t return netif; } +#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION static void ot_task_worker(void *aContext) { @@ -60,7 +62,6 @@ static void ot_task_worker(void *aContext) .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), }; - esp_netif_t *openthread_netif; // Initialize the OpenThread stack ESP_ERROR_CHECK(esp_openthread_init(&config)); @@ -68,19 +69,23 @@ static void ot_task_worker(void *aContext) // Initialize the OpenThread cli otAppCliInit(esp_openthread_get_instance()); +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION + esp_netif_t *openthread_netif; // Initialize the esp_netif bindings openthread_netif = init_openthread_netif(&config); -#if CONFIG_OPENTHREAD_CUSTOM_COMMAND esp_cli_custom_command_init(); -#endif // CONFIG_OPENTHREAD_CUSTOM_COMMAND +#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION // Run the main loop esp_openthread_launch_mainloop(); // Clean up +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION esp_netif_destroy(openthread_netif); esp_openthread_netif_glue_deinit(); +#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION + esp_vfs_eventfd_unregister(); vTaskDelete(NULL); } @@ -96,7 +101,9 @@ void app_main(void) }; ESP_ERROR_CHECK(esp_event_loop_create_default()); +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION ESP_ERROR_CHECK(esp_netif_init()); +#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config)); xTaskCreate(ot_task_worker, "ot_cli_main", 10240, xTaskGetCurrentTaskHandle(), 5, NULL); } diff --git a/examples/openthread/ot_cli/main/esp_ot_cli_extension.c b/examples/openthread/ot_cli/main/esp_ot_cli_extension.c index e792ec0b3e..2d1e718ef7 100644 --- a/examples/openthread/ot_cli/main/esp_ot_cli_extension.c +++ b/examples/openthread/ot_cli/main/esp_ot_cli_extension.c @@ -22,14 +22,10 @@ #include "openthread/cli.h" static const otCliCommand kCommands[] = { -#if CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE {"tcpsockserver", esp_ot_process_tcp_server}, {"tcpsockclient", esp_ot_process_tcp_client}, -#endif // CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE -#if CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE {"udpsockserver", esp_ot_process_udp_server}, {"udpsockclient", esp_ot_process_udp_client}, -#endif // CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE }; void esp_cli_custom_command_init() diff --git a/examples/openthread/ot_cli/main/esp_ot_tcp_socket.c b/examples/openthread/ot_cli/main/esp_ot_tcp_socket.c index b39dd5d20c..8cd3ec9e4f 100644 --- a/examples/openthread/ot_cli/main/esp_ot_tcp_socket.c +++ b/examples/openthread/ot_cli/main/esp_ot_tcp_socket.c @@ -19,20 +19,18 @@ #include "lwip/err.h" #include "lwip/sockets.h" -#if CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE #define TAG "ot_socket" static void tcp_socket_server_task(void *pvParameters) { char addr_str[128]; - char payload[] = "This message is from server\n"; char rx_buffer[128]; esp_err_t ret = ESP_OK; int err = 0; int len = 0; int listen_sock; int opt = 1; - int port = CONFIG_OPENTHEAD_EXAMPLE_TCP_SERVER_PORT; + int port = CONFIG_OPENTHREAD_CLI_TCP_SERVER_PORT; int client_sock = 0; struct timeval timeout; struct sockaddr_storage source_addr; // Large enough for both IPv6 @@ -108,7 +106,7 @@ static void tcp_socket_client_task(void *pvParameters) int client_sock; int err = 0; int len = 0; - int port = CONFIG_OPENTHEAD_EXAMPLE_TCP_SERVER_PORT; + int port = CONFIG_OPENTHREAD_CLI_TCP_SERVER_PORT; struct sockaddr_in6 dest_addr = { 0 }; inet6_aton(host_ip, &dest_addr.sin6_addr); @@ -162,4 +160,3 @@ void esp_ot_process_tcp_client(void *aContext, uint8_t aArgsLength, char *aArgs[ xTaskCreate(tcp_socket_client_task, "ot_tcp_socket_client", 4096, aArgs[0], 4, NULL); } } -#endif // CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE diff --git a/examples/openthread/ot_cli/main/esp_ot_tcp_socket.h b/examples/openthread/ot_cli/main/esp_ot_tcp_socket.h index 742af56f88..37c61de07b 100644 --- a/examples/openthread/ot_cli/main/esp_ot_tcp_socket.h +++ b/examples/openthread/ot_cli/main/esp_ot_tcp_socket.h @@ -18,7 +18,6 @@ extern "C" { #endif -#if CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE /** * @brief User command "tcpsockserver" process. * @@ -31,7 +30,6 @@ void esp_ot_process_tcp_server(void *aContext, uint8_t aArgsLength, char *aArgs[ */ void esp_ot_process_tcp_client(void *aContext, uint8_t aArgsLength, char *aArgs[]); -#endif // CONFIG_OPENTHREAD_ENABLE_TCP_SOCKET_EXAMPLE #ifdef __cplusplus } #endif diff --git a/examples/openthread/ot_cli/main/esp_ot_udp_socket.c b/examples/openthread/ot_cli/main/esp_ot_udp_socket.c index 8a752bb82f..3890ea78d4 100644 --- a/examples/openthread/ot_cli/main/esp_ot_udp_socket.c +++ b/examples/openthread/ot_cli/main/esp_ot_udp_socket.c @@ -19,7 +19,6 @@ #include "lwip/err.h" #include "lwip/sockets.h" -#if CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE #define TAG "ot_socket" static void udp_socket_server_task(void *pvParameters) @@ -31,7 +30,7 @@ static void udp_socket_server_task(void *pvParameters) int err = 0; int len; int listen_sock; - int port = CONFIG_OPENTHEAD_EXAMPLE_UDP_SERVER_PORT; + int port = CONFIG_OPENTHREAD_CLI_UDP_SERVER_PORT; struct timeval timeout; struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6 struct sockaddr_in6 listen_addr; @@ -88,7 +87,7 @@ static void udp_socket_client_task(void *pvParameters) char *host_ip = (char *)pvParameters; char *payload = "This message is from client\n"; int client_sock; - int port = CONFIG_OPENTHEAD_EXAMPLE_UDP_SERVER_PORT; + int port = CONFIG_OPENTHREAD_CLI_UDP_SERVER_PORT; int err = 0; int len; esp_err_t ret = ESP_OK; @@ -142,4 +141,3 @@ void esp_ot_process_udp_client(void *aContext, uint8_t aArgsLength, char *aArgs[ xTaskCreate(udp_socket_client_task, "ot_udp_socket_client", 4096, aArgs[0], 4, NULL); } } -#endif // CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE diff --git a/examples/openthread/ot_cli/main/esp_ot_udp_socket.h b/examples/openthread/ot_cli/main/esp_ot_udp_socket.h index 9874f0f033..f35731258c 100644 --- a/examples/openthread/ot_cli/main/esp_ot_udp_socket.h +++ b/examples/openthread/ot_cli/main/esp_ot_udp_socket.h @@ -18,7 +18,6 @@ extern "C" { #endif -#if CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE /** * @brief User command "udpsockserver" process. * @@ -30,7 +29,6 @@ void esp_ot_process_udp_server(void *aContext, uint8_t aArgsLength, char *aArgs[ * */ void esp_ot_process_udp_client(void *aContext, uint8_t aArgsLength, char *aArgs[]); -#endif // CONFIG_OPENTHREAD_ENABLE_UDP_SOCKET_EXAMPLE #ifdef __cplusplus }