对于单连接的主机,添加以下配置策略和启用白名单(已知地址),能显示增加广播回应用包的扫描成功率。最于需要维持多个连接的应用,并不适用。 应用新策略后,广播回应包的扫描成功率能提高约50%。 //for better scan performance *(__IO uint32_t *)0x41300080 = (*(__IO uint32_t *)0x41300080 & (~(0xFF<<16))) | (62<<16); void user_scan_start(void) { ob_scan_param_t scan_param; uint16_t time = 0; if (scan_cfg.status == true) { log_info("scanning..."); if (ob_gap_scan_stop() != OB_ERROR_NO_ERR) { OM_LOG_DEBUG("stop scan error"); return; } } log_info("scanning 1"); scan_cfg.found_counter = 0; // scan_dev_reported_flag = 0; if (scan_cfg.timeout == 0) { time = SCAN_TIME * 1000; } else { time = scan_cfg.timeout; } param_scan_1m.scan_type = true; param_scan_1m.interval = 100 / 0.625 ; //0x80;//0.625ms param_scan_1m.window = 80 / 0.625 ; //0x60;//0.625ms scan_param.addr_type = OB_ADV_ADDR_TYPE_PUBLIC; scan_param.filter_policy = OB_SCAN_FILTER_BASIC_UNFILTER; scan_param.timeout = 3000 / 10; //m scan_param.scan_coded = NULL; scan_param.scan_1m = ¶m_scan_1m; //clear scan records scan_dev_count = 0; // scan_dev_reported_flag = 0; memset(scan_dev_record, 0, sizeof(scan_dev_record)); //for better scan performance *(__IO uint32_t *)0x41300080 = (*(__IO uint32_t *)0x41300080 & (~(0xFF<<16))) | (62<<16); // #if 1 //使用白名单扫描广播、 if (timeout_test < 5) { scan_param.filter_policy = OB_SCAN_FILTER_BASIC_FILTER; uint8_t address[7] = {0}; ob_gap_addr_t addr_whitelist[14]; memcpy(address, &user_global.MW_para.wait4Connect_mac, sizeof(user_global.MW_para.wait4Connect_mac)); memset(addr_whitelist, 0, sizeof(addr_whitelist)); // memcpy(&addr_whitelist[0], address, 7); // addr_whitelist[0].addr_type = 0; memcpy(&addr_whitelist[1], address, 7); // addr_whitelist[1].addr_type = 1; ob_gap_accept_list_set(addr_whitelist, 2); } #endif // uint32_t res = ob_gap_scan_start(&scan_param); if (res != OB_ERROR_NO_ERR) { OM_LOG_DEBUG("start scan error =%d", res); } else { OM_LOG_DEBUG("start scan go.."); scan_cfg.status = true; observer.ads_len = 0; if (scan_cfg.type == SCAN_ONLY) { scan_dev_count = 0; memset(scan_dev_record, 0, sizeof(scan_dev_record)); } } } 找到设备后,在连接时,需要重新调整一下配置策略,以提高连接速度 //for better connect perfermance *(__IO uint32_t *)0x41300080 = (*(__IO uint32_t *)0x41300080 & (~(0xFF<<16))) | (82<<16); uint32_t user_connect_start(uint8_t *address, uint8_t timeout) { if (timeout == 0) { timeout = 5; } ob_gap_addr_t peer_addr; memcpy(&peer_addr, address, 7); ob_conn_phy_param_t conn_phy = { .scan_intv = 0xA0, //unit 0.625 SCAN Interval >>= scan window .scan_wind = 0x9E, //unit 0.625 .conn_intv_min = (uint16_t)(15 * 100 / 125), //unit 1.25 .conn_intv_max = (uint16_t)(15 * 100 / 125), //unit 1.25 .latency_max = 0, .timeout = 200, }; ob_conn_param_t conn_param = { OB_ADV_ADDR_TYPE_PUBLIC, //类型需要和地址匹配 OB_SCAN_FILTER_BASIC_UNFILTER, peer_addr, &conn_phy, &conn_phy, NULL, }; //for better connect performance *(__IO uint32_t *)0x41300080 = (*(__IO uint32_t *)0x41300080 & (~(0xFF<<16))) | (82<<16); #if 1 //使用白名单连接 ob_gap_addr_t addr_whitelist[14]; memset(addr_whitelist, 0, sizeof(addr_whitelist)); memcpy(&addr_whitelist[0], address, 7); addr_whitelist[0].addr_type = 0; memcpy(&addr_whitelist[1], address, 7); addr_whitelist[1].addr_type = 1; ob_gap_accept_list_set(addr_whitelist, 2); conn_param.filter_policy = OB_CONN_FILTER_USE;//使用白名单地址,忽略设置的地址 #endif // uint32_t res = ob_gap_connect(&conn_param); OM_LOG_DEBUG_ARRAY_EX("\npeer addr:", &peer_addr, 7); log_info("\nres=0x%x", res); if (res == OB_ERROR_NO_ERR) { // set_shell_busy("Connectting...Please wait\n"); evt_timer_set(&timer_conn, timeout * 1000, EVT_TIMER_ONE_SHOT, conn_timeout_cb, NULL); } else { log_info("cnt start error:0x%x", res); } return res; } |