17-Feb-84 10:54:02-EST,5106;000000000001
Return-Path: <bray%tennessee.tennessee@Rand-Relay>
Received: from rand-relay.ARPA by COLUMBIA-20.ARPA with TCP; Fri 17 Feb 84 10:53:50-EST
Date:     Thu, 16 Feb 84 22:13 EST
From: John Bray <bray.tennessee@Rand-Relay>
Return-Path: <bray%tennessee.tennessee@Rand-Relay>
Subject:  dialer
To: cc.fdc@columbia-20.arpa
Via:  tennessee; 17 Feb 84 7:35-PST




	frank,  we've been having a lot of dead and dying 1200 baud modems
	here recently.  of COURSE there aren't enough then.  result is
	an all too common hour wait while you re-dial about eight billion
	times.  i too impatient for that, so i cobbled up a little
	dialer routine.  it follows, if i can get csnet's send routine to
	take it.  claim that it's good c, but it does work.

	takes the system here about 10-12 secs to answer and get modems 
	talking, so i've found 13 seconds for carrier wait on the hayes
	is enoughve reliability.  it's dialed over 100 times reliably
	till it ganswer.  set it up to send \r's to get the network
	here to autobaud then exec the program.  since i usually have
	several versions of kermit in test, it's nice to be able to select
	the program to be exec'd.  thought that someone else without a 
	dialing version of kermit might find it useful too.

	i've got several comments to the recent discussion, but haven't been
	able to get csnet's mailer to take the file.  i'll get them to
	you some way.

	also, is there a way for up poor people without direct arpa con-
	nections to get at the new kermit files via direct dial-up?

	the dialer follows if i can get send to take it....





/*
 *		dial.c
 *
 *	for dc hayes smart modem 1200 (only?)
 *	developed for getting around the all lines busy problem at utcc for
 *	1200 baud lines.  redials until console character or modem answer.
 *	turns off verbose mode and speaker(always off) and turns on extended
 *	result   exec()'s a program
 *	on exit.
 *
 *	jmb - 11984
 */



/*
 *	COPYRIGHT NOTICE - copyright (c) 1984  by john miller bray.
 *		permission is granted to any individual or institution
 *		to copy or use this program, except for explicitly
 *		commercial purposes.  no warranty of the software or of
 *		the accuracy of any documentation surrounding it is
 *		expres implied, and the author does not acknowledge
 *		any liability resulting from program or documentation
 *		errors.
 */


#include "a:bdscio.h"

#define IN 0x02
#define OUT 0x01

/* these should be the only things you need to change */

#define MDM_STAT_PRT 0x15
#define MDM_DAT_PRT 0x14
#define MDM_IN_BIT 0x02
#define MDM_OUT_BIT 0x01

char ph_num[35],program[20],carrier_time[10];



main ()

{

	int	result_code, dial_count;

	/* first get the user's parameters */

	puts("\n\tenter phone number: ");
	gets(ph_num);
	puts("\tenter max time to wait for carrier: ");
	gets(carrier_time);
	puts("\terogram to execute: ");
	gets(prog
	puts("\n\thit any key to quit....\n\n");

	init_mdm();

	result_code = '3';
	dial_count = 0;
	while( result_code == '3') {		/* keep redialing */
		if (kbhi
			puts("\n\n\t\texit ");
			exit();
		}
		dial_count++;
		printf("\rdial count: %d",dial_count);
		sleep(5);
		mdm_prnt("ATDT",FALSE);
		mdm_prnt(ph_num,FALSE);
		mdm_prnt("\r",FALSE);
		result_code = get_result();
	}

	if (resul != '1' && result_code != '5') {
		printf("\t\007ERROR BAD RESULT CODE: 0x%x",result_code);
		exit();
	}

	puts("\007");
	puts ("\n\n\tconnect at ");
	puts((result_code == '5') ? "1200 baud" : "300 baud") ;
	sleep(35);
	mdm_prnt(ALSE);
	sleep(10);
	mdm_prnt("\r",FALSE);
	sleep(10);
	mdm_prnt("\r",FALSE);
	sleep(10);
	puts("\007");
	printf("\n\nrunning %s ...\n\n",program);
	puts("\007");
	exec(program);
	exit();
}


init_mdm()

{
	mdm_prnt("\rATZ\r",FALSE);
	sleep(25);
	mdm_prnt( M0 X1 E0 S7=",FALSE);
	mdm_prnt(r_time,FALSE);
	mdm_prnt("\r",FALSE);
	sleep(10);
}


get_result()

{
	int	tmp, 

	count = 0;
	tmp = 0;
	while (tmp < '0' || tmp > '5') {
		while ( ! mdm_stat(IN) ) {		/* delay till char ready */
			;
		}
		tmp = mdm_in();
		count++;
		if (coun400) exit(puts("\n\ntimeout: result code"));
	}
	return tmp;
}


mdm_stat(inout)		/* note that this presumes that ready is >> high << */

int	inout;

{
   return (inout == IN ? inp(MDM_STAT_PRT) & MDM_IN_BIT : inp(MDM_STAT_PRT) & MDM_OUT_BIT );
	
}


mdm_prnt(s,eat)		/* send a string to the modem.  if eat is TRUE,
			   eat a single echo per xmitted character.
			   does NOT account for echoed \n's after \r's
			   current version of dial turns off command echo
			   anyway, so no difference.
			*/
char	*s;
int	eat;

{
	while (*s) {
		while ( ! mdm_stat(OUT) ) {		/* delay till ready */
			;
		}
		outp(MDM_DAT_PRT,*s++);
		if (eat) {
			while ( !mdm_stat(IN) ) {	/* get echo, so */
				;			/* get_result won't */
			}
			mdm_in();
		}
	}
}


mdm_in()

{
	return (inp(MDM_DAT_PRT));
}
