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;
}
}
我使用的是 CC2650 launchpad
BLE SDK BLE_SDK_2_02_07_06
简单 BLE 外设示例按照进行了修改
这个线程。
我使用 malloc 和 realloc 来附加从 BLE 器件接收到的数据。
我已附上修改后的代码、
首先,我成功获得200个字节,然后我再次尝试下一个200个字节的数据包-它失败了。
如果我注释 malloc 和 realloc 修改后的代码、我将每包接收200个字节的数据。
(我想从另一个 BLE 接收 CC2650中的图像)