Skip to content
Snippets Groups Projects
Commit f6854896 authored by Jake Drahos's avatar Jake Drahos
Browse files

Still kinda broken

parent a309c835
No related branches found
No related tags found
No related merge requests found
# Declaration of variables
GCC=gcc
GXX=g++
CFLAGS= -Wall -Wpedantic -Wextra -Werror -std=c99 -g -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function
CFLAGS= -Wall -Wpedantic -Wextra -Werror -std=c99 -g -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable
CXXFLAGS= -Wall -Wno-reorder -std=c++11 -g
INCLUDES = $(foreach dir, $(INCDIR), -I$(dir))
......
......@@ -4,6 +4,7 @@
#define DEFAULT_SOCKET "/var/run/ucart.socket"
#define SOCKET_ENV "UCART_SOCKET"
#define NOQUAD_ENV "UCART_NO_QUAD"
#endif
......@@ -110,10 +110,10 @@ static void cb(struct ucart_vrpn_TrackerData * td)
int main(int argc, char **argv)
{
// pthread_t quadResponse, cliInput;
fd_set rfds;
fd_set rfds_master;
int activity;
int max_fd = 0;
FD_ZERO(&rfds);
FD_ZERO(&rfds_master);
/*
* Create backend listening socket
......@@ -147,7 +147,7 @@ int main(int argc, char **argv)
}
/* Add to socket set */
safe_fd_set(backendSocket, &rfds, &max_fd);
safe_fd_set(backendSocket, &rfds_master, &max_fd);
/* Initialize client buffers */
......@@ -185,11 +185,10 @@ int main(int argc, char **argv)
}
// writeStringToLog(logHeader);
// watch for input from stdin (fd 0) to see when it has input
safe_fd_set(fileno(stdin), &rfds, &max_fd);
safe_fd_set(fileno(stdin), &rfds_master, &max_fd);
// watch for input from the zybo socket
//safe_fd_set(zyboSocket, &rfds, &max_fd);
//safe_fd_set(zyboSocket, &rfds_master, &max_fd);
//printf("zyboSocket = %d, max_fd = %d\n", zyboSocket, max_fd);
......@@ -203,14 +202,23 @@ int main(int argc, char **argv)
// start the prompt
fprintf(stdout, "$microcart> ");
struct timeval timeout = {
.tv_sec = 1,
.tv_usec = 0
};
while(keepRunning)
{
fd_set rfds;
rfds = rfds_master;
activity = select(max_fd+1, &rfds, NULL, NULL, NULL);
if(activity == -1) {
perror("select() ");
} else if (activity) {
fprintf(stderr, "Select activity = %d\n", activity);
for(int fd = 0; fd <= max_fd; ++fd) {
if (FD_ISSET(fd, &rfds)) {
fprintf(stderr, "Select woke for fd %d\n", fd);
if (fd == fileno(stdin)) {
unsigned char userCommand[CMD_MAX_LENGTH];
read(fileno(stdin), (char *)userCommand, sizeof(userCommand));
......@@ -247,8 +255,10 @@ int main(int argc, char **argv)
if (new_fd < 0) {
warn("accept");
} else {
if (new_client(fd)) {
safe_fd_set(fd, &rfds, &max_fd);
fprintf(stderr, "Connection\n");
if (new_client(new_fd)) {
fprintf(stderr, "Added client\n");
safe_fd_set(new_fd, &rfds_master, &max_fd);
}
}
} else if (get_client_index(fd) > -1) {
......@@ -264,6 +274,8 @@ int main(int argc, char **argv)
remove_client(client_fds[i]);
}
}
timeout.tv_sec = 1;
timeout.tv_usec = 0;
}
}
......@@ -431,6 +443,9 @@ int safe_fd_clr(int fd, fd_set* fds, int* max_fd) {
static ssize_t writeQuad(const char * buf, size_t count) {
ssize_t retval;
if (getenv(NOQUAD_ENV)) {
return count;
}
if (pthread_mutex_lock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__);
}
......@@ -542,8 +557,9 @@ static void client_recv(int fd)
buffer[newline] = '\0';
unsigned char * packet;
fprintf(stderr, "Client sent: %s\n", buffer);
formatCommand((unsigned char *) buffer, &packet);
writeQuad((char *) packet, packet[6] << 8);
writeQuad((char *) packet, 4);
free(packet);
char * rest = &buffer[newline] + 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment