1#!xchat
2# @(#) Hangup.Hayes V1.1 Tue Sep  1 14:04:25 1992 (Bob Denny)
3#
4# xchat script for hanging up a Hayes-type modem. When used with Taylor
5# UUCP, this script should be run as the dialer-complete and dialer-abort
6# script with xchat.
7#
8# Usage:
9#	xchat Hangup.Hayes [ x ]
10#
11# where 'x' is any string. If it is present, this script will log the
12# modem reset as an ABORT reset, otherwise it will not log anything.
13#
14# Uncomment the lines starting with '###' to get debugging log.
15#
16start:
17###	dbgfile			Hangup.Log
18###	dbgset			15
19	zero
20	sleep	2000			# Wait for trailing garbage
21	flush				# Toss it out
22	ifnstr	wakemodem	0	# No abort indicator
23	log	Hangup on abort
24#
25# Get modem's attention via Hayes 'escape' protocol.
26#
27wakemodem:
28	sleep	4000
29	send	+++
30	sleep	4000
31	send	\r
32	timeout	reset		2000
33	expect	reset		OK
34#
35# We're (probably) in command mode. Use ATZ (reset) to hang up
36# as some modems don't behave well with ATH0 command.
37#
38reset:
39	send	ATZ\r
40	timeout	silent		5000
41	expect	done		OK
42#
43# Finished, modem is back in initial state.
44#
45done:
46	success
47#
48# No response to escape protocol. Log the error and force DTR low
49# in an attempt to get control of the modem. Then send ATZ just to
50# make sure.
51#
52silent:
53	logerr	Hangup: no response from modem
54	hangup				# Force DTR low as last gasp
55	send	ATZ\r
56	sleep	5000
57	failed
58