! 3 Apr 89
! telebit.cmd - initialize Telebit/PEP modems for fastest performance
!

!
! this proc resets modem and returns current baud rate
proc findbaud
	for b in (9600 19200 2400 1200 300 4800) do
		noerror baud $(b)
		xmit "at&f&w\r"		! restore factory defaults
		? '.';
		wait "OK",1
		if !_timeout
			baud 9600	! 9600 is factory default
			return
		endif
	endfor
	setvar b '0'			! modem not found
endproc

proc timout
	if _timeout
		? "Modem not responding, quitting"
		quit
	endif
endproc

! begin main program
!
cls
?
? "Telebit/PEP Modem Setup"
?
? "Searching for modem...";
do @findbaud
if b = '0'
	? "Can't find Telebit modem on default TERM port"
	? "Run 'term -z setup' and select 'Communications' option"
	quit
endif

? "Found."
? "Setting values..."
wait 1
flush
xmit "ati0\r"		! get product code
cread pcode,3
do @timout
!
! set extended results, normal dtr&soft reset, normal dcd&dsr, pass breaks,
! set compression on, lock serial interface
xmit "atx3s52=2s53=3s54=3s110=1s66=1\r"
wait "OK",3
do @timout
iferror baud 19200
	setvar bval '4'
else
	setvar bval '5'
endif
baud 9600
wait 1
xmit "ats51=$(bval)\r"
wait "OK",3
do @timout
if bval = '5'
	baud 19200
endif
if not (val(pcode)=961 or val(pcode)=964)
	wait 1
	xmit "at&w\r"
	wait "OK",3
	do @timout
	xmit "ate0q1&w\r"	! turn off echo for login modems
	wait 1
endif

? "The Telebit modem is now configured for $(_baud) baud."

if _baud = 19200
	? "TERM and Telebit/PEP setup complete."
	?
	? "TERM must now be configured to run at $(_baud) baud."
	? "Select 'Communications' option and select $(_baud)"
	pause Hit any key to run TERM's setup program.
	do setup
endif

? "TERM and Telebit/PEP setup complete."

quit
