# ntbatch rev[0.02]
# - GOLD version with command line arguement and test.
# - Usage: ntbatch
# -      : ntbatch /dev/tty 

################################### check_stty ################################
check_stty ()
{
	echo "###### dp $i0" >> ntdump
	./dp $i0 >> ntdump
	echo "###### duart $i0" >> ntdump
	./duart $i0 >> ntdump
	echo "###### stty $i0" >> ntdump
	stty -a < $DEVICES$i0 >> ntdump
	let i0=i0+1
	if test $i0 -gt $i1
	then 
		return 1
	fi
	return 0
}
################################### main ######################################
i0=1
i1=16

#Check to see if the passed in arguement is a real serial device?

if test $1
then 
	echo "looking for prefix $1$i0"
	if test -r $1$i0
	then 
		echo "Prefix $1$i0 found"
		DEVICES=$1
		echo "Using prefix $DEVICES for NT960 ports"
	else
		echo "Prefix $1$i0 not found"
		exit
	fi

else 
	#If no argument then try for /dev/nt?
	if test -r /dev/nt$i0
	then
		DEVICES="/dev/nt"
		echo "Prefix $DEVICES found"
		echo "Using prefix $DEVICES for NT960 ports"
	else
		echo "No valid NT960 port prefix found"
		exit
	fi
fi

read ans?'Continue (y/n)'
if test $ans != y
then
 	exit
fi

if test -r $DEVICES"17"
then
	i1=32
fi
date > ntdump
echo "ntbatch" >> ntdump

# dump port information
echo "Dumping NT960 port information $i0"
while check_stty
do
	echo "Dumping NT960 port information $i0"
done

echo "######" >> ntdump
echo "Dumping system information"
sin  >> ntdump
echo "######" >> ntdump
sin ir >> ntdump
echo "######" >> ntdump
sin ar >> ntdump
echo "######" >> ntdump
sin in >> ntdump
echo "######" >> ntdump
./irq_cnt -a -A >> ntdump
echo "######" >> ntdump

echo "Dumping driver memory"
./drvrmem >> ntdump

echo "Dumping NT960 Dual ported memory 64k"
./dm 800000 65536 >> ntdump

if test $i1 -eq 16
then
	# 16 port system
	echo "Dumping NT960 Main Memory 64k"
	echo "######" >> ntdump
	./dm 200000 65536 >> ntdump
	./dm 210000 131072 >> ntdump
	./dm 230000 65536 >> ntdump
else
	# 32 port system
	echo "Dumping NT960 Main Memory 128k"
	echo "######" >> ntdump
	./dm 200000 65536 >> ntdump
	./dm 210000 131072 >> ntdump
	./dm 230000 131072 >> ntdump
fi

date >> ntdump
if test -r ntdump.F
then
	echo "ntdump.F already exists, moving to ntdump1.F"
	mv ntdump.F ntdump1.F
fi
echo "Compressing file ntdump to ntdump.F"
freeze ntdump
echo "Operation complete, transfer file ntdump.F to Connect Tech"
