I have application base on the peripheral + observer simplePeripheral project.
The BLE device first scan other devices and saved these discovered device's address to white list, so later it can only scan these devices in the whitelist.
but I have problem to do that and need to know the right procedure of enable whiltelist during scan.
Below is the steps I did:
1) first initial scan parameter and start scan
uint8 WhiteState=FALSE;
DEFAULT_SCAN_DURATION = 4000 ; // 4s
GAP_SetParamValue( TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION );
uint8 scanRes = DEFAULT_MAX_SCAN_RES; // 8
GAPRole_SetParameter( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
// start scan
GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
DEFAULT_DISCOVERY_ACTIVE_SCAN,
WhiteState) )
2) add key pressed function for button SW1,
//toggle whitelist enable/disable
WhiteState = !WhiteState;
3) add key pressed function for SW2
HCI_LE_ClearWhiteListCmd(); //clear whitelist
HCI_LE_AddWhiteListCmd( HCI_PUBLIC_DEVICE_ADDRESS, simpleBLEDevList[i].addr )) //add discoveried device's address to whitelist
WhiteState=TRUE;
4) in the timeout of scan period call scan again
static void observerEventCB( observerRoleEvent_t *pEvent )
{
switch ( pEvent->gap.opcode )
{
case GAP_DEVICE_INFO_EVENT:
{
// scan again
GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
DEFAULT_DISCOVERY_ACTIVE_SCAN,
WhiteState) ) ;
}
break;
case GAP_DEVICE_INIT_DONE_EVENT:
//add device's address to simpleBLEDevList[i]
osal_memcpy( simpleBLEDevList[simpleBLEScanRes].addr, pEvent->deviceInfo.addr, B_ADDR_LEN );
break;
}
}
I press SW2 to add scanned device to list and after 4s , I turn on another BLE device and it will not been scan just as expetction.
later I pressed SW1 to toggle WhiteState to FALSE so the next scan will disable use whitelist, and new turned on device can be scanned by it.
also as expection.
pressed SW1 again to toggle WhiteState to TRUE so only devices in the whitelist can be discorved , but didn't find anyone !
and this is the problem I can't figure out. also I restart(reset) it , and seems exist the whitelist table but also didn't work when press SW2 switch the
WhiteState to TRUE.
Also even no saved addresses in whitelist, but call GAPObserverRole_StartDiscovery with WhiteState=TRUE, will not discover any devices.
Would like to know the right way of using whitelist with observer to avoid the problems I met.
Thanks in advance.