mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
memory leak in telnet + more tweaks
This commit is contained in:
@@ -37,9 +37,13 @@ static const char * TAG = "console";
|
|||||||
extern bool bypass_wifi_manager;
|
extern bool bypass_wifi_manager;
|
||||||
extern void register_squeezelite();
|
extern void register_squeezelite();
|
||||||
|
|
||||||
static EXT_RAM_ATTR QueueSetHandle_t stdin_queue_set;
|
|
||||||
static EXT_RAM_ATTR QueueHandle_t uart_queue;
|
static EXT_RAM_ATTR QueueHandle_t uart_queue;
|
||||||
static EXT_RAM_ATTR RingbufHandle_t stdin_buffer;
|
static EXT_RAM_ATTR struct {
|
||||||
|
uint8_t _buf[128];
|
||||||
|
StaticRingbuffer_t _ringbuf;
|
||||||
|
RingbufHandle_t handle;
|
||||||
|
QueueSetHandle_t queue_set;
|
||||||
|
} stdin_redir;
|
||||||
|
|
||||||
/* Prompt to be printed before each line.
|
/* Prompt to be printed before each line.
|
||||||
* This can be customized, made dynamic, etc.
|
* This can be customized, made dynamic, etc.
|
||||||
@@ -238,7 +242,7 @@ static ssize_t stdin_read(int fd, void* data, size_t size) {
|
|||||||
size_t bytes = -1;
|
size_t bytes = -1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
QueueSetMemberHandle_t activated = xQueueSelectFromSet(stdin_queue_set, portMAX_DELAY);
|
QueueSetMemberHandle_t activated = xQueueSelectFromSet(stdin_redir.queue_set, portMAX_DELAY);
|
||||||
|
|
||||||
if (activated == uart_queue) {
|
if (activated == uart_queue) {
|
||||||
uart_event_t event;
|
uart_event_t event;
|
||||||
@@ -251,12 +255,12 @@ static ssize_t stdin_read(int fd, void* data, size_t size) {
|
|||||||
for (int i = 0; i < bytes; i++) if (((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
for (int i = 0; i < bytes; i++) if (((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (xRingbufferCanRead(stdin_buffer, activated)) {
|
} else if (xRingbufferCanRead(stdin_redir.handle, activated)) {
|
||||||
char *p = xRingbufferReceiveUpTo(stdin_buffer, &bytes, 0, size);
|
char *p = xRingbufferReceiveUpTo(stdin_redir.handle, &bytes, 0, size);
|
||||||
// we might receive strings, replace null by \n
|
// we might receive strings, replace null by \n
|
||||||
for (int i = 0; i < bytes; i++) if (p[i] == '\0' || p[i] == '\r') p[i] = '\n';
|
for (int i = 0; i < bytes; i++) if (p[i] == '\0' || p[i] == '\r') p[i] = '\n';
|
||||||
memcpy(data, p, bytes);
|
memcpy(data, p, bytes);
|
||||||
vRingbufferReturnItem(stdin_buffer, p);
|
vRingbufferReturnItem(stdin_redir.handle, p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +280,7 @@ void initialize_console() {
|
|||||||
* correct while APB frequency is changing in light sleep mode.
|
* correct while APB frequency is changing in light sleep mode.
|
||||||
*/
|
*/
|
||||||
const uart_config_t uart_config = { .baud_rate =
|
const uart_config_t uart_config = { .baud_rate =
|
||||||
CONFIG_CONSOLE_UART_BAUDRATE, .data_bits = UART_DATA_8_BITS,
|
CONFIG_ESP_CONSOLE_UART_BAUDRATE, .data_bits = UART_DATA_8_BITS,
|
||||||
.parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1,
|
.parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1,
|
||||||
.use_ref_tick = true };
|
.use_ref_tick = true };
|
||||||
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
|
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
|
||||||
@@ -288,12 +292,10 @@ void initialize_console() {
|
|||||||
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
||||||
|
|
||||||
/* re-direct stdin to our own driver so we can gather data from various sources */
|
/* re-direct stdin to our own driver so we can gather data from various sources */
|
||||||
stdin_queue_set = xQueueCreateSet(2);
|
stdin_redir.queue_set = xQueueCreateSet(2);
|
||||||
stdin_buffer = xRingbufferCreateStatic(128, RINGBUF_TYPE_BYTEBUF,
|
stdin_redir.handle = xRingbufferCreateStatic(sizeof(stdin_redir._buf), RINGBUF_TYPE_BYTEBUF, stdin_redir._buf, &stdin_redir._ringbuf);
|
||||||
heap_caps_malloc(128, MALLOC_CAP_SPIRAM),
|
xRingbufferAddToQueueSetRead(stdin_redir.handle, stdin_redir.queue_set);
|
||||||
heap_caps_malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_SPIRAM));
|
xQueueAddToSet(uart_queue, stdin_redir.queue_set);
|
||||||
xRingbufferAddToQueueSetRead(stdin_buffer, stdin_queue_set);
|
|
||||||
xQueueAddToSet(uart_queue, stdin_queue_set);
|
|
||||||
|
|
||||||
const esp_vfs_t vfs = {
|
const esp_vfs_t vfs = {
|
||||||
.flags = ESP_VFS_FLAG_DEFAULT,
|
.flags = ESP_VFS_FLAG_DEFAULT,
|
||||||
@@ -334,7 +336,7 @@ void initialize_console() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool console_push(const char *data, size_t size) {
|
bool console_push(const char *data, size_t size) {
|
||||||
return xRingbufferSend(stdin_buffer, data, size, pdMS_TO_TICKS(100)) == pdPASS;
|
return xRingbufferSend(stdin_redir.handle, data, size, pdMS_TO_TICKS(100)) == pdPASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_start() {
|
void console_start() {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ extern bool bypass_wifi_manager;
|
|||||||
* Forward declarations
|
* Forward declarations
|
||||||
*/
|
*/
|
||||||
static void telnet_task(void *data);
|
static void telnet_task(void *data);
|
||||||
static int stdio_open(const char * path, int flags, int mode);
|
static int stdout_open(const char * path, int flags, int mode);
|
||||||
static int stdout_fstat(int fd, struct stat * st);
|
static int stdout_fstat(int fd, struct stat * st);
|
||||||
static ssize_t stdout_write(int fd, const void * data, size_t size);
|
static ssize_t stdout_write(int fd, const void * data, size_t size);
|
||||||
static char *eventToString(telnet_event_type_t type);
|
static char *eventToString(telnet_event_type_t type);
|
||||||
@@ -79,6 +79,7 @@ struct telnetUserData {
|
|||||||
|
|
||||||
void init_telnet(){
|
void init_telnet(){
|
||||||
char *val= get_nvs_value_alloc(NVS_TYPE_STR, "telnet_enable");
|
char *val= get_nvs_value_alloc(NVS_TYPE_STR, "telnet_enable");
|
||||||
|
|
||||||
if (!val || strlen(val) == 0 || !strcasestr("YXD",val) ) {
|
if (!val || strlen(val) == 0 || !strcasestr("YXD",val) ) {
|
||||||
ESP_LOGI(TAG,"Telnet support disabled");
|
ESP_LOGI(TAG,"Telnet support disabled");
|
||||||
if(val) free(val);
|
if(val) free(val);
|
||||||
@@ -123,7 +124,7 @@ void init_telnet(){
|
|||||||
const esp_vfs_t vfs = {
|
const esp_vfs_t vfs = {
|
||||||
.flags = ESP_VFS_FLAG_DEFAULT,
|
.flags = ESP_VFS_FLAG_DEFAULT,
|
||||||
.write = &stdout_write,
|
.write = &stdout_write,
|
||||||
.open = &stdio_open,
|
.open = &stdout_open,
|
||||||
.fstat = &stdout_fstat,
|
.fstat = &stdout_fstat,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,15 +138,17 @@ void init_telnet(){
|
|||||||
|
|
||||||
bIsEnabled=true;
|
bIsEnabled=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_telnet(void * pvParameter){
|
void start_telnet(void * pvParameter){
|
||||||
static bool isStarted=false;
|
static bool isStarted=false;
|
||||||
|
|
||||||
|
if(isStarted || !bIsEnabled) return;
|
||||||
|
|
||||||
StaticTask_t *xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
StaticTask_t *xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
StackType_t *xStack = heap_caps_malloc(TELNET_STACK_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
StackType_t *xStack = heap_caps_malloc(TELNET_STACK_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||||
|
|
||||||
if(!isStarted && bIsEnabled) {
|
xTaskCreateStatic( (TaskFunction_t) &telnet_task, "telnet", TELNET_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN, xStack, xTaskBuffer);
|
||||||
xTaskCreateStatic( (TaskFunction_t) &telnet_task, "telnet", TELNET_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN, xStack, xTaskBuffer);
|
isStarted=true;
|
||||||
isStarted=true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void telnet_task(void *data) {
|
static void telnet_task(void *data) {
|
||||||
@@ -354,7 +357,7 @@ static ssize_t stdout_write(int fd, const void * data, size_t size) {
|
|||||||
return bMirrorToUART?write(uart_fd, data, size):size;
|
return bMirrorToUART?write(uart_fd, data, size):size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stdio_open(const char * path, int flags, int mode) {
|
static int stdout_open(const char * path, int flags, int mode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user