Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

扫描、查找、连接并发送数据到 AC6328A 上的 SPP 设备 : SPP_BUFF NULL!!! #196

Open
0x0fe opened this issue Feb 25, 2023 · 0 comments

Comments

@0x0fe
Copy link

0x0fe commented Feb 25, 2023

我们的产品必须连接到第三方蓝牙 SPP 设备(ODBII 适配器),它将向其发送命令和接收数据。

由于第三方设备由最终用户提供,因此连接必须仅通过名称来完成。

在与 SDK 进行了数小时的斗争之后,仍然无法完成这个非常简单的任务。 显然,SDK 没有提供通过名称扫描和查找 SPP 设备然后连接到它的机制,因此我们可以使用正常的 SPP 功能来发送和接收数据。

我能找到的最好的方法是在将应用程序设置设置为 EDR 并使用 SPP 配置文件禁用 BLE 时使用 edr_emitter。 这样我至少可以看到设备,但仍然无法连接到它,也无法使用 SPP 功能。
我也没有看到 SPP 回调被触发,尽管它可以找到和设备并且似乎已连接。

我们能否获得一个简化的示例或存在此类示例的链接以实现以下目标:

  • 扫描具有任意名称的 SPP 设备,例如“ODBII”。
  • 连接到设备并设置 SPP 通信
  • 向设备发送一些 SPP 数据并在回调中接收响应
