1 Star 0 Fork 0

Shaco/rk3568_auto_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.sh 11.68 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2024-10-19 09:16 . 按键编号修改
#!/bin/bash
function environment()
{
echo -e "\033[31m配置完后会自动重新启动设备\033[0m"
echo -e "\033[31m安装软件包\033[0m"
sudo apt-get install -y git memtester mbw dmidecode iperf iperf3
echo -e "\033[31m部署WIFI\033[0m"
sudo cp -R usr /
ls /usr/lib/firmware/xr819
#配置wifi
nmcli dev
nmcli r wifi on
nmcli dev wifi
nmcli dev wifi connect "CSJDZ" password "26519965" ifname wlan0
sleep 5
#配置4G
#rndis模式切换
echo -e "AT+QCFG=\"usbnet\",3\r\n" > /dev/ttyUSB2
#开启网络
echo -e "at+QNETDEVCTL=3,1,1\r\n" > /dev/ttyUSB2
#开启热插拔
echo -e "AT+QSIMDET=1,1\r\n" > /dev/ttyUSB2
#重启命令
echo -e "AT+CFUN=1,1\r\n" > /dev/ttyUSB2
}
function memtest()
{
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=1 # 如果未传入参数,则默认测试 1 次
fi
echo "测试次数为: $test_times"
log_filemem="memtest_$(date +%Y%m%d_%H%M%S).log"
log_filembw="mbwtest_$(date +%Y%m%d_%H%M%S).log"
for i in $(seq 1 $test_times); do
echo -e "\033[31m内存稳定性测试\033[0m"
memtester 100M 1 | tee -a $log_filemem
echo -e "\033[31m内存带宽测试\033[0m"
mbw -q -n 1 100 | tee -a $log_filembw
done
}
function gpioouttest()
{
# 初始化GPIO
echo 8 > /sys/class/gpio/export
echo 13 > /sys/class/gpio/export
echo 14 > /sys/class/gpio/export
echo 90 > /sys/class/gpio/export
echo 91 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio8/direction
echo out > /sys/class/gpio/gpio13/direction
echo out > /sys/class/gpio/gpio14/direction
echo out > /sys/class/gpio/gpio90/direction
echo out > /sys/class/gpio/gpio91/direction
# 初始化按键状态
prev_key1=1
prev_key2=1
prev_key3=1
echo "GPIO循环输出测试开始,按esc退出测试"
while true; do
# 控制LED
echo 1 > /sys/class/gpio/gpio8/value
echo 1 > /sys/class/gpio/gpio13/value
echo 1 > /sys/class/gpio/gpio14/value
# 红灯
echo 0 > /sys/class/gpio/gpio8/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 绿灯
echo 1 > /sys/class/gpio/gpio8/value
echo 0 > /sys/class/gpio/gpio13/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 蓝灯
echo 1 > /sys/class/gpio/gpio13/value
echo 0 > /sys/class/gpio/gpio14/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 控制GPIO
echo 1 > /sys/class/gpio/gpio90/value
echo 1 > /sys/class/gpio/gpio91/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
echo 0 > /sys/class/gpio/gpio90/value
echo 0 > /sys/class/gpio/gpio91/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
done
# 清理GPIO
echo "清理GPIO状态"
echo 1 > /sys/class/gpio/gpio8/value
echo 1 > /sys/class/gpio/gpio13/value
echo 1 > /sys/class/gpio/gpio14/value
echo 1 > /sys/class/gpio/gpio90/value
echo 1 > /sys/class/gpio/gpio91/value
echo 8 > /sys/class/gpio/unexport
echo 13 > /sys/class/gpio/unexport
echo 14 > /sys/class/gpio/unexport
echo 90 > /sys/class/gpio/unexport
echo 91 > /sys/class/gpio/unexport
}
function gpiointest()
{
# 初始化GPIO
echo 88 > /sys/class/gpio/export
echo 89 > /sys/class/gpio/export
echo 114 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio88/direction
echo in > /sys/class/gpio/gpio89/direction
echo in > /sys/class/gpio/gpio114/direction
# 初始化按键状态
prev_key1=1
prev_key2=1
prev_key3=1
echo "GPIO输入测试开始,按esc退出测试"
while true; do
# 读取按键状态
key1=$(cat /sys/class/gpio/gpio88/value)
key2=$(cat /sys/class/gpio/gpio89/value)
key3=$(cat /sys/class/gpio/gpio114/value)
# 检查按键状态是否发生变化
if [[ "$key1" != "$prev_key1" ]]; then
echo "Key 1 state changed: $prev_key1 -> $key1"
prev_key1=$key1
fi
if [[ "$key2" != "$prev_key2" ]]; then
echo "Key 2 state changed: $prev_key2 -> $key2"
prev_key2=$key2
fi
if [[ "$key3" != "$prev_key3" ]]; then
echo "Key 3 state changed: $prev_key3 -> $key3"
prev_key3=$key3
fi
# 保存当前终端特性
stty_save=$(stty -g)
# 暂时禁用终端特性
stty -icanon -echo
if read -t 0.01 -n 1 -s key; then
echo "Exiting..."
break
fi
# 恢复终端特性
stty $stty_save
done
# 清理GPIO
echo "清理GPIO状态"
echo 88 > /sys/class/gpio/unexport
echo 89 > /sys/class/gpio/unexport
echo 114 > /sys/class/gpio/unexport
}
function rs485send()
{
echo 109 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio109/direction
echo out > /sys/class/gpio/gpio18/direction
echo 1 > /sys/class/gpio/gpio109/value
echo 1 > /sys/class/gpio/gpio18/value
echo -e "hello 485 test:123456789\r\n" > /dev/ttyS7
echo -e "hello 485 test:123456789\r\n" > /dev/ttyS3
}
function rs485rev()
{
echo 109 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio109/direction
echo out > /sys/class/gpio/gpio18/direction
echo 0 > /sys/class/gpio/gpio109/value
echo 0 > /sys/class/gpio/gpio18/value
cat /dev/ttyS7 &
cat /dev/ttyS3 &
}
function networktest()
{
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=10 # 如果未传入参数,则默认测试 10 次
fi
echo "测试次数为: $test_times"
# 默认参数
test_server="42.123.122.115"
log_dir="network_test_logs"
rm -rf network_test_logs
# 创建日志目录
mkdir -p "$log_dir"
# 获取可用网卡列表及其 IP 地址
available_interfaces=()
interface_ips=()
while IFS= read -r iface; do
ip=$(ip addr show "$iface" | awk '/inet / {print $2}' | cut -d'/' -f1)
if [ -n "$ip" ]; then
available_interfaces+=("$iface")
interface_ips+=("$ip")
fi
done < <(ip addr show | awk '/^[0-9]+: / {print $2}' | tr -d ':' | sed 's/[0-9]*@.*//g' | grep -v 'lo')
# 遍历可用网卡,进行测试
for i in "${!available_interfaces[@]}"; do
interface="${available_interfaces[$i]}"
ip="${interface_ips[$i]}"
log_file="$log_dir/network_test_${interface}_$(date +%Y%m%d_%H%M%S).log"
echo -e "\033[1;34m====== Testing $interface ($ip) ======\033[0m" | tee -a "$log_file"
# 关闭其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface down
fi
done
# 网络测试
echo -e "\033[1;31m网络测试\033[0m" | tee -a "$log_file"
for i in $(seq 10 -1 1); do
echo -ne "\r倒计时 $i 秒" | tee -a "$log_file"
sleep 1
done
echo -e "\n" | tee -a "$log_file"
ping -c $test_times $test_server -I $interface | tee -a "$log_file"
iperf3 -c $test_server -i 1 -t $test_times --connect-timeout 10000 | tee -a "$log_file"
# 恢复其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface up
fi
done
echo -e "\033[1;34m====== $interface ($ip) 测试结束 ======\033[0m\n" | tee -a "$log_file"
done
echo -e "\033[1;32m网络测试已完成,详细结果请查看日志文件夹: $log_dir\033[0m"
echo "ping网络操作,观察每次的时间是否均匀"
}
function networkeasytest()
{
rm *.log
rm -rf network_test_logs
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=20 # 如果未传入参数,则默认测试 10 次
fi
echo "测试次数为: $test_times"
# 默认参数
test_server="47.120.40.219"
log_dir="network_test_logs"
rm -rf network_test_logs
# 创建日志目录
mkdir -p "$log_dir"
# 获取可用网卡列表及其 IP 地址
available_interfaces=()
interface_ips=()
while IFS= read -r iface; do
ip=$(ip addr show "$iface" | awk '/inet / {print $2}' | cut -d'/' -f1)
if [ -n "$ip" ]; then
available_interfaces+=("$iface")
interface_ips+=("$ip")
fi
done < <(ip addr show | awk '/^[0-9]+: / {print $2}' | tr -d ':' | sed 's/[0-9]*@.*//g' | grep -v 'lo')
# 遍历可用网卡,进行测试
for i in "${!available_interfaces[@]}"; do
interface="${available_interfaces[$i]}"
ip="${interface_ips[$i]}"
log_file="$log_dir/network_test_${interface}_$(date +%Y%m%d_%H%M%S).log"
echo -e "\033[1;34m====== Testing $interface ($ip) ======\033[0m" | tee -a "$log_file"
# 关闭其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface down
fi
done
ping -c $test_times $test_server -I $interface | tee -a "$log_file"
# 恢复其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface up
fi
done
echo -e "\033[1;34m====== $interface ($ip) 测试结束 ======\033[0m\n" | tee -a "$log_file"
done
echo -e "\033[1;32m网络测试已完成,详细结果请查看日志文件夹: $log_dir\033[0m"
echo "ping网络操作,观察每次的时间是否均匀"
}
function test4G()
{
#检查SIM状态(查看SIM卡是否就绪)
echo -e "AT+CPIN?\r\n" > /dev/ttyUSB2
#(查看SIM卡注册状态)
echo -e "AT+CREG?\r\n" > /dev/ttyUSB2
#查看SIM卡注册属性
echo -e "AT+COPS?\r\n" > /dev/ttyUSB2
#查看SIM卡信号强度
echo -e "AT+CSQ\r\n" > /dev/ttyUSB2
killall -9 "cat /dev/ttyUSB2"
}
function main_menu()
{
echo -e `date`
cat<<EOF
-----------------------------------
`echo -e "\033[36m >>>3568硬件测试程序<<<\033[0m"`
`echo -e "\033[35m 0)环境部署\033[0m"`
`echo -e "\033[35m 1)内存测试\033[0m"`
`echo -e "\033[35m 2)测试4G\033[0m"`
`echo -e "\033[35m 3)网络测试\033[0m"`
`echo -e "\033[35m 4)GPIO输出测试\033[0m"`
`echo -e "\033[35m 5)GPIO输入测试\033[0m"`
`echo -e "\033[35m 6)485发送测试\033[0m"`
`echo -e "\033[35m 7)485接收测试\033[0m"`
`echo -e "\033[35m 8)简易网络测试\033[0m"`
`echo -e "\033[35m Q)退出\033[0m"`
-----------------------------------
EOF
read -p "请输入对应序列号:" num1
case $num1 in
0) environment;;
1) memtest 100;;
2) test4G;;
3) networktest 100;;
4) gpioouttest;;
5) gpiointest;;
6) rs485send;;
7) rs485rev;;
8) networkeasytest;;
Q|q)
killall -9 "cat"
systemctl enable check_all_route.service
echo -e "\033[32m--------退出--------- \033[0m"
exit 0
;;
*)
echo -e "\033[31m请输入正确的命令\033[0m"
esac
main_menu
}
while true
do
main_menu
done
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jun626/rk3568_auto_test.git
[email protected]:jun626/rk3568_auto_test.git
jun626
rk3568_auto_test
rk3568_auto_test
master

搜索帮助