连续签到天数:1天 | 签到总天数:154天 | 签到总奖励:1016金币 |
|
1 BLE 初始化: 添加如下: /* Initialise GAP */
- sinkBleGapInitialise();
- ConnectionDmBleConfigureLocalAddressReq(ble_local_addr_generate_resolvable, NULL);/* 配置用于BLE连接的本地设备地址*/
复制代码
2 设置广播参数 :修改如下:
- void sinkBleSetAdvertisingParamsDefault(uint16 adv_interval_min, uint16 adv_interval_max)
- {
- ble_adv_params_t params;
- params.undirect_adv.adv_interval_min = adv_interval_min;
- params.undirect_adv.adv_interval_max = adv_interval_max;
- params.undirect_adv.filter_policy = ble_filter_none;
- BLE_INFO(("Set BLE Default Advertising Params\n"));
- ConnectionDmBleSetAdvertisingParamsReq(ble_adv_ind, FALSE, BLE_ADV_CHANNEL_ALL, ¶ms);
- }
- ConnectionDmBleSetAdvertisingParamsReq(ble_adv_ind, FALSE, BLE_ADV_CHANNEL_ALL, ¶ms); // FALSE 改为TURE
复制代码
3 初始化上电完成后广播:
- case ble_gap_event_power_on: {
- /*On bootup, start whitelist scan/adverts only if LE device available in paired device list*/
- /* if(ConnectionDmBleCheckTdlDeviceAvailable())*/
- {
- /* Move to scanning and advertising state */
- sinkBleSetGapState(ble_gap_state_scanning_advertising); /*开启广播*/
- /* This will trigger scanning and advertising */
- sinkBleCheckNoConnectionsEvent();
- }
复制代码 4 广播完成之后读取本地蓝牙名称之后设置广播数据: 无修改
- void sinkBleGapReadLocalNameComplete(CL_DM_LOCAL_NAME_COMPLETE_T * cfm)
- {
- BLE_GAP_INFO(("CL_DM_LOCAL_NAME_COMPLETE\n"));
- if (cfm->status != success)
- {
- BLE_GAP_ERROR((" Failed!\n"));
- }
- if (GAP.name_read & ble_gap_read_name_gap_server)
- {
- /* Use local name to respond as GAP server */
- BLE_GAP_INFO((" Gap server response\n"));
- sinkGattGapServerSendLocalNameResponse(cfm);
- }
- if (GAP.name_read & ble_gap_read_name_advertising)
- {
- /* Use local name to setup advertising data */
- BLE_GAP_INFO((" Set advertising data bondable=[%u]\n", sinkBleGetGapState() == ble_gap_state_bondable_scanning_advertising ? TRUE : FALSE));
- bleSetupAdvertisingData(cfm->size_local_name,
- cfm->local_name,
- sinkBleGetGapState() == ble_gap_state_bondable_scanning_advertising ? adv_discoverable_mode_limited : adv_non_discoverable_mode);
- }
- GAP.name_read = 0;
- }
复制代码 5 广播完成之后 用lightblue 连接 总是断开 最后跟踪发现不是绑定设备所以就会断开 所以修改如下: 屏蔽非绑定设备的判断处理
- bool gattServerConnectionAdd(uint16 cid, const typed_bdaddr *client_taddr)
- {
- sink_attributes attributes;
- typed_bdaddr public_taddr;
- uint16 index;
- bool is_bonded_device = sinkBleCheckBdAddrtIsBonded(client_taddr, &public_taddr);
- if(is_bonded_device)
- {
- /* If we are trying to connect already bonded device in bondable
- * state, then we should be in proper state to allow the connection
- */
- if(!sinkBleGapIsConnectable())
- return FALSE;
- }
- #if 0 /*屏蔽掉设备绑定*/
- else
- {
- /* If the user has requested for bonding, and also the device is still in connectable state
- * only then we should allow non-bonded device to connect */
- if(!sinkBleGapIsBondable() || !sinkBleGapIsConnectable())
- {
- /* A non-bonded device is trying to connect, dont allow it */
- return FALSE;
- }
- }
- #endif
- /* So, we are in connectable state, now check if we still have slot for connection
- * in peripheral role */
- if(gattCommonAddConnections(cid, ble_gap_role_peripheral))
- {
- index = gattCommonConnectionFindByCid(cid);
- /* Set client service configuration to default value */
- memset(&GATT_SERVER.client_config, 0, sizeof(gatt_ccd_attributes_t));
- if (is_bonded_device)
- {
- /* Restore client configuration from PS */
- deviceManagerClearAttributes(&attributes);
- if (deviceManagerGetAttributes(&attributes, &public_taddr.addr))
- {
- GATT_SERVER.client_config = attributes.gatt_client;
- GATT_SERVER_DEBUG(("GATT Client: Read client config addr[%x:%x:%lx] config_gatt[0x%x] config_batt_l[0x%x] config_batt_r[0x%x] config_batt_p[0x%x]\n",
- public_taddr.addr.nap,
- public_taddr.addr.uap,
- public_taddr.addr.lap,
- GATT_SERVER.client_config.gatt,
- GATT_SERVER.client_config.battery_local,
- GATT_SERVER.client_config.battery_remote,
- GATT_SERVER.client_config.battery_peer
- ));
- }
- }
- /* check for repeated updates */
- if( LOCAL_UPDATE_REQD(GATT_SERVER) ||
- REMOTE_UPDATE_REQD(GATT_SERVER) ||
- PEER_UPDATE_REQD(GATT_SERVER) )
- {
- MessageCancelFirst( sinkGetBleTask(), BLE_INTERNAL_MESSAGE_BATTERY_READ_TIMER );
- MessageSend( sinkGetBleTask(), BLE_INTERNAL_MESSAGE_BATTERY_READ_TIMER, 0 );
- }
- return TRUE;
- }
- return FALSE;
- }
复制代码 之后搜索还是不能连接 请问下大神们我哪里出问题了 求助 我已经搞了几天了!!!!!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册 
×
|