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

Still kinda broken

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