#!/bin/sh
#
# Remember to make script executable with 'chmod +x scriptname'.
# Script designed to work within the full Debian environment.
#
# TS-ISO485 Juper Settings:
# ADD2, Share, IRQ2, IRQ4 are all ON; All else are OFF
#
# COMA   COMB
# 3AB    2A8
# $COMA  $COMB
# -------------
#  1  <==> 5
#  2  <==> 6
#  3  <==> 3
#  4  <==> 4
#  5  <==> 1
#  6  <==> 2

#Just in case the script has already been ran
rmmod ts7800_isa16550 2> /dev/null

echo -n "Enable PC104 Bus..."
. /initrd/ts7800.subr
pc104on
echo "done"

echo -n "Insert 16550 Driver for COMA..."
insmod /lib/modules/2.6.21-ts/kernel/drivers/serial/ts7800_isa16550.ko io=0x3a8 irq=6
echo "done"

echo -n "Remove 16550 Driver..."
rmmod ts7800_isa16550
echo "done"

echo -n "Insert 16550 Driver for COMB..."
insmod /lib/modules/2.6.21-ts/kernel/drivers/serial/ts7800_isa16550.ko io=0x2a8 irq=6
echo "done"

COMA=`dmesg | tail -n 2 | grep 3a8 | awk '{ print $2 }'`
COMB=`dmesg | tail -n 2 | grep 2a8 | awk '{ print $2 }'`

cat << EOF
COMA enumerated to /dev/$COMA device node. 
COMB enumerated to /dev/$COMB device node. 

Output from /proc/tty/driver/serial:
##########################################
`cat /proc/tty/driver/serial | grep A8`
##########################################

Sending random data through $COMA now...
`cat /dev/urandom > /dev/$COMA &`
The following LEDs should be ON:
   COMA Tx
   COMB Rx
Press any key to swap Rx and Tx... 
EOF

read -n1 any_key
echo
killall cat

cat << EOF
Sending random data through $COMB now...
`cat /dev/urandom > /dev/$COMB &`
The following LEDs should be ON:
   COMA Rx
   COMB Tx
Press any key to quit test...
EOF

read -n1 any_key
echo
killall cat
exit 0



#Another test would be to use 
#   cat /dev/$COMB &
#followed by 
#   echo "testing serial" > /dev/$COMA
