Quantcast
Channel: 蓝牙论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 7485

修改SimpleBLECentral的代码去连接notify的心率计的问题

$
0
0

TI技术你们好,我最近在想用cc2540主机模式去连接一个心率计并且读出其数据。

在SimpleBLECentral源代码基础之上进行修改,

步骤如下:

1、首先添加接收notify消息的回调

else if ( ( pMsg->method == ATT_HANDLE_VALUE_NOTI)||
( pMsg->method == ATT_ERROR_RSP ) ||
(pMsg->method == ATT_HANDLE_VALUE_IND) )

{

attHandleValueNoti_t noti;



if ( pMsg->method == ATT_ERROR_RSP )
{
uint8 status = pMsg->msg.errorRsp.errCode;

LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 );
sbpSerialAppWrite("Read Error\r\n",12);
}
else
{
// After a successful read, display the read value
//uint8 valueRead = pMsg->msg.readRsp.value[0];
noti.handle = pMsg->msg.handleValueNoti.handle;
noti.len = pMsg->msg.handleValueNoti.len;
osal_memcpy(&noti.value, &pMsg->msg.handleValueNoti.value,noti.len);

sbpSerialAppWrite("Read rsp2:\r\n",11);

}

}

2、将所有用到uuid的地方修改为心率计的uuid

#define Heartrate_UUID 0x180d
#define Heartrate_UUID_char 0x2a37

// if ( simpleBLEFindSvcUuid( SIMPLEPROFILE_SERV_UUID,

// pEvent->deviceInfo.pEvtData,
// pEvent->deviceInfo.dataLen ) )
if ( simpleBLEFindSvcUuid( Heartrate_UUID,
pEvent->deviceInfo.pEvtData,
pEvent->deviceInfo.dataLen ) )

//uint8 uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(SIMPLEPROFILE_SERV_UUID),
// HI_UINT16(SIMPLEPROFILE_SERV_UUID) };
uint8 uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(Heartrate_UUID),
HI_UINT16(Heartrate_UUID) };

//req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
//req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);

req.type.uuid[0] = LO_UINT16(Heartrate_UUID_char);
req.type.uuid[1] = HI_UINT16(Heartrate_UUID_char);

3、这样修改完了之后,central设备能够发现心率计设备,但是确不能正确发现句柄,跟踪之后发现是在此处不能正确产生simpleBLEConnHandle句柄。

GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );

将此函数改为(此两个函数在功能上都能产生字符巨柄)

GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId );

能够产生正常的句柄,并且进入 正确的ATT_READ_BY_TYPE_RSP消息回调。

4、如上修改之后,也是不能正确地进行从机notify的数据接收,查询资料发现,还需要主动去修改从机的skconfig值。

在发现从机字符巨柄之后,使用如下代码去修改从机skconfig的值。

attWriteReq_t req;
req.handle = simpleBLECharHdl+1;
req.len = 2;
req.value[0] = 0x01;
req.value[1] = 0x00;
req.sig = 0;
req.cmd = 0;

status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );

status 返回成功,随后携带msg数据进入

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;

请问以上步骤是否是写从机skconfig的时候出现错误了?如果是,应该如何去修正?


Viewing all articles
Browse latest Browse all 7485

Trending Articles