/*
speaker_freq()
*/
#include
#include /* open() */
#include /* O_RDONLY */
#include
#include "common.h" /* declarations for our command and status */
int speaker_freq(int freq)
{
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 "freq ",
*/
retval = 0;
/* parse the line and compose a command */
command.command = SOUND_ON;
command.freq = freq;
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;
}