| 1 | /* This program sends a file out the serial port to the PDP8. Use for |
| 2 | sending paper tape images. |
| 3 | It will prompt for the file to send or use first command |
| 4 | line argument. It needs a config file dumprest.cfg or $HOME/.dumprest.cfg |
| 5 | with the format defined in config.c |
| 6 | |
| 7 | The PDP8 end should be running before this program is started |
| 8 | |
| 9 | On the PC ctrl-break will terminate the program |
| 10 | */ |
| 11 | #ifdef PC |
| 12 | #include "encom.h" |
| 13 | #else |
| 14 | #include <termios.h> |
| 15 | #include <unistd.h> |
| 16 | #include <memory.h> |
| 17 | #endif |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <time.h> |
| 22 | #include <signal.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | |
| 26 | #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0])) |
| 27 | |
| 28 | int terminate = 0; |
| 29 | |
| 30 | #include "config.c" |
| 31 | #include "comm.c" |
| 32 | |
| 33 | main(argc,argv) |
| 34 | int argc; |
| 35 | char *argv[]; |
| 36 | { |
| 37 | int fd; |
| 38 | FILE *in; |
| 39 | char filename[256]; |
| 40 | char serial_dev[256]; |
| 41 | long baud; |
| 42 | int two_stop; |
| 43 | unsigned char buf[256]; |
| 44 | long count; |
| 45 | int rc; |
| 46 | |
| 47 | setup_config(&baud,&two_stop,serial_dev); |
| 48 | |
| 49 | if (argc > 1) { |
| 50 | strcpy(filename,argv[1]); |
| 51 | } else { |
| 52 | printf("Enter file name to send\n"); |
| 53 | fflush(stdout); |
| 54 | scanf("%s",filename); |
| 55 | } |
| 56 | |
| 57 | #ifdef PC |
| 58 | in = fopen(filename,"rb"); |
| 59 | #else |
| 60 | in = fopen(filename,"r"); |
| 61 | #endif |
| 62 | if (in == NULL) { |
| 63 | fprintf(stderr,"On file %s ",filename); |
| 64 | perror("open failed"); |
| 65 | exit(1); |
| 66 | } |
| 67 | |
| 68 | #if 0 |
| 69 | /* For testing write to file, only works in unix version */ |
| 70 | fd = open("dat",O_RDWR | O_CREAT | O_TRUNC,0666); |
| 71 | if (fd < 0) { |
| 72 | perror("Open failed on dat"); |
| 73 | exit(1); |
| 74 | } |
| 75 | #else |
| 76 | fd = init_comm(serial_dev,baud,two_stop); |
| 77 | #endif |
| 78 | |
| 79 | count = 0; |
| 80 | while(!terminate && !feof(in)) { |
| 81 | if ((rc = fread(buf,1,sizeof(buf),in)) < 0) { |
| 82 | perror("\nfile read failed\n"); |
| 83 | exit(1); |
| 84 | } |
| 85 | count += rc; |
| 86 | ser_write(fd,(char *)buf,rc); |
| 87 | } |
| 88 | if (terminate) |
| 89 | printf("Send aborted, %d bytes sent\n",count); |
| 90 | else |
| 91 | printf("Done, sent %d bytes (waiting for buffer to flush)\n",count); |
| 92 | exit(0); |
| 93 | } |