#!xchat
# @(#) dial.hayes V1.1 Tue Sep  1 13:59:58 1992 (Bob Denny)
#
# xchat script for dialing a vanilla Hayes modem
#
# Usage:
#	xchat dial.hayes telno
#
# where telno is the telephone number, subject to pause and wait
# character modification. 
#
# Uncomment the first two lines after "start:" to get debugging
# in file "Dial.Log"
#
# Flush input, zero counter, set telephone number if supplied,
# else fail if no telephone number given.
#
start:
###	dbgfile 		Dial.Log
###	dbgset  		15 
	zero
	flush
	ifnstr	notelno		0
	telno			0
	goto	initmodem
#
# Missing telephone number.
#
notelno:
	logerr	No telephone number given
	failed
#
# Reset the modem to nonvolatile profile. 
# Allow 3 sec. for response, as some modems are slow to reset.
#
initmodem:
	count
	ifgtr	cantinit	4
	send	ATZ\r
	timeout	initmodem	3000
	expect	setupmodem	OK
#
# No response from modem
#
cantinit:
	logerr	Can't wake modem
	failed
#
# Send the stuff needed to initialize the modem to the modes
# needed for the particular modem flavor. The string below
# is provided as a vanilla example. Allow 2 sec. for the
# modem to respond to this command.
#
setupmodem:
	sleep	1000
	send	ATM0S7=90S11=120\r
	timeout	setupfail	2000
	expect	setupfail	ERROR
	expect	dialnumber	OK
#
# Modem barfed or died on setup command.
#
setupfail:
	logerr	Error in modem setup string
	failed
#
# Dial the supplied number. Handle the various errors that
# can come back from the modem by logging the error.
#
dialnumber:
	sleep	1000
	send	ATDT
	dial
	send	\r
	flush
	timeout	timeout		90000
	expect	connected	CONNECT
	expect	busy		BUSY
	expect	nocarrier	NO CARRIER
	expect	noanswer	NO ANSWER
	expect	nodialtone	NO DIALTONE
#
# Success!
#
connected:
	success
#
# Handle modem dial failures
#
timeout:
	logerr	Modem or carrier timeout.
	failed
busy:
	logerr	BUSY
	failed
nocarrier:
	logerr	NO CARRIER
	failed
noanswer:
	logerr	NO ANSWER
	failed
nodialtone:
	logerr	NO DIALTONE
	failed
#
# end
#

