Bluetooth MCU Development Tour: The Problem of Device Name in Dialog 14585 Broadcast

Keywords: SDK

For some time, it was found that the device name could not be recognized in the Bluetooth broadcast of the spreadsheet. After debugging, it was found that the name of the device had been added repeatedly. Because we used Mijia's sdk, and then Mijia's SDK part of the code copied the original factory's sdk, and did not do a good job of compatibility. When using Mijia SDK to set or modify broadcast data, we need to provide adv_data and scan_resp_data at the same time. Then I add our device name to scan_resp_data, and then stop broadcasting, because the original SDK will automatically add the device name when setting broadcast data. The result of adding two device names is that the name can not be recognized. Mi's SDK copied it. It feels like this place is a low-level mistake made in dialog's sdk. What do you do when you make people want to change the device name? Yes, you have to stop broadcasting and restart it!

Attach debug traceable factory code:

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;
}

 

Posted by nickholas on Thu, 10 Oct 2019 08:11:07 -0700