1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <rtl_fifo.h>
#include <math.h>
void outf(int fd,double d)
{
char x[100];
int n = sprintf(x,"%f\n",d);
write(fd,x,n);
}
int main(void)
{
fd_set rfds;
struct timeval tv;
int fifofd[2], datafd[2];
int findex;
double d;
if ((fifofd[0] = open("/dev/rtf1", O_RDONLY)) < 0) {
fprintf(stderr, "Error opening /dev/rtf1\n");
exit(1);
}
if ((fifofd[1] = open("/dev/rtf2", O_RDONLY)) < 0) {
fprintf(stderr, "Error opening /dev/rtf2\n");
exit(1);
}
umask(0777);
if ((datafd[0] = creat("sin.data", 0777)) < 0) {
fprintf(stderr, "Error opening sin.data\n");
exit(1);
}
if ((datafd[1] = creat("cos.data", 0777)) < 0) {
fprintf(stderr, "Error opening cos.data\n");
exit(1);
}
/* now start the tasks */
printf("Starting\n");
FD_ZERO(&rfds);
FD_SET(fifofd[0], &rfds);
FD_SET(fifofd[1], &rfds);
tv.tv_sec = 1;
tv.tv_usec = 0;
while(select(FD_SETSIZE, &rfds, NULL, NULL, &tv) >0){
printf("!");
if(FD_ISSET(fifofd[0], &rfds)) findex = 0;
else findex = 1;
read(fifofd[findex], &d, sizeof(double));
outf(datafd[findex],d);
}
printf("Done!");
return 0;
}
|