home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / 2.9-derivatives / 2.9-pro350 / stand / getfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-02-26  |  1.8 KB  |  96 lines

  1. /* This program runs standalone to get a disk image off the
  2.  * line printer serial port. The program "putfile" is expected
  3.  * to be run on a unix machine connected to the line to do the
  4.  * downloading. Although some error recovery is implemented, the
  5.  * protocol is NOT fail safe.
  6.  */
  7. #include <stdio.h>
  8. #include <sys/param.h>
  9. #include <sys/inode.h>
  10. #include "../saio.h"
  11. char module[] = {"Getfile"};
  12. struct iob iodev;
  13. #define    PREFIX    05
  14. #define    ACK    07
  15. #define    NAK    011
  16. struct device {
  17.     int rcsr;
  18.     int rbuf;
  19.     int xcsr;
  20.     int xbuf;
  21. };
  22. #define KLADDR ((struct device *)0177560)
  23. #define DONE 0200
  24. main()
  25. {
  26.     register int i, chk;
  27.     register char *ptr;
  28.     char ack, str[100];
  29.     int devtype, ret;
  30.  
  31.     iodev.i_cc = 512;
  32.     iodev.i_ma = iodev.i_buf;
  33.     do {
  34.         printf("Controller type (0-R5 1-RD 2-RA) ?");
  35.         gets(str);
  36.     } while (str[0] < '0' || str[0] > '2');
  37.     devtype = (int)(str[0]-'0');
  38.     do {
  39.         printf("Drive # ?");
  40.         gets(str);
  41.     } while (str[0] < '0' || str[0] > '3');
  42.     iodev.i_unit = (int)(str[0] - '0');
  43.     do {
  44.         printf("Start offset ?");
  45.         gets(str);
  46.     } while (sscanf(str, "%D", &iodev.i_bn) != 1);
  47.     if (devtype == 2)
  48.         raopen(&iodev);
  49.     printf("Ready for putfile command\n");
  50.     while(1) {
  51.         chk = 0;
  52.         ptr = iodev.i_buf;
  53.         do {
  54.             ack = getch();
  55.         } while (ack != PREFIX);
  56.         for (i = 0; i < 512; i++) {
  57.             chk += (*ptr++ = getch());
  58.         }
  59.         ack = getch();
  60.         if ((ack & 0377) != (chk & 0377)) {
  61.             ack = NAK;
  62.         } else {
  63.             switch(devtype) {
  64.             case 0:
  65.                 ret = r5strategy(&iodev, WRITE);
  66.                 break;
  67.             case 1:
  68.                 ret = rdstrategy(&iodev, WRITE);
  69.                 break;
  70.             case 2:
  71.                 ret = rastrategy(&iodev, WRITE);
  72.             };
  73.             if (ret >= 0) {
  74.                 ack = ACK;
  75.                 iodev.i_bn++;
  76.             }
  77.             else
  78.                 ack = NAK;
  79.         }
  80.         putch(ack);
  81.     }
  82. }
  83. putch(c)
  84. char c;
  85. {
  86.     while ((KLADDR->xcsr & DONE) == 0) ;
  87.     KLADDR->xbuf = c;
  88. }
  89. getch()
  90. {
  91.     register char c;
  92.     while ((KLADDR->rcsr & DONE) == 0) ;
  93.     c = KLADDR->rbuf & 0377;
  94.     return(c);
  95. }
  96.