# 03-功能测试

## LCD

硬件连接

![1732673112060](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/1732673112060.png)

**显示**

```
fbinit
echo 8 > /sys/devices/virtual/disp/disp/attr/colorbar
```

![image-20241127100853924](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127100853924.png)

**触控**

```
ts_test
```

点击Draw按钮显示触摸轨迹

![image-20241127101444185](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127101444185.png)

**背光**

```
/usr/bin/lcd_bright_test 2 255
/usr/bin/lcd_bright_test 2 0
```

## 耳机

```
tinymix set "Headphone Switch" 1
aplay -Dhw:audiocodec -vv /etc/sample-15s.wav
```

![image-20241127110956315](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127110956315.png)

## 喇叭

![1730786055916](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/1730786055916.png)

播放音频

```
aplay -Dhw:audiocodec -vv /etc/sample-15s.wav
```

## 麦克风

```
arecord -Dhw:audiocodec -f S24_LE -r  16000  -vvv  test.wav
aplay -Dhw:audiocodec  -vv test.wav
```

## WIFI

**buildroot**

```shell
修改wifi名和密码
# vi /etc/wpa_supplicant.conf
# cat /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1

network={
        ssid="wifi_oranth_2.4"
        psk="123456789"
        key_mgmt=WPA-PSK
}


```

连接wifi并获取ip

```
wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B

udhcpc -i wlan0
```

![image-20241127182924328](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127182924328.png)

```
切换WIFI
killall wpa_supplicant
vim /etc/wpa_supplicant.conf
wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
udhcpc -i wlan0
wap_cli status

killall wpa_supplicant
killall udhcpc
vim /etc/wpa_supplicant.conf
wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
udhcpc -i wlan0
wap_cli status
```

**Ubuntu**

WiFi

```shell
查看网络设备列表
sudo nmcli dev

开启wifi
sudo nmcli r wifi on

关闭wifi
sudo nmcli r wifi off

扫描附件热点
sudo nmcli dev wifi

连接 用户 SSID 密码的 PASSWORD 的热点 (其他热点修改对应用户及密码)
sudo nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0
```

## 蓝牙

**ubuntu**

1.安装蓝牙工具

```shell
$ sudo apt-get update
$ sudo apt-get install pulseaudio-module-bluetooth
$ reboot
```

2.初始化蓝牙节点

```shell
$ echo 0 > /sys/class/rfkill/rfkill0/state
$ sleep 1
$ echo 1 > /sys/class/rfkill/rfkill0/state
$ sleep 1
$ hciconfig hci0 up
$ hciconfig hci0 piscan
$ hciconfig -a  
```

3.扫描蓝牙

```shell
经典蓝牙扫描
bluetoothctl scan on
配对
bluetoothctl pair 28:52:E0:19:17:69
连接
bluetoothctl connect 28:52:E0:19:17:69
信任此设备，下次可直接连接 无需配对
bluetoothctl trust 28:52:E0:19:17:69
断开
bluetoothctl disconnect 28:52:E0:19:17:69
解除配对
bluetoothctl remove FC:E8:06:E7:96:AF   
阻止连接
bluetoothctl block  FC:E8:06:E7:96:AF 
查看配好对的蓝牙设备
bluetoothctl paired-devices
```

设置蓝牙设备播放音频

```shell
查看配对的蓝牙设备
bluetoothctl paired-devices 
设置蓝牙播放
pacmd set-default-sink bluez_sink.28_52_E0_19_17_69.a2dp_sink
播放音频
aplay sample-15s.wav
```

![image-20250428144858777](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20250428144858777.png)

## RTC

主板上丝印为 RTC，测试 RTC 功能必须外接纽扣电池，并且确认电池电量充足

**掉电保存时间测试**

测试步骤：

设置系统时间并同步到外部RTC时钟

```
date -s "2024-11-06 10:30:00" && hwclock -w -f /dev/rtc1
```

断电，等待若干时间后，重新接上开发板电源

```
date && hwclock -f /dev/rtc1 
```

若系统时间与当前RTC时间一致，则RTC功能正常

## 4G Mobile

```
确认usb模块是否加载
lsusb

确认串口结点是否生成
ls /dev/ttyUSB*

插拔电话卡重新拨号
```

```
pppd call quectel-ppp &

ping www.baidu.com 测试

可能会出现没播通情况
通过ps -ef | grep pppd 查看进程号
kill -9 (进程号)
重新拨号 pppd call quectel-ppp &
```

外网ping测试

```shell
# ping www.baidu.com
```

ping外网可能出现DNS解析失败，需要添加对应DNS

修改resolv.conf文件

```shell
# vim /etc/resolv.conf
```

可以添加下面内容:

```shell
nameserver 8.8.8.8
nameserver 8.8.4.4
```

## SD

将格式化后的SD卡插入SD卡槽，系统自动挂载

```
time dd if=/dev/zero of=/dev/mmcblk1 bs=1M count=300 oflag=direct
```

![image-20241127183750626](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127183750626.png)

## USB

将格式化后的U盘接入USB接口，系统自动挂载

```
time dd if=/dev/zero of=/dev/sda bs=1M count=300 oflag=direct
```

![image-20241127183922113](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127183922113.png)

## CAN

**CAN收发测试**

K4B支持两路CAN接口，可将两路CAN连接后做收发测试

**硬件连接**

CANL <---> CANL

CANH <---> CANH

![image-20240930140153264](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20240930140153264.png)

**测试命令**

```
# 初始化CAN0
$ ip link set can0 down
$ ip link set can0 type can bitrate 500000
$ ip link set can0 up

# 初始化CAN1
$ ip link set can1 down
$ ip link set can1 type can bitrate 500000
$ ip link set can1 up

# 开始收发测试(CAN0接受、CAN1发送)
$ candump can0 &
$ cansend can1 123#DEADBEEF
```

![image-20241127184109190](http://tanzhtanzh.oss-cn-shenzhen.aliyuncs.com/img/image-20241127184109190.png)
