6626主持主从一体功能,在sdk下有ble_app_multilink对应的工程,使用示例如下操作:
2.使用muti工程,做主机示例 (1)修改工程上如下:app_gatt_client.c文件下修改 static void app_gatt_event_cb(uint16_t evt_id, const omble_evt_t *evt) { if (evt_id == OB_GAP_EVT_CONNECTED) { conn_idx = evt->gap.conn_idx; } else if (evt_id == OB_GAP_EVT_DISCONNECTED) { } else if (evt_id == OB_GAP_EVT_ADV_STATE_CHANGED) { } else if (evt_id == OB_GATT_EVT_MTU_EXCHANGED) { } else if (evt_id == OB_GATTC_EVT_FIND_SERV_RSP) { const ob_gattc_evt_find_serv_rsp_t *rsp = &evt->gatt.find_serv_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { for (int i = 0; i < rsp->service_num; i++) { OM_LOG_DEBUG("Service: 0x%04X - 0x%04X ", rsp->service[i].start_hdl, rsp->service[i].end_hdl); if (rsp->service[i].uuid_len == 2) { OM_LOG_DEBUG("0x%04X\n", rsp->service[i].uuid[0] + (rsp->service[i].uuid[1] << 8)); } else { OM_LOG_DEBUG_ARRAY(rsp->service[i].uuid, rsp->service[i].uuid_len); OM_LOG_DEBUG("\n"); } } } else if (rsp->status == OB_GATT_ERR_ATTRIBUTE_NOT_FOUND) { OM_LOG_DEBUG("No GATT service found.\n"); } } else if (evt_id == OB_GATTC_EVT_FIND_SERV_BY_UUID_RSP) { const ob_gattc_evt_find_serv_by_uuid_rsp_t *rsp = &evt->gatt.find_serv_by_uuid_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { for (int i = 0; i < rsp->service_num; i++) { OM_LOG_DEBUG("Service: 0x%04X - 0x%04X ", rsp->service[i].start_hdl, rsp->service[i].end_hdl); if (rsp->service[i].uuid_len == 2) { OM_LOG_DEBUG("0x%04X\n", rsp->service[i].uuid[0] + (rsp->service[i].uuid[1] << 8)); } else { OM_LOG_DEBUG_ARRAY(rsp->service[i].uuid, rsp->service[i].uuid_len); OM_LOG_DEBUG("\n"); } } } else if (rsp->status == OB_GATT_ERR_ATTRIBUTE_NOT_FOUND) { OM_LOG_DEBUG("No GATT service found.\n"); } } else if (evt_id == OB_GATTC_EVT_FIND_CHAR_RSP) { const ob_gattc_evt_find_char_rsp_t *rsp = &evt->gatt.find_char_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { for (int i = 0; i < rsp->char_num; i++) { OM_LOG_DEBUG("Char Value Handle: 0x%02X\n", rsp->characteristic[i].value_hdl); OM_LOG_DEBUG("Char UUID: "); if (rsp->characteristic[i].uuid_len == 2) { OM_LOG_DEBUG("0x%04X\n", rsp->characteristic[i].uuid[0] + (rsp->characteristic[i].uuid[1] << 8)); } else { OM_LOG_DEBUG_ARRAY(rsp->characteristic[i].uuid, rsp->characteristic[i].uuid_len); OM_LOG_DEBUG("\n"); } OM_LOG_DEBUG("Char Prop: %02X\n", rsp->characteristic[i].properties); } } else if (rsp->status == OB_GATT_ERR_ATTRIBUTE_NOT_FOUND) { OM_LOG_DEBUG("No GATT characteristic found.\n"); } } else if (evt_id == OB_GATTC_EVT_FIND_DESC_RSP) { const ob_gattc_evt_find_desc_rsp_t *rsp = &evt->gatt.find_desc_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { for (int i = 0; i < rsp->desc_num; i++) { OM_LOG_DEBUG("Desc Handle: 0x%02X\n", rsp->descriptor[i].att_hdl); OM_LOG_DEBUG("Desc UUID: "); if (rsp->descriptor[i].uuid_len == 2) { OM_LOG_DEBUG("0x%04X\n", rsp->descriptor[i].uuid[0] + (rsp->descriptor[i].uuid[1] << 8)); } else { OM_LOG_DEBUG_ARRAY(rsp->descriptor[i].uuid, rsp->descriptor[i].uuid_len); OM_LOG_DEBUG("\n"); } } } else if (rsp->status == OB_GATT_ERR_ATTRIBUTE_NOT_FOUND) { OM_LOG_DEBUG("No GATT descriptor found.\n"); } } else if (evt_id == OB_GATTC_EVT_READ_RSP) { const ob_gattc_evt_read_rsp_t *rsp = &evt->gatt.read_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { OM_LOG_DEBUG("GATT read by handle success: "); OM_LOG_DEBUG_ARRAY(rsp->data, rsp->len); OM_LOG_DEBUG("\n"); } else { OM_LOG_DEBUG("GATT read by handle failed: 0x%02X.\n", rsp->status); } } else if (evt_id == OB_GATTC_EVT_READ_BY_UUID_RSP) { const ob_gattc_evt_read_by_uuid_rsp_t *rsp = &evt->gatt.read_by_uuid_rsp; if (rsp->status == OB_GATT_ERR_NO_ERROR) { OM_LOG_DEBUG("GATT read by uuid success(hdl:0x%02X): ", rsp->att_hdl); OM_LOG_DEBUG_ARRAY(rsp->data, rsp->len); OM_LOG_DEBUG("\n"); } else { OM_LOG_DEBUG("GATT read by uuid failed: 0x%02X.\n", rsp->status); } } // else { // } else if(evt_id == OB_GATTC_EVT_HVX_IND)//NTF通道 增加接口 { OM_LOG_DEBUG("evt_id0x%02X.\n", evt_id); OM_LOG_DEBUG_ARRAY_EX("gatt=\r\n",evt->gatt.hvx_ind.data,evt->gatt.hvx_ind.len); //打印接收从机的数据 } } 3.主机使用操作步骤 (1)扫描 (2)连接 3 (3)搜索所有服务 (4)打开通知 (5)发送数据到从机 (6)接收到从机数据 |