From 9cc94f25f21fd142076f0381d9c83a62160aaa34 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Wed, 29 Nov 2023 00:24:50 +0100 Subject: [PATCH] tcp_cmd remove tcp_buffer --- project/Core/Src/tcp_cmd.c | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/project/Core/Src/tcp_cmd.c b/project/Core/Src/tcp_cmd.c index 72f477a..527b23a 100644 --- a/project/Core/Src/tcp_cmd.c +++ b/project/Core/Src/tcp_cmd.c @@ -24,7 +24,6 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t uint8_t check = 0; char* pc; - char tcp_buffer[1024]; char text[256]; char color_r[3]; char color_g[3]; @@ -43,12 +42,9 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t tcp_recved(pcb, p->tot_len); pc = (char*)p->payload; len = p->tot_len; + - for (size_t i = 0; i < len; i++) { - tcp_buffer[i] = pc[i]; - } - - if (!strncmp(tcp_buffer, "help", 4)) { + if (!strncmp(pc, "help", 4)) { check = 1; tcp_write(pcb, "help : laat lijst zien met alle commando's\r\n" "text : geeft tekst mee die op LCD komt (uw_text)\r\n" @@ -58,9 +54,9 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t "setImage : veranderd te afbeelding (naam_afbeelding)\r\n" "exit : sluit de verbinding\r\n", 354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); tcp_output(pcb); - } else if (!strncmp(tcp_buffer, "text ", 5)) { + } else if (!strncmp(pc, "text ", 5)) { for (i = 0; i < len - 4; i++) { - text[i] = tcp_buffer[i + 5]; + text[i] = pc[i + 5]; } text[i - 1] = '\0'; lcd_clear_text(); @@ -68,29 +64,29 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t check = 1; - } else if (!strncmp(tcp_buffer, "color", 5)) { + } else if (!strncmp(pc, "color", 5)) { for (size_t i = 0; i < 3; i++) { - color_r[i] = tcp_buffer[i + 6]; - color_g[i] = tcp_buffer[i + 10]; - color_b[i] = tcp_buffer[i + 14]; + color_r[i] = pc[i + 6]; + color_g[i] = pc[i + 10]; + color_b[i] = pc[i + 14]; } result_bg |= strtoul(color_r, &endptr, 10) << 16; result_bg |= strtoul(color_g, &endptr, 10) << 8; result_bg |= strtoul(color_b, &endptr, 10); check = 1; - } else if (!strncmp(tcp_buffer, "textColor", 9)) { + } else if (!strncmp(pc, "textColor", 9)) { for (size_t i = 0; i < 3; i++) { - text_color_r[i] = tcp_buffer[i + 10]; - text_color_g[i] = tcp_buffer[i + 14]; - text_color_b[i] = tcp_buffer[i + 18]; + text_color_r[i] = pc[i + 10]; + text_color_g[i] = pc[i + 14]; + text_color_b[i] = pc[i + 18]; } result_txt |= strtoul(text_color_r, &endptr, 10) << 16; result_txt |= strtoul(text_color_g, &endptr, 10) << 8; result_txt |= strtoul(text_color_b, &endptr, 10); check = 1; - } else if (!strncmp(tcp_buffer, "listImages", 10)) { + } else if (!strncmp(pc, "listImages", 10)) { number_of_files = llfs_file_count(); llfs_file_t file_list[number_of_files]; @@ -104,13 +100,13 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t } check = 1; - } else if (!strncmp(tcp_buffer, "setImage", 8)) { + } else if (!strncmp(pc, "setImage", 8)) { char filename[len - 8]; for (size_t i = 0; i < len - 9; i++) { - filename[i] = tcp_buffer[i + 9]; + filename[i] = pc[i + 9]; } for (size_t i = 0; i < 3; i++) { - extension[i] = tcp_buffer[i + len - 3]; + extension[i] = pc[i + len - 3]; } filename[sizeof(filename) - 1] = '\0'; extension[3] = '\0'; @@ -143,14 +139,14 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t } check = 1; - } else if (!strncmp(tcp_buffer, "exit", 4)) { + } else if (!strncmp(pc, "exit", 4)) { lcd_clear_images(); lcd_clear_text(); tcp_cmd_close(pcb); check = 1; } - if (!check && (strncmp(tcp_buffer, "\r\n", 2) != 0)) { + if (!check && (strncmp(pc, "\r\n", 2) != 0)) { tcp_write(pcb, "Onbestaand commando: help voor lijst van commando's\r\n", 53, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); } @@ -167,7 +163,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t if (err == ERR_OK && p == NULL) { tcp_cmd_close(pcb); } - if (strncmp(tcp_buffer, "\r\n", 2) != 0) { + if (strncmp(pc, "\r\n", 2) != 0) { tcp_write(pcb, "User: ", 6, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); }