小熊派鸿蒙社区
直播中

jf_07365693

1年用户 77经验值
擅长:嵌入式技术 控制/MCU
私信 关注
[经验]

【BearPi-Pico H3863星闪开发板体验连载】蓝牙 BLE 透传测试

蓝牙 BLE 透传测试

小熊派 Pico-H3863 开发板支持 BLE 1MHz/2MHz 频宽、BLE4.0/4.1/4.2/5.0/5.1/5.2 协议、BLE Mesh 和 BLE 网关功能,最大空口速率2Mbps.

服务端配置

**点击工具栏中的 **系统配置 选项,展开 Application 目录,勾选 Enable SampleEnable the Sample of productsSupport BLE UART sample 以及 Select ble uart type ,勾选 Enable BLE UART Server sample

BLE_Server_Config.png

**点击 **Save .

核心代码

**关键工程文件位于 **application - samples - products - ble_uart - ble_uart.c

static void *ble_uart_server_task(const char *arg)
{
    unused(arg);
    ble_uart_server_init();
    errcode_t ret = uapi_uart_register_rx_callback(CONFIG_BLE_UART_BUS,
                                                   UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
                                                   1, ble_uart_read_int_handler);
    if (ret != ERRCODE_SUCC) {
        osal_printk("Register uart callback fail.");
        return NULL;
    }
    while (1) {
        msg_data_t msg_data = { 0 };
        int msg_ret = osal_msg_queue_read_copy(mouse_msg_queue, &msg_data, &msg_rev_size, OSAL_WAIT_FOREVER);
        if (msg_ret != OSAL_SUCCESS) {
            osal_printk("msg queue read copy fail.");
            if (msg_data.value != NULL) {
                osal_vfree(msg_data.value);
            }
            continue;
        }
        if (msg_data.value != NULL) {
            ble_uart_server_send_input_report(msg_data.value, msg_data.value_len);
            osal_vfree(msg_data.value);
        }
    }
    return NULL;
}

重编译 工程后 程序加载 至开发板并重置 RST 开发板即可。

客户端配置

**点击工具栏中的 **系统配置 选项,展开 Application 目录,勾选 Enable SampleEnable the Sample of productsSupport BLE UART sample 以及 Select ble uart type ,勾选 Enable BLE UART Client sample

BLE_Client_Config.png

**点击 **Save .

核心代码

**关键工程文件位于 **application - samples - products - ble_uart - ble_uart.c

static void *ble_uart_client_task(const char *arg)
{
    unused(arg);
    osal_printk("ble_uart_client_task entry.");
    ble_uart_client_init();
    errcode_t ret = uapi_uart_register_rx_callback(CONFIG_BLE_UART_BUS,
                                                   UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
                                                   1, ble_uart_read_int_handler);
    if (ret != ERRCODE_SUCC) {
        osal_printk("Register uart callback fail.");
        return NULL;
    }
    while (1) {
        msg_data_t msg_data = { 0 };
        int msg_ret = osal_msg_queue_read_copy(mouse_msg_queue, &msg_data, &msg_rev_size, OSAL_WAIT_FOREVER);
        if (msg_ret != OSAL_SUCCESS) {
            osal_printk("msg queue read copy fail.");
            if (msg_data.value != NULL) {
                osal_vfree(msg_data.value);
            }
            continue;
        }
        if (msg_data.value != NULL) {
            uint16_t write_handle = ble_uart_get_write_vlaue_handle();
            ble_uart_client_write_cmd(msg_data.value, msg_data.value_len, write_handle);
            osal_vfree(msg_data.value);
        }
    }
    return NULL;
}

重编译 工程后 程序加载 至开发板并重置 RST 开发板即可。

测试

BLE_UART_test.png

视频

VID_20241004_BLE_UART

更多回帖

发帖
×
20
完善资料,
赚取积分