zoukankan      html  css  js  c++  java
  • CC2540/CC2541 : Set the Peripheral Being Advertising while It is Being Connected


     There is possible to set your CC254X be scanable when it is in connection. But, based on my test,the connecting would be sluggish if you modify the code as below steps:

      0. Check your BLE stack being 1.3.2 , if that is not, I apologize. if it is,  Backup the file :  TiBLEStackInstallationFolderBLE-CC254x-1.3.2ProjectsleProfilesRolesperipheralBroadcaster.c.

     1. Substitute the file peripheral.c as  peripheralBroadcaster.c in your IAR project. That is, enable PLUS_BROADCASTER macro in preprocessor define, exclude peripheral.c, and include peripheralBroadcaster.c in your project.


    Open the peripheralBroadcaster.c, it should be modified.

    2. for line 45 : add the line :

        #include "hci_tl.h"


    :
    #include "hci.h"
    #include "hci_tl.h"
    #include "l2cap.h"
    : 
     
    it is for passing compilation.

    3. For line 641, change the line :


    // Initialize the Profile Advertising and Connection Parameters
    gapRole_profileRole = GAP_PROFILE_PERIPHERAL;
    

    As :

    #if(1)  //GAIGER 
      gapRole_profileRole = GAP_PROFILE_PERIPHERAL;
    #else  
      gapRole_profileRole = (GAP_PROFILE_PERIPHERAL | GAP_PROFILE_BROADCASTER);
    #endif 
    

    The peripheral could advertise now.


    3. At the line 927 :

    // Since gapRole_AdvertOffTime is set to 0, the device should not
                  // automatically become discoverable again after a period of time.
                  // Set enabler to FALSE; device will become discoverable again when
                  // this value gets set to TRUE              
                  gapRole_AdvEnabled = FALSE;  
    


    Modify it as :


                  // Since gapRole_AdvertOffTime is set to 0, the device should not
                  // automatically become discoverable again after a period of time.
                  // Set enabler to FALSE; device will become discoverable again when
                  // this value gets set to TRUE              
    #if(0)    //GAIGER  
                  gapRole_AdvEnabled = FALSE;  
    #else    
                  osal_start_timerEx( gapRole_TaskID, START_ADVERTISING_EVT, 1000);
    #endif 
    


    The device would keep advertising which it is connected.

    4. For the line 937 :


      // Check whether update parameter request is enabled, and check the connection parameters
              if ( ( gapRole_ParamUpdateEnable == TRUE ) &&
                   ( (pPkt->connInterval < gapRole_MinConnInterval) ||
                     (pPkt->connInterval > gapRole_MaxConnInterval) ||
                     (pPkt->connLatency != gapRole_SlaveLatency)    ||
                     (pPkt->connTimeout != gapRole_TimeoutMultiplier) ))
              {
                gapRole_SendUpdateParam( pPkt->connInterval, pPkt->connLatency );
              }
                  
              // Notify the Bond Manager to the connection
              VOID GAPBondMgr_LinkEst( pPkt->devAddrType, pPkt->devAddr, pPkt->connectionHandle, GAP_PROFILE_PERIPHERAL ); 
    

    There should be insert a line for resuming advertise after disconnection event occuring:


      // Check whether update parameter request is enabled, and check the connection parameters
              if ( ( gapRole_ParamUpdateEnable == TRUE ) &&
                   ( (pPkt->connInterval < gapRole_MinConnInterval) ||
                     (pPkt->connInterval > gapRole_MaxConnInterval) ||
                     (pPkt->connLatency != gapRole_SlaveLatency)    ||
                     (pPkt->connTimeout != gapRole_TimeoutMultiplier) ))
              {
                gapRole_SendUpdateParam( pPkt->connInterval, pPkt->connLatency );
              }
              
    #if(1)    //GAIGER
              VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );
    #endif          
              // Notify the Bond Manager to the connection
              VOID GAPBondMgr_LinkEst( pPkt->devAddrType, pPkt->devAddr, pPkt->connectionHandle, GAP_PROFILE_PERIPHERAL ); 
    


       It is all, now the goal has been reached. Your cc 254x could keep advertising while it is on connection.

      I noet agagin, that would lead your peripheral be slow on connecting: it costs 5~8 seconds to discover services by using BLE scaner on my Sony Xperia Z3 compact, but for pure peripheral, it costs 1 second only at worst case.

      This method is refered from Texas  forum threads:

     https://e2e.ti.com/support/wireless_connectivity/f/538/t/197769

    http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/88540.aspx?

    keyMatch=gaiger&tisearch=Search-CN-Everything

  • 相关阅读:
    撩妹技能 get,教你用 canvas 画一场流星雨
    git详细使用教程入门到精通(史上最全的git教程)
    Google Performance工具,你还不会用?Git走起。
    使用PIE.htc让万恶的IE内核浏览器IE678支持CSS3部分属性
    HTML编码规范
    Canvas制作的下雨动画
    Flex 布局教程:语法和实例
    CSS编码规范
    奇葩程序写的神一样的注释,被老板看见会不会开出呢?
    Vertical-Align你应该知道的一切
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/6915194.html
Copyright © 2011-2022 走看看