终于找到原因了,主要是因为这个函数去处理了两个服务事件
void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
ble_nus_c_evt_t nus_c_evt;
memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));
ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE )
{
if(
p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE2 &&
p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type)
{
uint32_t i;
for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
{
switch (p_chars[i].characteristic.uuid.uuid)
{
// case BLE_UUID_NUS_TX_CHARACTERISTIC2:
// //printf("tx");
// nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
// break;
case BLE_UUID_NUS_RX_CHARACTERISTIC2:
//printf("RX\n");
nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
break;
default:
break;
}
}
if (p_ble_nus_c->evt_handler != NULL)
{
nus_c_evt.conn_handle = p_evt->conn_handle;
nus_c_evt.evt_type = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
}
}
else if (p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &&
p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type)
{
uint32_t i;
for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
{
switch (p_chars[i].characteristic.uuid.uuid)
{
case BLE_UUID_NUS_TX_CHARACTERISTIC:
//printf("tx");
nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
break;
// case BLE_UUID_NUS_RX_CHARACTERISTIC:
// //printf("RX\n");
// nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
// nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
// break;
default:
break;
}
}
if (p_ble_nus_c->evt_handler != NULL)
{
nus_c_evt.conn_handle = p_evt->conn_handle;
nus_c_evt.evt_type = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
}
}
}
}
把它改成处理一个服务事件就可以了。那么第二个服务的事件要怎么处理呢?这里毫无头绪