#define NP1 "np1" #define NP2 "np2" #define MAX_BUF_SIZE 255 #include #include #include #include #include #include #include #include /*----------------------------------- the idea here is 1. kb.c creates: () file kbData.txt to send keyboard chars to LC3:kbDevice () file kbHS1.txt to send STX to LC3:kbdevice. () NAMED pipe kbHS2.txt to get ACK from LC3:kbdevice. () NAMED pipe dispData.txt to get char from LC3:dispDevice. () write( kbHS.txt, ACK ) () write( dispHS.txt, ACK ) () fork() () child: exec( a.out ) LOOP: LOOP-kbDevice: () readmem( kbHS.txt ) () if (read(kbHS.txt) == ACK ) if (read(stdio) == nonNull ) write( kbData.txt, char ) write( kbHS.txt, STX ) () if readmem( kbHS.txt ) == STX readmem( kbData.txt, char ) newData <== char fwrite( kbHS.txt, ACK ) () go LOOP-kbDevice LOOP-dispDevice: () DDR <== char () if readmem( dispHS.txt ) == ACK fwrite( dispData.txt, char) fwrite( dispData.txt, STX) else goto if (ACK) goto LOOP-dispDevice () if (read(dispHS.txt) == STX) char = read(dispData.txt) write( dispHS.txt, ACK) write(stdout, char) goto LOOP-kb.c ..................................................................... ...keyboard.......................................................... ...|................................................................. ..(c)................................................................ ...|..........|=======[A]==kb-3.c-[_]<===fr'A===kbHS2<=====(A)===|... ...|..........|...............|..................................^... ..fr'c........|...............|..................................|.. ...|..........|...............|..................................|... ...|==>[__]-kb-1.c===[c]===kb-2.c==fw'c==>kbData==rmem'c=>|......|... .........^..|.|..............\............................|...$fw'ACK .........|..|.|===[d]====>|...fw'STX.....................(c)......\.. .........|..|.............|...|...........................|........\. ......fr'd..|.............|...|==>kbHS1==rmem'T==LC3kb-1===LC3kb-2==| .........|..|.............|.......................\......./..|....... .........|..|<==========kb-4.c==(d)==>stdout.......\=====/..w'c...... ........(d)..................................................|...... .........|<=====vidData<===(d)<==$fw<===(d)<==LC3vid........(c)...... .........................................................../==>kBDR.. */ int main(int argc, char *argv[]) { int rdfd, wrfd, ret_val, count, numread; char buf[MAX_BUF_SIZE]; /* Create the first named - pipe */ ret_val = mkfifo(NP1, 0666); if ((ret_val == -1) && (errno != EEXIST)) { perror("Error creating the named pipe"); exit (1); } ret_val = mkfifo(NP2, 0666); if ((ret_val == -1) && (errno != EEXIST)) { perror("Error creating the named pipe"); exit (1); } /* Open the first named pipe for reading */ rdfd = open(NP1, O_RDONLY); /* Open the second named pipe for writing */ wrfd = open(NP2, O_WRONLY); /* Read from the first pipe */ numread = read(rdfd, buf, MAX_BUF_SIZE); buf[numread] = '0'; printf("Full Duplex Server : Read From the pipe : %sn", buf); /* Convert to the string to upper case */ count = 0; while (count < numread) { buf[count] = toupper(buf[count]); count++; } /* * Write the converted string back to the second * pipe */ write(wrfd, buf, strlen(buf)); }