如何修改主机SimpleBLECentral读取sensortag中的值?
我想知道SimpleBLECentral怎样修改能得到sensortag中的值,我是参考串口透传的程序修改的,但是可以使能notify,读不出值来!有实例我可以看一下吗?
我实在是看不出哪里错了?是回调程序错了吗?
/*********************************************************************
* @fn simpleBLECentralProcessGATTMsg
*
* @brief Process GATT messages
*
* @return none
*/
static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )
{
if ( simpleBLEState != BLE_STATE_CONNECTED )
{
// In case a GATT message came after a connection has dropped,
// ignore the message
return;
}
if ( ( pMsg->method == ATT_READ_RSP ) ||
( ( pMsg->method == ATT_ERROR_RSP ) &&
( pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ ) ) )
{
if ( pMsg->method == ATT_ERROR_RSP )
{
uint8 status = pMsg->msg.errorRsp.errCode;
LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 );
}
else
{
// After a successful read, display the read value
uint8 valueRead = pMsg->msg.readRsp.value[0];
LCD_WRITE_STRING_VALUE( "Read rsp:", valueRead, 10, HAL_LCD_LINE_1 );
}
simpleBLEProcedureInProgress = FALSE;
}
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 == 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;
}
else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
{
simpleBLEGATTDiscoveryEvent( pMsg );
}
/*else if ( pMsg->method == ATT_HANDLE_VALUE_NOTI ||pMsg->method == ATT_HANDLE_VALUE_IND )
{
uint8 dataCount=0;
attHandleValueNoti_t noti;
dataCount = dataCount+ 1;
LCD_WRITE_STRING_VALUE( "Data Cnt: ", dataCount, 10, HAL_LCD_LINE_1 );
noti.handle = pMsg->msg.handleValueNoti.handle;
noti.len = pMsg->msg.handleValueNoti.len;
osal_memcpy(¬i.value, &pMsg->msg.handleValueNoti.value,noti.len);
//用户可在这里操作¬i,通过串口发送或者USB发送出去等等
NPI_WriteTransport(&pMsg->msg.handleValueNoti.value [1] , 4 );
}*/
else if ( pMsg->method == ATT_HANDLE_VALUE_NOTI )
{//CHAR7 的通知 串口打印
if( pMsg->msg.handleValueNoti.handle == irTempDataHdl )
{
attHandleValueNoti_t noti;
osal_memcpy(¬i.value,&pMsg->msg.handleValueNoti.value, pMsg->msg.handleValueNoti.len);
NPI_WriteTransport(&pMsg->msg.handleValueNoti.value [0] , 12 );
}
}
/*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 );
NPI_WriteTransport("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(¬i.value, &pMsg->msg.handleValueNoti.value,noti.len);
NPI_WriteTransport("Read rsp2:\r\n",11);
}
}*/
}
/
/*********************************************************************
* @fn simpleBLECentralEventCB
*
* @brief Central event callback function.
*
* @param pEvent - pointer to event structure
*
* @return none
*/
case GAP_LINK_PARAM_UPDATE_EVENT:
{
attWriteReq_t req;
uint8 ValueBuf[2] ;
uint8 status=1;
LCD_WRITE_STRING( "Param Update", HAL_LCD_LINE_1 );
req.handle = irTempDataHdl+1;//0x0026 ;//
req.len = 2;
req.sig = 0;
req.cmd = 1;
req.value[0]=0x01;
req.value[1]=0x00;
status = GATT_WriteNoRsp( simpleBLEConnHandle, &req);
if ( status == SUCCESS )
{
GAPBondMgr_UpdateCharCfg( simpleBLEConnHandle, req.handle, GATT_CLIENT_CFG_NOTIFY );
NPI_WriteTransport("write ok\r\n", 10);
simpleBLEProcedureInProgress = TRUE;
//simpleBLEDoWrite = !simpleBLEDoWrite;
}
// ValueBuf[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);//0x01;
//ValueBuf[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY); //0x00;
//osal_memcpy(req.value,ValueBuf,2);
//GATT_WriteCharValue( 0, &req, simpleBLETaskId );
// GATT_WriteCharValue( simpleBLEConnHandle, &req,simpleBLETaskId );
// GATT_WriteNoRsp( simpleBLEConnHandle, &req);
/*if ( GATT_WriteNoRsp( simpleBLEConnHandle, &req) == SUCCESS )
{
GAPBondMgr_UpdateCharCfg( simpleBLEConnHandle, req.handle, GATT_CLIENT_CFG_NOTIFY );
NPI_WriteTransport("Enable Notice\n", 14 );
simpleBLEProcedureInProgress = TRUE;
simpleBLEDoWrite = !simpleBLEDoWrite;
}*/
NPI_WriteTransport("Enable Notice\n", 14 );
}
break;
default:
break;
}
}
/*********************************************************************
* @fn simpleBLECentralStartDiscovery
*
* @brief Start service discovery.
*
* @return none
*/
static void simpleBLECentralStartDiscovery( void )
{
// uint8 uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(SIMPLEPROFILE_SERV_UUID),
// HI_UINT16(SIMPLEPROFILE_SERV_UUID) };
uint8 uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(0xAA00),
HI_UINT16(0xAA00) };
// Initialize cached handles
simpleBLESvcStartHdl = simpleBLESvcEndHdl = simpleBLECharHdl = 0;
simpleBLEDiscState = BLE_DISC_STATE_SVC;
// Discovery simple BLE service
GATT_DiscPrimaryServiceByUUID( simpleBLEConnHandle,
uuid,
ATT_BT_UUID_SIZE,
simpleBLETaskId );
}
/*********************************************************************
* @fn simpleBLEGATTDiscoveryEvent
*
* @brief Process GATT discovery event
*
* @return none
*/
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(IRTEMPERATURE_DATA_UUID);
req.type.uuid[1] = HI_UINT16(IRTEMPERATURE_DATA_UUID);
// GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
GATT_DiscCharsByUUID( 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 )
{
irTempDataHdl = 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;
}
}
这是什么问题,贴了这么多根本没法看的代码。
