• 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

  • 相关阅读:
    tips
    数学建模-预测模型优缺(搬运)
    数学建模-灰色预测模型GM(1,1)_MATLAB
    Floyd算法_MATLAB
    第二章 运算方法与运算器(浮点数的加减法,IEEE754标准32/64浮点规格化数)
    面向对象
    for循环
    if---else
    airflow的web任务管理
    airflow原理
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/6915194.html
Copyright © 2020-2023  润新知