可以通过下面调用服务调用的方式在调用调用后调用:
结果 = GATT_DiscAllChars(centralConnHandle,centralSvcStartHdl,centralSvcEndHdl,centralTaskId);
静态无效中央GATTDiscoveryEvent(gattMsgEvent_t *pMsg){
uint8_t 结果;
PRINT("centralGATTDiscoveryEventrn");
开关(ble_db_dis_state){
案例 BLE_DISC_STATE_SVC:
// 找到服务,存储句柄
如果(pMsg->方法== ATT_FIND_BY_TYPE_VALUE_RSP){
if( pMsg->msg.findByTypeValueRsp.numInfo > 0 ){
centralSvcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
centralSvcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
// 显示 Profile Service 句柄范围
PRINT("找到配置文件服务句柄 : %x ~ %x n",centralSvcStartHdl,centralSvcEndHdl);
}
if( ( pMsg->hdr.status == bleProcedureComplete )||( pMsg->method == ATT_ERROR_RSP ) ){
如果(中央SvcStartHdl!= 0){
//central_db_dis_change_state(BLE_DISC_STATE_CHAR);
结果 = GATT_DiscAllChars(centralConnHandle,centralSvcStartHdl,centralSvcEndHdl,centralTaskId);
PRINT("GATT_DiscAllChars:%02xrn",result);
}
}
}
休息;
案例 BLE_DISC_STATE_CHAR:
// 找到特征,存储句柄
如果(pMsg->方法== ATT_READ_BY_TYPE_RSP){
如果(pMsg->msg.readByTypeRsp.numPairs > 0){
//centralCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.pDataList[0],
// pMsg->msg.readByTypeRsp.pDataList[1] );
//PRINT("找到特征 1 句柄:%x n",centralCharHdl);
// 遍历找到的所有三对。
for(unsigned char i = 0; i < pMsg->msg.readByTypeRsp.numPairs ; i++){
#如果为0
//特征属性
uint8_t char_properties = pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i + 2];
#万一
uint16_t char_value_handle = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i+3],
pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i + 4]);
//特征uuid长度
uint8_t char_uuid_length = pMsg->msg.readByGrpTypeRsp.len - 5;
//uuid
uint8_t *chat_uuid = &(pMsg->msg.readByGrpTypeRsp.pDataList[pMsg->msg.readByGrpTypeRsp.len * i + 5]);
if(sizeof(write_uuid) == char_uuid_length){
如果(tmos_memcmp(write_uuid,chat_uuid,char_uuid_length)){
PRINT("找到write_uuid,句柄:%02xrn",char_value_handle);
}否则如果(tmos_memcmp(notify_uuid,chat_uuid,char_uuid_length)){
PRINT("通知 uuid 找到,句柄:%02xrn",char_value_handle);
}
}
}
}
if((pMsg->hdr.status == bleProcedureComplete) || (pMsg->method == ATT_ERROR_RSP)){
central_db_dis_change_state(BLE_DISC_STATE_CCCD);
PRINT("BLE_DISC_STATE_CHAR 完成rn");
}
}
休息;
案例 BLE_DISC_STATE_CCCD:
如果(pMsg->方法== ATT_READ_BY_TYPE_RSP){
如果(pMsg->msg.readByTypeRsp.numPairs > 0){
centralCCCDHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
pMsg->msg.readByTypeRsp.pDataList[1] );
PRINT("找到客户端特征配置句柄:%x n",centralCCCCDHdl);
central_enbale_notify(centralConnHandle,centralCCCCDHdl);
}
//centralDiscState = BLE_DISC_STATE_IDLE;
ble_db_dis_state = BLE_DISC_STATE_IDLE;
}
休息;
默认:
休息;
}
}
可以通过下面调用服务调用的方式在调用调用后调用:
结果 = GATT_DiscAllChars(centralConnHandle,centralSvcStartHdl,centralSvcEndHdl,centralTaskId);
静态无效中央GATTDiscoveryEvent(gattMsgEvent_t *pMsg){
uint8_t 结果;
PRINT("centralGATTDiscoveryEventrn");
开关(ble_db_dis_state){
案例 BLE_DISC_STATE_SVC:
// 找到服务,存储句柄
如果(pMsg->方法== ATT_FIND_BY_TYPE_VALUE_RSP){
if( pMsg->msg.findByTypeValueRsp.numInfo > 0 ){
centralSvcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
centralSvcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
// 显示 Profile Service 句柄范围
PRINT("找到配置文件服务句柄 : %x ~ %x n",centralSvcStartHdl,centralSvcEndHdl);
}
if( ( pMsg->hdr.status == bleProcedureComplete )||( pMsg->method == ATT_ERROR_RSP ) ){
如果(中央SvcStartHdl!= 0){
//central_db_dis_change_state(BLE_DISC_STATE_CHAR);
结果 = GATT_DiscAllChars(centralConnHandle,centralSvcStartHdl,centralSvcEndHdl,centralTaskId);
PRINT("GATT_DiscAllChars:%02xrn",result);
}
}
}
休息;
案例 BLE_DISC_STATE_CHAR:
// 找到特征,存储句柄
如果(pMsg->方法== ATT_READ_BY_TYPE_RSP){
如果(pMsg->msg.readByTypeRsp.numPairs > 0){
//centralCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.pDataList[0],
// pMsg->msg.readByTypeRsp.pDataList[1] );
//PRINT("找到特征 1 句柄:%x n",centralCharHdl);
// 遍历找到的所有三对。
for(unsigned char i = 0; i < pMsg->msg.readByTypeRsp.numPairs ; i++){
#如果为0
//特征属性
uint8_t char_properties = pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i + 2];
#万一
uint16_t char_value_handle = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i+3],
pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len * i + 4]);
//特征uuid长度
uint8_t char_uuid_length = pMsg->msg.readByGrpTypeRsp.len - 5;
//uuid
uint8_t *chat_uuid = &(pMsg->msg.readByGrpTypeRsp.pDataList[pMsg->msg.readByGrpTypeRsp.len * i + 5]);
if(sizeof(write_uuid) == char_uuid_length){
如果(tmos_memcmp(write_uuid,chat_uuid,char_uuid_length)){
PRINT("找到write_uuid,句柄:%02xrn",char_value_handle);
}否则如果(tmos_memcmp(notify_uuid,chat_uuid,char_uuid_length)){
PRINT("通知 uuid 找到,句柄:%02xrn",char_value_handle);
}
}
}
}
if((pMsg->hdr.status == bleProcedureComplete) || (pMsg->method == ATT_ERROR_RSP)){
central_db_dis_change_state(BLE_DISC_STATE_CCCD);
PRINT("BLE_DISC_STATE_CHAR 完成rn");
}
}
休息;
案例 BLE_DISC_STATE_CCCD:
如果(pMsg->方法== ATT_READ_BY_TYPE_RSP){
如果(pMsg->msg.readByTypeRsp.numPairs > 0){
centralCCCDHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
pMsg->msg.readByTypeRsp.pDataList[1] );
PRINT("找到客户端特征配置句柄:%x n",centralCCCCDHdl);
central_enbale_notify(centralConnHandle,centralCCCCDHdl);
}
//centralDiscState = BLE_DISC_STATE_IDLE;
ble_db_dis_state = BLE_DISC_STATE_IDLE;
}
休息;
默认:
休息;
}
}
举报