! 1 Sep 87   &>>AT&T 4024<<
!
! Terrence R. Lambert
!
! mdma4024.cmd		-	AT&T Model 4024 Modem command set
!
!
! AT&T 4024 modem dialer (4024 modem and manual used as reference)
!
! this dialer script has entry procedures dial, hangup, and answer
!

!
! the "not responding" message.  It's a little more verbose, but it's worth
! saving them a phone call by making sure that:
!		1) modem is reset
!		2) cable is ok
!
proc notrsp
	? "The modem dialer you are using assumes that you are using AT&T"
	? "command set (referred to as 'The Data Terminal Command Set')."
	? "If you have been using the Hayes ('AT') command set with another"
	? "software package, you should probably use the Hayes modem dialer"
	? "rather than this one.  If you are still having problems, check"
	? "your modem cable and the internal switch and jumper settings."
	? "Remember that the AT&T 4024 modem comes configured in Hayes mode"
	? "and that unless you require the AT&T command set, and have set"
	? "it before making a call with this dialer, it will NOT work."
	? "Make sure, also, that your cable and switch settings are correct."
endproc notrsp

!
! call number [redials [timeout]]
!
proc call
on abort
  set dtr off		! turn it off to disconnect
  display "Call aborted, hanging up"
  xmit "@"		! Cancel character (@) stops command execution
  wait 2
  flush
  set dtr on		!1 turn it back on to make it happy otherwise
  return 2
endon
on error
  do @dhangup
  return 1
endon

! Determine Phone Number and Baud Rate
if '$1' = ''
  display "Usage: dial number [redials] [timeout]"
  return 1
endif

if '$2' = ''
  setvar n 3
else
  setvar n $2
endif
if '$3' = ''
  setvar tmout 60
else
  setvar tmout $3
endif

display "Calling $1"

	flush
	! set options to necessary values
	xmit "ATOD,O4=N,O20=99,O7=N,O19=Y\r"	! take my word for it
	wait "now n",1
	wait "now n",1
	wait "now y",1			! wait for all confirmation to complete
	flush
	wait 1				! another second to ignore cr/lf's
	xmit "\r"			! wake up "friendly" mode
	wait ":",1			! in case it spits stuff at us
repeat
	xmit "$1\r"			! dial the number
	wait "Calling",3
	if _timeout
		xmit "@\r"		! Cancel
		? "No dial tone"
		wait 1
		xmit "Q\r"
		wait 1
		return 1
	endif
	wait "Answered",tmout
	if _timeout
		setvar n n-1
		if n <= 0
			display "Too many retries, call aborted"
			do @dhangup
			return 1
		endif
		do @dhangup
		display "Redialing..."
	else
		display "Call connected"
		return 0
	endif
until f
endproc call

!
! hangup line and terminate connection
!
proc hangup
display "Hanging up phone"
set dtr off		! turn it off to disconnect...
wait 2
xmit "\$:"		! go to interactive mode
wait ":",4
if !_timeout
	xmit "Q\r"	! quit
else
	wait 2
	xmit "\$:"		! go to interactive mode
	wait ":",4
	xmit "Q\r"	! quit
endif
set dtr on		!1 turn it back on to make it happy otherwise
endproc hangup

!
! answer [code]
!
proc answer
	if "$1"=""
		? "Usage: @answer code [now wait auto off]"
		return 1
	endif
	setvar code "$1"
	on abort
	  display "Answer aborted"
	  return 2
	endon
if code = "wait"			! wait for ring BLOWNOUT
	display "Cannot wait for ring using AT&T Command set"
	return 1
	flush
	wait 1
	return 0
elseif code = "auto"			! autoanswer ON
	xmit "O20=1,ATO7=Y\r"
	wait "now y",2
	if _timeout
		display "Autoanswer NOT set, modem not responding"
		return 1
	endif
	flush
elseif code = "now"			! answer NOW
	display "Answering phone"
	xmit "\r"		! freindly mode only accessable if on hook
	wait ":",4
	if _timeout
		display "Answer failed, modem not responding"
		xmit "Q\r"			! go back to idle mode
		return 1
	endif
	xmit "ANS\r"
	dwait "failure",3
	if !_timeout				! failed
		xmit "Q\r"			! go back to idle mode
		return 1
	endif
	xmit "Q\r"				! go back to idle mode
	flush
	return 0
elseif code = "off"			! autoanswer OFF
	xmit "ATO7=N\r"
	wait "now n",2
	if _timeout
		display "Autoanswer NOT reset, modem not responding"
		return 1
	endif
	flush
endif
endproc answer

!
! hangup for redial attempts, local procedure
!
proc dhangup
xmit "@"	! an at (@) sign will abort a dial in progress
wait ":",2
xmit "Q\r"
wait 1
flush
endproc hangup

set ddtr on		! dtr required, most modems
set dtr on		! dtr required, most modems
