mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-10-22 16:09:44 +02:00
82524c80e3
* Adds setMaxResults to NimBLEScan to limit the number of advertised devices stored. If set to 0 no devices will be stored in memory and only the callback will be invoked. If set to 0xFF (default) stored devices will be unlimited. Any other value will be the limit. * Uses the controller to filter duplicate devices from the scan results when wantDuplicates == false.
101 lines
3.4 KiB
C++
101 lines
3.4 KiB
C++
/*
|
|
* NimBLEScan.h
|
|
*
|
|
* Created: on Jan 24 2020
|
|
* Author H2zero
|
|
*
|
|
* Originally:
|
|
*
|
|
* BLEScan.h
|
|
*
|
|
* Created on: Jul 1, 2017
|
|
* Author: kolban
|
|
*/
|
|
#ifndef COMPONENTS_NIMBLE_SCAN_H_
|
|
#define COMPONENTS_NIMBLE_SCAN_H_
|
|
#include "sdkconfig.h"
|
|
#if defined(CONFIG_BT_ENABLED)
|
|
|
|
#include "nimconfig.h"
|
|
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
|
|
|
#include "NimBLEAdvertisedDevice.h"
|
|
#include "NimBLEUtils.h"
|
|
|
|
#include "host/ble_gap.h"
|
|
|
|
#include <vector>
|
|
|
|
class NimBLEDevice;
|
|
class NimBLEScan;
|
|
class NimBLEAdvertisedDevice;
|
|
class NimBLEAdvertisedDeviceCallbacks;
|
|
class NimBLEAddress;
|
|
|
|
/**
|
|
* @brief A class that contains and operates on the results of a BLE scan.
|
|
* @details When a scan completes, we have a set of found devices. Each device is described
|
|
* by a NimBLEAdvertisedDevice object. The number of items in the set is given by
|
|
* getCount(). We can retrieve a device by calling getDevice() passing in the
|
|
* index (starting at 0) of the desired device.
|
|
*/
|
|
class NimBLEScanResults {
|
|
public:
|
|
void dump();
|
|
int getCount();
|
|
NimBLEAdvertisedDevice getDevice(uint32_t i);
|
|
std::vector<NimBLEAdvertisedDevice*>::iterator begin();
|
|
std::vector<NimBLEAdvertisedDevice*>::iterator end();
|
|
NimBLEAdvertisedDevice *getDevice(const NimBLEAddress &address);
|
|
|
|
private:
|
|
friend NimBLEScan;
|
|
std::vector<NimBLEAdvertisedDevice*> m_advertisedDevicesVector;
|
|
};
|
|
|
|
/**
|
|
* @brief Perform and manage %BLE scans.
|
|
*
|
|
* Scanning is associated with a %BLE client that is attempting to locate BLE servers.
|
|
*/
|
|
class NimBLEScan {
|
|
public:
|
|
bool start(uint32_t duration, void (*scanCompleteCB)(NimBLEScanResults), bool is_continue = false);
|
|
NimBLEScanResults start(uint32_t duration, bool is_continue = false);
|
|
bool isScanning();
|
|
void setAdvertisedDeviceCallbacks(NimBLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, bool wantDuplicates = false);
|
|
void setActiveScan(bool active);
|
|
void setInterval(uint16_t intervalMSecs);
|
|
void setWindow(uint16_t windowMSecs);
|
|
void setDuplicateFilter(bool enabled);
|
|
void setLimitedOnly(bool enabled);
|
|
void setFilterPolicy(uint8_t filter);
|
|
bool stop();
|
|
void clearResults();
|
|
NimBLEScanResults getResults();
|
|
void setMaxResults(uint8_t maxResults);
|
|
void erase(const NimBLEAddress &address);
|
|
|
|
|
|
private:
|
|
friend class NimBLEDevice;
|
|
|
|
NimBLEScan();
|
|
~NimBLEScan();
|
|
static int handleGapEvent(ble_gap_event* event, void* arg);
|
|
void onHostReset();
|
|
void onHostSync();
|
|
|
|
NimBLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
|
|
void (*m_scanCompleteCB)(NimBLEScanResults scanResults);
|
|
ble_gap_disc_params m_scan_params;
|
|
bool m_ignoreResults;
|
|
NimBLEScanResults m_scanResults;
|
|
uint32_t m_duration;
|
|
ble_task_data_t *m_pTaskData;
|
|
uint8_t m_maxResults;
|
|
};
|
|
|
|
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
|
#endif /* CONFIG_BT_ENABLED */
|
|
#endif /* COMPONENTS_NIMBLE_SCAN_H_ */
|