#!/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 0 audio/networkWait.pcm
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 0 audio/uploadOEMPIDStart.pcm
else
    ./playOrRecord -p 0 audio/networkFailed.pcm
    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 0 audio/oemidUploadSuccess.pcm
elif [ $ret -eq 1 ];then 
	./playOrRecord -p 0 audio/pidModifySuccess.pcm
	./playOrRecord -p 0 audio/oemidUploadSuccess.pcm
elif [ $ret -eq 2 ];then 
	./playOrRecord -p 0 audio/pidOemidUploadSuccess.pcm
elif [ $ret -eq 3 ];then 
	./playOrRecord -p 0 audio/licenseFileParseFailed.pcm
elif [ $ret -eq 4 ];then 
	./playOrRecord -p 0 audio/pidModifyFailed.pcm
elif [ $ret -eq 5 ];then 
	./playOrRecord -p 0 audio/pidUploadFailed.pcm
elif [ $ret -eq 6 ];then 
	./playOrRecord -p 0 audio/pidModifySuccess.pcm
	./playOrRecord -p 0 audio/pidUploadFailed.pcm
elif [ $ret -eq 7 ];then 
	./playOrRecord -p 0 audio/oemidUploadfailed.pcm
elif [ $ret -eq 8 ];then 
	./playOrRecord -p 0 audio/pidModifySuccess.pcm
	./playOrRecord -p 0 audio/oemidUploadfailed.pcm
else 
	./playOrRecord -p 0 audio/unknownErr.pcm
fi
sleep 1

exit 0
