#! /bin/bash
# 2021/08/24 週二 函式名稱 確認是否有接上SIM卡，有接上將1寫入/app/Wireless/CheckSimCard.ini
# 沒有接上 將0寫入 /app/Wireless/CheckSimCard.ini;
CheckInputSimCard()
{
	rm /var/lock/LCK..ttyUSB3;
	CheckSimCardPath=/app/Wireless/CheckSimCard.ini;
	rm $CheckSimCardPath;
	for i in {1..5};
	do
		SimCard_Check=`/app/Wireless/SIM_Card.sh | grep "OK" | head -n 1`;
		if [ "$SimCard_Check" == "OK" ]; then
			echo "1" > $CheckSimCardPath;	
			export LD_LIBRARY_PATH=/app/Wireless;
			/app/Wireless/wvdial -C /app/Wireless/wvdial.conf;
			break;
		else
			echo "0" > $CheckSimCardPath;
		fi
		sleep 1;
	done

}

for i in {1..30};
do
    echo "2c7c 0125" > /sys/bus/usb-serial/drivers/option1/new_id
    if [ -e /sys/bus/usb-serial/devices/ttyUSB3 ]; then
    {
		CheckInputSimCard;
		break;
    }
	fi
    sleep 1;
done



