[comp.sys.tandy] dial.c for Tandy 16/16b/6000

jpr@dasys1.UUCP (Jean-Pierre Radley) (11/05/88)

In article <1368@nmtsun.nmt.edu> peter@hydrovax.nmt.edu (Peter Blemel) writes:
>In article <7@trilby.UUCP>, mike@trilby.UUCP (Michael K. Hammond) writes...
>>Questions for Tandy 16/16b/6000 owners
>>	2. Is there any way to use a HAYES modem instead of a tandy
>>	   modem with UUCP?
>The XENIX software includes a source code program for the tandy dialer that
>I hacked for hayes. Its just a matter of replacing the dial codes constants.
>Its in the UUCP lib dir called dial.c or tandy.c or something similar.

It isn't quite so straightforward. The script for dial.c needs a bit of
hacking to function properly with a Hayes compatible modem, and I am
appending my hacked version to this posting.

Go into /usr/lib/uucp, and remove the existing 'dial' program, and the
other binaries for tandy, hayes, or vadic. Rename the original 'dial.c' to
'dial.c.orig', if you want to keep it around. Or if you trust me, then just
remove 'dial.c' completely. Use my dial.c in its place, and type
	link_dial ; strip -sex dial

I also recommend that you rename /bin/cu to /bin/cu.tandy, and rename the
system 3 program, /bin/cu.s3, to /bin/cu. Then you can type "cu" like the
rest of Unix users. All I can say is that with this program, I've had
hours of successful usage of cu and uucp.

--cut here for dial.c source for Hayes-compatible modems on the t6k--

/* @(#) dial.c revised by JPRadley 2/15/88
 *  Simple dialer program for Hayes-compatible modems.
 *	See Hayes manual for command definitions
 *  Usage:  dial -Fn ttyname telnumber speed 
 *	returns 0 if a connection was made
 *		-1 otherwise
 */

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <termio.h>

#define SAME	0
struct termio term;
int baudrate;
char buffer[80];
int alrmint();

main(argc,argv)
int argc;
char *argv[];
{
	FILE *fdr,*fdw;
	int fd;

	if( argc != 5) {
		fprintf(stderr,"Usage: dial  -Fn devicename [number] speed\n");
		exit(-1);
	}
	if( (fd=open(argv[2],O_RDWR|O_NDELAY)) < 0 ) {
		fprintf(stderr,"dial: Can't open device: %s for reading.\n",argv[2]);
		exit(-1);
	}
	switch(atoi(argv[4])) {
		case 300:
			baudrate = B300;
			break;
		case 1200:
			baudrate = B1200;
			break;
		case 2400:
			baudrate = B2400;
			break;
		default:		 /* make YOUR choice here ! */
			baudrate = B2400;
	}		
	/* set line for no echo and specific speed */
	ioctl(fd, TCGETA, &term);
	term.c_cflag &= ~CBAUD;
	term.c_cflag |= CLOCAL|HUPCL|baudrate;
	term.c_lflag &= ~ECHO;
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	ioctl(fd, TCSETAW, &term);
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY);
	if( (fdr=fopen(argv[2],"r")) == NULL ) {
		fprintf(stderr,"dial: Can't open device: %s for reading.\n",argv[2]);
		exit(-1);
	}
	if( (fdw=fopen(argv[2],"w")) == NULL ) {
		fprintf(stderr,"dial: Can't open device: %s for writing.\n",argv[2]);
		exit(-1);
	}
	setbuf(fdw,0);			/* Want unbuffered I/O */
	/* setup for timeout in 10 seconds if no response */
	signal(SIGALRM, alrmint);
	alarm(10);
reread:
	fprintf(fdw,"AT\r");		/* Put Hayes into command mode */
	if( fgets(buffer,sizeof buffer, fdr) == (char *)NULL )
		exit(-1);
	if( strncmp(buffer, "OK",2) != SAME ) {	/* got back an OK? */
		sleep(1);
		goto reread;
	}
	alarm(0);				/* turn off alarm */
	sleep(1);
	fprintf(fdw,"ATDT %s\r", argv[3]);	/* put out dialing string */
	/* setup alarm.  (Longer timeout period for longer numbers) */
	alarm((2*strlen(argv[3])) + 5);
again:
	if( fgets(buffer,sizeof buffer,fdr) == (char *)NULL )
		exit(-1);
	if( strncmp(buffer, "NO CARRIER",10) == SAME )
		exit(-1);
	if( strncmp(buffer, "BUSY",4) == SAME )
		exit(-1);
	if( strncmp(buffer, "CONNECT",7) != SAME )
		 goto again;
	/* turn off CLOCAL now, since we want modem interrupts to work */
	ioctl(fd, TCGETA, &term);
	term.c_cflag &= ~CLOCAL;
	ioctl(fd, TCSETA, &term);
	exit(0);
}

alrmint()
{
	exit(-1);
}

cleanup()
{
	exit(0);	/* this was missing altogether, but there must be more
			 * to it than just exit! JPRadley */
}
--end of dial.c--
-- 
Jean-Pierre Radley		Honi soit		jpr@dasys1.UUCP
New York, New York		qui mal			...!hombre!jpradley!jpr
CIS: 76120,1341			y pense			...!hombre!trigere!jpr