# 执行蓝牙 SPP 客户端功能

您可以使用 `spp_client_menu` 选项执行 SPP 客户端功能。

开始之前，请设置设备并转到 SPP 客户端菜单，如[设置设备以使用蓝牙 SPP 功能](https://docs.qualcomm.com/doc/80-70018-13SC/topic/set_up_bluetooth_in_spp.html#context-bgp-lts-s1c)中所述。

## 配置 DUT 为 SPP 客户端角色

要配置 DUT 为 SPP 客户端角色，执行以下操作：

1. 在远程设备 SPP 应用程序中运行 SPP 服务器。
2. 通过运行以下命令从 DUT 启动 SPP profile 文件连接：

connect <bt_addr>
        Copy to clipboard

    **参数**

    `<bt_addr>` 是远程设备的蓝牙地址。

    [运行蓝牙查询扫描](https://docs.qualcomm.com/doc/80-70018-13SC/topic/gap_commands.html#section-iy1-xnf-41c)以获取 `<bt_addr>`。
3. 查看 DUT 上的输出以确定 SPP 连接是否成功。

    **示例输出**

    以下示例输出显示已成功建立 SPP 连接：

spp_client_menu
        
        ***************** Menu *******************
                 connect <bt_addr>
                 disconnect
                 send_file<space><directory_with_file_name>eg: send_file /var/fileName.txt
                 recv_file<space><directory_with_file_name>eg: recv_file /var/fileName.txt
                 send_data<space><with_size>eg: send_data 1000[Note:1000 means 1MB]
                 recv_data
                 main_menu
        ******************************************
        connect 22:22:85:3d:2e:50
        Connecting Device ... Please wait ...!!!
        ACL state:0 change with reason 00 for device: 22:22:85:3d:2e:50
        Device is Connected
        -----------------------
        Device Address       : 22:22:85:3d:2e:50
        Connection Direction : Client
        Copy to clipboard

Note

如果您在 `/var` 目录中遇到任何权限问题，请使用 `/etc/bluetooth` 目录发送或接收文件。

## 以客户端角色发送文件

以客户端角色发送文件，执行以下操作：

1. 在 SPP 应用程序中将远程设备设置为接收模式（如果可行的话）。
2. 创建一个包含数据的测试文件，并将该文件放在 DUT `/etc/bluetooth` 的目录中。

    例如，创建一个测试文件 `bt_stack.conf`。
3. 通过运行以下命令将测试文件发送到远程设备：

send_file <directory_with_file_name>
        Copy to clipboard

    **参数**

    `<directory_with_file_name>` 是完整的文件路径和文件名。

    **示例**

    要发送位于 `/etc/bluetooth` 的测试文件 `bt_stack.conf`，请运行以下命令：

send_file /etc/bluetooth/bt_stack.conf
        Copy to clipboard

    **示例输出**

send_file /etc/bluetooth/bt_stack.conf
        File Transfer Complete
        ---------------------
        Device Address : 22:22:85:3d:2e:50
        File Name      : /etc/bluetooth/bt_stack.conf
        Copy to clipboard

Note

如果出现问题，断开与设备的连接并恢复该过程。
4. 查看对端应用程序上的文件接收状态。

## 以客户端角色接收文件

以客户端角色接收文件，执行以下操作：

1. 将 DUT 设置为接收模式。
2. 通过运行以下命令从远程设备接收文件：

recv_file <directory_with_file_name>
        Copy to clipboard

    **参数**

    `<directory_with_file_name>` 是完整的文件路径和文件名。

Note

要接收文件，请仅使用 `/etc/bluetooth` 目录。

    **示例**

    要从远程设备的 `fileName.txt` 处接收 `/etc/bluetooth`，请运行以下命令：

recv_file /etc/bluetooth/fileName.txt
        Copy to clipboard
3. 从远程设备 SPP 服务应用程序发送文件。
4. 验证收到的文件，如下所示：

    1. 打开命令提示符窗口。
    2. 运行以下命令，拉取收到的文件：

scp -r root@<IP_address>:<source_file_path> <destination_file_path>
            Copy to clipboard

        要将文件拉取到当前文件路径，请在命令中输入 `<destination_file_path>` 作为 `.`。

Note

提示输入密码时，输入 `oelinux123` 以通过安全复制协议 (SCP) 对文件传输进行身份验证。

        **示例**

        设备的 IP 地址是 `10.92.160.222`。要从 `/etc/bluetooth` 中提取 `fileName.txt`，请运行以下命令：

scp -r root@10.92.160.222:/etc/bluetooth/fileName.txt .
            Copy to clipboard
    3. 打开收到的文件并验证内容。
5. 通过运行以下命令断开 SPP 与 DUT 的连接：

disconnect
        Copy to clipboard

Last Published: Apr 30, 2025

[Previous Topic
执行蓝牙 SPP 服务器功能](https://docs.qualcomm.com/bundle/publicresource/80-70018-13SC/topics/perform_bluetooth_functions_in_spp_server.md) [Next Topic
通用属性 Profile (General Attribute Profile)](https://docs.qualcomm.com/bundle/publicresource/80-70018-13SC/topics/set_up_ble_gatt.md)