Autobaud routine

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Thu Nov 24 20:14:29 AEST 1983


Ok, enough people have asked for it that I'll post it.  Since I
announced it on net.unix-wizards, and this goes out to ARPAnet
sites (whereas net.sources doesn't), I'm posting it here; to keep
it short, I'm just posting the autobauding routines, not the whole
of getty.

Notes:
1) The "time_out" is to get around the fact that when someone dials
in via our Gandalf switch, logging out leaves the line connected,
and even if the user hangs up the phone, the Gandalf just doesn't
let go until we drop DTR.

2) Won't run as-is on 4.2 since signals have changed; also, since
all system calls get restarted (or do they?) you'd probably have to
use setjmp/longjmp in the "a_zap" routine.

3) Don't forget to cut off the ".signature".  (Is there any way to
tell inews not to grab it?  I suppose I could 'mv' it temporarily....)

Chris

---------------------------begin autobaud------------------------
/*
 * Drop data terminal ready for one second.  This is important for Gandalf
 * lines which must be told to disconnect.  This affects all autobauding
 * lines after a 60 second timeout.
 */

time_out () {			/* 2-Feb-1983 FLB */
	puts ("\r\r\n\nTimeout\r\r\n\n");
	sleep (2);
	tmode.sg_ispeed = tmode.sg_ospeed = B0;
	stty (0, &tmode);
	sleep (3);
	exit (0);
}

/*
 * Try to figure out what speed the terminal is set to based on what
 * a carriage-return looks like at 2400 baud.  This doesn't distinguish
 * all speeds, but gets the good ones at least.  5/18/82 FLB
 */

struct autobaud {
	int s_speed;
	char *s_string;
} a_tab[] = {
	B110,	"\3\000\000\000",
	B300,	"\3\200\200\000",
	B300,	"\3\200\000\000",
	B300,	"\3\000\200\000",
	B600,	"\3\000\376\000",
	B1200,	"\2\346\200",
	B1200,	"\2\346\340",
	B1800,	"\2\000\376",
	B1800,	"\2\000\377",
	B2400,	"\1\15",
	B2400,	"\1\215",
	B4800,	"\1\361",	/* needed for Gandalf */
	B4800,	"\1\362",
	B4800,	"\1\363",	/* needed for Gandalf */
	B4800,	"\1\371",	/* needed for Gandalf */
	B4800,	"\1\375",	/* needed for Gandalf */
	B4800,	"\1\376",	/* needed for Gandalf */
	B9600,	"\1\377",	/* needed for Gandalf */
	B110,	"\1\0",		/* so a ``break'' will let you escape */
	0, 0
};

auto_baud () {
    register struct autobaud *tp;
    struct sgttyb ttyb;
    char buf[10];
    int i;

    ttyb.sg_ispeed = ttyb.sg_ospeed = B2400;
    ttyb.sg_flags = ANYP|RAW;
    stty (0, &ttyb);

    for (;;) {
	signal (SIGALRM, time_out);		/* 2-Feb-1983 FLB */
	alarm (60);				/* 2-Feb-1983 FLB */
	input (buf);

	for (tp = a_tab; tp -> s_speed; tp++)
	    for (i = 0; buf[i] == tp -> s_string[i] && i < sizeof buf; i++)
		if (i == *buf) {
		    signal (SIGALRM, time_out);	/* 2-Feb-1983 FLB */
		    alarm (60);			/* 2-Feb-1983 FLB */
		    return (tp -> s_speed);
		}
	stty (0, &ttyb);
    }
}

a_zap () {}

input (s)
char *s;
{
	register char *cp = s + 1;

	read (0, cp, 1);
	cp++;
	signal (SIGALRM, a_zap);
	alarm (1);
	while (read (0, cp, 1) > 0)
		cp++;

	*s = (cp - s) - 1;
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris.umcp-cs at CSNet-Relay



More information about the Comp.unix.wizards mailing list