#! /bin/sh

echo "Select Ch1"

IP=192.168.1.1

TRGCHK=true
#TRGCHK=false
BUSYCHK=true
#BUSYCHK=false

nev=$1


wget http://${IP}/download.cgi?"command=select:control ch1" -O /dev/null > /dev/null 2>&1

echo "Select isf format"

wget http://${IP}/download.cgi?"command=save:waveform:fileformat internal" -O /dev/null > /dev/null 2>&1


i=0
while [ $i -lt ${nev} ]; do
i=`expr $i + 1`
echo $i

wget http://${IP}/download.cgi?"command=FPANEL:PRESS+SINGLESEQ" -O /dev/null > /dev/null 2>&1

seq=`printf "%04d" $i`
echo $seq

while ${TRGCHK}; do
wget http://${IP}/download.cgi?"command=trigger:state?" -O xxx > /dev/null 2>&1
state=`head -1 xxx`
echo $state
[ "$state" = "SAV" ] && break
done
#sleep 1

while ${BUSYCHK}; do
wget http://${IP}/download.cgi?"command=busy?" -O xxx > /dev/null 2>&1
state=`head -1 xxx`
echo $state
[ "$state" = "0" ] && break
done

wget http://${IP}/download.cgi?"wfmsend=Get" -O ch1.$seq.isf > /dev/null 2>&1

done
