home *** CD-ROM | disk | FTP | other *** search
- /* xmrglf1.c - Xmodem receive using G'Leaf Comm lib */
- #include "stdio.h"
- #include "gf.h"
- #include "asiports.h"
-
- #define CARD 2 /* which RS-232 port to use */
-
- char combuf[1150] ;
- char obuf[1150] ;
- int port = 1 ;
-
-
- main(argc,argv)
- int argc ;
- char *argv[] ;
- {
- int c , err , n , t ,speed , lstat , mstat ;
-
- if( argc < 3 )
- { printf(" no file name or baud rate \n");
- exit(5) ;
- }
-
- sscanf(argv[2],"%d",&speed) ;
- asisetup(port,ASINOUT,0,combuf,1000,obuf,1000) ;
- asdtr(port,ON) ;
- asiinit(port,speed,0,1,8) ;
- asistart(port,ASINOUT) ;
-
- eltime() ;
- err = rcv_filet(argv[1],&n) ;
- t = eltime() ;
- printf(" %4d Ticks or %8.2f Secs \n",t,((float) t) / 18.2) ;
- printf(" rcv_file - err=%d no recs. xmtted=%d \n",err,n) ;
-
- asiquit(port) ;
- }
-
-
- int rcv_file(fn,pn)
- char fn[] ; /* file name */
- int *pn ; /* put record count here */
- {
- FILE *fd ;
- char buf[140] ;
- int block , ret ,nw ;
- struct XMBUF locparms ;
-
- fd = fopen(fn,"wb") ;
- if( fd == NULL )
- { printf(" can't open file \n");
- return(-1) ;
- }
-
- block = 1 ;
- ret = -200 ;
- while( 1 == 1 )
- { locparms.xblocknum = block ;
- ret = asixrecvbuf(port,buf,&locparms) ;
- if( ret == 0 )
- {
- nw = fwrite(buf,1,128,fd) ;
- printf(" block %4d - rcvd OK \n",block );
- }
- else if( locparms.xstatus == 6 )
- { printf(" rcvd EOT \n") ;
- asiputc(port,ACK) ;
- break ;
- }
- else
- { printf(" block %4d - error %d \n",block);
- break ;
- }
- block ++ ;
- }
- fclose(fd) ;
- *pn = block ;
- return( ret ) ;
- }