1#!xchat
2# @(#) modified from dial.hayes V1.1 Tue Sep  1 13:59:58 1992 (Bob Denny)
3#      modification by prye@picu-sgh.demon.co.uk (Peter Rye) 
4#      Fri May 15 18:46:06 BST 1998
5#
6# xchat script for using "ringback" with a vanilla Hayes modem
7#
8# Usage:
9#	xchat Hayes.Ringback telno
10#
11# where telno is the telephone number, subject to pause and wait
12# character modification. 
13#
14# Uncomment the first two lines after "start:" to get debugging
15# in file "Dial.Log"
16#
17# Flush input, zero counter, set telephone number if supplied,
18# else fail if no telephone number given.
19#
20start:
21	##dbgfile 		Dial.Log
22	##dbgset  		15 
23	zero
24	flush
25	ifnstr	notelno		0
26	telno			0
27	goto	initmodem
28#
29# Missing telephone number.
30#
31notelno:
32	logerr	No telephone number given
33	failed
34#
35# Reset the modem to nonvolatile profile. 
36# Allow 3 sec. for response, as some modems are slow to reset.
37#
38initmodem:
39	count
40	ifgtr	cantinit	4
41	send	ATZ\r
42	timeout	initmodem	3000
43	expect	setupmodem	OK
44#
45# No response from modem
46#
47cantinit:
48	logerr	Can't wake modem
49	failed
50#
51# Send the stuff needed to initialize the modem to the modes
52# needed for the particular modem flavor. The string below
53# is provided as a vanilla example. Allow 2 sec. for the
54# modem to respond to this command.
55#
56setupmodem:
57	sleep	1000
58	send	ATZ\r
59	timeout	setupfail	2000
60	expect	setupfail	ERROR
61	expect	dialnumber	OK
62#
63# Modem barfed or died on setup command.
64#
65setupfail:
66	logerr	Error in modem setup string
67	failed
68#
69# Dial the supplied number. Handle the various errors that
70# can come back from the modem by logging the error.
71#
72dialnumber:
73	sleep	1000
74	send	ATDT
75	dial
76	send	\r
77	flush
78	timeout	hangup	4000
79	expect	errconnect	CONNECT
80	expect	busy		BUSY
81	expect	nocarrier	NO CARRIER
82	expect	noanswer	NO ANSWER
83	expect	nodialtone	NO DIALTONE
84
85hangup:
86	hangup
87	sleep	4000
88	send	+++
89	sleep	4000
90	send	\r
91	sleep	1000
92	send	ATZ\r
93	timeout	resetup		2000
94	expect	resetup		OK
95
96resetup:	
97	sleep	8000
98	send	ATZ\r
99	expect	redial	OK
100
101redial:
102	sleep	1000
103	send	ATDT
104	dial
105	send	\r
106	flush
107	timeout	timeout		30000
108	expect connected	CONNECT
109	expect	busy		BUSY
110	expect	nocarrier	NO CARRIER
111	expect	noanswer	NO ANSWER
112	expect	nodialtone	NO DIALTONE
113	
114#
115# Success!
116#
117connected:
118	success
119#
120# Handle modem dial failures
121#
122timeout:
123	logerr	Modem or carrier timeout.
124	failed
125errconnect:
126	logerr	Connected on first call.
127	failed
128busy:
129	logerr	BUSY
130	failed
131nocarrier:
132	logerr	NO CARRIER
133	failed
134noanswer:
135	logerr	NO ANSWER
136	failed
137nodialtone:
138	logerr	NO DIALTONE
139	failed
140#
141# end
142#
143