#!/bin/sh

MPID=`ps ax | grep "cy_buffering" | grep -v grep | cut -b -6`
if [ ! "$MPID" = "" ] ; then
  kill -int $MPID
fi

MPID=`ps ax | grep "cy_ras" | grep -v grep | cut -b -6`
if [ ! "$MPID" = "" ] ; then
  kill -int $MPID
fi

dhcpcd -k
sleep 3
ifconfig eth0 192.168.160.10

MT=`/bin/set_nports 1`

nports=`/bin/set_nports`

echo
echo Running $0 with : $MT
echo
echo Number of ports detected : $nports
echo
echo After kill execute the command "'sh x'" to kill all command "cat's"
echo
echo -e "kill -9 \c" > x
cnt=$nports
while [ $cnt -gt 0 ]
do
  cat < /dev/ttyS$cnt > /dev/null&
  echo -e $! " \c" >> x
  stty -echo < /dev/ttyS$cnt
  cnt=`expr $cnt - 1`
done

ping 192.168.160.100 &

while true
do
  cnt=1
  while [ $cnt -le $nports ]
  do
    #stty -echo < /dev/ttyS$cnt
    echo "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMttyS"$cnt > /dev/ttyS$cnt
    cnt=`expr $cnt + 1`
  done
done

