Skip to content

Commit

Permalink
add function cli_transmit_task_post
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Sep 14, 2023
1 parent 56ab765 commit fd56ef5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,33 @@
#include "openthread_cli_register.h"
#include "platform/ESP32/OpenthreadLauncher.h"
#include <lib/shell/Engine.h>
#include <memory>

#define CLI_INPUT_BUFF_LENGTH 256u
namespace chip {

static CHIP_ERROR OtcliHandler(int argc, char * argv[])
{
/* the beginning of command "matter esp ot cli" has already been removed */
char * cli_str = (char *) malloc(CLI_INPUT_BUFF_LENGTH);
memset(cli_str, 0, CLI_INPUT_BUFF_LENGTH);
std::unique_ptr<char[]> cli_str(new char[CLI_INPUT_BUFF_LENGTH]);
memset(cli_str.get(), 0, CLI_INPUT_BUFF_LENGTH);
uint8_t len = 0;
for (size_t i = 0; i < (size_t) argc; ++i)
{
len = len + strlen(argv[i]) + 1;
if (len > CLI_INPUT_BUFF_LENGTH - 1)
{
free(cli_str);
return CHIP_ERROR_INTERNAL;
}
strcat(cli_str, argv[i]);
strcat(cli_str, " ");
strcat(cli_str.get(), argv[i]);
strcat(cli_str.get(), " ");
}

QueueHandle_t cli_trans_queue = get_cli_transmit_task_queue();
if (!cli_trans_queue || xQueueSend(cli_trans_queue, &cli_str, portMAX_DELAY) != pdTRUE)
if (cli_transmit_task_post(cli_str) != CHIP_NO_ERROR)
{
free(cli_str);
return CHIP_ERROR_INTERNAL;
}
cli_str.release();
return CHIP_NO_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static_library("ESP32") {
"../OpenThread/GenericNetworkCommissioningThreadDriver.cpp",
"../OpenThread/GenericNetworkCommissioningThreadDriver.h",
"../OpenThread/OpenThreadUtils.cpp",
"OpenthreadLauncher.c",
"OpenthreadLauncher.cpp",
"OpenthreadLauncher.h",
"ThreadStackManagerImpl.cpp",
"ThreadStackManagerImpl.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@
#include "openthread/instance.h"
#include "openthread/logging.h"
#include "openthread/tasklet.h"
#include <lib/core/CHIPError.h>
#include <memory>

static esp_netif_t * openthread_netif = NULL;
static esp_openthread_platform_config_t * s_platform_config = NULL;
static TaskHandle_t cli_transmit_task = NULL;
static QueueHandle_t cli_transmit_task_queue = NULL;

QueueHandle_t get_cli_transmit_task_queue(void)
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> & cli_str)
{
return cli_transmit_task_queue;
if (!cli_transmit_task_queue || xQueueSend(cli_transmit_task_queue, &cli_str, portMAX_DELAY) != pdTRUE)
{
return CHIP_ERROR_INTERNAL;
}
return CHIP_NO_ERROR;
}

static int cli_output_callback(void * context, const char * format, va_list args)
Expand All @@ -65,20 +71,21 @@ static void esp_openthread_matter_cli_init(void)

static void cli_transmit_worker(void * context)
{
cli_transmit_task_queue = xQueueCreate(8, sizeof(char **));
cli_transmit_task_queue = xQueueCreate(8, sizeof(std::unique_ptr<char[]>));
if (!cli_transmit_task_queue)
{
vTaskDelete(NULL);
return;
}
char * command_line = NULL;

while (true)
{
std::unique_ptr<char[]> command_line(nullptr);
if (xQueueReceive(cli_transmit_task_queue, &command_line, portMAX_DELAY) == pdTRUE)
{
if (command_line)
{
esp_openthread_cli_input(command_line);
free(command_line);
esp_openthread_cli_input(command_line.get());
}
else
{
Expand All @@ -93,7 +100,7 @@ static void cli_transmit_worker(void * context)

static esp_err_t cli_command_transmit_task(void)
{
xTaskCreate(cli_transmit_worker, "ocli_trans", 3072, xTaskGetCurrentTaskHandle(), 4, &cli_transmit_task);
xTaskCreate(cli_transmit_worker, "ocli_trans", 3072, xTaskGetCurrentTaskHandle(), 5, &cli_transmit_task);
return ESP_OK;
}

Expand Down
12 changes: 3 additions & 9 deletions src/platform/ESP32/OpenthreadLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@

#include <esp_err.h>
#include <esp_openthread_types.h>

#ifdef __cplusplus
extern "C" {
#endif
#include <lib/core/CHIPError.h>
#include <memory>

esp_err_t set_openthread_platform_config(esp_openthread_platform_config_t * config);
esp_err_t openthread_init_stack(void);
esp_err_t openthread_launch_task(void);
QueueHandle_t get_cli_transmit_task_queue(void);

#ifdef __cplusplus
}
#endif
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> & cli_str);

0 comments on commit fd56ef5

Please sign in to comment.