home *** CD-ROM | disk | FTP | other *** search
- /* xmsglf1.c - Xmodem send 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) ;
- err = asisetup(port,ASINOUT,0,combuf,1000,obuf,1000) ;
- printf(" asisetup - err=%d \n",err) ;
- asdtr(port,ON) ;
- err = asiinit(port,speed,0,1,8) ;
- printf(" asiinit - err=%d \n",err) ;
- err = asistart(port,ASINOUT) ;
- printf(" asistart - err=%d \n",err) ;
- eltime() ;
- err = send_filet(argv[1],&n) ;
- t = eltime() ;
- printf(" %4d Ticks or %8.2f Secs \n",t,((float) t) / 18.2) ;
- printf(" send_file - err=%d no recs. xmtted=%d \n",err,n) ;
-
- asiquit(port) ;
- }
-
-
- int send_file(fn,pn)
- char fn[] ; /* file name */
- int *pn ; /* put record count here */
- {
- FILE *fd ;
- char buf[140] ;
- int block , ret , nr ;
- struct XMBUF locparms ;
-
- fd = fopen(fn,"rb") ;
- if( fd == NULL )
- { printf(" can't open file \n");
- return(-1) ;
- }
-
- block = 1 ;
- ret = -200 ;
- nr = fread(buf,1,128,fd) ;
- while( nr > 0 )
- { while( nr < 128 )
- { buf[nr] = '\0' ;
- nr ++ ;
- }
- ret = asixsendbuf(port,buf,block) ;
- if( ret == 0 )
- printf(" block %4d - sent OK \n",block );
- else
- { printf(" block %4d - error %d \n",block,ret);
- break ;
- }
- nr = fread(buf,1,128,fd) ;
- block++ ;
- }
- asiputc(port,EOT) ;
- fclose(fd) ;
- *pn = block ;
- return( ret ) ;
- }