#include #include #include #include #include #include #include #include "pcl4c.h" #include "ascii.h" #include "term_io.h" #include "xypacket.h" #include "xymodem.h" #define FALSE 0 #define TRUE !FALSE int TxyModem( int Port, /* COM port [0..3] */ char Filename[], /* filename buffer */ char Buffer[], /* 1024 byte data buffer */ int OneKflag, /* if TRUE, use 1K blocks when possible */ int BatchFlag) /* if TRUE, send filename in packet 0 */ {int i, k; int Code; int Handle; /* file Handle */ char c; int p; char PacketType; char PacketNbr; int PacketSize; int FirstPacket; unsigned short CheckSum; int Number1K = 0; /* total # 1K packets */ int Number128 = 0; /* total # 128 byte packets */ char NCGchar = NAK; long FileSize; char temp[81]; int EmptyFlag = FALSE; /* begin */ if(BatchFlag) if(Filename[0]=='\0') EmptyFlag = TRUE; if(!EmptyFlag) {/* Filename is not empty */ EmptyFlag = FALSE; Handle = open(Filename,O_RDONLY|O_BINARY,S_IREAD); if(Handle<0) {strcpy(temp,"Cannot open "); strcat(temp,Filename); DisplayLine(temp,NULL,0); return(FALSE); } } DisplayLine("XYMODEM send: waiting for Receiver ",NULL,0); while(SioKeyPress()) SioKeyRead(); /* compute # blocks */ if(!EmptyFlag) {FileSize = filelength(Handle); if(OneKflag) Number1K = (int) (FileSize / 1024L); Number128 = (int) ((FileSize-1024L*(long)Number1K) / 128L); if(128L*Number128+1024*Number1K < FileSize) Number128++; sprintf(temp,"%d 1024 & %d 128 byte packets",Number1K,Number128); DisplayLine(temp,NULL,0); } else {/* empty file */ Number128 = 0; Number1K = 0; /*DisplayLine("Empty File",NULL,0);*/ } /* clear comm port ( there may be several NAKs queued up ) */ SioRxFlush(Port); /* get receivers start up NAK, 'C', or 'G' */ if(!TxStartup(Port,&NCGchar)) return(FALSE); /* loop over all packets */ if(BatchFlag) FirstPacket = 0; else FirstPacket = 1; for(p=FirstPacket;p<=Number1K+Number128;p++) {/* user aborts ? */ if(SioKeyPress()) if((char)SioKeyRead()==CAN) {TxCAN(Port); DisplayLine("*** Canceled by USER ***",NULL,0); return(FALSE); } /* issue message */ sprintf(temp,"Packet %d",p); DisplayLine(temp,NULL,0); /* load up Buffer */ if(p==0) { /* Filename packet ! */ PacketSize = 128; k = 0; for(i=0;i 0 */ {/* DATA Packet: use 1K or 128 byte block ? */ if(p<=Number1K) PacketSize = 1024; else PacketSize = 128; /* read next block from disk */ Code = read(Handle,Buffer,PacketSize); if(Code<=0) {SayError(Port,"Error on disk read"); return(FALSE); } for(i=Code;i