This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Switching between GAP roles

Hi

I'm hoping to switch between the Broadcaster role and the Peripheral role. Is a restart of the module supposed to be required? I'm basically merging the example projects SimpleBLEPeripheral with SimpleBLEBroadcaster (and added my own controller of course).

If my understanding is correct, switching between the two is simply a matter of calling GAPRole_SetParameter on the relevant parameters. Could these parameters actually be updated after being initialised though - which would be necessary to switch between roles.

Cheers

Steve

  • Hello. To actually switch roles, yes you would need to do some type of software reset or reset the GAP module.

    However, I think a better solution would be to just function as a peripheral / broadcaster at the same time and use each functionality as needed. The only difference between the two is that peripheral does connectable advertising and accepts connections while broadcaster does non-connectable advertising. Therefore, you can just modify the advertising type depending on what role you want to function in.

    Also note that there is a PLUS_BROADCASTER in the preprocessor definitions of the simpleBLEPeripheral project which, when defined, will allow broadcasting during a connection.

    I'm assuming you're using the 1.4.1 stack here: www.ti.com/bletstack.
  • Hi Tim

    By "function as a peripheral / broadcaster at the same time", do you mean that a device could be set to become *both* a peripheral and a broadcaster? Or are you suggesting that I could just pick from either peripheral or broadcaster and just manipulate the advertisement type depending on the desired mode dynamically (without reset)?

    Thanks
    Steve
  • The device will be both a peripheral and a broadcaster: there will be no reset involved. If you want to be a peripheral, advertise with connectable advertising. If you want to only be a broadcaster, advertise with non-connectable advertising.
  • Isn't there more to peripheral mode than to just advertise with the connectable type? AFAIK peripherals perform RX after TX to listen for connect/scan requests. So there should be additional configurational considerations - or are they handled internally when the parameters are set using GAPRole_SetParameter()?

    Also, looking at the SimpleBLEPeripheral code, setting PLUS_BROADCASTER only allows advertising whilst in a connection. It doesn't switch between NONCONN to CONN (or vice versa) - in fact, it doesn't perform any switching at all, as far as I can see.

    Is P/B needed? Could I just do the following

    uint8 advertEnabled = FALSE;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advertEnabled );
    
    uint8 connEnable = TRUE;
    GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof( connEnable ), &connEnable);
    
    advertEnabled = TRUE;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advertEnabled );

    In fact, is it necessary to turn advertising off before setting GAPROLE_ADV_NONCONN_ENABLED? The source code states "// Connectable advertising must be disabled." but setting GAPROLE_ADV_NONCONN_ENABLED to FALSE completely disables advertising (not just connectable advertising). Why does advertising need to be completely disabled (and re-enabled)?


    Thanks

  • The GAP role does not affect the hardware (TX / RX, etc). If you doing non-connectable advertising, there will not be any RX, regardless of the GAPRole.

    The PLUS_BROADCASTER is another topic. It is just something I mentioned and it doesn't sound like you need it.

    You have the correct idea for your code but it needs to be done within the context of the GAPRole state machine. Note that the GAPROLE_ADVERT_ENABLED parameter is for connectable advertising (its not a global advertising parameter). The GAPROLE_ADV_NONCONN_ENABLED parameter is for non-connectable advertising. The two parameters are mutually exclusive. To go from connectable advertising to non-connectable advertising:

    1. Disable connectable advertising: set GAPROLE_ADVERT_ENABLED to false
    2. Wait to receive GAPROLE_WAITING event in application's peripheralStateNotificationCB.
    3. Enable nonconnectable advertising: set GAPROLE_ADV_NONCONN_ENABLED to true

    It needs to be done in this manner because this is how the GAPRole state machine (in peripheral.c) is constructed. You are free to modify this as it suits yours needs. For more information on the GAPRole, see the software developer's guide included with the 1.4.1 installer.
  • Is GAPROLE_ADVERT_ENABLED really not a global advertising parameter? How come setting GAPROLE_ADVERT_ENABLED to FALSE appears to switch off advertising completely?

    uint8 oldAdvEnabled = gapRole_AdvEnabled;
    gapRole_AdvEnabled = *((uint8*)pValue);


    if ( (oldAdvEnabled) && (gapRole_AdvEnabled == FALSE) )
    {
    // Turn off advertising.
    if ( (gapRole_state == GAPROLE_ADVERTISING)
    || (gapRole_state == GAPROLE_WAITING_AFTER_TIMEOUT) )
    {
    VOID GAP_EndDiscoverable( gapRole_TaskID );
    }
    }

    Thanks
  • You can use the following code to stop advertising.

    initialAdvertEnable=FALSE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&initialAdvertEnable);
  • Sure. That's what I had. The main issue I have is that why setting GAPROLE_ADVERT_ENABLED to FALSE is often considered to be "disabling *connectable* advertising". Shouldn't it be disabling advertising rather? It disables advertising completely rather than a subset of advertising, e.g., connectable advertising - isn't it?
  • The code you referenced exists in both the GAPROLE_ADVERT_ENABLED and the GAPROLE_ADV_NONCONN_ENABLED set parameter case statements. I'm not sure what the confusion is here. It sounds like you understand that:

    - GAPROLE_ADVERT_ENABLED controls connectable advertising

    - GAPROLE_ADV_NONCONN_ENABLED controls non-connectable advertising.

    As to whether this is how it should / shouldn't be implemented, note that the peripheral.c file is simply a sample implementation of how GAP functionality can be controlled in the peripheral role.  It is certainly possible that it does not suit your needs exactly and will need to be modified for custom use cases.