Commit 567ed673 authored by Mitch Burnett's avatar Mitch Burnett
Browse files

Make indentation consistent through code

Minor file formatting and clean up to help readability while going through to
read and debug the code
parent 8888f355
......@@ -35,122 +35,106 @@ const int MAX_CMD_LEN = 64;
int open_fifo(char *fifo_loc)
{
int fifo_fd = open(fifo_loc, O_RDONLY | O_NONBLOCK);
if (fifo_fd<0)
{
fprintf(stderr, "vegas_fits_writer: Error opening control fifo %s\n", fifo_loc);
perror("open");
// exit(1);
}
fprintf(stderr, "FIFO created with fd: %d\n", fifo_fd);
return fifo_fd;
int fifo_fd = open(fifo_loc, O_RDONLY | O_NONBLOCK);
if (fifo_fd<0)
{
fprintf(stderr, "vegas_fits_writer: Error opening control fifo %s\n", fifo_loc);
perror("open");
// exit(1);
}
fprintf(stderr, "FIFO created with fd: %d\n", fifo_fd);
return fifo_fd;
}
cmd_t check_cmd(int fifo_fd)
{
// fprintf(stderr, "Checking FIFO with fd: %d\n", fifo_fd);
char cmd[MAX_CMD_LEN];
// fprintf(stderr, "fifo_fd: %d\n", fifo_fd);
struct pollfd pfd[1];
//pfd[1].fd = fifo_fd;
//pfd[1].events = POLLIN;
pfd[0].fd = fileno(stdin);
pfd[0].events = POLLIN;
// ?, num file desc, timeout
int rv = poll(pfd, 1, 0);
if (rv==0)
{
// fprintf(stderr, "rv == 0 :(\n");
return INVALID; //????
}
else if (rv<0)
{
if (errno!=EINTR)
{
perror("poll");
}
// fprintf(stderr, "rv < 0 :(\n");
return INVALID; //????
}
// printf("NEW COMMAND!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
// clear the command
memset(cmd, 0, MAX_CMD_LEN);
int i;
for (i=0; i<1; ++i)
{
rv = 0;
if (pfd[i].revents & POLLIN)
{
if (read(pfd[i].fd, cmd, MAX_CMD_LEN-1)<1)
{
// fprintf(stderr, "read failed :(\n");
// perror("read");
// return INVALID;
}
else
{
// fprintf(stderr, "read success :(\n");
rv = 1;
break;
}
}
}
if (pfd[0].revents==POLLHUP) {
//fprintf(stderr, "POLLHUP :(\n");
}
if (rv==0)
{
// fprintf(stderr, "rv == 0 again :(\n");
return INVALID;
}
else if (rv<0)
{
// fprintf(stderr, "rv < 0 again :(\n");
if (errno==EAGAIN)
{
return INVALID;
}
else
{
perror("read");
return INVALID;
}
}
// Truncate at newline
// TODO: allow multiple commands in one read?
char *ptr = strchr(cmd, '\n');
if (ptr!=NULL)
{
*ptr='\0';
}
// Process the command
if (strncasecmp(cmd,"START",MAX_CMD_LEN)==0)
{
return START;
}
else if (strncasecmp(cmd,"STOP",MAX_CMD_LEN)==0)
{
printf("FIFO: A STOP was issued to the hashpipe codes!!!!!!!!!!!!!!!!!!\n");
return STOP;
}
else if (strncasecmp(cmd,"QUIT",MAX_CMD_LEN)==0)
{
printf("FIFO: A QUIT was issued to the hashpipe codes!!!!!!!!!!!!!!!!!!\n");
return QUIT;
}
else
{
// Unknown command
return INVALID;
}
// fprintf(stderr, "Checking FIFO with fd: %d\n", fifo_fd);
char cmd[MAX_CMD_LEN];
// fprintf(stderr, "fifo_fd: %d\n", fifo_fd);
struct pollfd pfd[1];
//pfd[1].fd = fifo_fd;
//pfd[1].events = POLLIN;
pfd[0].fd = fileno(stdin);
pfd[0].events = POLLIN;
// ?, num file desc, timeout
int rv = poll(pfd, 1, 0);
if (rv==0) {
//fprintf(stderr, "rv == 0 :(\n");
return INVALID; //????
} else if (rv<0) {
if (errno!=EINTR) {
perror("poll");
}
//fprintf(stderr, "rv < 0 :(\n");
return INVALID; //????
}
// printf("NEW COMMAND!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
// clear the command
memset(cmd, 0, MAX_CMD_LEN);
int i;
for (i=0; i<1; ++i) {
rv = 0;
if (pfd[i].revents & POLLIN) {
if (read(pfd[i].fd, cmd, MAX_CMD_LEN-1)<1) {
//fprintf(stderr, "read failed :(\n");
//perror("read");
//return INVALID;
} else {
//fprintf(stderr, "read success :(\n");
rv = 1;
break;
}
}
}
if (pfd[0].revents==POLLHUP) {
//fprintf(stderr, "POLLHUP :(\n");
}
if (rv==0) {
//fprintf(stderr, "rv == 0 again :(\n");
return INVALID;
} else if (rv<0) {
//fprintf(stderr, "rv < 0 again :(\n");
if (errno==EAGAIN) {
return INVALID;
} else {
perror("read");
return INVALID;
}
}
// Truncate at newline
// TODO: allow multiple commands in one read?
char *ptr = strchr(cmd, '\n');
if (ptr!=NULL) {
*ptr='\0';
}
// Process the command
if (strncasecmp(cmd,"START",MAX_CMD_LEN)==0) {
return START;
} else if (strncasecmp(cmd,"STOP",MAX_CMD_LEN)==0) {
printf("FIFO: A STOP was issued to the hashpipe codes!!!!!!!!!!!!!!!!!!\n");
return STOP;
} else if (strncasecmp(cmd,"QUIT",MAX_CMD_LEN)==0) {
printf("FIFO: A QUIT was issued to the hashpipe codes!!!!!!!!!!!!!!!!!!\n");
return QUIT;
} else {
// Unknown command
return INVALID;
}
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment