#!/bin/sh
# number of rings to wait:
RINGS=3
CARD=0

if test -f cur/restore
then
cur/restore
fi

# main loop:
while true
do

rm -f temp:e:v
if test -f cur/restore
then
cur/restore
fi

LEFT=$RINGS
FLAG=

while test $LEFT -gt 0
do
echo waiting for anything FLAG= $FLAG
vwait -c $CARD -e 62 -l 0 -D $FLAG
T=$?
echo vwait returned $T
case $T in
2 ) 
LEFT=`expr $LEFT - 1`
FLAG="-o 5"
;;
3 )
echo "waiting for HUP"
start=`gettime`
vwait -c $CARD -e 20 -l 0 -D
end=`gettime`
echo your call took ` expr $end - $start` seconds
if test $? = 129
then
echo interupted, waiting for semophore to go away
while test -f just_a_sec
do
sleep 30
done
fi
LEFT=$RINGS
FLAG=
;;
4|13)
LEFT=$RINGS
FLAG=
;;
129)
echo Interupted.  Waiting for semophore to go away
while test -f just_a_sec
do
sleep 30
done
LEFT=$RINGS
FLAG=
;;
esac
done

# play outgoing:
echo "I'm answering now!!!"
vda main -c $CARD -i -l 2 -D -r 606000
getstatus &

done

