add filterRssi() and filterUuid()
This commit is contained in:
hathach committed 2017-07-18 15:16:43 +07:00
1 parent 1aae171957
commit 32767269c1
3 files changed
+37 -6

No files matched your search

@@ -27,6 +27,7 @@ void setup()
/* Enable both peripheral and central modes */
Bluefruit.begin(true, true);
Bluefruit.setTxPower(4);
/* Set the device name */
Bluefruit.setName("Bluefruit52");
@@ -36,12 +37,15 @@ void setup()
/* Start Central Scanning
* - Enable auto scan if disconnected
* - Interval = 100 ms, window = 80 ms
* - Filter out packet with a min rssi
* - Interval = 100 ms, window = 50 ms
* - Use active scan (used to retrieve the optional scan response adv packet)
* - Start(0) = will scan forever since no timeout is given
*/
Bluefruit.Scanner.setRxCallback(scan_callback);
Bluefruit.Scanner.restartOnDisconnect(true);
Bluefruit.Scanner.filterRssi(-80);
Bluefruit.Scanner.filterUuid(BLEUART_UUID_SERVICE);
Bluefruit.Scanner.setInterval(160, 80); // in units of 0.625 ms
Bluefruit.Scanner.useActiveScan(true); // Request scan response data
Bluefruit.Scanner.start(0); // 0 = Don't stop scanning after n seconds
+24 -3
View File
@@ -42,6 +42,9 @@ BLEScanner::BLEScanner(void)
_runnning = false;
_start_if_disconnect = true;
_filter_rssi = INT8_MIN;
_filter_uuid = NULL;
_rx_cb = NULL;
_stop_cb = NULL;
@@ -220,6 +223,17 @@ bool BLEScanner::checkReportForService(const ble_gap_evt_adv_report_t* report, B
return checkReportForUuid(report, svc.uuid);
}
void BLEScanner::filterRssi(int8_t min_rssi)
{
_filter_rssi = min_rssi;
}
void BLEScanner::filterUuid(BLEUuid ble_uuid)
{
if ( _filter_uuid == NULL ) _filter_uuid = new BLEUuid();
(*_filter_uuid) = ble_uuid;
}
/**
* Event Handler
@@ -230,10 +244,17 @@ void BLEScanner::_eventHandler(ble_evt_t* evt)
switch ( evt->header.evt_id )
{
case BLE_GAP_EVT_ADV_REPORT:
{
// evt_conn_hdl is equal to BLE_CONN_HANDLE_INVALID
{ // evt_conn_hdl is equal to BLE_CONN_HANDLE_INVALID
ble_gap_evt_adv_report_t const* evt_report = &evt->evt.gap_evt.params.adv_report;
// filter by rssi
if ( _filter_rssi > evt_report->rssi ) break;
// filter by uuid
if ( _filter_uuid && !checkReportForUuid(evt_report, *_filter_uuid) ) break;
ble_gap_evt_adv_report_t* adv_report = (ble_gap_evt_adv_report_t*) rtos_malloc( sizeof(ble_gap_evt_adv_report_t) );
(*adv_report) = evt->evt.gap_evt.params.adv_report;
(*adv_report) = (*evt_report);
if (_rx_cb) ada_callback(adv_report, _rx_cb, adv_report);
}
break;
+8 -2
View File
@@ -58,6 +58,9 @@ public:
void setIntervalMS(uint16_t interval, uint16_t window);
void restartOnDisconnect(bool enable);
void filterRssi(int8_t min_rssi);
void filterUuid(BLEUuid ble_uuid);
bool start(uint16_t timeout = 0);
bool stop(void);
@@ -81,8 +84,11 @@ public:
void _eventHandler(ble_evt_t* evt);
private:
bool _runnning;
bool _start_if_disconnect;
bool _runnning;
bool _start_if_disconnect;
int8_t _filter_rssi;
BLEUuid* _filter_uuid;
rx_callback_t _rx_cb;
stop_callback_t _stop_cb;