打印

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

[复制链接]
4529|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
skevil|  楼主 | 2015-9-4 08:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我在CC2541上看到这样一段程序,猜它应该是使能notify功能的函数
/*********************************************************************
* @fn          simpleProfile_HandleConnStatusCB
*
* [url=home.php?mod=space&uid=247401]@brief[/url]       Simple Profile link status change handler function.
*
* @param       connHandle - connection handle
* @param       changeType - type of change
*
* [url=home.php?mod=space&uid=266161]@return[/url]      none
*/
static void testProfile_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
{
  // Make sure this is not loopback connection
  if ( connHandle != LOOPBACK_CONNHANDLE )
  {
    // Reset Client Char Config if connection has dropped
    if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
         ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
           ( !linkDB_Up( connHandle ) ) ) )
    {
      GATTServApp_InitCharCfg( connHandle, TestChar2Config );

    }
  }
}


但是我应用到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的程序

//此部分为获取句柄,用了GATT_DiscAllChars获取,句柄存放于simpleBLECharHdl[1]当中
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 )
                        {
                                simpleBLEDiscState = BLE_DISC_STATE_CHAR;
                                //req.startHandle = simpleBLESvcStartHdl;
                                //req.endHandle = simpleBLESvcEndHdl;
                                //req.type.len = ATT_BT_UUID_SIZE;
                                //req.type.uuid[0] = LO_UINT16(PROFILE_CHAR1_UUID);//通道1
                                //req.type.uuid[1] = HI_UINT16(PROFILE_CHAR1_UUID);
                                //GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
                                
                                GATT_DiscAllChars(simpleBLEConnHandle,simpleBLESvcStartHdl,simpleBLESvcEndHdl,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[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[2],pMsg->msg.readByTypeRsp.dataList[3]);
                        
                        simpleBLECharHdl[0] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[3],pMsg->msg.readByTypeRsp.dataList[4]);
                        simpleBLECharHdl[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[7],pMsg->msg.readByTypeRsp.dataList[8]);
//                        simpleBLEProcedureInProgress = FALSE;               
//                        osal_set_event( simpleBLETaskId, CEN_DISCOVERY_OK_EVT);//发现完成事件OK
                        osal_set_event( simpleBLETaskId, CEN_DATA_SEND_EVT );
                        
                        
   
                        
                }
                else
                {
                        osal_start_timerEx( simpleBLETaskId, CEN_START_DISCOVERY_EVT, DEFAULT_SVC_DISCOVERY_DELAY );
                }
                simpleBLEDiscState = BLE_DISC_STATE_IDLE;
        }
}



这部分为发送notify使能消息到从机,
static uint8 CentralConfig(void)
{
    attWriteReq_t writeReq;
    uint8 state;
   
    writeReq.len = 2;
    writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);
    writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
    writeReq.sig = 0;
    writeReq.cmd = 0;
    writeReq.handle = simpleBLECharHdl[1]+1;
    state = GATT_WriteCharValue(simpleBLEConnHandle, &writeReq, simpleBLETaskId);
    return(state);
}


以下为主机的写回调函数
static bStatus_t Test_WriteAttrCB(uint16_t connHandle,
                                           gattAttribute_t *pAttr,
                                           uint8_t *pValue, uint16_t len,
                                           uint16_t offset, uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      case TEST_CHAR1_UUID:
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len > TEST_CHAR1_LEN )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          //VOID osal_memcpy(pAttr->pValue, pValue, len);   
          for(char i=0;i<len;i++)
            pAttr->pValue[i]=pValue[i];
         
          notifyApp = TEST_CHAR1;
        }
        break;
      //使能notify处理函数
      case GATT_CLIENT_CHAR_CFG_UUID:
   
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a characteristic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && Test_AppCBs && Test_AppCBs->pfnTestChange )
  {
    Test_AppCBs->pfnTestChange( notifyApp);  
  }
  
  return ( status );
}

我设了断电,但是主机发送使能notify后,无法跳进GATT_CLIENT_CHAR_CFG_UUID中,我用手机使能从机notify则可以跳转进去,求救。。。。

使用特权

评论回复
板凳
cemaj| | 2015-9-5 21:48 | 只看该作者
帮你顶一下。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

1

粉丝