ti技术你们好,我最近在想用cc2541主机模式去连接从机并且读出其数据。
在SimpleBLECentral源代码基础之上进行修改,
发现uuid 服务
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_CHAR7;
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_CHAR7_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR7_UUID);
GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
// 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;
// osal_start_timerEx( simpleBLETaskId, GUA_READ_CHAR1_EVT, 1000 );
]
在这里找到对应的特征值句柄了 0x0037
之后在按键添加开启notify功能
if ( keys & HAL_KEY_SW_6 )
[
attWriteReq_t req;
req.handle = 0x0038; //char6的CCC的特征值句柄,这里写死可通过btool获取到
req.len = 2;
req.value[0] = 0x01;//LO_UINT16(GATT_CLIENT_CFG_NOTIFY); //0x0001为开notify
req.value[1] = 0x00;//HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
req.sig = 0;
req.cmd = 0;
//osal_memcpy(req.value,ValueBuf,2);
GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
最后显示
static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )处理函数
else if ( ( pMsg->method == ATT_WRITE_RSP ) ||
( ( pMsg->method == ATT_ERROR_RSP ) &&
( pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ ) ) )
[
if ( pMsg->method == ATT_ERROR_RSP)
[
uint8 status = pMsg->msg.errorRsp.errCode;
LCD_WRITE_STRING_VALUE( "Write Error", status, 10, HAL_LCD_LINE_1 );
]
else
[
// After a succesful write, display the value that was written and increment value
LCD_WRITE_STRING_VALUE( "Write sent:", simpleBLECharVal++, 10, HAL_LCD_LINE_1 );
]
simpleBLEProcedureInProgress = FALSE;
]
进入此函数之后返回
Write Error 3;
这里是设置错误了吗?请大神帮忙看看