cc2640的从机如何自动使能notify功能?

[复制链接]
4926|2
 楼主| skevil 发表于 2015-9-4 08:51 | 显示全部楼层 |阅读模式
我在CC2541上看到这样一段程序,猜它应该是使能notify功能的函数
  1. /*********************************************************************
  2. * @fn          simpleProfile_HandleConnStatusCB
  3. *
  4. * [url=home.php?mod=space&uid=247401]@brief[/url]       Simple Profile link status change handler function.
  5. *
  6. * @param       connHandle - connection handle
  7. * @param       changeType - type of change
  8. *
  9. * [url=home.php?mod=space&uid=266161]@return[/url]      none
  10. */
  11. static void testProfile_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
  12. {
  13.   // Make sure this is not loopback connection
  14.   if ( connHandle != LOOPBACK_CONNHANDLE )
  15.   {
  16.     // Reset Client Char Config if connection has dropped
  17.     if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
  18.          ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
  19.            ( !linkDB_Up( connHandle ) ) ) )
  20.     {
  21.       GATTServApp_InitCharCfg( connHandle, TestChar2Config );

  22.     }
  23.   }
  24. }


但是我应用到CC2640上则一直报错说
Error[Li005]: no definition for "linkDB_Register" [referenced from C:\ti\simplelink\ble_cc26xx_2_01_00_44423\Projects\ble\SimpleBLEPeripheral\CC26xx\IAR\Application\CC2640\FlashROM\Obj\testprofiles.o]
Error while running Linker

相应的头文件我已经包含进来了,不知道为何还会出错,如果各位大神知道cc2640从机如何自己使能notify功能的请告诉小弟呗,感激不尽啊
 楼主| skevil 发表于 2015-9-4 10:03 | 显示全部楼层
关于上面贴出的代码好像不是那么回事。。。。。。。有没有大神知道CC2640从机能够自己使能notify的咧?我尝试用了CC2541的主机去使能CC2640从机notify功能,但是没反应,以下是我发送使能notify的程序

  1. //此部分为获取句柄,用了GATT_DiscAllChars获取,句柄存放于simpleBLECharHdl[1]当中
  2. static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
  3. {
  4.         attReadByTypeReq_t req;
  5.   
  6.         if( simpleBLEDiscState == BLE_DISC_STATE_SVC )
  7.         {
  8.                 // Service found, store handles
  9.                 if(( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) && (pMsg->msg.findByTypeValueRsp.numInfo > 0))
  10.                 {
  11.                         simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
  12.                         simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
  13.                 }
  14.    
  15.                 // If procedure complete
  16.                 if(( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->hdr.status == bleProcedureComplete )||
  17.                         ( pMsg->method == ATT_ERROR_RSP ) )
  18.                 {
  19. //                        if ( simpleBLESvcStartHdl != 0 )
  20.                         {
  21.                                 simpleBLEDiscState = BLE_DISC_STATE_CHAR;
  22.                                 //req.startHandle = simpleBLESvcStartHdl;
  23.                                 //req.endHandle = simpleBLESvcEndHdl;
  24.                                 //req.type.len = ATT_BT_UUID_SIZE;
  25.                                 //req.type.uuid[0] = LO_UINT16(PROFILE_CHAR1_UUID);//通道1
  26.                                 //req.type.uuid[1] = HI_UINT16(PROFILE_CHAR1_UUID);
  27.                                 //GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
  28.                                 
  29.                                 GATT_DiscAllChars(simpleBLEConnHandle,simpleBLESvcStartHdl,simpleBLESvcEndHdl,simpleBLETaskId);
  30.                         }
  31.                 }
  32.         }
  33.         else if( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
  34.         {

  35.                 // Characteristic found, store handle
  36.                 if ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->msg.readByTypeRsp.numPairs > 0 )
  37.                 {
  38.                        
  39.                         //simpleBLECharHdl[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[2],pMsg->msg.readByTypeRsp.dataList[3]);
  40.                         
  41.                         simpleBLECharHdl[0] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[3],pMsg->msg.readByTypeRsp.dataList[4]);
  42.                         simpleBLECharHdl[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[7],pMsg->msg.readByTypeRsp.dataList[8]);
  43. //                        simpleBLEProcedureInProgress = FALSE;               
  44. //                        osal_set_event( simpleBLETaskId, CEN_DISCOVERY_OK_EVT);//发现完成事件OK
  45.                         osal_set_event( simpleBLETaskId, CEN_DATA_SEND_EVT );
  46.                         
  47.                         
  48.    
  49.                         
  50.                 }
  51.                 else
  52.                 {
  53.                         osal_start_timerEx( simpleBLETaskId, CEN_START_DISCOVERY_EVT, DEFAULT_SVC_DISCOVERY_DELAY );
  54.                 }
  55.                 simpleBLEDiscState = BLE_DISC_STATE_IDLE;
  56.         }
  57. }



  1. 这部分为发送notify使能消息到从机,
  2. static uint8 CentralConfig(void)
  3. {
  4.     attWriteReq_t writeReq;
  5.     uint8 state;
  6.    
  7.     writeReq.len = 2;
  8.     writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);
  9.     writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
  10.     writeReq.sig = 0;
  11.     writeReq.cmd = 0;
  12.     writeReq.handle = simpleBLECharHdl[1]+1;
  13.     state = GATT_WriteCharValue(simpleBLEConnHandle, &writeReq, simpleBLETaskId);
  14.     return(state);
  15. }


