Skip to content
Snippets Groups Projects
Commit f092d261 authored by burneykb's avatar burneykb
Browse files

Cleaning up code

parent ada358cd
No related branches found
No related tags found
No related merge requests found
......@@ -163,7 +163,7 @@ int main(int argc, char **argv)
if ((zyboSocket = connectToZybo()) < 0)
{
perror("Error connecting to Zybo...");
perror("Error connecting to Quad...");
free(respBuf);
free(commandBuf);
exit(1);
......@@ -182,16 +182,14 @@ int main(int argc, char **argv)
perror("Error creating log file...");
exit(1);
}
// writeStringToLog(logHeader);
// writeStringToLog(logHeader);
// watch for input from stdin (fd 0) to see when it has input
safe_fd_set(fileno(stdin), &rfds_master, &max_fd);
// watch for input from the zybo socket
safe_fd_set(zyboSocket, &rfds_master, &max_fd);
//printf("zyboSocket = %d, max_fd = %d\n", zyboSocket, max_fd);
//tell the quad we are ready to send it vrpn data
// Tell the quad we are ready to send it vrpn data
sendStartPacket();
// this function will be called whenever tracker receives data
......@@ -214,8 +212,9 @@ int main(int argc, char **argv)
} else if (activity) {
for(int fd = 0; fd <= max_fd; ++fd) {
if (FD_ISSET(fd, &rfds)) {
if(wasDisconnected(fd))
if(wasDisconnected(fd)){
break;
}
if (fd == fileno(stdin)) {
// break;
......@@ -247,13 +246,13 @@ int main(int argc, char **argv)
// Read the response from the control loop
int available;
ioctl(fd, FIONREAD, &available);
if (available < 12)
if (available < 12) {
continue;
}
int respLen = readQuad(respBuf, 12);
if(respLen <= 0) {
printf("CLI: ERROR reading from socket %d: %s\n", respLen, strerror(errno));
perror("ERROR reading from quad...\n");
}
//printf("recognized info from quad\n");
int id = getInt((unsigned char *)respBuf, 7);
findTimeDiff(id);
// if(respLen == 11) {
......@@ -384,8 +383,8 @@ int connectToZybo() {
int status = 0;
/* Use bluetooth by default */
if (getenv(QUAD_WIFI_ENV) == NULL && 0) {
printf("Using BT Settings\n")
if (!getenv(QUAD_WIFI_ENV)) {
printf("Using BT Settings\n");
struct sockaddr_rc addr;
// allocate a socket
......@@ -424,7 +423,6 @@ int connectToZybo() {
/* Quick 'n dirty, oh yeah! */
addr.sin_port = htons(atoi(getenv(QUAD_PORT_ENV)));
} else {
printf("using default port\n");
addr.sin_port = htons(QUAD_PORT_DEFAULT);
}
......@@ -433,6 +431,7 @@ int connectToZybo() {
perror("socket");
return -1;
}
printf("Connecting to Quad @ %s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
status = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
}
......@@ -475,7 +474,7 @@ 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 (0) {//getenv(NOQUAD_ENV)) {
if (getenv(NOQUAD_ENV)) {
return count;
}
if (pthread_mutex_lock(&quadSocketMutex)) {
......
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