I am trying to modify advertisement data on the simpleBLEBroadcaster and am running into a strange side effect. I am uploading this to a keyfob and in the OEM code there is no use for HAL_KEY_SW_1 so I am using that to toggle my advertising data update. The code works, after pressing the right button, the default advertisement data appears on the sniffer, I can stop and start advertisements at this time be pressing the right button again. While I'm not advertising, I press the left button, to update the advertising data as per my code and it works, the problem is once I press the left button while advertising, I can no longer cease advertising by pressing the right button. However, if I press the left button to update my data while I'm NOT advertising, than it updates the data and I retain control over turning advertising on and off. Does anyone know what might be going on here? I have posted my code below, it is identical to the simpleBLEBroadcaster_HandleKeys function with the exception of SW_1 statements. Thank you! -Chris
static void simpleBLEBroadcaster_HandleKeys( uint8 shift, uint8 keys )
{
VOID shift; // Intentionally unreferenced parameter
if ( keys & HAL_KEY_SW_1)
{
advertData[5] = 8;
advertData[6] = 5;
advertData[7] = 8;
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
}
if ( keys & HAL_KEY_SW_2 )
{
// pressing the right key should toggle advertising on and off
uint8 current_adv_enabled_status;
uint8 new_adv_enabled_status;
//Find the current GAP advertisement status
GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status );
if( current_adv_enabled_status == FALSE )
{
new_adv_enabled_status = TRUE;
}
else
{
new_adv_enabled_status = FALSE;
}
//change the GAP advertisement status to opposite of current status
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
}
}
I have also added the following line to broadcaster.c as perscribed in an earlier thread...
GAP_UpdateAdvertisingData(gapRole_TaskID, TRUE, B_MAX_ADV_LEN, gapRole_AdvertData);