format
remove dangling else if when every other thing is if
use Lorenz's way of tcp_recv_cb
This commit is contained in:
2023-11-30 11:12:57 +01:00
parent 9aa53db35f
commit 0f1f041cbf

View File

@@ -117,7 +117,6 @@ static void tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
tcp_cmd_write(pcb, "Usage: bgcolor <background color>\n");
tcp_cmd_write(pcb, "Usage: bgcolor r g b\n");
return;
} if (strcmp(argv[0], "color") == 0) {
if (argc == 2) {
color_txt = (uint32_t)strtol(argv[1], NULL, 16);
@@ -148,8 +147,7 @@ static void tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
tcp_cmd_write(pcb, "File is not a bmp\n");
return;
}
}
if (argc == 2) {
} if (argc == 2) {
lcd_clear_images();
lcd_draw_img_from_fs(argv[1], 0, 0);
return;
@@ -161,15 +159,14 @@ static void tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
tcp_cmd_write(pcb, "Usage: setimage <filename>\n");
tcp_cmd_write(pcb, "Usage: setimage <filename> <x> <y>\n");
return;
} else if (strcmp(argv[0], "setgif") == 0) {
} if (strcmp(argv[0], "setgif") == 0) {
if (argc >= 2) {
char* ext = get_filename_ext(argv[1]);
if (strcmp(ext, "gif") != 0) {
tcp_cmd_write(pcb, "File is not a gif\n");
return;
}
}
if (argc == 2) {
} if (argc == 2) {
lcd_clear_images();
lcd_draw_gif_from_fs(argv[1], 0, 0);
return;
@@ -200,8 +197,19 @@ static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, er
char* argv[MAX_TOKENS];
LWIP_UNUSED_ARG(arg);
if (err == ERR_OK && p != NULL) {
tcp_recved(pcb, p->tot_len);
LOG_DEBUG(TAG, "TCP data received");
// Connection closed?
if (p == NULL && err == ERR_OK) {
LOG_INFO(TAG, "Remote closed connection");
return tcp_close(pcb);
}
if (err != ERR_OK) {
LOG_WARN(TAG, "TCP data received with error(%d): %s", err, lwip_strerr(err));
return ERR_OK;
}
char* next;
// Make sure the string is null terminated
@@ -213,6 +221,9 @@ static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, er
pbuf_copy_partial(p, cmd, len, 0);
cmd[len] = '\0';
// Tell the tcp stack that we have taken the data
tcp_recved(pcb, p->tot_len);
remove_newline(cmd);
// Split string into tokens by delimiter (space)
argv[0] = get_next_token(cmd, " ", &next);
@@ -226,15 +237,11 @@ static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, er
}
tcp_cmd_parser(pcb, argc, argv);
} else {
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
tcp_cmd_close(pcb);
}
tcp_cmd_write(pcb, "$> ");
defer:
pbuf_free(p);
return ERR_OK;
}