diff --git a/groundStation/src/microcart_cli.c b/groundStation/src/microcart_cli.c index 4f9ca0164ad86e30b8e56bd0514c53eceb1d92bc..52930cf27575840987f61b2251d04e08a28744be 100644 --- a/groundStation/src/microcart_cli.c +++ b/groundStation/src/microcart_cli.c @@ -45,6 +45,7 @@ int safe_fd_set(int , fd_set* , int* ); int safe_fd_clr(int , fd_set* , int* ); static void cb(struct ucart_vrpn_TrackerData *); +static int new_client(int fd); /* Thread-safe wrappers */ pthread_mutex_t quadSocketMutex; @@ -58,6 +59,12 @@ static int backendSocket; struct ucart_vrpn_tracker * tracker = NULL; const char *logHeader = "";//"#\n#\tDefault log header\n#\tEverything after '#'`s will be printed as is in the processed logs.\n#\n\0"; +#define MAX_CLIENTS 32 +#define CLIENT_BUFFER_SIZE 1024 +static char client_buffers[MAX_CLIENTS][CLIENT_BUFFER_SIZE]; +static int client_fds[MAX_CLIENTS]; +static size_t num_clients = 0; + pthread_mutex_t quadResponseMutex, cliInputMutex ; unsigned char *respBuf, *commandBuf; int newQuadResponse = 0, newCliInput = 0; @@ -131,6 +138,13 @@ int main(int argc, char **argv) /* Add to socket set */ safe_fd_set(backendSocket, &rfds, &max_fd); + + /* Initialize client buffers */ + for (int i = 0; i < MAX_CLIENTS; i++) { + client_fds[i] = -1; + client_buffers[i][0] = '\n'; + } + signal(SIGINT, killHandler); if (pthread_mutex_lock(&quadSocketMutex)) { @@ -222,6 +236,9 @@ int main(int argc, char **argv) if (new_fd < 0) { warn("accept"); } else { + if (new_client(fd)) { + safe_fd_set(fd, &rfds, &max_fd); + } } } } @@ -406,3 +423,19 @@ static ssize_t writeQuad(const char * buf, size_t count) { return retval; } + +static int new_client(int fd) +{ + if (num_clients >= MAX_CLIENTS) { + close(fd); + return 0; + } + num_clients++; + + int new_slot; + for (size_t i = 0; i < MAX_CLIENTS; i++) { + if + } + + return 1; +}