以下为主机的写回调函数
  1. static bStatus_t Test_WriteAttrCB(uint16_t connHandle,
  2.                                            gattAttribute_t *pAttr,
  3.                                            uint8_t *pValue, uint16_t len,
  4.                                            uint16_t offset, uint8_t method)
  5. {
  6.   bStatus_t status = SUCCESS;
  7.   uint8 notifyApp = 0xFF;
  8.   
  9.   // If attribute permissions require authorization to write, return error
  10.   if ( gattPermitAuthorWrite( pAttr->permissions ) )
  11.   {
  12.     // Insufficient authorization
  13.     return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  14.   }
  15.   
  16.   if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  17.   {
  18.     // 16-bit UUID
  19.     uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
  20.     switch ( uuid )
  21.     {
  22.       case TEST_CHAR1_UUID:
  23.         //Validate the value
  24.         // Make sure it's not a blob oper
  25.         if ( offset == 0 )
  26.         {
  27.           if ( len > TEST_CHAR1_LEN )
  28.           {
  29.             status = ATT_ERR_INVALID_VALUE_SIZE;
  30.           }
  31.         }
  32.         else
  33.         {
  34.           status = ATT_ERR_ATTR_NOT_LONG;
  35.         }
  36.         
  37.         //Write the value
  38.         if ( status == SUCCESS )
  39.         {
  40.           //VOID osal_memcpy(pAttr->pValue, pValue, len);   
  41.           for(char i=0;i<len;i++)
  42.             pAttr->pValue[i]=pValue[i];
  43.          
  44.           notifyApp = TEST_CHAR1;
  45.         }
  46.         break;
  47.       //使能notify处理函数
  48.       case GATT_CLIENT_CHAR_CFG_UUID:
  49.    
  50.         status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
  51.                                                  offset, GATT_CLIENT_CFG_NOTIFY );
  52.         break;
  53.         
  54.       default:
  55.         // Should never get here! (characteristics 2 and 4 do not have write permissions)
  56.         status = ATT_ERR_ATTR_NOT_FOUND;
  57.         break;
  58.     }
  59.   }
  60.   else
  61.   {
  62.     // 128-bit UUID
  63.     status = ATT_ERR_INVALID_HANDLE;
  64.   }

  65.   // If a characteristic value changed then callback function to notify application of change
  66.   if ( (notifyApp != 0xFF ) && Test_AppCBs && Test_AppCBs->pfnTestChange )
  67.   {
  68.     Test_AppCBs->pfnTestChange( notifyApp);  
  69.   }
  70.   
  71.   return ( status );
  72. }

我设了断电,但是主机发送使能notify后,无法跳进GATT_CLIENT_CHAR_CFG_UUID中,我用手机使能从机notify则可以跳转进去,求救。。。。
cemaj 发表于 2015-9-5 21:48 | 显示全部楼层
帮你顶一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部