#!/bin/sh
identifier=${1}
shift

if [ "${identifier}" == "" ]; then
    default=`date +%s`
    echo -n "test identifier [${default}] ? "
    read identifier
    if [ "${identifier}" == "" ]; then
	identifier=${default}
    fi
fi

SUGAR_CONFIG=/home/olpc/.sugar/default/config
ID=1
if test -f ${SUGAR_CONFIG}; then
    ID=`grep nickname ${SUGAR_CONFIG} | cut -f2 -d-`
    if test -z "${ID}"; then
	ID=1
    fi
fi

ADDR=`ifconfig eth1 | grep HWaddr | awk '{print $5}'`

# swapped from aa
case "$ADDR" in
    "00:50:43:28:0B:07")
	IP=10.1.6.52
	SN=0652
	;;
    "00:50:43:28:0B:0D")
        IP=10.1.6.66
        SN=0666
	;;
    *)
	echo 'hardware address not in test set'
	exit 1
	;;
esac

address=${1}
shift

if [ "${address}" == "" ]; then
    if [ "${IP}" != "" ]; then
	address=${IP}
    else
	echo -n "address ? "
	read address
    fi
fi

echo "aat: throughput test to ${address} recording to ${identifier}.log"
echo "aat: begin test" >> ${identifier}.log
date +%s >> ${identifier}.log
bing -e 500 -S 500 $* 127.0.0.1 ${address} | tee --append ${identifier}.log
echo "aat: end test" >> ${identifier}.log

aplay /usr/share/olpc-radio-testing/sounds/sine-46.wav 2>/dev/null >/dev/null
