参考stack中的BloodPressure例子,注意几点:
1.从他的profile,bpservice.c,可以了解如何定义一个indicaiton.
2.bloodPressure_WriteAttrCB() 中如何enable indicaiton.
case GATT_CLIENT_CHAR_CFG_UUID:
if ( pAttr->handle == bloodPressureAttrTbl[BLOODPRESSURE_MEAS_CONFIG_POS].handle )
{
// BloodPressure Indications
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
offset, GATT_CLIENT_CFG_INDICATE );
if ( status == SUCCESS )
{
uint16 value = BUILD_UINT16( pValue[0], pValue[1] );
(*bloodPressureServiceCB)( (value == GATT_CFG_NO_OPERATION) ?
BLOODPRESSURE_MEAS_NOTI_DISABLED :
BLOODPRESSURE_MEAS_NOTI_ENABLED);
}
}
3. 如何使用indcation发送数据
bStatus_t BloodPressure_MeasIndicate( uint16 connHandle, attHandleValueInd_t *pNoti,uint8 taskId )
{
uint16 value = GATTServApp_ReadCharCfg( connHandle, bloodPressureMeasConfig );
// If indications enabled
if ( value & GATT_CLIENT_CFG_INDICATE )
{
// Set the handle
pNoti->handle = bloodPressureAttrTbl[BLOODPRESSURE_MEAS_VALUE_POS].handle;
// Send the Indication
return GATT_Indication( connHandle, pNoti, FALSE, taskId );
}
return bleIncorrectMode;
}
4. 如何获得indicaiton的confirm
static void bloodPressureProcessGattMsg( gattMsgEvent_t *pMsg )
{
//Measurement Indication Confirmation
if( pMsg->method == ATT_HANDLE_VALUE_CFM)
{
bpSendStoredMeas();
}
if ( pMsg->method == ATT_HANDLE_VALUE_NOTI ||
pMsg->method == ATT_HANDLE_VALUE_IND )
{
timeAppIndGattMsg( pMsg );
}
else if ( pMsg->method == ATT_READ_RSP ||
pMsg->method == ATT_WRITE_RSP )
{
timeAppConfigState = timeAppConfigGattMsg ( timeAppConfigState, pMsg );
if ( timeAppConfigState == TIMEAPP_CONFIG_CMPL )
{
timeAppDiscoveryCmpl = TRUE;
}
}
else
{
timeAppDiscState = timeAppDiscGattMsg( timeAppDiscState, pMsg );
if ( timeAppDiscState == DISC_IDLE )
{
// Start characteristic configuration
timeAppConfigState = timeAppConfigNext( TIMEAPP_CONFIG_START );
}
}
}
联系客服