微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > 当特征值6发送一个20字节的包时,发生错误0x0A

当特征值6发送一个20字节的包时,发生错误0x0A

时间:10-02 整理:3721RD 点击:

当包字节数小于20时,没问题。

当是20字节时,发现不能进入语句

if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )

于是,我改成

if (( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )|| pMsg->method == ATT_ERROR_RSP)

if( pMsg->method == ATT_ERROR_RSP )
{
HalLcdWriteStringValueValue("opcode,handle",pMsg->msg.errorRsp.reqOpcode,16,pMsg->msg.errorRsp.handle,16,HAL_LCD_LINE_4);
HalLcdWriteStringValue("errCode",pMsg->msg.errorRsp.errCode,16,HAL_LCD_LINE_5);

}

果然是发生了错误

reqOpcode   0x08

handle     0x0035———————————正好是特征值6的句柄

errorCode   0x0A

#define ATT_ERR_ATTR_NOT_FOUND           0x0a //!< No attribute found within the given attribute handle range

在给定的attr句柄范围内没有找到attribute,为什么找不到?

if ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo > 0 )
{

HalLcdWriteStringValueValue("handlesInfo",pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle,16,pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle,16,HAL_LCD_LINE_5);

simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
}

handle范围:

simpleBLESvcStartHdl:0x0023

simpleBLESvcStartHdl:0xFFFF

这没什么问题啊,value长度改成19这个范围也是这么多;

TI的工程师能不能回复一个?

一直没人回复我

代码:

uint8 status;

// Do a read or write as long as no other read or write is in progress
if ( simpleBLEDoWrite )
{
//hc add
static uint8 simpleBLEWriteCharVal[20] = {80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99};
// Do a write
attWriteReq_t req;

req.handle = simpleBLECharHdl;
//req.handle = 0x0035;
HalLcdWriteStringValue("req.handle = ", req.handle, 16, HAL_LCD_LINE_3);
req.len = SIMPLEPROFILE_CHAR6_LEN;
for(i=0;i<req.len;i++)
{
req.value[i] = simpleBLEWriteCharVal[i];
}
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
}
else
{
// Do a read
attReadReq_t req;

req.handle = simpleBLECharHdl;
HalLcdWriteStringValue("req.handle = ", req.handle, 16, HAL_LCD_LINE_3);
status = GATT_ReadCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
}

if ( status == SUCCESS )
{
simpleBLEProcedureInProgress = TRUE;
simpleBLEDoWrite = !simpleBLEDoWrite;
HalLcdWriteString("r/w SUCCESS",HAL_LCD_LINE_3);
}
else
{
HalLcdWriteString("r/w error",HAL_LCD_LINE_3);
}

红色部分都不能打印。按键完全没反应。哪里有问题?

原因找到了,是因为没有发现特征值6的句柄。

改为req.handle = 0x0035;

能正常读写。

但是,为什么长度改为20,simpleBLEGATTDiscoveryEvent函数就找不到特征值6的句柄呢?

static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
{
attReadByTypeReq_t req_char6;

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 ) )
{
//GATT_DiscAllChars(simpleBLEConnHandle , simpleBLESvcStartHdl, simpleBLESvcEndHdl, simpleBLETaskId );
if ( simpleBLESvcStartHdl != 0 )
{
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;

req_char6.startHandle = simpleBLESvcStartHdl;
req_char6.endHandle = simpleBLESvcEndHdl;
req_char6.type.len = ATT_BT_UUID_SIZE;
req_char6.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR6_UUID);
req_char6.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR6_UUID);

//GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req_char6, simpleBLETaskId );//ATT_READ_BLOB_RSP消息
}
}
}
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_3 );
simpleBLEProcedureInProgress = FALSE;
}

simpleBLEDiscState = BLE_DISC_STATE_IDLE;
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top