#!/bin/sh

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo $script_path

DNS=114.114.114.114

#配置有线网络
$script_path/eth0Setup.sh

./playOrRecord -p audio/networkWait.pcm -s 8000 -f 1
nPingCnt=0
while [ $nPingCnt -le 4 ]
do
    echo $nPingCnt
    ping -w 1 -c 1 $DNS>/dev/null
    ret=$?
    if [ $ret -eq 0 ];then 
        #echo "OnLine"
        break; #Ping通了就退出了
    else 
        echo "Retry..."
        sleep 1 ; #1秒后再来       
        let "nPingCnt = $nPingCnt+1"
    fi   
done
if [ $nPingCnt -le 4 ];then 
    ./playOrRecord -p audio/uploadOEMPIDStart.pcm -s 8000 -f 1
else
    ./playOrRecord -p audio/networkFailed.pcm -s 8000 -f 1
    exit -1;
fi 

$script_path/UploadDev2ndOEMIDPID $script_path/license.bin
ret=$?

:<<EOF
UploadDev2ndOEMIDPID返回结果定义：
typedef enum
{
	RET_UPLOAD_OEMID_SUCCESSD = 0,					//OEMID上传成功
	RET_MODIFY_PID_AND_UPLOAD_OEMID_SUCCESSD = 1,	//PID修改成功 | OEMID上传成功
	RET_MODIFY_PID_AND_UPLOAD_PID_SUCCESSD = 2,		//PID与OEMID上传成功

	RET_PARSE_FAILED = 3,							//授权文件解析失败
	RET_MODIFY_PID_FAILED = 4,						//PID修改失败
	RET_UPLOAD_PID_FAILED = 5,						//PID上传失败
	RET_MODIFY_PID_BUT_UPLOAD_PID_FAILED = 6,		//PID修改成功 | PID上传失败
	RET_UPLOAD_OEMID_FAILED = 7,					//OEMID上传失败
	RET_MODIFY_PID_BUT_UPLOAD_OEMID_FAILED = 8		//PID修改成功 | OEMID上传失败
}ret_defs;
EOF

echo UploadDev2ndOEMIDPID ret:$ret >> test

if [ $ret -eq 0 ];then 
	./playOrRecord -p audio/oemidUploadSuccess.pcm -s 8000 -f 1
elif [ $ret -eq 1 ];then 
	./playOrRecord -p audio/pidModifySuccess.pcm -s 8000 -f 1
	./playOrRecord -p audio/oemidUploadSuccess.pcm -s 8000 -f 1
elif [ $ret -eq 2 ];then 
	./playOrRecord -p audio/pidOemidUploadSuccess.pcm -s 8000 -f 1
elif [ $ret -eq 3 ];then 
	./playOrRecord -p audio/licenseFileParseFailed.pcm -s 8000 -f 1
elif [ $ret -eq 4 ];then 
	./playOrRecord -p audio/pidModifyFailed.pcm -s 8000 -f 1
elif [ $ret -eq 5 ];then 
	./playOrRecord -p audio/pidUploadFailed.pcm -s 8000 -f 1
elif [ $ret -eq 6 ];then 
	./playOrRecord -p audio/pidModifySuccess.pcm -s 8000 -f 1
	./playOrRecord -p audio/pidUploadFailed.pcm -s 8000 -f 1
elif [ $ret -eq 7 ];then 
	./playOrRecord -p audio/oemidUploadfailed.pcm -s 8000 -f 1
elif [ $ret -eq 8 ];then 
	./playOrRecord -p audio/pidModifySuccess.pcm -s 8000 -f 1
	./playOrRecord -p audio/oemidUploadfailed.pcm -s 8000 -f 1
else 
	./playOrRecord -p audio/unknownErr.pcm -s 8000 -f 1
fi
sleep 1

exit 0
