/* speaker_on.c */ #include <stdio.h> #include <unistd.h> /* open() */ #include <fcntl.h> /* O_RDONLY */ #include <readline/readline.h> #include "common.h" /* declarations for our command and status */ int speaker_on() { COMMAND_STRUCT command; STATUS_STRUCT status; int command_fd; int status_fd; int retval; /* Open the command and status FIFOs. */ if ((command_fd = open(RTF_COMMAND_DEV, O_WRONLY)) < 0) { fprintf(stderr, "error opening %s\n", RTF_COMMAND_DEV); return -1; } if ((status_fd = open(RTF_STATUS_DEV, O_RDONLY)) < 0) { fprintf(stderr, "error opening %s\n", RTF_STATUS_DEV); return -1; } /* We set "on" speaker on at the last set frequency. */ retval = 0; command.command = SOUND_ON; if (sizeof(command) != write(command_fd, &command, sizeof(command))) { fprintf(stderr, "can't write command\n"); retval = -1; } /* now check for the reply */ if (sizeof(status) == read(status_fd, &status, sizeof(status))) { if(status.command==SOUND_OFF) printf("status: off freq:%d heartbeat:%d\n", status.freq, status.heartbeat); else printf("status: on freq:%d heartbeat:%d\n", status.freq, status.heartbeat); } close(status_fd); close(command_fd); return retval; }