Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: CC2650
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t len,
uint16_t offset, uint8_t method)
{
bStatus_t status = SUCCESS;
uint8 notifyApp = 0xFF;
if (pAttr->type.len == ATT_BT_UUID_SIZE)
{
// 16-bit UUID
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch (uuid)
{
case SIMPLEPROFILE_CHAR1_UUID:
case SIMPLEPROFILE_CHAR3_UUID:
//Validate the value
// Make sure it's not a blob oper
if (offset == 0)
{
if (len != 1)
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
//Write the value
if (status == SUCCESS)
{
uint8 *pCurValue = (uint8 *) pAttr->pValue;
*pCurValue = pValue[0];
if (pAttr->pValue == &simpleProfileChar1)
{
notifyApp = SIMPLEPROFILE_CHAR1;
}
else
{
notifyApp = SIMPLEPROFILE_CHAR3;
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID:
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue,
len, offset,
GATT_CLIENT_CFG_NOTIFY);
break;
case SIMPLEPROFILE_CHAR5_UUID:
//Validate the value
// Make sure it's not a blob oper
if (offset == 0)
{
if (len > SIMPLEPROFILE_CHAR5_LEN)
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
//Write the value
if (status == SUCCESS)
{
uint8 *pCurValue = (uint8 *) pAttr->pValue; //-------------------------------------------------------------------------------
memcpy(pCurValue, pValue, len); //--------------------------------------//here i get the correct length of received data bytes - put breakpoint here to see
//my code starts here
test_len = len;
if (round_number == 0)
{
if (test_len > 0)
{
ptr = (uint8*) malloc(test_len);
if (ptr == NULL)
{
// printf("Error! memory not allocated.");
exit(0);
}
for (uint8 i = 0; i < test_len; ++i)
{
ptr[i] = simpleProfileChar5[i];
}
prev_len = test_len;
}
}
else if (round_number > 0)
{
new_len = prev_len + test_len;
ptr = realloc(ptr, new_len); //allocated new memory size
if (ptr == NULL)
{
// printf("Error! memory not allocated.");
exit(0);
}
else
{
int j = 0;
for (int i = prev_len; i <= new_len; i++)
{
ptr[i] = simpleProfileChar5[j];
j++;
}
prev_len = new_len;
}
}
//my code ends here
// free(ptr);
// round_number++;
if (pAttr->pValue == &simpleProfileChar5) //-- org 1
{
notifyApp = SIMPLEPROFILE_CHAR5;
} //-- org 1
// EPD_2IN66_Display(simpleProfileChar5); // this function call writes received data array from android bluetooth to epd display
}
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
}
I am using CC2650 lauchpad
ble sdk ble_sdk_2_02_07_06
Simple BLE peripheral Example is modified as per
this thread.
I am using malloc and realloc to append data received from BLE device.
I have attached my modified code ,
first I get 200 bytes Successfully then I again try for next packet of 200 bytes - - It fails.
If I comment malloc and realloc modified code I receive data 200 bytes per packet.
(I want to receive image in CC2650 from another BLE)