feature to send image from tcp connection

This commit is contained in:
Adolfo Reyna
2025-12-28 21:59:59 -05:00
parent 03e826653b
commit ed927e16b1
9 changed files with 212 additions and 3 deletions

View File

@@ -8,7 +8,7 @@
#define TCP_PORT 4242
#define DEBUG_BUF_SIZE 2048
#define TCP_IN_BUF_SIZE 128
#define TCP_IN_BUF_SIZE 20000 // Increased to hold full image + commands
// Circular buffer for debug output
static char debug_buf[DEBUG_BUF_SIZE];
@@ -97,11 +97,18 @@ static err_t tcp_server_poll(void *arg, struct tcp_pcb *tpcb) {
return ERR_OK;
}
static tcp_connection_callback_t g_conn_callback = NULL;
void tcp_set_connection_callback(tcp_connection_callback_t callback) {
g_conn_callback = callback;
}
static err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) {
if (!p) {
tcp_close(tpcb);
client_pcb = NULL;
printf("TCP debug client disconnected\n");
if (g_conn_callback) g_conn_callback(false);
return ERR_OK;
}
@@ -133,6 +140,7 @@ static err_t tcp_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
// Already have a client, reject or close old?
// Let's close the old one and accept the new one (last one wins)
tcp_abort(client_pcb);
if (g_conn_callback) g_conn_callback(false);
}
client_pcb = newpcb;
@@ -144,6 +152,7 @@ static err_t tcp_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
// However, we can also trigger writes from the main loop if we wanted, but polling is safer for threading.
printf("TCP debug client connected\n");
if (g_conn_callback) g_conn_callback(true);
return ERR_OK;
}