|
#define CHAR_HANDLE_MAX 11这里我改的11
这是我修改后的dsp
void app_service_discovery (void)
{
// 定义UUID常量
static const u8 custom_service_uuid[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00};
static const u8 custom_char_uuid1[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00};
static const u8 custom_char_uuid2[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00};
//----
att_db_uuid16_t db16[ATT_DB_UUID16_NUM];
att_db_uuid128_t db128[ATT_DB_UUID128_NUM];
memset (db16, 0, ATT_DB_UUID16_NUM * sizeof (att_db_uuid16_t));
memset (db128, 0, ATT_DB_UUID128_NUM * sizeof (att_db_uuid128_t));
if ( central_sdp_pending && host_att_discoveryService (central_sdp_pending, db16, ATT_DB_UUID16_NUM, db128, ATT_DB_UUID128_NUM) == BLE_SUCCESS) // service discovery OK
{
// 存储服务特征句柄
// 新增:识别RX/TX特性并记录属性
// 增加对自定义服务的处理
cur_sdp_device.char_handle[8] = blm_att_findHandleOfUuid128(db128, custom_service_uuid);
cur_sdp_device.char_handle[9] = blm_att_findHandleOfUuid128(db128, custom_char_uuid1); // 00001001-xxx
cur_sdp_device.char_handle[10] = blm_att_findHandleOfUuid128(db128, custom_char_uuid2); // 00001002-xxx
//---
cur_sdp_device.char_handle[0] = blm_att_findHandleOfUuid128 (db128, my_MicUUID); //MIC
cur_sdp_device.char_handle[2] = blm_att_findHandleOfUuid128 (db128, my_OtaUUID); //OTA
cur_sdp_device.char_handle[3] = blm_att_findHandleOfUuid16 (db16, CHARACTERISTIC_UUID_HID_REPORT,
HID_REPORT_ID_CONSUME_CONTROL_INPUT | (HID_REPORT_TYPE_INPUT<<8)); //consume report(media key report)
cur_sdp_device.char_handle[4] = blm_att_findHandleOfUuid16 (db16, CHARACTERISTIC_UUID_HID_REPORT,
HID_REPORT_ID_KEYBOARD_INPUT | (HID_REPORT_TYPE_INPUT<<8)); //normal key report
//cur_sdp_device.char_handle[6] = blm_att_findHandleOfUuid128 (db128, TelinkSppDataServer2ClientUUID); //BLE Module, SPP Server to Client
//cur_sdp_device.char_handle[7] = blm_att_findHandleOfUuid128 (db128, TelinkSppDataClient2ServerUUID); //BLE Module, SPP Client to Server
/* add the peer device att_handle value to conn_dev_list after service discovery is correctly finished */
dev_char_info_add_peer_att_handle(&cur_sdp_device);
/* peer device att_handle value store in flash */
dev_char_info_store_peer_att_handle(&cur_sdp_device);
//tlkapi_send_string_data(APP_DUMP_SDP_EN,"OTA handle", (u8*)&cur_sdp_device.char_handle[2], 2);
//tlkapi_send_string_data(APP_DUMP_SDP_EN,"CMKEY handle", (u8*)&cur_sdp_device.char_handle[3], 2);
//tlkapi_send_string_data(APP_DUMP_SDP_EN,"KBKEY handle", (u8*)&cur_sdp_device.char_handle[4], 2);
}
central_sdp_pending = 0; //service discovery finish
}
这张图可以是我用手机给从机发送后 从机也回复了信息 是可以读写的
app.c中
* @brief BLE Connection complete event handler BLE连接完成事件处理程序
* @param[in] p Pointer point to event parameter buffer.
* @return
*/
int app_le_connection_complete_event_handle(u8 *p)
{
hci_le_connectionCompleteEvt_t *pConnEvt = (hci_le_connectionCompleteEvt_t *)p;
my_connHandle = pConnEvt->connHandle; 这里我获取了句柄
......
}
// 新建设据发送函数
void send_data_to_target(u16 connHandle, u8 data) {
dev_char_info_t* dev_info = dev_char_info_search_by_connhandle(connHandle);
if (dev_info && dev_info->char_handle[10] != 0) {
u8 value = data;
// 使用 Write Without Response (属性支持)
gpio_write(LED_PIN, 1); // 连接时亮
blc_gatt_pushWriteCommand(connHandle, dev_info->char_handle[10], &value, 1);
}
// ble_sts_t status = ble_gatt_pushReadByTyRequest()
}目前就是 连接时没有问题 就是或者句柄特征的存储 和获取有疑问?不知道到底要修改那些地方? |
-
|