#!/bin/ch
/*
fifo_app.c
Shows how to set up a normal user-level Linux process to communicate
with an RT task using FIFOs. FIFOs are queues of data, first-in-first-out,
that are set up as Linux character devices much like a serial port.
There are 64 FIFOs, named /dev/rtf0 through /dev/rtf63. These can be
accessed as usual for character devices, using the Unix open(), read(),
write() and close() functions.
This program opens one FIFO to the RT task for commands, and another
from the RT task for status back. There is handshaking in the RT task
such that status is written back for each command. This simplifies
programming here.
In general, a user task may have numerous FIFOs open between itself
and an RT task. The Unix function select() can be used to read from
the first available FIFO. We don't show that here.
*/
/*
THIS SOFTWARE WAS PRODUCED BY EMPLOYEES OF THE U.S. GOVERNMENT AS PART
OF THEIR OFFICIAL DUTIES AND IS IN THE PUBLIC DOMAIN.
*/
#include
#include
#include
#include /* open() */
#include /* O_RDONLY */
#include
#include "common.h" /* declarations for our command and status */
int main()
{
char * line;
char prompt[] = "> ";
static COMMAND_STRUCT command;
STATUS_STRUCT status;
int command_fd;
int status_fd;
static double freq;
int retval;
class CRequest Request;
class CResponse Response;
chchar *frequency, *onoff, *commands;
/*
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;
}
/*
Now we'll enter a loop, reading input from the terminal, parsing
it and composing a command written to the RT task FIFO. After this
we wait for a response, print it and continue.
We can handle "on", "off", and "freq ", where "on" turns the
speaker on at the last set frequency, "off" turns it off, and
is the frequency we want to set. "quit" quits.
*/
command.command_num = 0;
retval = 0;
line = 0; /* no input yet */
Response.begin();
Response.title("Web speaker control");
onoff = Request.getForm("onoff");
commands = Request.getForm("command");
/* parse the line and compose a command */
if (! strcmp(onoff, "On")) {
command.command = SOUND_ON;
}else if (! strcmp(onoff, "Off")) {
command.command = SOUND_OFF;
}
frequency= Request.getForm("x");
freq = strtod(frequency, NULL);
command.freq = freq;
/* if we dropped through to here, it's time to send the command */
command.command_num++;
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))) {
//printf("status: %d %d\n", status.command_num_echo, status.heartbeat);
}
/* set a new web page */
printf("\n");
printf(" Web RTAI Control \n");
printf(" \n");
printf(" ");
printf("