11/*
2- * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Unlicense OR CC0-1.0
55 */
66
7+ #include "stdlib.h"
78#include "driver/uart.h"
89#include "freertos/FreeRTOS.h"
910#include "freertos/task.h"
@@ -31,7 +32,7 @@ extern void spp_msg_args_parser(char *buf, int len);
3132
3233void spp_msg_handler (char * buf , int len )
3334{
34- ESP_LOGE (TAG_CNSL , "Command [%s]" , buf );
35+ ESP_LOGI (TAG_CNSL , "Command [%s]" , buf );
3536 spp_msg_args_parser (buf , len );
3637}
3738
@@ -44,13 +45,18 @@ static void console_uart_task(void *pvParameters)
4445 spp_msg_parser_register_callback (parser , spp_msg_handler );
4546 spp_msg_show_usage ();
4647#define TMP_BUF_LEN 128
47- uint8_t tmp_buf [128 ] = {0 };
48+ uint8_t * tmp_buf = NULL ;
49+
50+ if ((tmp_buf = (uint8_t * )calloc (TMP_BUF_LEN , sizeof (uint8_t ))) == NULL ) {
51+ ESP_LOGE (TAG_CNSL ,"temp buf malloc fail" );
52+ return ;
53+ }
4854
4955 for (;;) {
5056 //Waiting for UART event.
5157 if (xQueueReceive (uart_queue , (void * )& event , (TickType_t )portMAX_DELAY )) {
5258 switch (event .type ) {
53- //Event of UART receving data
59+ //Event of UART receiving data
5460 case UART_DATA :
5561 {
5662 len = uart_read_bytes (CONSOLE_UART_NUM , tmp_buf , TMP_BUF_LEN , 0 );
@@ -95,6 +101,8 @@ static void console_uart_task(void *pvParameters)
95101 }
96102 }
97103 }
104+
105+ free (tmp_buf );
98106 vTaskDelete (NULL );
99107}
100108
0 commit comments