Part Number: CC2640R2F
Hello,
I am trying to enable notifications from my simple_central based program but I am having some issues. I have read many posts about it and see that it consists of three modifications:
1. Call GATT_DiscAllCharDescs to get handle of CCCD
2. Write 0x01 to CCCD handle to enable notification
3. Add ATT_HANDLE_VALUE_NOTI to event handler in main loop
I am trying to add the first part but it always returns 0x016 (blePending error). Below is my discovery function which I have modified to handle 128 bit uuids:
static void SimpleCentral_processGATTDiscEvent(gattMsgEvent_t *pMsg)
{
if (discState == BLE_DISC_STATE_MTU)
{
// MTU size response received, discover simple service
if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
{
uint8_t uuid[ATT_UUID_SIZE] = {FANGRECEIVER_SERV_UUID};
// Just in case we're using the default MTU size (23 octets)
sprintf(displayBuff, "MTU Size: %d", ATT_MTU_SIZE);
queueDisplayString(displayBuff);
discState = BLE_DISC_STATE_SVC;
// Discovery simple service
VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_UUID_SIZE,
selfEntity);
}
}
else if (discState == BLE_DISC_STATE_SVC)
{
// Service found, store handles
if (pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo > 0)
{
svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
}
// If procedure complete
if (((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) &&
(pMsg->hdr.status == bleProcedureComplete)) ||
(pMsg->method == ATT_ERROR_RSP))
{
if (svcStartHdl != 0)
{
discState = BLE_DISC_STATE_CHAR;
//Discover All Characteristics
status = GATT_DiscAllChars(connHandle, svcStartHdl, svcEndHdl, selfEntity);
sprintf(displayBuff, "Disconnections: %d", disconnections);
queueDisplayString(displayBuff);
}
}
}
else if (discState == BLE_DISC_STATE_CHAR)
{
// Characteristic found, store handle
if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&
(pMsg->msg.readByTypeRsp.numPairs > 0))
{
uint16_t len = pMsg->msg.readByTypeRsp.len;
uint8_t i;
uint8_t j;
uint8_t k = 0;
uint8_t uuidChar[ATT_UUID_SIZE]= {0};
uint8_t uuidChar1[ATT_UUID_SIZE] = {FANGRECEIVER_CHAR1_UUID};
uint8_t uuidChar2[ATT_UUID_SIZE] = {FANGRECEIVER_CHAR2_UUID};
uint8_t uuidChar3[ATT_UUID_SIZE] = {FANGRECEIVER_CHAR3_UUID};
// uint8_t uuidChar4[ATT_UUID_SIZE] = {FANGRECEIVER_CHAR4_UUID};
for(i=0; pMsg->msg.readByTypeRsp.numPairs > i; i++)
{
if(i==0)
memcpy(uuidChar, uuidChar1, 17);
if(i==1)
memcpy(uuidChar, uuidChar2, 17);
if(i==2)
memcpy(uuidChar, uuidChar3, 17);
// if(i==3)
// memcpy(uuidChar, uuidChar4, 17);
//check out uuid of char:
for(j=0; j<=16; j++)
{
//start at 5 and go to 20 plus offset (i*len)
if(pMsg->msg.readByTypeRsp.pDataList[(5+j)+(i*len)] == uuidChar[j])
k++;
}
if(k==16)
{
if(i==0)
char1Hdl = pMsg->msg.readByTypeRsp.pDataList[3+(len*i)];
if(i==1)
char2Hdl = pMsg->msg.readByTypeRsp.pDataList[3+(len*i)];
if(i==2)
char3Hdl = pMsg->msg.readByTypeRsp.pDataList[3+(len*i)];
// if(i==3)
// char4Hdl = pMsg->msg.readByTypeRsp.pDataList[3+(len*i)];
}
k=0;
}
if(!char1Hdl||!char2Hdl||!char3Hdl)
queueDisplayString("Char Dsc Error");
queueDisplayString("Simple Svc Found");
//Discover all characteristic descriptors
//status = GATT_DiscAllCharDescs(connHandle, svcStartHdl, svcEndHdl, selfEntity);
procedureInProgress = FALSE;
}
discState = BLE_DISC_STATE_IDLE;
}
}
Any guidance on where I should be calling the GATT_DiscAllCharDescs so I don't get a blePending error would be greatly appreciated.
Thanks!