add timestamp tracking to UDP client table

This commit is contained in:
jess 2026-04-03 03:47:51 -07:00
parent 3e0cbfd131
commit a9f6f9f6ac
1 changed files with 3 additions and 1 deletions

View File

@ -20,7 +20,6 @@
#define UDP_PORT 5941 #define UDP_PORT 5941
#define UDP_BUF_SIZE 128 #define UDP_BUF_SIZE 128
#define UDP_CLIENTS_MAX 16 #define UDP_CLIENTS_MAX 16
#define CLIENT_TIMEOUT_MS 30000
static int udp_sock = -1; static int udp_sock = -1;
static esp_netif_t *ap_netif; static esp_netif_t *ap_netif;
@ -28,6 +27,7 @@ static esp_netif_t *ap_netif;
static struct { static struct {
struct sockaddr_in addr; struct sockaddr_in addr;
uint8_t mac[6]; uint8_t mac[6];
uint32_t last_touch_ms;
bool active; bool active;
} clients[UDP_CLIENTS_MAX]; } clients[UDP_CLIENTS_MAX];
@ -41,6 +41,7 @@ static void client_touch(const struct sockaddr_in *addr)
for (int i = 0; i < client_count; i++) { for (int i = 0; i < client_count; i++) {
if (clients[i].addr.sin_addr.s_addr == addr->sin_addr.s_addr && if (clients[i].addr.sin_addr.s_addr == addr->sin_addr.s_addr &&
clients[i].addr.sin_port == addr->sin_port) { clients[i].addr.sin_port == addr->sin_port) {
clients[i].last_touch_ms = xTaskGetTickCount() * portTICK_PERIOD_MS;
xSemaphoreGive(client_mutex); xSemaphoreGive(client_mutex);
return; return;
} }
@ -63,6 +64,7 @@ static void client_touch(const struct sockaddr_in *addr)
} }
} }
clients[client_count].last_touch_ms = xTaskGetTickCount() * portTICK_PERIOD_MS;
client_count++; client_count++;
printf("UDP: client added (%d)\n", client_count); printf("UDP: client added (%d)\n", client_count);
} }