Dialog 14585 广播中设备名称的问题

     有一段日子,发现电子表的蓝牙广播中无法识别出设备名称了。后来经过烧脑的调试,发现原来是设备名称重复添加了。因为我们使用了米家的sdk,然后米家的sdk部分代码照抄了原厂的sdk,又没有做好兼容工作。在使用米家sdk设置或者修改广播数据的时候,需要同时提供adv_data和scan_resp_data,然后我往scan_resp_data中添加了我们的设备名称,然后就不广播了,因为原厂的sdk在设置广播数据的时候,最后会自动添加设备名称,添加两次设备名称的后果就是名称无法识别出来了。米家的sdk给抄了个正着。感觉这个地方真是dialog的sdk中犯下的低级错误,你让人家想修改设备名称的时候咋办呢,对,必须要停下广播再重新开启!

     有遇到这个问题的,要么不额外在广播数据中添加设备名称,要么直接将sdk中的源码相关的部分注释掉。

     附debug追溯的原厂代码,对,就是那个append_device_name:

static struct gapm_start_advertise_cmd* app_easy_gap_non_connectable_advertise_start_create_msg(void)
{
    // Allocate a message for GAP
    if (adv_cmd == NULL)
    {
        ASSERT_ERROR(USER_ADVERTISE_DATA_LEN <= ADV_DATA_LEN); // The Flags data type may be omitted (CCSv6)
        ASSERT_ERROR(USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN <= SCAN_RSP_DATA_LEN);

        struct gapm_start_advertise_cmd *cmd;
        cmd = app_advertise_start_msg_create();
        adv_cmd = cmd;

        cmd->op.code = GAPM_ADV_NON_CONN;
        cmd->op.addr_src = user_adv_conf.addr_src;
        cmd->intv_min = user_adv_conf.intv_min;
        cmd->intv_max = user_adv_conf.intv_max;
        cmd->channel_map = user_adv_conf.channel_map;
        cmd->info.host.mode = user_adv_conf.mode;
        cmd->info.host.adv_filt_policy = user_adv_conf.adv_filt_policy;
        cmd->info.host.adv_data_len = USER_ADVERTISE_DATA_LEN;
        memcpy(&(cmd->info.host.adv_data[0]), USER_ADVERTISE_DATA, USER_ADVERTISE_DATA_LEN);
        cmd->info.host.scan_rsp_data_len = USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN;
        memcpy(&(cmd->info.host.scan_rsp_data[0]), USER_ADVERTISE_SCAN_RESPONSE_DATA, USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN);

        // Place the Device Name in the Advertising Data or in the Scan Response Data
        if (USER_DEVICE_NAME_LEN > 0)
        {
            // Get remaining space in the Advertising Data ( plus 2 bytes are used for the length and flag bytes of the Device Name)
            uint16_t total_adv_space = adv_cmd->info.host.adv_data_len + 2 + USER_DEVICE_NAME_LEN;
            // Get remaining space in the Scan Response Data ( plus 2 bytes are used for the length and flag bytes of the Device Name)
            uint16_t total_scan_space = adv_cmd->info.host.scan_rsp_data_len + 2 + USER_DEVICE_NAME_LEN;

            if (total_adv_space <= ADV_DATA_LEN)
            {
                append_device_name(&cmd->info.host.adv_data_len,
                                   USER_DEVICE_NAME_LEN,
                                   &(cmd->info.host.adv_data[cmd->info.host.adv_data_len]),
                                   USER_DEVICE_NAME);
            }
            else if (total_scan_space <= SCAN_RSP_DATA_LEN)
            {
                append_device_name(&cmd->info.host.scan_rsp_data_len,
                                   USER_DEVICE_NAME_LEN,
                                   &(cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len]),
                                   USER_DEVICE_NAME);
            }
         }
    }
    return adv_cmd;
}

 

你可能感兴趣的:(#,BLE,物联网)