主机用GATT_WriteCharValue向从机发送数据
我使用GATT_WriteCharValue( uint16 connHandle, attWriteReq_t *pReq, uint8 taskId )向从机发送数据,主机这边返回的是ATT_ERROR_RSP(
If the return status from this function is SUCCESS, the calling application task will receive an OSAL GATT_MSG_EVENT message. The type of the message will be either ATT_WRITE_RSP or ATT_ERROR_RSP (if an error occurred on the server)
),从机那边没有调用simpleProfile_WriteAttrCB。用手机向从机Write能接收到数据。请问这是什么原因?谢谢!
shengzhang,
你的GATT_WriteCharValue的参数是怎么填的呢?特别是attWriteReq_t 结构里面的内容。
谢谢您的回答!
我是这样写的:
vdid CentralSendToPeripheral(uint16 ConnHandle, uint16 handle, uint8*p, uint8 len )
{
arrWriteReq_t req;
req.handle = handle;
req.len = len;
req.sig = 0;
req.cmd = 0;
osal_memcpy(req.val, p, len);
(void)GATT_WriteCharValue(ConnHandle,&req,serial_TaskID);
}
请问这有什么问题?
下面的例子是获取CHAR1的handle的,请问我要获取CHAR2的handle应该怎么改?我更改req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR2_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR2_UUID);后为什么获取不了?请问还有什么地方需要更改的?谢谢!
static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
{
attReadByTypeReq_t req;
if ( simpleBLEDiscState == BLE_DISC_STATE_SVC )
{
// Service found, store handles
if ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo > 0 )
{
simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
}
// If procedure complete
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->hdr.status == bleProcedureComplete ) ||
( pMsg->method == ATT_ERROR_RSP ) )
{
if ( simpleBLESvcStartHdl != 0 )
{
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;
req.startHandle = simpleBLESvcStartHdl;
req.endHandle = simpleBLESvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);
GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
}
}
}
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
{
// Characteristic found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
pMsg->msg.readByTypeRsp.dataList[1] );
LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;
}
simpleBLEDiscState = BLE_DISC_STATE_IDLE;
}
}