我们6621CxC(BLE5.1)的SDK默认的广播包是31-3个字节。 若实际需求使用大于31-3字节的广播需求,可以使用扩展广播包来支持。 +默认广播包 和 扩展广播包不能共存 +2Mbps模式下才支持 +6621CxB,6621P 类同 以下用SDK 中ble_app_simple_server为例子,介绍开启扩展广播包方法,测试时用到的手机要求也是支持BLE5.0以后的手机。 例 #define EXTENDED_ADV 1. static void appm_advertising_init(void) { struct app_adv_modes_config_tag adv_config; adv_config.whitelist_enabled = false; adv_config.directed_enabled = false; adv_config.directed_timeout = APP_ADV_DIRECTED_TIMEOUT; adv_config.fast_enabled = true; adv_config.fast_interval = APP_ADV_FAST_INTERVAL; adv_config.fast_timeout = APP_ADV_FAST_TIMEOUT; adv_config.slow_enabled = false; adv_config.slow_interval = APP_ADV_SLOW_INTERVAL; adv_config.slow_timeout = APP_ADV_SLOW_TIMEOUT; appm_adv_init(NULL, &adv_config); #ifdef EXTENDED_ADV //增加 uint8_t default_adv_data[EXT_ADV_DATA_MAX_LEN - 3]; uint16_t adv_len = 0; appm_build_adv_data(ADV_DATA_LEN - 3, &adv_len, (uint8_t*)default_adv_data); appm_adv_set_adv_data((uint8_t*)default_adv_data, adv_len); #else uint8_t default_adv_data[ADV_DATA_LEN - 3]; uint16_t adv_len = 0; appm_build_adv_data(ADV_DATA_LEN - 3, &adv_len, (uint8_t*)default_adv_data); appm_adv_set_adv_data((uint8_t*)default_adv_data, adv_len); #endif //uint8_t res_data[APP_ADV_MAX_LEN]; //uint8_t res_data_len = APP_SCNRSP_DATA_LEN; //memcpy(res_data, APP_SCNRSP_DATA, sizeof(APP_SCNRSP_DATA)); //appm_adv_set_res_data(res_data, res_data_len); } 2. static void appm_adv_create_advertising(void) { //log_debug("%s@%d\n", __func__, __LINE__); if (app_adv_env.state == APP_ADV_STATE_IDLE) { // Prepare the GAPM_ACTIVITY_CREATE_CMD message struct gapm_activity_create_adv_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, TASK_GAPM, TASK_APP, gapm_activity_create_adv_cmd); // Set operation code p_cmd->operation = GAPM_CREATE_ADV_ACTIVITY; // Fill the allocated kernel message p_cmd->own_addr_type = GAPM_STATIC_ADDR; #if (BLE_APP_PRIVACY) if (app_sec_get_bond_status()) { p_cmd->own_addr_type = GAPM_GEN_RSLV_ADDR; } #endif #ifdef EXTENDED_ADV //增加 p_cmd->adv_param.type = GAPM_ADV_TYPE_EXTENDED; p_cmd->adv_param.prop = GAPM_EXT_ADV_PROP_UNDIR_CONN_MASK; #else p_cmd->adv_param.type = GAPM_ADV_TYPE_LEGACY; p_cmd->adv_param.prop = GAPM_ADV_PROP_UNDIR_CONN_MASK; #endif p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY; #if (BLE_APP_WHITE_LIST) if (app_sec_get_bond_status()) { p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_WLST_CON_WLST; } #endif p_cmd->adv_param.prim_cfg.chnl_map = APP_ADV_CHMAP; p_cmd->adv_param.prim_cfg.phy = GAP_PHY_LE_1MBPS; #ifdef EXTENDED_ADV //增加 p_cmd->adv_param.second_cfg.phy = GAP_PHY_LE_2MBPS; #endif #ifdef BLE_APP_ADV_DISC_MODE p_cmd->adv_param.disc_mode = BLE_APP_ADV_DISC_MODE; #else p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC; #endif ...... } 3.测试效果,修改广播字节内容(大于31字节) static void appm_build_adv_data(uint16_t max_length, uint16_t *p_length, uint8_t *p_buf) { // Remaining Length uint8_t rem_len = max_length; uint8_t dev_name[18] = {0}; uint8_t manufa[25] = {0}; uint8_t addr_test[6] = {0}; nvds_tag_len_t temp_len = 6; // Set appearance // memcpy(p_buf, APP_ADV_DATA_APPEARANCE, APP_ADV_DATA_APPEARANCE_LEN); // *p_length += APP_ADV_DATA_APPEARANCE_LEN; // p_buf += APP_ADV_DATA_APPEARANCE_LEN; // Set list of UUIDs memcpy(p_buf, APP_ADV_DATA_UUID, APP_ADV_DATA_UUID_LEN); *p_length += APP_ADV_DATA_UUID_LEN; p_buf += APP_ADV_DATA_UUID_LEN; // Sanity check ASSERT_ERR(rem_len >= max_length); // Manufacturer Specific Data manufa[0] = sizeof(manufa) - 1; manufa[1] = APP_ADV_DATATYPE_MANUFACTURER_SPECIFIC_DATA; manufa[2] = 0x02; // manufa[3] = 0xfe; // nvds_get(NVDS_TAG_BD_ADDRESS, &temp_len, &addr_test[0]); manufa[4] = addr_test[5]; // manufa[5] = addr_test[4]; // manufa[6] = addr_test[3]; // manufa[7] = addr_test[2]; // manufa[8] = addr_test[1]; // manufa[9] = addr_test[0]; // manufa[10] = 0xaa; // manufa[11] = addr_test[5]; // manufa[12] = addr_test[4]; // manufa[13] = addr_test[3]; // manufa[14] = addr_test[2]; // manufa[15] = addr_test[1]; // manufa[16] = addr_test[0]; // manufa[17] = 0xaa; // manufa[18] = addr_test[5]; // manufa[19] = addr_test[4]; // manufa[20] = addr_test[3]; // manufa[21] = addr_test[2]; // manufa[22] = addr_test[1]; // manufa[23] = addr_test[0]; // manufa[24] = 0xaa; // memcpy(p_buf, manufa, sizeof(manufa)); *p_length += sizeof(manufa); p_buf += sizeof(manufa); // dev name dev_name[0] = strlen(APP_DFLT_DEVICE_NAME)+1; dev_name[1] = APP_ADV_DATATYPE_COMPLETE_LOCAL_NAME;//'\x09'; memcpy(dev_name+2, APP_DFLT_DEVICE_NAME, strlen(APP_DFLT_DEVICE_NAME)); dev_name[2+strlen(APP_DFLT_DEVICE_NAME)] = 0x00; memcpy(p_buf, dev_name, sizeof(dev_name)); *p_length += sizeof(dev_name); p_buf += sizeof(dev_name); } 4.经过以上步骤,可以实现开启扩展包 |