remove tcp_buffer
This commit is contained in:
2023-11-29 00:24:50 +01:00
parent 3cfb22f590
commit 9cc94f25f2

View File

@@ -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; uint8_t check = 0;
char* pc; char* pc;
char tcp_buffer[1024];
char text[256]; char text[256];
char color_r[3]; char color_r[3];
char color_g[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); tcp_recved(pcb, p->tot_len);
pc = (char*)p->payload; pc = (char*)p->payload;
len = p->tot_len; len = p->tot_len;
for (size_t i = 0; i < len; i++) { if (!strncmp(pc, "help", 4)) {
tcp_buffer[i] = pc[i];
}
if (!strncmp(tcp_buffer, "help", 4)) {
check = 1; check = 1;
tcp_write(pcb, "help : laat lijst zien met alle commando's\r\n" 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" "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" "setImage : veranderd te afbeelding (naam_afbeelding)\r\n"
"exit : sluit de verbinding\r\n", 354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); "exit : sluit de verbinding\r\n", 354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
tcp_output(pcb); tcp_output(pcb);
} else if (!strncmp(tcp_buffer, "text ", 5)) { } else if (!strncmp(pc, "text ", 5)) {
for (i = 0; i < len - 4; i++) { for (i = 0; i < len - 4; i++) {
text[i] = tcp_buffer[i + 5]; text[i] = pc[i + 5];
} }
text[i - 1] = '\0'; text[i - 1] = '\0';
lcd_clear_text(); 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; check = 1;
} else if (!strncmp(tcp_buffer, "color", 5)) { } else if (!strncmp(pc, "color", 5)) {
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
color_r[i] = tcp_buffer[i + 6]; color_r[i] = pc[i + 6];
color_g[i] = tcp_buffer[i + 10]; color_g[i] = pc[i + 10];
color_b[i] = tcp_buffer[i + 14]; color_b[i] = pc[i + 14];
} }
result_bg |= strtoul(color_r, &endptr, 10) << 16; result_bg |= strtoul(color_r, &endptr, 10) << 16;
result_bg |= strtoul(color_g, &endptr, 10) << 8; result_bg |= strtoul(color_g, &endptr, 10) << 8;
result_bg |= strtoul(color_b, &endptr, 10); result_bg |= strtoul(color_b, &endptr, 10);
check = 1; check = 1;
} else if (!strncmp(tcp_buffer, "textColor", 9)) { } else if (!strncmp(pc, "textColor", 9)) {
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
text_color_r[i] = tcp_buffer[i + 10]; text_color_r[i] = pc[i + 10];
text_color_g[i] = tcp_buffer[i + 14]; text_color_g[i] = pc[i + 14];
text_color_b[i] = tcp_buffer[i + 18]; text_color_b[i] = pc[i + 18];
} }
result_txt |= strtoul(text_color_r, &endptr, 10) << 16; result_txt |= strtoul(text_color_r, &endptr, 10) << 16;
result_txt |= strtoul(text_color_g, &endptr, 10) << 8; result_txt |= strtoul(text_color_g, &endptr, 10) << 8;
result_txt |= strtoul(text_color_b, &endptr, 10); result_txt |= strtoul(text_color_b, &endptr, 10);
check = 1; check = 1;
} else if (!strncmp(tcp_buffer, "listImages", 10)) { } else if (!strncmp(pc, "listImages", 10)) {
number_of_files = llfs_file_count(); number_of_files = llfs_file_count();
llfs_file_t file_list[number_of_files]; 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; check = 1;
} else if (!strncmp(tcp_buffer, "setImage", 8)) { } else if (!strncmp(pc, "setImage", 8)) {
char filename[len - 8]; char filename[len - 8];
for (size_t i = 0; i < len - 9; i++) { 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++) { 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'; filename[sizeof(filename) - 1] = '\0';
extension[3] = '\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; check = 1;
} else if (!strncmp(tcp_buffer, "exit", 4)) { } else if (!strncmp(pc, "exit", 4)) {
lcd_clear_images(); lcd_clear_images();
lcd_clear_text(); lcd_clear_text();
tcp_cmd_close(pcb); tcp_cmd_close(pcb);
check = 1; 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); 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) { if (err == ERR_OK && p == NULL) {
tcp_cmd_close(pcb); 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); tcp_write(pcb, "User: ", 6, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
} }