关于attHandleValueNoti_t pReport结构体填充的问题
时间:10-02
整理:3721RD
点击:
attHandleValueNoti_t pReport;
pReport.handle=0x2e;
pReport.len = 1 ;
pReport.value[0]='f';
GATT_Notification(0, &pReport, FALSE );
上面函数中,为什么pReport.handle要等于0x2e?还有GATT_Notification(0, &pReport, FALSE )中第一个参数为什么是0?求解!
这个handle的值也是我在纠结的问题,如果楼主知道了请不吝回复。
GATT_Notification的第一个参数是connHandle,也就是蓝牙连接的handle,因为比如BLEcentral的话可以连接多个Periphral,所以可能连接数不止一个。0的话就是第一个连接了。具体的handle如何确定请看http://www.deyisupport.com/question_answer/wireless_connectivity/f/45/t/23478.aspx
dengchenguang,
能说明一下是在哪个工程里的代码吗?我记得TI提供的标准协议栈里面应该没有这些代码。
这个handle是特征值attribute在系统中被指定的句柄值。在cc254x代码中由服务注册的时候底层系统自动分配的。像这样在代码里面直接十六进制写出来,一般都是之前代码做过测试,通过远端,比如BTool通过服务查找功能知道句柄后,然后在代码里写死来完成一些特定功能吧。
是淘宝卖家ghostyu的代码,代码如附件所示,截图如下:
uint8 len;
if(length > 20)
len = 20;
else
len = length;
static attHandleValueNoti_t pReport;
pReport.handle=0x2e;//char4
pReport.len = len;
osal_memcpy(pReport.value, pBuffer, len);
GATT_Notification( 0, &pReport, FALSE );
下面是simpleGATTprofile.c里的代码,我也不明白
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint8 len, uint16 offset )
{
bStatus_t status = SUCCESS;
uint8 notifyApp = 0xFF;
// If attribute permissions require authorization to write, return error
if ( gattPermitAuthorWrite( pAttr->permissions ) )
{
// Insufficient authorization
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
}
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 )
{
//对方(Central)用串口发送数据个数的随意的(暂时人为约定小于等于20 SIMPLEPROFILE_CHAR1_LEN)//若>20就任务错了,因为我的attribute table中的buffer只有 SIMPLEPROFILE_CHAR1_LEN 大//(也可以不用判断,我只接收20个一次)//还可以在Central端发送的时候判断下,多于20个就不发并且提示错误 这样比发过来接收了不处理更好//还可以在Central端把多于20字节的情况分多次发送 暂时不考虑这种情况if ( len > SIMPLEPROFILE_CHAR1_LEN ) //len 等于多少是由谁决定的 ,是simpleProfileAttrTbl之characteristic 1之Characteristic Value长度决定的 (错){ //为什么不是其他 characteristic (错) status = ATT_ERR_INVALID_VALUE_SIZE;}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
//Write the value
if ( status == SUCCESS )
{
uint8 *pCurValue = (uint8 *)pAttr->pValue;
osal_memset(pCurValue,0,SIMPLEPROFILE_CHAR1_LEN);//将开辟的内存全部设置为0
//osal_memcpy(void * dst,const void GENERIC * src,unsigned int len)
//VOID osal_memcpy( pCurValue, pValue, SIMPLEPROFILE_CHAR1_LEN );
VOID osal_memcpy( pCurValue, pValue, len ); //再看下
//这个len在本文件的其他函数也能用到比如GetParameter
//在本函数的最后回调函数也能用到,虽不能传参数,但是可用全局变量
//但是由于len长度不会太长,所以就用最大值 SIMPLEPROFILE_CHAR1_LEN 也可以
if( pAttr->pValue == simpleProfileChar1 ) //等于simpleProfileChar1是由谁决定的
//simpleProfileAttrTbl之characteristic 1之Characteristic Value决定的
//(为什么不是其他characteristic 2、3、4、5,怎样才能用上这些characteristic)
//在这里是数组名 simpleProfileChar1
{
notifyApp = SIMPLEPROFILE_CHAR1; //除了char1和char3还有其他的吧,特别是char5
SPChar1_datalen = len;
}
else
{
notifyApp = SIMPLEPROFILE_CHAR3;
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID: //干什么用的? 能否被执行到 ?
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
offset, GATT_CLIENT_CFG_NOTIFY );
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
}
else
{
// 128-bit UUID
status = ATT_ERR_INVALID_HANDLE;
}
// If a charactersitic value changed then callback function to notify application of change
if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
{
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp ); //调用回调函数 simpleProfileChangeCB()
}
return ( status );
}
