首先从机和主机的gattprofile.h文件中的 SIMPLEPROFILE_CHAR1_LEN均改为了5,但接受时只有第一个数据正确,请大佬指教!谢谢!!!
发送函数:
uint8 BLE_Send_Txt[5]={10,15,32,86,65}; static uint16 connect0_ProcessEvent( uint8 task_id, uint16 events ) { if ( events & START_READ_OR_WRITE_EVT ) { if( centralConnList[CONNECT0_ITEM].procedureInProgress == FALSE ) { if( centralDoWrite ) { // Do a write attPrepareWriteReq_t req; req.handle = centralConnList[CONNECT0_ITEM].charHdl; req.len = SIMPLEPROFILE_CHAR1_LEN; req.pValue = GATT_bm_alloc(centralConnList[CONNECT0_ITEM].connHandle,ATT_WRITE_REQ,req.len,NULL,0); if ( req.pValue != NULL ) { *req.pValue = BLE_Send_Txt[0]; if( GATT_WriteLongCharValue(centralConnList[CONNECT0_ITEM].connHandle,&req,centralTaskId) == SUCCESS ) { centralConnList[CONNECT0_ITEM].procedureInProgress = TRUE; centralDoWrite = !centralDoWrite; tmos_start_task( centralConnList[CONNECT0_ITEM].taskID, START_READ_OR_WRITE_EVT, DEFAULT_READ_OR_WRITE_DELAY); } else { GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ); } } }
接收方是这样的
uint8 txt[SIMPLEPROFILE_CHAR1_LEN]; static void simpleProfileChangeCB( uint8 paramID, uint8 *pValue, uint16 len ) { switch( paramID ) { case SIMPLEPROFILE_CHAR1: { tmos_memcpy( txt, pValue, len ); PRINT("profile ChangeCB CHAR1.. \n"); break; } case SIMPLEPROFILE_CHAR3: { tmos_memcpy( txt, pValue, len ); PRINT("profile ChangeCB CHAR3..\n"); break; } default: // should not reach here! break; } }
但调试结果是这样的: