; ----- CONNECT: Autoanswer script
; ----------------------------------------------------------------
;	Note: This script waits for a received call.  It auto-bauds
;	according to the modem's CONNECT response.  It initializes
;	COM-AND to chat mode, CR -> CRLF, and CLOGs the fact.
; ----------------------------------------------------------------
;	Note: The hard coded autoanswer command here may need
;	recoding according to your modem.
; ----------------------------------------------------------------
;
;	Initialize
;
	ON ESCAPE GOSUB EXIT		; Escape pressed
	SET PARITY NONE 		; Turn off parity
	SET DATA 8			; Set 8 databits
	SET MASK ON			; Mask received text to 7 bits
;
;	Go into auto answer (echo off, answer on 2nd)
;	.. Also: Return result codes, word form, with CONNECT 1200
;
Restart:
	LEGEND " Waiting for call"
	Pause 3 			; Wait 3 seconds
	HANGUP				; HANGUP and leave modem in cmd mode
	PAUSE 3 			; Wait 3 secs
	MESSAGE "^MWaiting..."
	TRANSMIT "ATE0Q0V1X1S0=2 S7=30 S9=10^M"
;
; -----------------------------------------------------------------------
; ----- Wait for a connect
; -----------------------------------------------------------------------
;
Wait_Connect:
	RGET S9 80 180			; Wait for a line
	IF NOT SUCCESS			; If nothing was read
	   GOTO Wait_Connect
	   ENDIF

	FIND S9 "NO CARRIER"            ; Look for a disconn
	IF FOUND
	   GOTO Restart
	   ENDIF

	FIND S9 "CONNECT"               ; Anything else BUT CONNECT
	IF NOT FOUND			; .. waits
	   GOTO Wait_Connect
	   ENDIF

;***	IF NOT CONNECTED		; SOme modems aren't fast enough
;***	   GOTO Wait_Connect		; .. to set this right away
;***	   ENDIF
;
; -----------------------------------------------------------------------
; ----- Change baud rate according to connect (unles Alt-O flag is set)
; -----------------------------------------------------------------------
;
	IF FIND "_DDOVER" "ON" GOTO Finish

	IF FIND S9 "1200"               ; Test for 1200 baud
	   SET BAUD 1200		; Set to 1200 baud
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "2400"               ; Test for 2400 baud
	   SET BAUD 2400		; Set to 2400 baud
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "4800"
	   SET BAUD 4800		; Set to 2400 baud
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "9600"               ; Test for 9600 baud
	   SET BAUD 9600		; Set to 9600 baud
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "14400" or FIND S9 "14.4"
	   SET BAUD 14k 		; Set to new rate
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "19200" or FIND S9 "19.2"
	   SET BAUD 19k 		; Set to new rate
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "38400" or FIND S9 "38.4"
	   SET BAUD 38k 		; Set to new rate
	   GOTO Finish			; We're done.
	   ENDIF

	IF FIND S9 "57600" or FIND S9 "57.6"
	   SET BAUD 57k 		; Set to new rate
	   GOTO Finish			; We're done.
	   ENDIF
;
;	None of the above... set to 300
;
	SET BAUD 300			; Set to 1200 baud
;
;	Exit - set-up for conversational mode
;
Finish:
	SET CHAT ON			; Set chat mode
	SET CR CR_LF			; Incoming Cr's as CRLF
	CLOG "* Auto-answer"            ; Log it
	ALARM				; Sound alarm
;
;	The exit is separately labelled to allow ESC to terminate quickly
;
Exit:
	EXIT