void bt_emitter_search_complete(u8 result)
{
    struct  inquiry_noname_remote *remote, *n;
    __this->bt_search_busy = 0;
    set_start_search_spp_device(0);
    u8 wait_connect_flag = 1;

    log_info("%s,%d\n", __FUNCTION__, __LINE__);
    if (__this->bt_connect_start) {
        __this->bt_connect_start = 0;
        log_info("connecting...");
        char *bfr ={"AT+NAME\r\n"};
        transport_spp_send_data_check(9);
        transport_spp_send_data(bfr,9);
        return;
    }

    if (!list_empty(&inquiry_noname_list)) {
        user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL);
    }

    if (!result) {
        list_for_each_entry_safe(remote, n, &inquiry_noname_list, entry) {
            if (remote->match) {
                user_send_cmd_prepare(USER_CTRL_START_CONNEC_VIA_ADDR, 6, remote->addr);
                wait_connect_flag = 0;
            }
            list_del(&remote->entry);
            free(remote);
        }
    }

    __this->read_name_start = 0;
    if (wait_connect_flag) {
        /* log_info("wait conenct\n"); */
        user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL);
        if (!result) {
            user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL);
        }
        user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL);
        __bt_search_device();
        /* #endif */
    }
}
static u8 __search_bd_name_filt(char *data, u8 len, u32 dev_class, char rssi)
{

    #if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED)
    char bd_name[64] = {0};
    u8 i;
    char *targe_name = NULL;
    char char_a = 0, char_b = 0;

    if ((len > (sizeof(bd_name))) || (len == 0)) {
        //printf("bd_name_len error:%d\n", len);
        return FALSE;
    }

    memset(bd_name, 0, sizeof(bd_name));
    memcpy(bd_name, data, len);
    log_info("name:%s,len:%d,class %x ,rssi %d\n", bd_name, len, dev_class, rssi);

    #if SEARCH_NAME_DEBUG
    extern char *get_edr_name(void);
    printf("tar name:%s,len:%d\n", get_edr_name(), strlen(get_edr_name()));
    targe_name = (char *)get_edr_name();

    #if  1
    //不区分大小写
    for (i = 0; i < len; i++) {
        char_a = bd_name[i];
        char_b = targe_name[i];
        if ('A' <= char_a && char_a <= 'Z') {
            char_a += 32;    //转换成小写
        }
        if ('A' <= char_b && char_b <= 'Z') {
            char_b += 32;    //转换成小写
        }
        //printf("{%d-%d}",char_a,char_b);
        if (char_a != char_b) {
            return FALSE;
        }
    }
    log_info("\n*****find dev ok******\n");
    return TRUE;
    #else
    //区分大小写
    if (memcmp(data, bt_get_emitter_connect_name(), len) == 0) {
        log_info("\n*****find dev ok******\n");
        return TRUE;
    }
    return FALSE;
    #endif

    #else
    /* for (i = 0; i < (sizeof(bd_name_filt) / sizeof(bd_name_filt[0])); i++) { */
    
    puts("\n*****find dev ok******\n");
    return TRUE;

    for (i = 0; i < bd_name_filt_nums; i++) {
        if (memcmp(data, bd_name_filt[i], len) == 0) {
            puts("\n*****find dev ok******\n");
            return TRUE;
        }
    }
    return FALSE;
    #endif

    #else
    return FALSE;
    #endif
}
[00:00:00.441][Info]: [DONGLE]=======================================
[00:00:00.447][Info]: [DONGLE]-------------usb + dongle demo---------
[00:00:00.454][Info]: [DONGLE]=======================================
[00:00:00.461][Info]: [DONGLE]app_file: ../../../../apps/spp_and_le/examples/dongle/app_dongle.c
[00:00:00.470][Info]: [COMM_EDR]sniff_mode:0
[00:00:00.474][Info]: [COMM_EDR]cnt_time:1
[00:00:00.478][Info]: [COMM_EDR]check_timer_ms:1000
[00:00:00.483][Info]: [COMM_EDR]max_interval_slots:800
[00:00:00.488][Info]: [COMM_EDR]min_interval_slots:100
[00:00:00.493][Info]: [COMM_EDR]attempt_slots:4
[00:00:00.498][Info]: [COMM_EDR]timeout_slots:1
[00:00:00.502][Info]: [COMM_EDR]---edr's address
CB C4 5E DB EA 6B 
[00:00:00.509][Info]: [EDR_EM]bt_emitter_set_match_name,bd_name_filt_nums= 1
[00:00:00.516]le_support:1 1
[00:00:00.519]le_config:0 0 0 0
[00:00:00.591]bredr_bd_init
[00:00:00.594]bredr_bd_init: exit
[00:00:00.599][Info]: [DONGLE]----dongle_bt_connction_status_event_handler 3
[00:00:00.606][Info]: [COMM_EDR]--------bt_comm_edr_status_event_handler: 3
[00:00:00.614][Info]: [COMM_EDR]STATUS_INIT_OK
[00:00:00.618][Info]: [SPP_TRANS]trans_spp_init
[00:00:00.623][Info]: [SPP_TRANS]spp_file: ../../../../apps/spp_and_le/modules/bt/spp_trans.c
[00:00:00.632][Info]: [EDR_EM]bt_emitter_init
[00:00:00.636][Info]: [EDR_EM]bt_emitter_set_match_name,bd_name_filt_nums= 1
[00:00:00.645][Info]: [EDR_EM]bt_search_start >>>>>>>>>
[00:00:00.651][Info]: [COMM_EDR]---sys_auto_sniff_controle,1
[00:00:00.657][Info]: [COMM_EDR]check_sniff_enable
[00:00:03.355][Info]: [EDR_EM]search no_name:
[00:00:03.360][Info]: [EDR_EM]===================SEARCH_BD_NAME_LIMITED=================
BA 89 67 45 23 01 
[00:00:03.390]link_page_enable 0
CB C4 5E DB EA 6B 
BA 89 67 45 23 01 
CCCCCCCC1CCCCCCCC1CCCCCCCCCCCCCCCCCCCCCCCCC1CCCCCCCC1CCCCCCCC123
[00:00:06.889][Info]: [EDR_EM]remote_name: OBDII
[00:00:06.895][Info]: [EDR_EM]name:OBDII,len:5,class 0 ,rssi 0
[00:00:06.901]*****find dev ok******
[00:00:06.905][Info]: [EDR_EM]get device,start to connect
[00:00:07.080]persent: 100, 0, 0, 0
[00:00:07.085][Info]: [DONGLE]----dongle_bt_hci_event_handler reason 1 0
[00:00:07.092][Info]: [COMM_EDR]--------bt_comm_edr_hci_event_handler reason 1 0
[00:00:07.099][Info]: [COMM_EDR] HCI_EVENT_INQUIRY_COMPLETE 
[00:00:07.105][Info]: [EDR_EM]bt_emitter_search_complete,378
[00:00:07.111][Info]: [EDR_EM]connecting...
[00:00:07.115][Info]: [SPP_TRANS]spp_api_tx(9) 
[00:00:07.120]SPP_BUFF NULL!!!

@0x0fe 0x0fe changed the title 扫描、查找、连接并发送数据到 AC6328A 上的 SPP 设备 扫描、查找、连接并发送数据到 AC6328A 上的 SPP 设备 : SPP_BUFF NULL!!! Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant